HighLAND
Public Member Functions | Protected Attributes | List of all members
InputManager Class Reference

#include <InputManager.hxx>

Inheritance diagram for InputManager:
HighlandInputManager

Public Member Functions

 InputManager ()
 Constructor.
 
virtual ~InputManager ()
 Destructor, which cleans up the spills.
 
virtual void Reset ()
 Reset the converters and the UniqueID.
 
bool Initialize (const std::string &infile_name, const std::string &conv, const bool isCosmic=false)
 
virtual void DeleteSpill ()
 clean up the remaining pointers to the spills.
 
bool ReadFile (const std::string &infile_name, bool isROOTFile)
 
virtual bool LoadSpill (Long64_t &entry)
 
bool LoadEvent (Long64_t &entry, bool delPrevious=true)
 
Long64_t LoadTree (Long64_t entry)
 Call InputConverter::LoadTree() for the selected converter.
 
Long64_t GetEntries ()
 Return the number of entries in the input file tree(s).
 
Int_t GetNEvents (Int_t entries=-1)
 Return the number of events for a given number of entries in the input file tree(s).
 
TChain * GetChain (const std::string &name)
 Get a TChain with a specific name from the selected converter.
 
std::string FindFirstFile (const std::string &infile_name, bool isROOTFile)
 
bool IsROOTFile (const std::string &infile_name)
 Is this a ROOT file ?
 
InputConverterGetConverter ()
 Get the current selected converter.
 
void SelectConverter (InputConverter *sel)
 Set this converter as the selected one.
 
void SelectConverter (const std::string &conv)
 Set the converter with name as the selected one.
 
void AddConverter (const std::string &name, InputConverter *conv)
 Add this converter to the vector of recognised converters.
 
void ReplaceConverter (const std::string &name, InputConverter *conv)
 Replace an existing converter.
 
bool HasConverter (const std::string &conv, bool err_message=true)
 Whether the vector of converters contains one registered with this name.
 
void IncrementPOTBySpill ()
 
bool InputIsFlatTree ()
 Whether a FlatTree converter has been selected.
 
bool InputIsMiniTree ()
 Whether a FlatTree converter has been selected.
 
void RemoveConverters ()
 Delete all the converters that have been added.
 
void MakeFinalSpill ()
 Creates a clone of the corrected Spill. This must be done after applying corrections.
 
AnaSpillCGetCorrectedSpill ()
 Get the current spill (to have corrections applied to it).
 
AnaSpillCGetSpill ()
 Get the current spill (to have corrections and systematics applied to it).
 
void SetCorrectedSpill (AnaSpillC *Spill)
 Set the current spill (to have corrections applied to it).
 
AnaSuperEventBGetSuperEvent ()
 Create the event. More...
 
void ResetSpillToCorrected ()
 
bool AddDataFileToConverter (const std::string &infile_name, const std::string &conv, const bool isCosmic=false, bool reset=false)
 
bool GetIsMC ()
 
const std::string & GetSoftwareVersion ()
 Returns the software version from the header.
 
Headerheader ()
 

Protected Attributes

std::vector< InputConverter * > _converters
 Vector of converters.
 
InputConverter_selected
 Selected converter.
 
AnaSpillC_CorrectedSpill
 The current corrected spill.
 
AnaSpillC_Spill
 The current spill with corrections and systematics.
 
AnaSuperEventB_sevent
 The super event.
 
AnaSuperEventB_prevSEvent
 The previous Super Event for deleting if necessary.
 
bool _IsMC
 Data/MC status.
 
Int_t _uniqueID
 The current Event UniqueID.
 

Detailed Description

class to handle correctly any input file and convert it into the analysis structure. It contains a collection of InputConverters, and automatically selects the correct converter based on the file type.

The manager keeps track of the current active spill, and provides three copies:

Definition at line 17 of file InputManager.hxx.

Member Function Documentation

§ AddDataFileToConverter()

