36 : FairFileSourceBase()
48 , fSourceIdentifier(0)
50 , IsInitialized(kFALSE)
54 , fEventTimeInMCHeader(kTRUE)
55 , fEvtHeaderIsNew(kFALSE)
64 , fCheckFileLayout(kTRUE)
66 if ((!fRootFile) || fRootFile->IsZombie()) {
67 LOG(fatal) <<
"Error opening the Input file";
71 LOG(debug) <<
"BmnFileSource created------------";
75 : FairFileSourceBase()
87 , fSourceIdentifier(0)
89 , IsInitialized(kFALSE)
93 , fEventTimeInMCHeader(kTRUE)
94 , fEvtHeaderIsNew(kFALSE)
103 , fCheckFileLayout(kTRUE)
105 fRootFile = TFile::Open(RootFileName->Data());
106 if ((!fRootFile) || fRootFile->IsZombie()) {
107 LOG(fatal) <<
"Error opening the Input file";
111 LOG(debug) <<
"BmnFileSource created------------";
115 : FairFileSourceBase()
127 , fSourceIdentifier(0)
129 , IsInitialized(kFALSE)
133 , fEventTimeInMCHeader(kTRUE)
134 , fEvtHeaderIsNew(kFALSE)
136 , fTimeforEntryNo(-1)
143 , fCheckFileLayout(kTRUE)
145 fRootFile = TFile::Open(RootFileName.Data());
146 if ((!fRootFile) || fRootFile->IsZombie()) {
147 LOG(fatal) <<
"Error opening the Input file";
151 LOG(debug) <<
"BmnFileSource created------------";
156 : FairFileSourceBase()
157 , fInputTitle(
"InputRootFile")
168 , fSourceIdentifier(0)
170 , IsInitialized(kFALSE)
174 , fEventTimeInMCHeader(kTRUE)
175 , fEvtHeaderIsNew(kFALSE)
177 , fTimeforEntryNo(-1)
184 , fCheckFileLayout(kTRUE)
186 fRootFile = TFile::Open(RootFileName.Data());
187 if ((!fRootFile) || fRootFile->IsZombie()) {
188 LOG(fatal) <<
"Error opening the Input file";
193 period_number = fPeriodNumber;
194 run_number = fRunNumber;
195 LOG(debug) <<
"BmnFileSource created------------";
264 LOG(info) <<
"BmnFileSource already initialized";
268 fInChain =
new TChain(FairRootManager::GetTreeName(), Form(
"/%s", FairRootManager::GetFolderName()));
269 LOG(debug) <<
"BmnFileSource::Init() chain created";
270 FairRootManager::Instance()->SetInChain(fInChain);
272 fInChain->Add(fRootFile->GetName());
276 fCbmroot = fRootFile->Get<TFolder>(FairRootManager::GetFolderName());
278 fCbmroot = fRootFile->Get<TFolder>(
"cbmroot");
280 fCbmroot = fRootFile->Get<TFolder>(
"cbmout");
282 fCbmroot = gROOT->GetRootFolder()->AddFolder(FairRootManager::GetFolderName(),
"Main Folder");
284 fCbmroot->SetName(FairRootManager::GetFolderName());
301 auto list = fRootFile->Get<TList>(
"BranchList");
303 LOG(debug) <<
"No Branch list in the input file";
305 TString chainName = fInputTitle;
306 fInputLevel.push_back(chainName);
310 LOG(debug) <<
"Entries in the list " << list->GetEntries();
311 for (Int_t
i = 0;
i < list->GetEntries();
i++) {
312 Obj =
dynamic_cast<TObjString*
>(list->At(
i));
314 ObjName = Obj->GetString();
315 LOG(debug) <<
"Branch name " << ObjName.Data();
316 fCheckInputBranches[chainName].push_back(ObjName);
317 FairRootManager::Instance()->AddBranchToList(ObjName.Data());
324 TObjArray* fBranchList = fInChain->GetListOfBranches();
326 if (fBranchList == NULL)
329 LOG(debug) <<
"Entries in the chain " << fBranchList->GetEntries();
330 TObject** ppObj =
new TObject*[fBranchList->GetEntries()];
331 for (
int i = 0;
i < fBranchList->GetEntries();
i++) {
332 TBranch* pBranch = (TBranch*)fBranchList->At(
i);
333 TString ObjName = pBranch->GetName();
334 LOG(debug) <<
"Branch name " << ObjName.Data();
336 fCheckInputBranches[chainName].push_back(ObjName);
337 FairRootManager::Instance()->AddBranchToList(ObjName.Data());
341 fInChain->SetBranchAddress(ObjName, &ppObj[
i]);
342 FairRootManager::Instance()->RegisterInputObject(ObjName, ppObj[
i]);
346 gROOT->GetListOfBrowsables()->Add(fCbmroot);
347 fListFolderBmn.Add(fCbmroot);
359 TDirectory::TContext restorecwd{};
361 for (
auto fileName : fInputChainList) {
364 TFile* inputFile = TFile::Open(fileName);
365 if (inputFile->IsZombie()) {
366 LOG(fatal) <<
"Error opening the file " << fileName.Data()
367 <<
" which should be added to the input chain or as friend chain";
370 if (fCheckFileLayout) {
372 Bool_t isOk = CompareBranchList(inputFile, chainName);
374 LOG(fatal) <<
"Branch structure of the input file " << fRootFile->GetName()
375 <<
" and the file to be added " << fileName.Data() <<
" are different.";
383 fInChain->Add(fileName);
389 fNoOfEntries = fInChain->GetEntries();
391 LOG(debug) <<
"Entries in this Source " << fNoOfEntries;
393 for (Int_t
i = 0;
i < fListFolderBmn.GetEntriesFast();
i++) {
394 TFolder* fold =
static_cast<TFolder*
>(fListFolderBmn.At(
i));
396 if ((fFileType == 1) || (fFileType == 11)) {
397 fEvtHeader = (
DstEventHeader*)fold->FindObjectAny(
"DstEventHeader.");
399 ActivateObject(
reinterpret_cast<TObject**
>(&fEvtHeader),
"DstEventHeader.");
401 fEvtHeader =
static_cast<FairEventHeader*
>(fold->FindObjectAny(
"EventHeader."));
403 ActivateObject(
reinterpret_cast<TObject**
>(&fEvtHeader),
"EventHeader.");
406 fMCHeader =
static_cast<FairMCEventHeader*
>(fold->FindObjectAny(
"MCEventHeader."));
408 ActivateObject(
reinterpret_cast<TObject**
>(&fMCHeader),
"MCEventHeader.");
412 FairRootManager::Instance()->SetListOfFolders(&fListFolderBmn);
416 auto timebasedlist = fRootFile->Get<TList>(
"TimeBasedBranchList");
417 if (timebasedlist == 0) {
418 LOG(debug) <<
"No time based branch list in input file";
420 FairRootManager::Instance()->SetTimeBasedBranchNameList(timebasedlist);
483 list<TString> friendList;
484 for (
auto fileName : fFriendFileList) {
485 if (find(friendList.begin(), friendList.end(), fileName) == friendList.end()) {
486 friendList.push_back(fileName);
492 TDirectory::TContext restorecwd{};
494 Int_t friendType = 1;
496 for (
auto fileName : friendList) {
503 Bool_t inputLevelFound = kFALSE;
505 for (
auto level : fInputLevel) {
508 inputFile = TFile::Open(fileName);
509 if (inputFile->IsZombie()) {
510 LOG(fatal) <<
"Error opening the file " << level.Data()
511 <<
" which should be added to the input chain or as friend chain";
516 Bool_t isOk = CompareBranchList(inputFile, inputLevel);
518 inputLevelFound = kTRUE;
524 if (!inputLevelFound) {
525 inputLevel = Form(
"FriendTree_%i", friendType);
530 TChain* chain = fFriendTypeList[inputLevel];
531 chain->AddFile(fileName, TTree::kMaxEntries, FairRootManager::GetTreeName());
539 for (
const auto& mi : fFriendTypeList) {
540 TChain* chain =
static_cast<TChain*
>(mi.second);
541 fInChain->AddFriend(chain);
577 multimap<TString, multimap<TString, TArrayI>>::iterator it1;
578 multimap<TString, TArrayI> map1;
581 it1 = fRunIdInfoAll.find(
"InputChain");
584 vector<Int_t> events;
585 for (
auto& mmi : map1) {
586 TArrayI bla = mmi.second;
587 runid.push_back(bla[0]);
588 events.push_back(bla[1]);
596 for (
auto level : fInputLevel) {
598 if (!inputLevel.Contains(
"InputChain")) {
599 it1 = fRunIdInfoAll.find(inputLevel);
601 if (runid.size() != map1.size()) {
607 for (
auto& mmi : map1) {
608 TArrayI bla = mmi.second;
609 if ((bla[0] != runid[counter]) || (bla[1] != events[counter])) {
625 LOG(error) <<
"The input chain and the friend chain " << inputLevel.Data() <<
" have a different structure:";
626 if (errorFlag == 1) {
627 LOG(error) <<
"The input chain has the following runids and event numbers:";
628 for (UInt_t
i = 0;
i < runid.size();
i++) {
629 LOG(error) <<
" - Runid " << runid[
i] <<
" with " << events[
i] <<
" events";
631 LOG(error) <<
"The " << inputLevel.Data() <<
" chain has the following runids and event numbers:";
632 for (
auto& mmi : map1) {
633 TArrayI bla = mmi.second;
634 LOG(error) <<
" - Runid " << bla[0] <<
" with " << bla[1] <<
" events";
637 if (errorFlag == 2) {
639 for (
auto& mmi : map1) {
640 TArrayI bla = mmi.second;
641 LOG(error) <<
"Runid Input Chain, " << inputLevel.Data() <<
" chain: " << bla[0] <<
", "
643 LOG(error) <<
"Event number Input Chain, " << inputLevel.Data() <<
" chain: " << bla[1] <<
", "
648 LOG(fatal) <<
"Event structure mismatch";
654 TDirectory::TContext restorecwd{};
655 TFile*
f = TFile::Open(inputFile);
658 TString folderName1 = FairRootManager::GetFolderName();
659 TString folderName = Form(
"/%s", folderName1.Data());
660 auto added =
f->Get<TFolder>(folderName1);
662 folderName =
"/cbmout";
663 folderName1 =
"cbmout";
664 added =
f->Get<TFolder>(
"cbmout");
666 folderName =
"/cbmroot";
667 folderName1 =
"cbmroot";
668 added =
f->Get<TFolder>(
"cbmroot");
670 LOG(fatal) <<
"Could not find folder cbmout nor cbmroot.";
675 folderName1 = folderName1 +
"_" + inputLevel;
676 added->SetName(folderName1);
677 fListFolderBmn.Add(added);
680 auto list =
f->Get<TList>(
"BranchList");
681 TString chainName = inputLevel;
682 fInputLevel.push_back(chainName);
685 for (Int_t
i = 0;
i < list->GetEntries();
i++) {
686 Obj =
dynamic_cast<TObjString*
>(list->At(
i));
687 fCheckInputBranches[chainName].push_back(Obj->GetString());
688 FairRootManager::Instance()->AddBranchToList(Obj->GetString().Data());
692 TChain* chain =
new TChain(inputLevel, folderName);
693 fFriendTypeList[inputLevel] = chain;
701 fInTree->SetBranchStatus(BrName, 1);
702 fInTree->SetBranchAddress(BrName, obj);
705 fInChain->SetBranchStatus(BrName, 1);
706 fInChain->SetBranchAddress(BrName, obj);
802 LOG(debug) <<
"-- Get Event Time --";
803 if (!fEvtHeaderIsNew && fEvtHeader != 0) {
804 Double_t EvtTime = fEvtHeader->GetEventTime();
805 if (!(EvtTime < 0)) {
810 if (fEventTimeInMCHeader && !fMCHeader) {
811 LOG(debug) <<
"No MCEventHeader, time is set to 0";
813 }
else if (fEventTimeInMCHeader && fMCHeader) {
814 fEventTime = fMCHeader->GetT();
815 LOG(debug) <<
"Get event time from MCEventHeader : " << fEventTime <<
" ns";
819 if (fTimeforEntryNo != fCurrentEntryNo) {
822 LOG(debug) <<
"Calculate event time from user input : " << fEventTime <<
" ns";