R3BROOT
R3B analysis software
Loading...
Searching...
No Matches
R3BFileSource.h
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) 2019 GSI Helmholtzzentrum für Schwerionenforschung GmbH *
3 * Copyright (C) 2019-2025 Members of R3B Collaboration *
4 * *
5 * This software is distributed under the terms of the *
6 * GNU General Public Licence (GPL) version 3, *
7 * copied verbatim in the file "LICENSE". *
8 * *
9 * In applying this license GSI does not waive the privileges and immunities *
10 * granted to it by virtue of its status as an Intergovernmental Organization *
11 * or submit itself to any jurisdiction. *
12 ******************************************************************************/
13
14// -----------------------------------------------------------
15// ----- R3BFileSource -----
16// ----- Created 12/05/21 by J.L. Rodriguez-Sanchez -----
17// -----------------------------------------------------------
18
19#ifndef R3BFileSource_H
20#define R3BFileSource_H 1
21
22#include "FairSource.h"
23#include "TChain.h"
24#include "TF1.h"
25#include "TFile.h"
26#include "TFolder.h"
27#include "TMCtls.h"
28#include <fstream>
29#include <list>
30
31class FairEventHeader;
32class FairFileHeader;
33class FairMCEventHeader;
34class TString;
35class FairLogger;
36class FairRuntimeDb;
37class R3BEventHeader;
38
39class R3BFileSource : public FairSource
40{
41 public:
42 R3BFileSource(TFile* f, const char* Title = "InputRootFile", UInt_t identifier = 0);
43 R3BFileSource(const TString* RootFileName, const char* Title = "InputRootFile", UInt_t identifier = 0);
44 R3BFileSource(const TString RootFileName, const char* Title = "InputRootFile", UInt_t identifier = 0);
45
46 ~R3BFileSource() override;
47
51 static R3BFileSource* Instance();
52
53 Bool_t Init() override;
54 Int_t ReadEvent(UInt_t i = 0) override;
55 void Close() override;
56 void Reset() override;
57
58 Source_Type GetSourceType() override { return kFILE; }
59
60 void SetParUnpackers() override {}
61
62 Bool_t InitUnpackers() override { return kTRUE; }
63
64 Bool_t ReInitUnpackers() override { return kTRUE; }
65
67 Int_t CheckMaxEventNo(Int_t EvtEnd = 0) override;
69 void ReadBranchEvent(const char* BrName) override;
71 void ReadBranchEvent(const char* BrName, Int_t Entry) override;
72 void FillEventHeader(FairEventHeader* feh) override;
73
74 const TFile* GetRootFile() { return fRootFile; }
76 void AddFriend(TString FileName);
78 void AddFile(TString FileName);
79 void AddFriendsToChain();
80 void PrintFriendList();
81 Bool_t CompareBranchList(TFile* fileHandle, TString inputLevel);
82 void CheckFriendChains();
83 void CreateNewFriendChain(TString inputFile, TString inputLevel);
84 TTree* GetInTree() { return fInChain->GetTree(); }
85 TChain* GetInChain() { return fInChain; }
86 TFile* GetInFile() { return fRootFile; }
88 {
89 if (fRootFile)
90 {
91 fRootFile->Close();
92 }
93 }
94
95 void SetInTree(TTree* tempTree);
96 TObjArray* GetListOfFolders() { return fListFolder; }
97 TFolder* GetBranchDescriptionFolder() { return fFolderIn; }
98 UInt_t GetEntries() { return fNoOfEntries; }
99
100 void SetInputFile(TString name);
101
104 void SetBeamTime(Double_t beamTime, Double_t gapTime);
106 void SetEventTimeInterval(Double_t min, Double_t max);
108 void SetEventMeanTime(Double_t mean);
109 void SetEventTime();
110 Double_t GetDeltaEventTime();
111 void SetFileHeader(FairFileHeader* f) { fFileHeader = f; }
112 Double_t GetEventTime();
113
114 Bool_t ActivateObject(TObject** obj, const char* BrName) override;
115
120 void SetEvtHeaderNew(Bool_t Status) { fEvtHeaderIsNew = Status; }
121 Bool_t IsEvtHeaderNew() { return fEvtHeaderIsNew; }
122
125 void SetCheckFileLayout(Bool_t enable) { fCheckFileLayout = enable; }
126
127 void SetInputFileName(TString tstr) { fInputFileName = tstr; }
128
130#if ROOT_VERSION_CODE <= ROOT_VERSION(6, 22, 8)
131 Bool_t SpecifyRunId();
132#else
133 Bool_t SpecifyRunId() override;
134#endif
135
136 private:
137 // static pointer to this class
138 static TMCThreadLocal R3BFileSource* fSourceInstance;
140 TString fInputTitle;
142 TFile* fRootFile;
144 Int_t fCurrentEntryNr;
146 std::list<TString> fFriendFileList;
147 std::list<TString> fInputChainList;
148 std::map<TString, TChain*> fFriendTypeList;
149 std::map<TString, std::list<TString>*> fCheckInputBranches;
150 std::list<TString> fInputLevel;
151 std::map<TString, std::multimap<TString, TArrayI>> fRunIdInfoAll;
153 TChain* fInChain;
155 TTree* fInTree;
157 TObjArray* fListFolder;
159 FairRuntimeDb* fRtdb;
161 TFolder* fFolderOut;
163 TFolder* fFolderIn;
164 /***/
165 UInt_t fSourceIdentifier;
167 UInt_t fNoOfEntries;
169 Bool_t IsInitialized;
170
172 FairMCEventHeader* fMCHeader;
173
175 R3BEventHeader* fEvtHeader;
176
178 FairFileHeader* fFileHeader;
179
181 Bool_t fEventTimeInMCHeader;
186 Bool_t fEvtHeaderIsNew;
187
189 UInt_t fCurrentEntryNo;
191 UInt_t fTimeforEntryNo;
192
194 Double_t fEventTimeMin;
196 Double_t fEventTimeMax;
198 Double_t fEventTime;
200 Double_t fBeamTime;
202 Double_t fGapTime;
204 Double_t fEventMeanTime;
206 TF1* fTimeProb;
210 Bool_t fCheckFileLayout;
211
213 Int_t GetRunid(uint64_t ts);
214
216 std::ifstream fInputFile;
217 TString fInputFileName;
218
219 UInt_t fExpid;
220 std::vector<UInt_t> fRunid;
221 std::vector<uint64_t> fTimestamp;
222 uint64_t prevts, nextts;
223
225 R3BFileSource operator=(const R3BFileSource&);
226
227 ClassDefOverride(R3BFileSource, 0)
228};
229
230#endif /* R3BFileSource_H */
TFile * GetInFile()
void FillEventHeader(FairEventHeader *feh) override
Double_t GetEventTime()
static R3BFileSource * Instance()
static instance
Int_t ReadEvent(UInt_t i=0) override
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...
Bool_t InitUnpackers() override
void SetEventTimeInterval(Double_t min, Double_t max)
Set the min and max limit for event time in ns.
Int_t CheckMaxEventNo(Int_t EvtEnd=0) override
Check the maximum event number we can run to.
R3BFileSource(TFile *f, const char *Title="InputRootFile", UInt_t identifier=0)
Double_t GetDeltaEventTime()
void SetInTree(TTree *tempTree)
Set the input tree when running on PROOF worker.
void AddFriend(TString FileName)
Add a friend file (input) by name)
void AddFile(TString FileName)
Add ROOT file to input, the file will be chained to already added files.
TTree * GetInTree()
Bool_t ActivateObject(TObject **obj, const char *BrName) override
void SetEvtHeaderNew(Bool_t Status)
Set the status of the EvtHeader.
Bool_t SpecifyRunId()
Read one event from source to find out which RunId to use.
void SetInputFile(TString name)
void SetParUnpackers() override
~R3BFileSource() override
UInt_t GetEntries()
Bool_t ReInitUnpackers() override
void Close() override
Bool_t Init() override
TFolder * GetBranchDescriptionFolder()
void SetCheckFileLayout(Bool_t enable)
Allow to disable the testing the file layout when adding files to a chain.
Bool_t IsEvtHeaderNew()
void CreateNewFriendChain(TString inputFile, TString inputLevel)
Source_Type GetSourceType() override
TChain * GetInChain()
void Reset() override
void ReadBranchEvent(const char *BrName) override
Read the tree entry on one branch.
void SetFileHeader(FairFileHeader *f)
void SetInputFileName(TString tstr)
Bool_t CompareBranchList(TFile *fileHandle, TString inputLevel)
void SetEventMeanTime(Double_t mean)
Set the mean time for the event in ns.
TObjArray * GetListOfFolders()
const TFile * GetRootFile()