bool InputManager::AddDataFileToConverter ( const std::string &  infile_name,
const std::string &  conv,
const bool  isCosmic = false,
bool  reset = false 
)

Method to add a data file to the InputConverter without resetting all the trees in that converter This allows analysers to load each data event as it comes, rather than preloading them

Definition at line 49 of file InputManager.cxx.

49  {
50 //********************************************************************
51 
52  // Check wehther this is a root file
53  bool isROOTFile = IsROOTFile(infile_name);
54 
55  // Find out the input format (FlatTre, oaAnalysisTree, etc)
56  std::string conv2 = conv;
57  if (conv2 == "") {
58  std::cout << "InputManager::Initialize(). Input type (oaAnalysisTree, FlatTree, ...) not specified. Find it automatically..." << std::endl;
59  std::string firstFile = FindFirstFile(infile_name, isROOTFile);
60  for (std::vector<InputConverter*>::const_iterator it = _converters.begin(); it != _converters.end(); it++) {
61  if ((*it)->IsCorrectType(firstFile)) {
62  conv2 = (*it)->Name();
63  break;
64  }
65  }
66  }
67 
68  if (conv2 == "") {
69  std::cerr << "ERROR: Unable to find an input converter for your input files - check that your input files are valid!" << std::endl;
70  exit(EXIT_FAILURE);
71  }
72 
73  if (!HasConverter(conv2)) return false;
74 
75  std::cout << "InputManager::Initialize(). Input type is: " << conv2 << std::endl;
76 
77  // Select the specified converter
78  SelectConverter(conv2);
79 
80  // Reset the trees in the TChain and the number of entries
81  if (reset) GetConverter().Reset();
82 
83  // Initialize the converter. Define tree branches, etc
84  if (!GetConverter().Initialize()) return false;
85  GetConverter().SetCosmicMode(isCosmic);
86 
87  // Read the input file
88  if (!ReadFile(infile_name, isROOTFile)) return false;
89 
90  // Get the number of entries in the tree
91  Long64_t nentries = GetEntries();
92  std::cout << "InputManager::input tree has " << nentries << " entries" << std::endl;
93 
94  return true;
95 }
std::vector< InputConverter * > _converters
Vector of converters.
void SelectConverter(InputConverter *sel)
Set this converter as the selected one.
virtual void Reset()
Reset the trees in the TChain and the number of entries. Also the header (POT, etc) ...
virtual void SetCosmicMode(const bool cosmic)
bool HasConverter(const std::string &conv, bool err_message=true)
Whether the vector of converters contains one registered with this name.
std::string FindFirstFile(const std::string &infile_name, bool isROOTFile)
InputConverter & GetConverter()
Get the current selected converter.
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).
bool Initialize(const std::string &infile_name, const std::string &conv, const bool isCosmic=false)
bool ReadFile(const std::string &infile_name, bool isROOTFile)

§ FindFirstFile()

std::string InputManager::FindFirstFile ( const std::string &  infile_name,
bool  isROOTFile 
)

Find the first file in a list of files (if isROOTFile is true), or simply the name of the file if isROOTFile is false.

Definition at line 170 of file InputManager.cxx.

170  {
171 //*****************************************************************************
172 
173  TString infileName(infile_name);
174  std::ifstream inputFile(infileName.Data(), std::ios::in);
175 
176  //if(!inputFile){
177  //std::cerr << "Cannot open input file '" << infileName.Data() << "'. Exit!" << std::endl;
178  //std::string fal = "false";
179  //return fal;
180  //}
181 
182  std::string inputString=infile_name;
183 
184  if (!isROOTFile)
185  inputFile >> inputString;
186 
187  return inputString;
188 }

§ GetIsMC()

bool InputManager::GetIsMC ( )
inline

Return whether thi is Monte Carlo we are dealing with This assumes data/MC status is defined once and for all for the full input (does not change on event basis)

Definition at line 163 of file InputManager.hxx.

163 {return header().GetIsMC();}
bool GetIsMC() const
returns the Data/MC mode
Definition: Header.hxx:97

