13 #include "StPicoMessMgr.h"
14 #include "StPicoDstReader.h"
15 #include "StPicoEvent.h"
16 #include "StPicoTrack.h"
17 #include "StPicoEmcTrigger.h"
18 #include "StPicoMtdTrigger.h"
19 #include "StPicoBbcHit.h"
20 #include "StPicoEpdHit.h"
21 #include "StPicoBTowHit.h"
22 #include "StPicoBTofHit.h"
23 #include "StPicoMtdHit.h"
24 #include "StPicoFmsHit.h"
25 #include "StPicoBEmcPidTraits.h"
26 #include "StPicoBTofPidTraits.h"
27 #include "StPicoMtdPidTraits.h"
28 #include "StPicoTrackCovMatrix.h"
29 #include "StPicoBEmcSmdEHit.h"
30 #include "StPicoBEmcSmdPHit.h"
31 #include "StPicoETofHit.h"
32 #include "StPicoETofPidTraits.h"
33 #include "StPicoMcVertex.h"
34 #include "StPicoMcTrack.h"
35 #include "StPicoArrays.h"
36 #include "StPicoDst.h"
45 mPicoDst(new
StPicoDst()), mChain(NULL), mTree(NULL),
46 mEventCounter(0), mPicoArrays{}, mStatusArrays{} {
50 std::fill_n(mStatusArrays,
sizeof(mStatusArrays) /
sizeof(mStatusArrays[0]), 1);
51 mInputFileName = inFileName;
65 void StPicoDstReader::clearArrays() {
66 for(Int_t iArr=0; iArr<StPicoArrays::NAllPicoArrays; iArr++) {
67 mPicoArrays[iArr]->Clear();
73 if(strncmp(branchNameRegex,
"St", 2) == 0) {
78 TRegexp re(branchNameRegex, 1);
79 for(Int_t iArr=0; iArr<StPicoArrays::NAllPicoArrays; iArr++) {
82 LOG_INFO <<
"StPicoDstMaker::SetStatus " << enable
84 mStatusArrays[iArr] = enable;
87 setBranchAddresses(mChain);
91 void StPicoDstReader::setBranchAddresses(TChain *chain) {
93 chain->SetBranchStatus(
"*", 0);
95 for (Int_t i = 0; i < StPicoArrays::NAllPicoArrays; ++i) {
96 if (mStatusArrays[i] == 0)
continue;
98 TBranch* tb = chain->GetBranch(bname);
100 LOG_WARN <<
"setBranchAddress: Branch name " << bname <<
" does not exist!" << endm;
105 chain->SetBranchStatus(ts, 1);
106 chain->SetBranchAddress(bname, mPicoArrays + i);
107 assert(tb->GetAddress() == (
char*)(mPicoArrays + i));
109 mTree = mChain->GetTree();
113 void StPicoDstReader::streamerOff() {
116 StPicoEvent::Class()->IgnoreTObjectStreamer();
117 StPicoTrack::Class()->IgnoreTObjectStreamer();
118 StPicoBTofHit::Class()->IgnoreTObjectStreamer();
119 StPicoBTowHit::Class()->IgnoreTObjectStreamer();
120 StPicoMtdHit::Class()->IgnoreTObjectStreamer();
121 StPicoBbcHit::Class()->IgnoreTObjectStreamer();
122 StPicoEpdHit::Class()->IgnoreTObjectStreamer();
123 StPicoFmsHit::Class()->IgnoreTObjectStreamer();
124 StPicoEmcTrigger::Class()->IgnoreTObjectStreamer();
125 StPicoMtdTrigger::Class()->IgnoreTObjectStreamer();
126 StPicoBTofPidTraits::Class()->IgnoreTObjectStreamer();
127 StPicoBEmcPidTraits::Class()->IgnoreTObjectStreamer();
128 StPicoMtdPidTraits::Class()->IgnoreTObjectStreamer();
129 StPicoTrackCovMatrix::Class()->IgnoreTObjectStreamer();
130 StPicoBEmcSmdEHit::Class()->IgnoreTObjectStreamer();
131 StPicoBEmcSmdPHit::Class()->IgnoreTObjectStreamer();
132 StPicoETofHit::Class()->IgnoreTObjectStreamer();
133 StPicoETofPidTraits::Class()->IgnoreTObjectStreamer();
134 StPicoMcVertex::Class()->IgnoreTObjectStreamer();
135 StPicoMcTrack::Class()->IgnoreTObjectStreamer();
139 void StPicoDstReader::createArrays() {
141 for(Int_t iArr=0; iArr<StPicoArrays::NAllPicoArrays; iArr++) {
145 mPicoDst->
set(mPicoArrays);
160 mChain =
new TChain(
"PicoDst");
163 std::string
const dirFile = mInputFileName.Data();
165 if( dirFile.find(
".list") != std::string::npos ||
166 dirFile.find(
".lis") != std::string::npos ) {
168 std::ifstream inputStream( dirFile.c_str() );
171 LOG_ERROR <<
"ERROR: Cannot open list file " << dirFile << endm;
177 while(getline(inputStream, file)) {
181 pos = file.find_first_of(
" ");
182 if (pos != std::string::npos ) file.erase(pos,file.length()-pos);
185 if(file.find(
".picoDst.root") != std::string::npos) {
186 TFile* ftmp = TFile::Open(file.c_str());
187 if(ftmp && !ftmp->IsZombie() && ftmp->GetNkeys()) {
188 LOG_INFO <<
" Read in picoDst file " << file << endm;
189 mChain->Add(file.c_str());
199 LOG_INFO <<
" Total " << nFile <<
" files have been read in. " << endm;
201 else if(dirFile.find(
".picoDst.root") != std::string::npos) {
202 mChain->Add(dirFile.c_str());
205 LOG_WARN <<
" No good input file to read ... " << endm;
209 setBranchAddresses(mChain);
210 mChain->SetCacheSize(50e6);
211 mChain->AddBranchToCache(
"*");
212 mPicoDst->
set(mPicoArrays);
219 Int_t mStatusRead =
true;
222 LOG_WARN <<
" No input files ... ! EXIT" << endm;
227 Int_t bytes = mChain->GetEntry(mEventCounter++);
230 if( mEventCounter >= mChain->GetEntriesFast() ) {
233 LOG_WARN <<
"Encountered invalid entry or I/O error while reading event "
234 << mEventCounter <<
" from \"" << mChain->GetName() <<
"\" input tree\n";
235 bytes = mChain->GetEntry(mEventCounter++);
237 LOG_WARN <<
"Not input has been found for: " << nCycles <<
" times" << endm;
239 LOG_ERROR <<
"Terminating StPicoDstReader::ReadProcess(Long64_t) after "
240 << nCycles <<
" times!" << endm;
Bool_t readPicoEvent(Long64_t iEvent)
Read next event in the chain.
Allows to read picoDst file(s)
void SetStatus(const Char_t *branchNameRegex, Int_t enable)
Set enable/disable branch matching when reading picoDst.
static const char * picoArrayNames[NAllPicoArrays]
Names of the TBranches in the TTree/File.
static int picoArraySizes[NAllPicoArrays]
Maximum sizes of the TClonesArrays.
static const char * picoArrayTypes[NAllPicoArrays]
Names of the classes, the TClonesArrays are arrays of this type.
static void set(TClonesArray **)
Set the pointers to the TClonesArrays.
Main class that keeps TClonesArrays with main classes.
void Init()
Calls openRead()
~StPicoDstReader()
Destructor.
void Finish()
Close files and finilize.