HighLAND
InputManager.hxx
1 #ifndef InputManager_h
2 #define InputManager_h
3 
4 #include "InputConverter.hxx"
5 #include "Deprecated.hxx"
6 
7 /// class to handle correctly any input file and convert it into the
8 /// analysis structure. It contains a collection of InputConverters, and
9 /// automatically selects the correct converter based on the file type.
10 ///
11 /// The manager
12 /// keeps track of the current active spill, and provides three copies:
13 /// - RawSpill: the spill as read in from the input file.
14 /// - CorrectedSpill: for applying corrections to.
15 /// - Spill: for applying corrections and systematics to.
16 
18  public :
19 
20  /// Constructor
21  InputManager();
22 
23  /// Destructor, which cleans up the spills.
24  virtual ~InputManager(){}
25 
26  /// Reset the converters and the UniqueID
27  virtual void Reset();
28 
29  /// Initializes input tree(s) branches, selecting the appropriate converter
30  /// and initializing it. The "conv" parameter is deprecated.
31  /// Returns whether initialization was successful.
32  bool Initialize(const std::string& infile_name, const std::string& conv, const bool isCosmic = false);
33 
34  /// clean up the remaining pointers to the spills.
35  virtual void DeleteSpill();
36 
37  /// Read the input file, adding it to the TChains of the selected converter.
38  /// If isROOTFile is false, treats the file as a text file containing a list
39  /// of ROOT files to add.
40  /// Returns whether the file was successfully read.
41  bool ReadFile(const std::string& infile_name, bool isROOTFile);
42 
43  /// Read one or several entries in the input tree(s) to fill a raw AnaSpill, and
44  /// sets the CorrectedSpill and Spill as copies of it (to be manipulated
45  /// later).
46  /// The argument entry (the entry number in the input tree)
47  /// will be modified inside the method by the specific converter (hence the non-cont reference).
48  /// The way entry is modified will depend on whether the input file is SPILL based
49  /// (every call to this method will increment by one the argument entry) or
50  /// EVENT based (entry number will be incremented in several units to account for
51  /// several events -- bunches -- in the same spill). At the moment oaAnalysis and MiniTree are SPILL based
52  /// while FlatTree is EVENT based.
53  ///
54  /// Examples on how to use this method are available in highland2/highlandTools/vXrY/src/AnalysisLoop.cxx,
55  /// and highland2/highlandTools/vXrY/src/SimpleLoopBase.cxx. Just search for LoadSpill in those files.
56  ///
57  /// This method Returns whether the event was successfully filled.
58  virtual bool LoadSpill(Long64_t& entry);
59 
60  /// Fill the raw AnaEventB structure and create a AnaSuperEventB from
61  /// the raw event. The argument entry (the entry number in the input tree)
62  /// will be modified inside the method by the specific converter (hence the non-cont reference).
63  /// The way entry is modified will depend on whether the input file is EVENT based
64  /// (every call to this method will increment by one the argument entry) or
65  /// SPILL based (several events -- one per bunch -- correspond to the same spill, so
66  /// once the first event in a given spill is read entry number will not be varied
67  /// until all events in that spill are processed). At the moment oaAnalysis and MiniTree are SPILL based
68  /// while FlatTree is EVENT based.
69  ///
70  /// Examples on how to use this method are available in psyche/psycheSteering/vXrY/app/RunExample.cxx
71  /// and psyche/psycheSteering/vXrY/src/AnalysisManager.cxx. Just search for LoadEvent in those files.
72  ///
73  /// This method Returns whether the event was successfully filled.
74  bool LoadEvent(Long64_t& entry, bool delPrevious=true);
75 
76  /// Call InputConverter::LoadTree() for the selected converter.
77  Long64_t LoadTree(Long64_t entry);
78 
79  /// Return the number of entries in the input file tree(s).
80  Long64_t GetEntries();
81 
82  /// Return the number of events for a given number of entries in the input file tree(s).
83  Int_t GetNEvents(Int_t entries=-1){return GetConverter().GetNEvents(entries);}
84 
85  /// Get a TChain with a specific name from the selected converter.
86  TChain* GetChain(const std::string& name){return GetConverter().GetChain(name);}
87 
88  /// Find the first file in a list of files (if isROOTFile is true), or simply
89  /// the name of the file if isROOTFile is false.
90  std::string FindFirstFile(const std::string& infile_name, bool isROOTFile);
91 
92  /// Is this a ROOT file ?
93  bool IsROOTFile(const std::string& infile_name);
94 
95  /// Get the current selected converter.
97 
98  /// Set this converter as the selected one.
100 
101  /// Set the converter with name as the selected one.
102  void SelectConverter(const std::string& conv);
103 
104  /// Add this converter to the vector of recognised converters.
105  void AddConverter(const std::string& name, InputConverter* conv);
106 
107  /// Replace an existing converter
108  void ReplaceConverter(const std::string& name, InputConverter* conv);
109 
110  /// Whether the vector of converters contains one registered with this name.
111  bool HasConverter(const std::string& conv, bool err_message=true);
112 
113  /// Record the POT for the current spill, based on information in the AnaBeam
114  /// member of the current AnaSpill.
115  void IncrementPOTBySpill();
116 
117  /// Whether a FlatTree converter has been selected.
118  bool InputIsFlatTree() { return (_selected->Name() == "FlatTree"); }
119 
120  /// Whether a FlatTree converter has been selected.
121  bool InputIsMiniTree() { return (_selected->Name() == "MiniTree"); }
122 
123  /// Delete all the converters that have been added.
124  void RemoveConverters();
125 
126 
127  //-------------------------------
128 
129  /// Creates a clone of the corrected Spill. This must be done after applying corrections
130  void MakeFinalSpill();
131 
132  /// Get the current spill (to have corrections applied to it).
134 
135  /// Get the current spill (to have corrections and systematics applied to it).
136  AnaSpillC& GetSpill(){return *_Spill;}
137 
138  /// Set the current spill (to have corrections applied to it).
140 
141  /// Create the event
142  // virtual AnaEventC* MakeEvent();
143 
144  /// Create the event from the Final Spill
145  // AnaEventC* MakeEventFromFinalSpill();
146 
147  /// Create the SuperEvent
148  // AnaSuperEventB* MakeSuperEvent();
149 
150  /// Get the current spill (to have corrections and systematics applied to it).
152 
153  /// Reset the main spill to the corrected spill. This removes all the variations
154  /// applied by the systematics.
155  void ResetSpillToCorrected();
156 
157  /// Method to add a data file to the InputConverter without resetting all the trees in that converter
158  /// This allows analysers to load each data event as it comes, rather than preloading them
159  bool AddDataFileToConverter(const std::string& infile_name, const std::string& conv, const bool isCosmic = false, bool reset=false);
160 
161  /// Return whether thi is Monte Carlo we are dealing with
162  /// This assumes data/MC status is defined once and for all for the full input (does not change on event basis)
163  bool GetIsMC() {return header().GetIsMC();}
164 
165  /// Returns the software version from the header
166  const std::string& GetSoftwareVersion(){return header().GetSoftwareVersion();}
167 
168  // Returns the Header class
169  Header& header() {return GetConverter().header();}
170 
171  protected:
172 
173  /// Vector of converters.
174  std::vector<InputConverter*> _converters;
175 
176  /// Selected converter.
178 
179  /// The current corrected spill.
181 
182  /// The current spill with corrections and systematics.
184 
185  /// The super event
187 
188  /// The previous Super Event for deleting if necessary
190 
191  /// Data/MC status
192  bool _IsMC;
193 
194  /// The current Event UniqueID
195  Int_t _uniqueID;
196 
197 };
198 
199 #endif
200 
201 
virtual void Reset()
Reset the converters and the UniqueID.
AnaSpillC & GetCorrectedSpill()
Get the current spill (to have corrections applied to it).
Long64_t LoadTree(Long64_t entry)
Call InputConverter::LoadTree() for the selected converter.
const std::string & GetSoftwareVersion()
Returns the software version.
Definition: Header.hxx:103
std::vector< InputConverter * > _converters
Vector of converters.
AnaSpillC * _Spill
The current spill with corrections and systematics.
virtual bool LoadSpill(Long64_t &entry)
AnaSuperEventB * _sevent
The super event.
bool LoadEvent(Long64_t &entry, bool delPrevious=true)
void SelectConverter(InputConverter *sel)
Set this converter as the selected one.
virtual Int_t GetNEvents(Int_t entries=-1)
Return the total number of events for a given number of entries in the tree.
This class handles POT info, SoftwareVersion and IsMC.
Definition: Header.hxx:10
const std::string & Name() const
Return the name of this converter.
void RemoveConverters()
Delete all the converters that have been added.
virtual ~InputManager()
Destructor, which cleans up the spills.
Int_t GetNEvents(Int_t entries=-1)
Return the number of events for a given number of entries in the input file tree(s).
void IncrementPOTBySpill()
bool HasConverter(const std::string &conv, bool err_message=true)
Whether the vector of converters contains one registered with this name.
bool GetIsMC() const
returns the Data/MC mode
Definition: Header.hxx:97
TChain * GetChain(const std::string &name="")
void ReplaceConverter(const std::string &name, InputConverter *conv)
Replace an existing converter.
TChain * GetChain(const std::string &name)
Get a TChain with a specific name from the selected converter.
InputManager()
Constructor.
Definition: InputManager.cxx:6
AnaSpillC & GetSpill()
Get the current spill (to have corrections and systematics applied to it).
std::string FindFirstFile(const std::string &infile_name, bool isROOTFile)
Int_t _uniqueID
The current Event UniqueID.
InputConverter & GetConverter()
Get the current selected converter.
AnaSuperEventB & GetSuperEvent()
Create the event.
bool IsROOTFile(const std::string &infile_name)
Is this a ROOT file ?
Long64_t GetEntries()
Return the number of entries in the input file tree(s).
AnaSuperEventB * _prevSEvent
The previous Super Event for deleting if necessary.
bool AddDataFileToConverter(const std::string &infile_name, const std::string &conv, const bool isCosmic=false, bool reset=false)
bool _IsMC
Data/MC status.
bool InputIsMiniTree()
Whether a FlatTree converter has been selected.
virtual void DeleteSpill()
clean up the remaining pointers to the spills.
bool Initialize(const std::string &infile_name, const std::string &conv, const bool isCosmic=false)
void AddConverter(const std::string &name, InputConverter *conv)
Add this converter to the vector of recognised converters.
InputConverter * _selected
Selected converter.
bool ReadFile(const std::string &infile_name, bool isROOTFile)
void MakeFinalSpill()
Creates a clone of the corrected Spill. This must be done after applying corrections.
Header & header()
Returns the Header manager.
void SetCorrectedSpill(AnaSpillC *Spill)
Set the current spill (to have corrections applied to it).
const std::string & GetSoftwareVersion()
Returns the software version from the header.
AnaSpillC * _CorrectedSpill
The current corrected spill.
bool InputIsFlatTree()
Whether a FlatTree converter has been selected.
void ResetSpillToCorrected()