forked from hep-cce2/root_serialization
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPDSSource.cc
More file actions
77 lines (65 loc) · 1.99 KB
/
PDSSource.cc
File metadata and controls
77 lines (65 loc) · 1.99 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "PDSSource.h"
#include "TClass.h"
#include "Deserializer.h"
#include "UnrolledDeserializer.h"
using namespace cce::tf;
using namespace cce::tf::pds;
bool PDSSource::readEvent(long iEventIndex) {
while(iEventIndex != presentEventIndex_) {
auto skipped = skipToNextEvent(file_);
if(not skipped) {return false;}
++presentEventIndex_;
}
if(readEventContent()) {
++presentEventIndex_;
return true;
}
return false;
}
bool PDSSource::readEventContent() {
std::vector<uint32_t> buffer;
if(not readCompressedEventBuffer(file_, eventID_, buffer)) {
return false;
}
std::vector<uint32_t> uBuffer = uncompressEventBuffer(compression_, buffer);
deserializeDataProducts(uBuffer.begin(), uBuffer.end(), dataProducts_, deserializers_);
return true;
}
PDSSource::PDSSource(std::string const& iName) :
SourceBase(),
file_{iName, std::ios_base::binary}
{
pds::Serialization serialization;
auto productInfo = readFileHeader(file_, compression_, serialization);
switch(serialization) {
case pds::Serialization::kRoot: {
deserializers_ = DeserializeStrategy::make<DeserializeProxy<Deserializer>>(); break;
}
case pds::Serialization::kRootUnrolled: {
deserializers_ = DeserializeStrategy::make<DeserializeProxy<UnrolledDeserializer>>(); break;
}
}
dataProducts_.reserve(productInfo.size());
dataBuffers_.resize(productInfo.size(), nullptr);
deserializers_.reserve(productInfo.size());
size_t index =0;
for(auto const& pi : productInfo) {
TClass* cls = TClass::GetClass(pi.className().c_str());
dataBuffers_[index] = cls->New();
assert(cls);
dataProducts_.emplace_back(index,
&dataBuffers_[index],
pi.name(),
cls,
&delayedRetriever_);
deserializers_.emplace_back(cls);
++index;
}
}
PDSSource::~PDSSource() {
auto it = dataProducts_.begin();
for( void * b: dataBuffers_) {
it->classType()->Destructor(b);
++it;
}
}