/** @file CbmFileSource.h ** @author Mohammad Al-Turany ** @author Christian Simon ** @since 08.02.2014 ** @date 17.05.2017 **/ #ifndef CBMFILESOURCE_H #define CBMFILESOURCE_H 1 #include "FairSource.h" #include #include "TChain.h" #include "TFile.h" #include "TFolder.h" #include "TF1.h" class FairEventHeader; class FairFileHeader; class FairMCEventHeader; class TString; class FairLogger; class FairRuntimeDb; class CbmFileSource : public FairSource { public: CbmFileSource(TFile *f, const char* Title="InputRootFile", UInt_t identifier=0); CbmFileSource(const TString* RootFileName, const char* Title="InputRootFile", UInt_t identifier=0); CbmFileSource(const TString RootFileName, const char* Title="InputRootFile", UInt_t identifier=0); // CbmFileSource(const CbmFileSource& file); virtual ~CbmFileSource(); Bool_t Init(); Int_t ReadEvent(UInt_t i=0); void Close(); void Reset(); virtual Source_Type GetSourceType() { return kFILE; } virtual void SetParUnpackers() {} virtual Bool_t InitUnpackers() { return kTRUE; } virtual Bool_t ReInitUnpackers() { return kTRUE; } /**Check the maximum event number we can run to*/ virtual Int_t CheckMaxEventNo(Int_t EvtEnd=0); /**Read the tree entry on one branch**/ virtual void ReadBranchEvent(const char* BrName); /**Read specific tree entry on one branch**/ virtual void ReadBranchEvent(const char* BrName, Int_t Entry); virtual void FillEventHeader(FairEventHeader* feh); const TFile* GetRootFile(){return fRootFile;} /** Add a friend file (input) by name)*/ void AddFriend(TString FileName); /**Add ROOT file to input, the file will be chained to already added files*/ void AddFile(TString FileName); void AddPath(const TString& directoryName, const TString& fileNameWildCard); void AddFriendsToChain(); void PrintFriendList(); Bool_t CompareBranchList(TFile* fileHandle, TString inputLevel); void CheckFriendChains(); void CreateNewFriendChain(TString inputFile, TString inputLevel); TTree* GetInTree() {return fInChain->GetTree();} TChain* GetInChain() {return fInChain;} TFile* GetInFile() {return fRootFile;} void CloseInFile() { if(fRootFile) { fRootFile->Close(); }} /**Set the input tree when running on PROOF worker*/ void SetInTree (TTree* tempTree); TObjArray* GetListOfFolders(){return fListFolder;} TFolder* GetBranchDescriptionFolder(){return fCbmroot;} UInt_t GetEntries(){return fNoOfEntries; } // TList* GetBranchNameList() {return fBranchNameList;} void SetInputFile(TString name); /** Set the repetition time of the beam when it can interact (beamTime) and when no interaction happen (gapTime). The total repetition time is beamTime + gapTime */ void SetBeamTime(Double_t beamTime, Double_t gapTime); /** Set the min and max limit for event time in ns */ void SetEventTimeInterval(Double_t min, Double_t max); /** Set the mean time for the event in ns */ void SetEventMeanTime(Double_t mean); void SetEventTime(); Double_t GetDeltaEventTime(); void SetFileHeader(FairFileHeader* f) {fFileHeader =f;} Double_t GetEventTime(); /** Set the time offset for all events in ns */ void SetEventTimeOffset(Double_t dOffset) {fEventTimeOffset = dOffset;} Double_t GetEventTimeOffset() {return fEventTimeOffset;} void SetMaxSpillNo(Int_t iSpillNumber) {fiMaxSpillNo = iSpillNumber;} // virtual Bool_t SetObject(TObject* obj, const char* ObjType); // virtual void SetObjectName(const char* ObjName, const char* ObjType); virtual Bool_t ActivateObject(TObject** obj, const char* BrName); /**Set the status of the EvtHeader *@param Status: True: The header was creatged in this session and has to be filled FALSE: We use an existing header from previous data level */ void SetEvtHeaderNew(Bool_t Status) {fEvtHeaderIsNew = Status;} Bool_t IsEvtHeaderNew() {return fEvtHeaderIsNew;} /** Allow to disable the testing the file layout when adding files to a chain. */ void SetCheckFileLayout(Bool_t enable) {fCheckFileLayout = enable;} UInt_t GetCurrentEntryNo() {return fCurrentEntryNo;} private: /** Title of input source, could be input, background or signal*/ TString fInputTitle; /**ROOT file*/ TFile* fRootFile; /** Current Entry number */ Int_t fCurrentEntryNr; //! /** List of all files added with AddFriend */ std::list fFriendFileList; //! std::list fInputChainList;//! std::map fFriendTypeList;//! std::map* > fCheckInputBranches; //! std::list fInputLevel; //! std::map > fRunIdInfoAll; //! /**Input Chain */ TChain* fInChain; /**Input Tree */ TTree* fInTree; /** list of folders from all input (and friends) files*/ TObjArray *fListFolder; //! /** RuntimeDb*/ FairRuntimeDb* fRtdb; /**folder structure of output*/ TFolder* fCbmout; /**folder structure of input*/ TFolder* fCbmroot; /***/ UInt_t fSourceIdentifier; /**No of Entries in this source*/ UInt_t fNoOfEntries; /**Initialization flag, true if initialized*/ Bool_t IsInitialized; CbmFileSource(const CbmFileSource&); CbmFileSource operator=(const CbmFileSource&); /** MC Event header */ FairMCEventHeader* fMCHeader; //! /**Event Header*/ FairEventHeader* fEvtHeader; //! /**File Header*/ FairFileHeader* fFileHeader; //! /** This is true if the event time used, came from simulation*/ Bool_t fEventTimeInMCHeader; //! /**This flag is true if the event header was created in this session * otherwise it is false which means the header was created in a previous data * level and used here (e.g. in the digi) */ Bool_t fEvtHeaderIsNew; //! /** for internal use, to return the same event time for the same entry*/ UInt_t fCurrentEntryNo; //! /** for internal use, to return the same event time for the same entry*/ UInt_t fTimeforEntryNo; //! /** min time for one event (ns) */ Double_t fEventTimeMin; //! /** max time for one Event (ns) */ Double_t fEventTimeMax; //! /** Time of event since th start (ns) */ Double_t fEventTime; //! /** Time of particles in beam (ns) */ Double_t fBeamTime; //! /** Time without particles in beam (gap) (ns) */ Double_t fGapTime; //! /** EventMean time used (P(t)=1/fEventMeanTime*Exp(-t/fEventMeanTime) */ Double_t fEventMeanTime; //! /** Time offset for all events (ns) */ Double_t fEventTimeOffset; //! /** used to generate random numbers for event time; */ TF1* fTimeProb; //! /** True if the file layout should be checked when adding files to a chain. * Default value is true. */ Bool_t fCheckFileLayout; //! /** Stop reading new events after providing the given number of spills */ Int_t fiMaxSpillNo; //! /** Spill count */ Int_t fiCurrentSpillIndex; //! ClassDef(CbmFileSource, 2) }; #endif