SFrame 3.6
SCycleBaseHist Class Reference

Histogramming part of SCycleBase. More...

#include <core/include/SCycleBaseHist.h>

Inheritance diagram for SCycleBaseHist:
Collaboration diagram for SCycleBaseHist:

List of all members.

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.

Detailed Description

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...

Version:
Revision:
335

Definition at line 47 of file SCycleBaseHist.h.


Constructor & Destructor Documentation

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.


Member Function Documentation

template<class T >
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 ) );

Warning:
The function returns a pointer to the created object in the file. It is a good practice to keep the pointer to the object, as SCycleBaseHist::Book and SCycleBaseHist::Retrieve are quite slow.
See also:
SCycleBaseHist::Retrieve
Parameters:
histoThe object (usually histogram) to put into the output
directoryOptional directory name where the object should end up
inFileIf 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 );

Parameters:
nameThe name of the histogram
dirThe name of the directory the histogram is in

Definition at line 129 of file SCycleBaseHist.cxx.

References REPORT_VERBOSE.

template<class T >
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" );

See also:
SCycleBaseHist::Book
Parameters:
nameThe name of the object you're looking for
directoryThe directory the object is supposed to be in
outputOnlySearch only amongst the output objects of the cycle
Returns:
A pointer to the object in question, or a null pointer if the object can't be found

Definition at line 120 of file SCycleBaseHist.icc.

References SCycleOutput::GetObject(), REPORT_ERROR, REPORT_VERBOSE, and SError::SkipCycle.

template<class T >
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" );

Parameters:
nameThe name of the object(s) we're looking for
directoryThe directory in which the object(s) is/are located
Returns:
A vector of pointers to the objects found

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.

Parameters:
outputThe 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 );

Parameters:
objConstant reference to the object to be written out
directoryOptional directory name in which to save the object
inFileIf set to kTRUE, the object will be merged using the output file, and not in memory

Definition at line 71 of file SCycleBaseHist.cxx.


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