SFrame 3.6
|
Histogramming part of SCycleBase. More...
#include <core/include/SCycleBaseHist.h>
Public Member Functions | |
SCycleBaseHist () | |
Default constructor. | |
virtual void | SetHistOutput (TList *output) |
Set which list should be used for the histogramming output. | |
virtual TList * | GetHistOutput () const |
Check which list should be used for the histogramming output. | |
template<class T > | |
T * | Book (const T &histo, const char *directory=0, Bool_t inFile=kFALSE) throw ( SError ) |
Function placing a ROOT object in the output file. | |
template<class T > | |
T * | Retrieve (const char *name, const char *directory=0, Bool_t outputOnly=kFALSE) throw ( SError ) |
Function searching for a ROOT object in the output file. | |
template<class T > | |
std::vector< T * > | RetrieveAll (const char *name, const char *directory=0) throw ( SError ) |
Function retrieving all ROOT objects of this name from the input file. | |
void | WriteObj (const TObject &obj, const char *directory=0, Bool_t inFile=kFALSE) throw ( SError ) |
Function for persistifying a ROOT object to the output. | |
TH1 * | Hist (const char *name, const char *dir=0) throw ( SError ) |
Function searching for 1-dimensional histograms in the output file. | |
Protected Member Functions | |
virtual void | SetHistInputFile (TDirectory *file) |
Set the current input file. | |
virtual TDirectory * | GetHistInputFile () const |
Get the currently set input file. | |
virtual void | WriteHistObjects (TDirectory *output) |
Write the objects meant to be merged using the output file. |
Histogramming part of SCycleBase.
Class holding all the histogramming functionality available to the analysis cycles. Unfortunately the object has to be initialised for each new InputData, which is done in the SCycleBase::ExecuteInputData function. It's error prone, but I haven't found any nicer way of doing it...
Definition at line 47 of file SCycleBaseHist.h.
SCycleBaseHist::SCycleBaseHist | ( | ) |
Default constructor.
The constructor initialises the base class and the member variables.
Definition at line 33 of file SCycleBaseHist.cxx.
References REPORT_VERBOSE.
T * SCycleBaseHist::Book | ( | const T & | histo, |
const char * | directory = 0 , |
||
Bool_t | inFile = kFALSE |
||
) | throw ( SError ) |
Function placing a ROOT object in the output file.
Function for creating any kind of object inheriting from TH1 and which has a correct dictionary loaded, in the output file. You either have to give it an already existing object, which will be copied to the output, or you can use a formalism like this:
TH1D* hist = Book( TH1D( "hist", "Histogram", 100, 0.0, 100.0 ) );
histo | The object (usually histogram) to put into the output |
directory | Optional directory name where the object should end up |
inFile | If set to kTRUE , the object will be merged using the output file, and not in memory |
Definition at line 50 of file SCycleBaseHist.icc.
References SCycleOutput::GetObject(), and REPORT_VERBOSE.
TDirectory * SCycleBaseHist::GetHistInputFile | ( | ) | const [protected, virtual] |
Get the currently set input file.
Implements ISCycleBaseHist.
Definition at line 153 of file SCycleBaseHist.cxx.
TList * SCycleBaseHist::GetHistOutput | ( | ) | const [virtual] |
Check which list should be used for the histogramming output.
Implements ISCycleBaseHist.
Definition at line 47 of file SCycleBaseHist.cxx.
TH1 * SCycleBaseHist::Hist | ( | const char * | name, |
const char * | dir = 0 |
||
) | throw ( SError ) |
Function searching for 1-dimensional histograms in the output file.
This function is very similar to SCycleBaseHist::Retrieve. It looks for a 1-dimensional histogram in the output file with a given name in a given directory and returns a pointer to it.
The important difference wrt. SCycleBaseHist::Retrieve is that it only uses the slow ROOT methods for finding the histogram once for each new output file. It uses a caching mechanism for all histograms that were already searched for, making the n-th search much faster than that performed by SCycleBaseHist::Retrieve. It's still slower than using separate pointers, but not by much.
It should be especially useful when handling a lot of histograms. Having a pointer for each of these histograms can be a pain above a certain number. Instead you can book a histogram once in SCycleBase::BeginInputData and then you can access it with:
In BeginInputData: Book( TH1D( "hist", "Histogram", 100, 0.0, 100.0 ) );
In ExecuteEvent: Hist( "hist" )->Fill( 50.0 );
name | The name of the histogram |
dir | The name of the directory the histogram is in |
Definition at line 129 of file SCycleBaseHist.cxx.
References REPORT_VERBOSE.
T * SCycleBaseHist::Retrieve | ( | const char * | name, |
const char * | directory = 0 , |
||
Bool_t | outputOnly = kFALSE |
||
) | throw ( SError ) |
Function searching for a ROOT object in the output file.
Function searching for any kind of object (inheriting from TObject). First the function searches for the object in the output object list, and if it doesn't find it there, it looks for it in the currently open input file.
You have to specify the return type to the function explicitely, as the compiler can't know this from the argument list.
Example:
TH1* hist = Retrieve< TH1 >( "hist" );
name | The name of the object you're looking for |
directory | The directory the object is supposed to be in |
outputOnly | Search only amongst the output objects of the cycle |
Definition at line 120 of file SCycleBaseHist.icc.
References SCycleOutput::GetObject(), REPORT_ERROR, REPORT_VERBOSE, and SError::SkipCycle.
std::vector< T * > SCycleBaseHist::RetrieveAll | ( | const char * | name, |
const char * | directory = 0 |
||
) | throw ( SError ) |
Function retrieving all ROOT objects of this name from the input file.
This function can be used to retrieve all versions of a given object from the input file. It doesn't search in the output list, as each object should only be present in one version in the output.
The main use-case for this function right now is to be able to read the lumiblock metadata from input ATLAS D3PDs.
Example:
std::vector< TObjString* > lumiblocks = RetrieveAll< TObjString* >( "physics", "Lumi" );
name | The name of the object(s) we're looking for |
directory | The directory in which the object(s) is/are located |
Definition at line 222 of file SCycleBaseHist.icc.
References DEBUG, SLogger::endmsg(), REPORT_ERROR, and SError::StopExecution.
void SCycleBaseHist::SetHistInputFile | ( | TDirectory * | file | ) | [protected, virtual] |
Set the current input file.
Implements ISCycleBaseHist.
Definition at line 147 of file SCycleBaseHist.cxx.
void SCycleBaseHist::SetHistOutput | ( | TList * | output | ) | [virtual] |
Set which list should be used for the histogramming output.
Implements ISCycleBaseHist.
Definition at line 40 of file SCycleBaseHist.cxx.
void SCycleBaseHist::WriteHistObjects | ( | TDirectory * | output | ) | [protected, virtual] |
Write the objects meant to be merged using the output file.
This is a tricky little function. The code will not always use an output file when running on PROOF. So, if the user requested some histograms or objects to be merged using an output file, but an output file is not available, we still have to try to merge them in memory at least. After printing some warning messages.
output | The output file to write the objects to. If set to a null pointer, the objects are added to the PROOF output instead. |
Implements ISCycleBaseHist.
Definition at line 168 of file SCycleBaseHist.cxx.
References SLogger::endmsg(), SCycleBaseBase::m_logger, and WARNING.
void SCycleBaseHist::WriteObj | ( | const TObject & | obj, |
const char * | directory = 0 , |
||
Bool_t | inFile = kFALSE |
||
) | throw ( SError ) |
Function for persistifying a ROOT object to the output.
Function for writing any kind of object inheriting from TObject into the output file. It is meant to be used with objects that are created once, then they don't have to be touched again. (Like TGraph and friends.)
To write out a TGraph for instance, you could write something like:
TGraph mygraph( n, x_array, y_array );
mygraph.SetName( "MyGraph" );
WriteObj( mygraph );
obj | Constant reference to the object to be written out |
directory | Optional directory name in which to save the object |
inFile | If set to kTRUE , the object will be merged using the output file, and not in memory |
Definition at line 71 of file SCycleBaseHist.cxx.