8 #ifndef SIMPLEROOTSAMPLER_H
9 #define SIMPLEROOTSAMPLER_H
19 #include <TClonesArray.h>
24 #include <FairMQLogger.h>
25 #include <FairMQMessage.h>
27 template<
typename DataType>
56 void SetFileProperties(
const std::string& filename,
const std::string& treename,
const std::string& branchname)
60 fBranchName = branchname;
66 fInputFile = TFile::Open(fFileName.c_str(),
"READ");
68 fTree =
static_cast<TTree*
>(fInputFile->Get(fTreeName.c_str()));
70 fTree->SetBranchAddress(fBranchName.c_str(), &
fInput);
71 fIndexMax = fTree->GetEntries();
73 LOG(error) <<
"Could not find tree " << fTreeName;
76 LOG(error) <<
"Could not open file " << fFileName <<
" in SimpleTreeReader::InitSource()";
86 void SetIndex(int64_t Event) { fIndex = Event; }
92 fTree->GetEntry(Event);
97 fTree->GetEntry(Event);
103 fTree->GetEntry(Event);
109 fTree->GetEntry(Event);
124 std::vector<std::vector<T>> allObj;
125 std::vector<T> tempObj;
127 if (std::is_same<DataType, TClonesArray>::value) {
128 for (int64_t i = 0; i < fTree->GetEntries(); i++) {
131 for (int64_t iobj = 0; iobj <
fInput->GetEntriesFast(); ++iobj) {
132 T* data =
reinterpret_cast<T*
>(
fInput->At(iobj));
136 tempObj.push_back(*data);
138 allObj.push_back(tempObj);
141 for (int64_t i = 0; i < fTree->GetEntries(); i++) {
145 tempObj.push_back(data);
146 allObj.push_back(tempObj);
153 void BindSendHeader(std::function<
void(
int)> callback) { fSendHeader = callback; }
163 std::function<void(int)> fSendHeader;
164 std::function<int()> fGetSocketNumber;
165 std::function<int()> fGetCurrentIndex;
167 std::string fFileName;
168 std::string fTreeName;
169 std::string fBranchName;
BaseSimpleTreeReader operator=(const BaseSimpleTreeReader &)=delete
void GetOutData(DataType *&data, int64_t Event)
void SetIndex(int64_t Event)
void deserialize_impl(int64_t Event)
void BindSendHeader(std::function< void(int)> callback)
void deserialize_impl(DataType *&data, int64_t Event)
virtual ~BaseSimpleTreeReader()
std::vector< std::vector< T > > GetDataVector()
int64_t GetNumberOfEvent()
void BindGetSocketNumber(std::function< int()> callback)
void SetFileProperties(const std::string &filename, const std::string &treename, const std::string &branchname)
void BindGetCurrentIndex(std::function< int()> callback)
DataType * GetOutData(int64_t Event)