§ GetSuperEvent()

AnaSuperEventB& InputManager::GetSuperEvent ( )
inline

Create the event.

Create the event from the Final Spill Create the SuperEvent Get the current spill (to have corrections and systematics applied to it).

Definition at line 151 of file InputManager.hxx.

151 {return *_sevent;}
AnaSuperEventB * _sevent
The super event.

§ IncrementPOTBySpill()

void InputManager::IncrementPOTBySpill ( )

Record the POT for the current spill, based on information in the AnaBeam member of the current AnaSpill.

Definition at line 331 of file InputManager.cxx.

331  {
332 //********************************************************************
333 
335 }
virtual void IncrementPOTBySpill()=0
InputConverter & GetConverter()
Get the current selected converter.

§ Initialize()

bool InputManager::Initialize ( const std::string &  infile_name,
const std::string &  conv,
const bool  isCosmic = false 
)

Initializes input tree(s) branches, selecting the appropriate converter and initializing it. The "conv" parameter is deprecated. Returns whether initialization was successful.

Definition at line 98 of file InputManager.cxx.

98  {
99 //********************************************************************
100 
101  if (!AddDataFileToConverter(infile_name, conv, isCosmic, true)) return false;
102 
103  // Check whether is data or MC
104  if(GetIsMC())
105  std::cout << "InputManager:: MC mode" << std::endl;
106  else
107  std::cout << "InputManager:: Data mode" << std::endl;
108 
109  // SoftwareVersion
110  std::cout << "InputManager:: SoftwareVersion for original file is " << GetSoftwareVersion() << std::endl;
111 
112  return true;
113 }
bool AddDataFileToConverter(const std::string &infile_name, const std::string &conv, const bool isCosmic=false, bool reset=false)
const std::string & GetSoftwareVersion()
Returns the software version from the header.

§ LoadEvent()

bool InputManager::LoadEvent ( Long64_t &  entry,
bool  delPrevious = true 
)

Fill the raw AnaEventB structure and create a AnaSuperEventB from the raw event. The argument entry (the entry number in the input tree) will be modified inside the method by the specific converter (hence the non-cont reference). The way entry is modified will depend on whether the input file is EVENT based (every call to this method will increment by one the argument entry) or SPILL based (several events – one per bunch – correspond to the same spill, so once the first event in a given spill is read entry number will not be varied until all events in that spill are processed). At the moment oaAnalysis and MiniTree are SPILL based while FlatTree is EVENT based.

Examples on how to use this method are available in psyche/psycheSteering/vXrY/app/RunExample.cxx and psyche/psycheSteering/vXrY/src/AnalysisManager.cxx. Just search for LoadEvent in those files.

This method Returns whether the event was successfully filled.

Definition at line 216 of file InputManager.cxx.

216  {
217 //*****************************************************************************
218 
219  Long64_t ientry = LoadTree(entry);
220  if (ientry < 0) return false;
221 
222  // Empty pointer filled inside GetEvent method
223  AnaEventC* RawEvent = NULL;
224 
225  // Fill the event structure from the input tree
226  Int_t nb = GetConverter().GetEvent(entry,RawEvent);
227  if (nb <=0 ) return false;
228 
229  // Set the event unique ID
230  RawEvent->UniqueID = _uniqueID++;
231 
232  // Create a AnaSuperEvent
233  _sevent = new AnaSuperEventB(RawEvent);
234 
235  // Delete the previous event
236  if (_prevSEvent && delPrevious){
237  delete _prevSEvent;
238  }
239 
241 
242  return true;
243 }
Long64_t LoadTree(Long64_t entry)
Call InputConverter::LoadTree() for the selected converter.
virtual Int_t GetEvent(Long64_t &entry, AnaEventC *&event)=0
AnaSuperEventB * _sevent
The super event.
Int_t UniqueID
The event unique ID.
Int_t _uniqueID
The current Event UniqueID.
InputConverter & GetConverter()
Get the current selected converter.
AnaSuperEventB * _prevSEvent
The previous Super Event for deleting if necessary.

