MpdMiniDstFileSource.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. #ifndef MPDMINIDSTFILESOURCE_H
  2. #define MPDMINIDSTFILESOURCE_H
  3. #include <FairSource.h>
  4. #include <FairEventHeader.h>
  5. #include <FairFileHeader.h>
  6. #include <FairRuntimeDb.h>
  7. #include <TFile.h>
  8. #include <TString.h>
  9. #include <TChain.h>
  10. #include <TFolder.h>
  11. #include <TF1.h>
  12. #include <list>
  13. using namespace std;
  14. class MpdMiniDstFileSource : public FairSource {
  15. public:
  16. MpdMiniDstFileSource(TFile* f, const char* Title = "BmnRootFile", UInt_t identifier = 0);
  17. MpdMiniDstFileSource(const TString* RootFileName, const char* Title = "MiniDst", UInt_t identifier = 0);
  18. MpdMiniDstFileSource(const TString RootFileName, const char* Title = "MiniDst", UInt_t identifier = 0);
  19. virtual ~MpdMiniDstFileSource();
  20. Bool_t Init();
  21. Int_t ReadEvent(UInt_t i = 0);
  22. void Close();
  23. void Reset();
  24. virtual Source_Type GetSourceType() {
  25. return kONLINE;
  26. } //kBMNFILE
  27. virtual void SetParUnpackers() {
  28. }
  29. virtual Bool_t InitUnpackers() {
  30. return kTRUE;
  31. }
  32. virtual Bool_t ReInitUnpackers() {
  33. return kTRUE;
  34. }
  35. /**Check the maximum event number we can run to*/
  36. virtual Int_t CheckMaxEventNo(Int_t EvtEnd = 0);
  37. /**Read the tree entry on one branch**/
  38. virtual void ReadBranchEvent(const char* BrName);
  39. /**Read specific tree entry on one branch**/
  40. virtual void ReadBranchEvent(const char* BrName, Int_t Entry);
  41. virtual void FillEventHeader(FairEventHeader* feh);
  42. const TFile* GetRootFile() {
  43. return fRootFile;
  44. }
  45. /** Add a friend file (input) by name)*/
  46. void AddFriend(TString FileName);
  47. /**Add ROOT file to input, the file will be chained to already added files*/
  48. void AddFile(TString FileName);
  49. void AddFriendsToChain();
  50. void PrintFriendList();
  51. Bool_t CompareBranchList(TFile* fileHandle, TString inputLevel);
  52. void CheckFriendChains();
  53. void CreateNewFriendChain(TString inputFile, TString inputLevel);
  54. TTree* GetInTree() {
  55. return fInChain->GetTree();
  56. }
  57. TChain* GetInChain() {
  58. return fInChain;
  59. }
  60. TFile* GetInFile() {
  61. return fRootFile;
  62. }
  63. void CloseInFile() {
  64. if (fRootFile) fRootFile->Close();
  65. }
  66. /**Set the input tree when running on PROOF worker*/
  67. void SetInTree(TTree* tempTree);
  68. TObjArray* GetListOfFolders() {
  69. return fListFolder;
  70. }
  71. TFolder* GetBranchDescriptionFolder() {
  72. return fCbmroot;
  73. }
  74. UInt_t GetEntries() {
  75. return fNoOfEntries;
  76. }
  77. void SetInputFile(TString name);
  78. /** 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 */
  79. void SetBeamTime(Double_t beamTime, Double_t gapTime);
  80. /** Set the min and max limit for event time in ns */
  81. void SetEventTimeInterval(Double_t min, Double_t max);
  82. /** Set the mean time for the event in ns */
  83. void SetEventMeanTime(Double_t mean);
  84. void SetEventTime();
  85. Double_t GetDeltaEventTime();
  86. void SetFileHeader(FairFileHeader* f) {
  87. fFileHeader = f;
  88. }
  89. Double_t GetEventTime();
  90. virtual Bool_t ActivateObject(TObject** obj, const char* BrName);
  91. /**Set the status of the EvtHeader
  92. *@param Status: True: The header was creatged in this session and has to be filled
  93. FALSE: We use an existing header from previous data level
  94. */
  95. void SetEvtHeaderNew(Bool_t Status) {
  96. fEvtHeaderIsNew = Status;
  97. }
  98. Bool_t IsEvtHeaderNew() {
  99. return fEvtHeaderIsNew;
  100. }
  101. private:
  102. /** Title of input source, could be input, background or signal*/
  103. TString fInputTitle;
  104. /**ROOT file*/
  105. TFile* fRootFile;
  106. /** Current Entry number */
  107. Int_t fCurrentEntryNr; //!
  108. /** List of all files added with AddFriend */
  109. list<TString> fFriendFileList; //!
  110. list<TString> fInputChainList; //!
  111. map<TString, TChain*> fFriendTypeList; //!
  112. map<TString, list<TString>* > fCheckInputBranches; //!
  113. list<TString> fInputLevel; //!
  114. map<TString, std::multimap<TString, TArrayI> > fRunIdInfoAll; //!
  115. /**Input Chain */
  116. TChain* fInChain;
  117. /**Input Tree */
  118. TTree* fInTree;
  119. /** list of folders from all input (and friends) files*/
  120. TObjArray* fListFolder; //!
  121. /** RuntimeDb*/
  122. FairRuntimeDb* fRtdb;
  123. /**folder structure of output*/
  124. TFolder* fCbmout;
  125. /**folder structure of input*/
  126. TFolder* fCbmroot;
  127. /***/
  128. UInt_t fSourceIdentifier;
  129. /**No of Entries in this source*/
  130. UInt_t fNoOfEntries;
  131. /**Initialization flag, true if initialized*/
  132. Bool_t IsInitialized;
  133. MpdMiniDstFileSource(const MpdMiniDstFileSource&) = delete;
  134. MpdMiniDstFileSource operator=(const MpdMiniDstFileSource&) = delete;
  135. /**Event Header*/
  136. FairEventHeader* fEvtHeader; //!
  137. /**File Header*/
  138. FairFileHeader* fFileHeader; //!
  139. /**This flag is true if the event header was created in this session
  140. * otherwise it is false which means the header was created in a previous data
  141. * level and used here (e.g. in the digi)
  142. */
  143. Bool_t fEvtHeaderIsNew; //!
  144. /** for internal use, to return the same event time for the same entry*/
  145. UInt_t fCurrentEntryNo; //!
  146. /** for internal use, to return the same event time for the same entry*/
  147. UInt_t fTimeforEntryNo; //!
  148. /** min time for one event (ns) */
  149. Double_t fEventTimeMin; //!
  150. /** max time for one Event (ns) */
  151. Double_t fEventTimeMax; //!
  152. /** Time of event since th start (ns) */
  153. Double_t fEventTime; //!
  154. /** Time of particles in beam (ns) */
  155. Double_t fBeamTime; //!
  156. /** Time without particles in beam (gap) (ns) */
  157. Double_t fGapTime; //!
  158. /** EventMean time used (P(t)=1/fEventMeanTime*Exp(-t/fEventMeanTime) */
  159. Double_t fEventMeanTime; //!
  160. /** used to generate random numbers for event time; */
  161. TF1* fTimeProb; //!
  162. /** True if the file layout should be checked when adding files to a chain.
  163. * Default value is true.
  164. */
  165. Bool_t fCheckFileLayout; //!
  166. ClassDef(MpdMiniDstFileSource, 0)
  167. };
  168. #endif /* defined(BMNFILESOURCE_H) */