12#include "BmnEventHeader.h"
13#include "DigiRunHeader.h"
14#include "DstEventHeader.h"
15#include "DstRunHeader.h"
16#include "FairEventHeader.h"
17#include "FairMCEventHeader.h"
18#include "FairRootManager.h"
30#include <fairlogger/Logger.h>
67 LOG(fatal) <<
"Error opening the Input file";
71 LOG(debug) <<
"BmnFileSource created------------";
107 LOG(fatal) <<
"Error opening the Input file";
111 LOG(debug) <<
"BmnFileSource created------------";
147 LOG(fatal) <<
"Error opening the Input file";
151 LOG(debug) <<
"BmnFileSource created------------";
188 LOG(fatal) <<
"Error opening the Input file";
195 LOG(debug) <<
"BmnFileSource created------------";
201 int isSimulationFile = 0;
203 isSimulationFile = 1;
207 if (digi_run_header) {
211 delete digi_run_header;
214 if (dst_run_header) {
218 delete dst_run_header;
223 LOG(fatal) <<
"ERROR: no 'bmndata' tree in file: " <<
fRootFile->GetName();
230 LOG(fatal) <<
"ERROR: no entries in 'bmndata' tree (file: " <<
fRootFile->GetName() <<
")";
236 LOG(debug) <<
"ERROR: headers not found in 'bmndata' tree (file: " <<
fRootFile->GetName()
237 <<
") to extract the period and run numbers";
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);
282 fCbmroot =
gROOT->GetRootFolder()->AddFolder(FairRootManager::GetFolderName(),
"Main Folder");
284 fCbmroot->SetName(FairRootManager::GetFolderName());
303 LOG(debug) <<
"No Branch list in the input file";
310 LOG(debug) <<
"Entries in the list " << list->GetEntries();
311 for (
Int_t i = 0;
i < list->GetEntries();
i++) {
315 LOG(debug) <<
"Branch name " << ObjName.
Data();
316 fCheckInputBranches[chainName].push_back(ObjName);
317 FairRootManager::Instance()->AddBranchToList(ObjName.
Data());
326 if (fBranchList == NULL)
329 LOG(debug) <<
"Entries in the chain " << fBranchList->
GetEntries();
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]);
366 LOG(fatal) <<
"Error opening the file " << fileName.Data()
367 <<
" which should be added to the input chain or as friend chain";
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.";
391 LOG(debug) <<
"Entries in this Source " <<
fNoOfEntries;
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;
485 if (find(friendList.begin(), friendList.end(), fileName) == friendList.end()) {
486 friendList.push_back(fileName);
494 Int_t friendType = 1;
496 for (
auto fileName : friendList) {
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);
554 LOG(info) <<
"The input consists out of the following trees and files: ";
555 LOG(info) <<
" - " <<
fInChain->GetName();
557 TIter next(fileElements);
560 LOG(info) <<
" - " << chEl->
GetTitle();
565 LOG(info) <<
" - " << chain->
GetName();
567 TIter next1(fileElements);
570 LOG(info) <<
" - " << chEl->
GetTitle();
577 multimap<TString, multimap<TString, TArrayI>>::iterator it1;
578 multimap<TString, TArrayI> map1;
584 vector<Int_t> events;
585 for (
auto& mmi : map1) {
587 runid.push_back(bla[0]);
588 events.push_back(bla[1]);
598 if (!inputLevel.
Contains(
"InputChain")) {
601 if (runid.size() != map1.size()) {
607 for (
auto& mmi : map1) {
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) {
634 LOG(error) <<
" - Runid " << bla[0] <<
" with " << bla[1] <<
" events";
637 if (errorFlag == 2) {
639 for (
auto& mmi : map1) {
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";
658 TString folderName1 = FairRootManager::GetFolderName();
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);
680 auto list = f->Get<
TList>(
"BranchList");
681 TString chainName = inputLevel;
685 for (
Int_t i = 0;
i < list->GetEntries();
i++) {
687 fCheckInputBranches[chainName].push_back(Obj->
GetString());
688 FairRootManager::Instance()->AddBranchToList(Obj->
GetString().
Data());
701 fInTree->SetBranchStatus(BrName, 1);
702 fInTree->SetBranchAddress(BrName, obj);
705 fInChain->SetBranchStatus(BrName, 1);
706 fInChain->SetBranchAddress(BrName, obj);
715 return ActivateObjectAnyImpl(
fInTree, obj, info, BrName);
718 return ActivateObjectAnyImpl(
fInChain, obj, info, BrName);
727 LOG(fatal) <<
"Error opening the input file";
729 LOG(info) <<
"BmnFileSource set------------";
734 Int_t MaxEventNo = 0;
738 MaxEventNo =
fInChain->GetEntries();
747 fTimeProb = make_unique<TF1>(
"TimeProb",
"(1/[0])*exp(-x/[0])", 0., mean * 10);
774 LOG(debug) <<
"Set event time for Entry = " <<
fTimeforEntryNo <<
" , where the current entry is "
792 LOG(debug) <<
"Time set via sampling method : " << deltaTime;
795 LOG(debug) <<
"Time set via Uniform Random : " << deltaTime;
802 LOG(debug) <<
"-- Get Event Time --";
805 if (!(EvtTime < 0)) {
811 LOG(debug) <<
"No MCEventHeader, time is set to 0";
815 LOG(debug) <<
"Get event time from MCEventHeader : " <<
fEventTime <<
" ns";
822 LOG(debug) <<
"Calculate event time from user input : " <<
fEventTime <<
" ns";
849 fInTree->FindBranch(BrName)->GetEntry(Entry);
854 fInChain->FindBranch(BrName)->GetEntry(Entry);
865 feh->SetMCEntryNumber(
fEvtHeader->GetMCEntryNumber());
872 feh->SetMCEntryNumber(
fMCHeader->GetEventID());
874 feh->SetInputFileId(0);
friend F32vec4 min(const F32vec4 &a, const F32vec4 &b)
friend F32vec4 max(const F32vec4 &a, const F32vec4 &b)
R__EXTERN TRandom * gRandom
char * Form(const char *fmt,...)
std::map< TString, TChain * > fFriendTypeList
TChain * fInChain
Input Chain.
UInt_t fNoOfEntries
No of Entries in this source.
void SetBeamTime(Double_t beamTime, Double_t gapTime)
Set the repetition time of the beam when it can interact (beamTime) and when no interaction happen (g...
TFolder * fCbmout
folder structure of output
BmnFileSource(TFile *f, const char *Title="InputRootFile", UInt_t identifier=0)
TTree * fInTree
Input Tree.
UInt_t fCurrentEntryNo
for internal use, to return the same event time for the same entry
Int_t CheckMaxEventNo(Int_t EvtEnd=0) override
Check the maximum event number we can run to.
Double_t fGapTime
Time without particles in beam (gap) (ns).
TFile * fRootFile
ROOT file.
Bool_t SpecifyRunId() override
Read one event from source to find out which RunId to use.
std::list< TString > fFriendFileList
List of all files added with AddFriend.
void SetInputFile(TString name)
Bool_t ActivateObject(TObject **obj, const char *BrName) override
Bool_t fEvtHeaderIsNew
This flag is true if the event header was created in this session otherwise it is false which means t...
void SetEventTimeInterval(Double_t min, Double_t max)
Set the min and max limit for event time in ns.
void CreateNewFriendChain(TString inputFile, TString inputLevel)
int ExtractRunNumber()
function to extract period and run numbers in the class constructor if exist
Int_t fFileType
input file type (data level): 0 - EXP DIGI, 1 - EXP DST, 10 - SIM DIGI, 11 - SIM DST,...
TString fInputTitle
Title of input source, could be input, background or signal.
void SetInTree(TTree *tempTree)
std::map< TString, std::multimap< TString, TArrayI > > fRunIdInfoAll
FairEventHeader * fEvtHeader
Event Header.
void SetEventMeanTime(Double_t mean)
Set the mean time for the event in ns.
Double_t fEventTimeMax
max time for one Event (ns)
Double_t fEventMeanTime
EventMean time used (P(t)=1/fEventMeanTime*Exp(-t/fEventMeanTime).
std::unique_ptr< TF1 > fTimeProb
used to generate random numbers for event time;
Double_t fEventTime
Time of event since th start (ns).
FairMCEventHeader * fMCHeader
MC Event header.
Int_t fPeriodNumber
period number extracted in the class constructor if exists
Bool_t fEventTimeInMCHeader
This is true if the event time used, came from simulation.
~BmnFileSource() override
Bool_t IsInitialized
Initialization flag, true if initialized.
void AddFriend(TString FileName)
Add a friend file (input) by name).
Int_t ReadEvent(UInt_t i=0) override
Bool_t ActivateObjectAny(void **, const std::type_info &, const char *) override
Bool_t fCheckFileLayout
True if the file layout should be checked when adding files to a chain.
std::list< TString > fInputLevel
Double_t fBeamTime
Time of particles in beam (ns).
Int_t fRunNumber
run number extracted in the class constructor if exists
void FillEventHeader(FairEventHeader *feh) override
Double_t fEventTimeMin
min time for one event (ns)
Double_t GetDeltaEventTime()
TFolder * fCbmroot
folder structure of input
void AddFile(TString FileName)
Add ROOT file to input, the file will be chained to already added files.
FairFileHeader * fFileHeader
File Header.
std::list< TString > fInputChainList
UInt_t fTimeforEntryNo
for internal use, to return the same event time for the same entry
void ReadBranchEvent(const char *BrName) override
Read the tree entry on one branch.
TObjArray fListFolderBmn
list of folders from all input (and friends) files
TObjArray * GetListOfFiles() const
virtual Int_t AddFile(const char *name, Long64_t nentries=TTree::kMaxEntries, const char *tname="")
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
void Close(Option_t *option="") override
virtual TObject * FindObjectAny(const char *name) const
const char * GetName() const override
const char * GetTitle() const override
Int_t GetEntries() const override
TObject * At(Int_t idx) const override
const TString & GetString() const
R__ALWAYS_INLINE Bool_t IsZombie() const
const char * Data() const
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
virtual Int_t GetEntry(Long64_t entry, Int_t getall=0)
TFile * GetCurrentFile() const
virtual Long64_t GetEntries() const
Int_t SetBranchAddress(const char *bname, T **add, TBranch **ptr=nullptr)
static constexpr Long64_t kMaxEntries
RVec< PromoteTypes< T0, T1 > > fmod(const RVec< T0 > &v, const T1 &y)