§ LoadSpill()

bool InputManager::LoadSpill ( Long64_t &  entry)
virtual

Read one or several entries in the input tree(s) to fill a raw AnaSpill, and sets the CorrectedSpill and Spill as copies of it (to be manipulated later). The argument entry (the entry number in the input tree) will be modified inside the method by the specific converter (hence the non-cont reference). The way entry is modified will depend on whether the input file is SPILL based (every call to this method will increment by one the argument entry) or EVENT based (entry number will be incremented in several units to account for several events – bunches – in the same spill). At the moment oaAnalysis and MiniTree are SPILL based while FlatTree is EVENT based.

Examples on how to use this method are available in highland2/highlandTools/vXrY/src/AnalysisLoop.cxx, and highland2/highlandTools/vXrY/src/SimpleLoopBase.cxx. Just search for LoadSpill in those files.

This method Returns whether the event was successfully filled.

Reimplemented in HighlandInputManager.

Definition at line 191 of file InputManager.cxx.

191  {
192 //*****************************************************************************
193 
194  Long64_t ientry = LoadTree(entry);
195  if (ientry < 0) return false;
196 
197  // The spill to be read
198  AnaSpillC* SpillToRead = NULL;
199 
200  // Fill the spill structure from the input tree. The SpillToRead instance is created internally by the converter
201  Int_t nb = GetConverter().GetSpill(entry,SpillToRead);
202  if (nb <=0 || !SpillToRead){
203  return false;
204  }
205 
206  // If the spill is succesfully read the previous successfully read spill must be deleted
207  DeleteSpill();
208 
209  // We can now associate the spill just read with the _CorrectedSpill
210  _CorrectedSpill = SpillToRead;
211 
212  return true;
213 }
Long64_t LoadTree(Long64_t entry)
Call InputConverter::LoadTree() for the selected converter.
InputConverter & GetConverter()
Get the current selected converter.
virtual void DeleteSpill()
clean up the remaining pointers to the spills.
virtual Int_t GetSpill(Long64_t &entry, AnaSpillC *&spill)=0
AnaSpillC * _CorrectedSpill
The current corrected spill.

§ ReadFile()

bool InputManager::ReadFile ( const std::string &  infile_name,
bool  isROOTFile 
)

Read the input file, adding it to the TChains of the selected converter. If isROOTFile is false, treats the file as a text file containing a list of ROOT files to add. Returns whether the file was successfully read.

Definition at line 142 of file InputManager.cxx.

142  {
143 //*****************************************************************************
144 
145  // Load data files
146  TString infileName(infile_name);
147  std::ifstream inputFile(infileName.Data(), std::ios::in);
148 
149  //if(!inputFile){
150  //std::cerr << "Cannot open input file '" << infileName.Data() << "'. Exit!" << std::endl;
151  //return false;
152  //}
153 
154  //Loop over the input files
155  std::string inputString=infile_name;
156 
157  if (!isROOTFile){
158  while (inputFile >> inputString) {
159  if (!GetConverter().AddFileToTChain(inputString)) return false;
160  }
161  }
162  else{
163  if (!GetConverter().AddFileToTChain(inputString)) return false;
164  }
165 
166  return true;
167 }
InputConverter & GetConverter()
Get the current selected converter.
virtual bool AddFileToTChain(const std::string &inputString)=0
Add the file specified to fChain, and any friend chains that were set up.

§ ResetSpillToCorrected()

void InputManager::ResetSpillToCorrected ( )

Reset the main spill to the corrected spill. This removes all the variations applied by the systematics.

Definition at line 345 of file InputManager.cxx.

345  {
346 //*****************************************************************************
347  if (_Spill) {
348  delete _Spill;
350  }
351 }
AnaSpillC * _Spill
The current spill with corrections and systematics.
virtual AnaSpillC * Clone()=0
Clone this object.
AnaSpillC * _CorrectedSpill
The current corrected spill.

The documentation for this class was generated from the following files: