forked from hep-cce2/root_serialization
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsourceFactoryGenerator.cc
More file actions
62 lines (60 loc) · 2.67 KB
/
sourceFactoryGenerator.cc
File metadata and controls
62 lines (60 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "sourceFactoryGenerator.h"
#include "RootSource.h"
#include "RepeatingRootSource.h"
#include "SerialRootSource.h"
#include "PDSSource.h"
#include "SharedPDSSource.h"
#include "EmptySource.h"
#include "ReplicatedSharedSource.h"
#include "TestProductsSource.h"
std::function<std::unique_ptr<cce::tf::SharedSourceBase>(unsigned int, unsigned long long)>
cce::tf::sourceFactoryGenerator(std::string_view iType, std::string_view iOptions) {
std::function<std::unique_ptr<SharedSourceBase>(unsigned int, unsigned long long)> sourceFactory;
if( iType == "ReplicatedRootSource") {
std::string fileName( iOptions );
sourceFactory = [fileName](unsigned int iNLanes, unsigned long long iNEvents) {
return std::make_unique<ReplicatedSharedSource<RootSource>>(iNLanes, iNEvents, fileName);
};
} else if( iType == "RepeatingRootSource") {
std::string fileName( iOptions );
unsigned int nUniqueEvents = 10;
std::string branchToRead;
auto pos = fileName.find(':');
if(pos != std::string::npos) {
nUniqueEvents = std::stoul(fileName.substr(pos+1));
auto leftOptions = fileName.substr(pos+1);
fileName = fileName.substr(0,pos);
pos = leftOptions.find(':', 0);
if(pos != std::string::npos) {
branchToRead = leftOptions.substr(pos+1);
}
}
sourceFactory = [fileName, nUniqueEvents, branchToRead](unsigned int iNLanes, unsigned long long iNEvents) {
return std::make_unique<RepeatingRootSource>(fileName, nUniqueEvents, iNLanes, iNEvents, branchToRead);
};
} else if( iType == "SerialRootSource") {
std::string fileName( iOptions );
sourceFactory = [fileName](unsigned int iNLanes, unsigned long long iNEvents) {
return std::make_unique<SerialRootSource>(iNLanes, iNEvents, fileName);
};
} else if( iType == "ReplicatedPDSSource") {
std::string fileName( iOptions );
sourceFactory = [fileName](unsigned int iNLanes, unsigned long long iNEvents) {
return std::make_unique<ReplicatedSharedSource<PDSSource>>(iNLanes, iNEvents, fileName);
};
} else if( iType == "SharedPDSSource") {
std::string fileName( iOptions );
sourceFactory = [fileName](unsigned int iNLanes, unsigned long long iNEvents) {
return std::make_unique<SharedPDSSource>(iNLanes, iNEvents, fileName);
};
} else if( iType == "EmptySource") {
sourceFactory = [](unsigned int iNLanes, unsigned long long iNEvents) {
return std::make_unique<EmptySource>(iNEvents);
};
} else if(iType == "TestProductsSource") {
sourceFactory = [](unsigned int iNLanes, unsigned long long iNEvents) {
return std::make_unique<TestProductsSource>(iNLanes, iNEvents);
};
}
return sourceFactory;
}