GGS(GenericGEANT4Simulation)Software
2.7.0
|
Class to manage ROOT output readers. More...
#include <GGSTRootReader.h>
Public Member Functions | |
GGSTRootReader () | |
Constructor. | |
~GGSTRootReader () | |
Destructor. | |
GGSTFilesHandler * | Open (const std::string &fileName, GGSTFilesHandler *filesHandler=nullptr, bool force=false) |
Open ROOT files. More... | |
GGSTFilesHandler * | Open (const char *fileName, GGSTFilesHandler *filesHandler=nullptr, bool force=false) |
Open ROOT files. More... | |
bool | OpenFile (const char *fileName) |
Opens a ROOT file. More... | |
template<class T > | |
T * | GetReader (GGSTFilesHandler *filesHandler=nullptr, const TString &treeName="") |
Get a chain reader. More... | |
void | GetEntry (Long64_t entry) |
Reads an event. More... | |
Long64_t | GetEntries () |
The total number of events. More... | |
Long64_t | GetReadEntry () |
Returns the current entry (event). More... | |
const GGSTSimInfo * | GetSimInfo (const GGSTFilesHandler *filesHandler=nullptr) |
Returns the simulation informations. More... | |
const GGSTGeoParams * | GetGeoParams (const GGSTFilesHandler *filesHandler=nullptr) |
Returns the geometry parameters. More... | |
const GGSTParameters * | GetGenParams (const GGSTFilesHandler *filesHandler=nullptr) |
Returns the generator parameters. More... | |
const TGeoManager * | GetROOTGeometry (const GGSTFilesHandler *filesHandler=nullptr) |
Returns the simulation geometry in TGeo format. More... | |
Class to manage ROOT output readers.
GGS actions which write output on a ROOT file generally write each one on its own tree. So for each of these trees there should be a reader class to read back the data. GGSTRootReader simplifies the handling of multiple tree reader classes, by providing facilities for opening ROOT files and reading entries for all the trees. The main method of this class is the GetReader method. See its documentation for further details.
Definition at line 38 of file GGSTRootReader.h.
Long64_t GGSTRootReader::GetEntries | ( | ) |
The total number of events.
This method returns the number of events in the event chain. Since all the chains are enforced to contain the same number of event when they are created, there is no ambiguity on the returned value even in presence of multiple chains. If no reader has already been retrieved by GetReader when this method is called then there is still no chain. This is because chains are created when calling GetReader to connect each reader to its chain and branches. In this case a "blind" number of entries is returned: the files belonging to the files handler created by the first call to Open are scanned and when the first TTree object is found a chain is created and the number of its entries is used as the return value. This value might be incorrect in some corner cases, e.g. if two handlers containing a different number of events are opened and the second one is the one which will be effectively used for the analysis.
Definition at line 297 of file GGSTRootReader.cpp.
void GGSTRootReader::GetEntry | ( | Long64_t | entry | ) |
Reads an event.
This method reads the event specified by entry. It calls GetEntry for every chain associated with the already instantiated readers (
entry | The event to be read. |
Definition at line 289 of file GGSTRootReader.cpp.
const GGSTParameters * GGSTRootReader::GetGenParams | ( | const GGSTFilesHandler * | filesHandler = nullptr | ) |
Returns the generator parameters.
filesHandler | The handler to the file(s) containing the desired info object. If nullptr then the handler returned by the first invocation of Open will be automatically used. |
Definition at line 332 of file GGSTRootReader.cpp.
const GGSTGeoParams * GGSTRootReader::GetGeoParams | ( | const GGSTFilesHandler * | filesHandler = nullptr | ) |
Returns the geometry parameters.
filesHandler | The handler to the file(s) containing the desired info object. If nullptr then the handler returned by the first invocation of Open will be automatically used. |
Definition at line 320 of file GGSTRootReader.cpp.
|
inline |
Returns the current entry (event).
Definition at line 161 of file GGSTRootReader.h.
T * GGSTRootReader::GetReader | ( | GGSTFilesHandler * | filesHandler = nullptr , |
const TString & | treeName = "" |
||
) |
Get a chain reader.
The template argument T is the class name of a reader class, which must inherit from GGSTChainReader. The method will return a pointer to a reader of class T for the specified tree, eventually chaining all the files handled by the GGSTFilesHandler passed as first argument. The reader will be automatically set to current entry.
If a nullptr value is passed for GGSTFilesHandler then the first handler (i.e. the file(s) opened with the first call to Open) will be used. If an empty std::string is passed for treeName, then the default tree name will be used.
filesHandler | Handler to the Root files to be read by the reader. |
treeName | The name of the tree to be read by the reader T. |
Definition at line 233 of file GGSTRootReader.h.
const TGeoManager * GGSTRootReader::GetROOTGeometry | ( | const GGSTFilesHandler * | filesHandler = nullptr | ) |
Returns the simulation geometry in TGeo format.
filesHandler | The handler to the file(s) containing the desired info object. If nullptr then the handler returned by the first invocation of Open will be automatically used. |
Definition at line 344 of file GGSTRootReader.cpp.
const GGSTSimInfo * GGSTRootReader::GetSimInfo | ( | const GGSTFilesHandler * | filesHandler = nullptr | ) |
Returns the simulation informations.
Since this class can manage many handlers, the user can specify from which of them the simulation informations must be read. If no handler is specified, then the one obtained with the first call to Open will be used. All the files belonging to the same handler are forced to have the same GGSTSimInfo object, except for the initial seeds.
filesHandler | The handler to the file(s) containing the desired info object. If nullptr then the handler returned by the first invocation of Open will be automatically used. |
Definition at line 308 of file GGSTRootReader.cpp.
GGSTFilesHandler * GGSTRootReader::Open | ( | const std::string & | fileName, |
GGSTFilesHandler * | filesHandler = nullptr , |
||
bool | force = false |
||
) |
Open ROOT files.
The argument of this method can either be the name of a single file or multiple files, in turn specified using wildcards (*, ? and []) or the name of a txt file containing the full paths to the desired files (one per row). The reader will handle the files and return a pointer to a GGSTFilesHandler object handling all the files that have been opened.
When opening with wildcards the files will be sorted in alphabetical order, while when using the txt file the order will not be modified.
If the file(s) do not exist or in case of an error, a nullptr value will be returned. When opening multiple files a consistency check is done in order to assure that all the files have been produced in the same way. The check is based on the content of the GGSTSimInfo stored in each file, and currently it only checks that the content of each member of the GGSTSimInfo objects exactly match those of the GGSTSimInfo object contained in the first file. This means that two file produced with two datacards with different names will be considered as inconsistent, even if the content of the datacards was actually the same. Files which are inconsistent with respecto to the first one will be ignored. The consistency check can be turned off using the #force argument.
The pointer to the handler can eventually be passed to GetReader to specify which files the desired reader should use (see GetReader).
After a handler has been created by calling Open, more files can be added to it by passing it as the second argument to subsequent calls of Open. In this case the returned address will be equal to that of the argument. If an error occurs the method will return nullptr and the handler will not be modified (i.e. no files will be appended).
The reader retains the ownership of the handler objects it creates and will adopt eventual handlers instantiated explicitly by the user and passed to Open as the second argument (e.g. the user must not delete the handler in these cases)
fileName | Path to Root file (eventually with wildcards) or to a txt file containing the list of desired Root files. |
filesHandler | The files handler to which the newly opened file will be appended. If nullptr a new handler will be created. |
force | if true, no consistency check between different files will be done. |
Definition at line 36 of file GGSTRootReader.cpp.
|
inline |
Open ROOT files.
Overload with const char *.
fileName | Path to Root file (eventually with wildcards) or to a txt file containing the list of desired Root files. |
filesHandler | The files handler to which the newly opened file will be appended. If nullptr a new handler will be created. |
force | if true, no consistency check between different files will be done. |
Definition at line 101 of file GGSTRootReader.h.
|
inline |
Opens a ROOT file.
This method is kept for backward compatibility. It opens a single Root file. The usage of this method is discouraged and it will be deprecated in some future release. The suggested method is Open.
fileName | Path to file. |
Definition at line 113 of file GGSTRootReader.h.