forked from hep-cce2/root_serialization
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRootSource.cc
More file actions
74 lines (64 loc) · 1.86 KB
/
RootSource.cc
File metadata and controls
74 lines (64 loc) · 1.86 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
#include "RootSource.h"
#include <iostream>
#include "TBranch.h"
#include "TTree.h"
#include "TFile.h"
#include "TClass.h"
using namespace cce::tf;
RootSource::RootSource(std::string const& iName) :
file_{TFile::Open(iName.c_str())},
eventAuxReader_{*file_}
{
events_ = file_->Get<TTree>("Events");
auto l = events_->GetListOfBranches();
const std::string eventAuxiliaryBranchName{"EventAuxiliary"};
const std::string eventIDBranchName{"EventID"};
dataProducts_.reserve(l->GetEntriesFast());
branches_.reserve(l->GetEntriesFast());
TBranch* aux_branch{nullptr};
for( int i=0; i< l->GetEntriesFast(); ++i) {
auto b = dynamic_cast<TBranch*>((*l)[i]);
//std::cout<<b->GetName()<<std::endl;
//std::cout<<b->GetClassName()<<std::endl;
if(eventIDBranchName == b->GetName()) {
eventIDBranch_ = b;
continue;
}
b->SetupAddresses();
TClass* class_ptr=nullptr;
EDataType type;
b->GetExpectedType(class_ptr,type);
dataProducts_.emplace_back(i,
reinterpret_cast<void**>(b->GetAddress()),
b->GetName(),
class_ptr,
&delayedReader_);
branches_.emplace_back(b);
if(eventAuxiliaryBranchName == dataProducts_.back().name()) {
eventAuxBranch_ = b;
}
}
}
EventIdentifier RootSource::eventIdentifier() {
if(eventIDBranch_) {
return id_;
}
return eventAuxReader_.doWork(eventAuxBranch_);
}
long RootSource::numberOfEvents() {
return events_->GetEntriesFast();
}
bool RootSource::readEvent(long iEventIndex) {
if(iEventIndex<numberOfEvents()) {
if(eventIDBranch_) {
eventIDBranch_->SetAddress(&id_);
eventIDBranch_->GetEntry(iEventIndex);
}
auto it = dataProducts_.begin();
for(auto b: branches_) {
(it++)->setSize( b->GetEntry(iEventIndex) );
}
return true;
}
return false;
}