SFrame 3.6
|
NTuple handling part of SCycleBase. More...
#include <core/include/SCycleBaseNTuple.h>
Public Member Functions | |
SCycleBaseNTuple () | |
Default constructor. | |
virtual | ~SCycleBaseNTuple () |
Default destructor. | |
virtual void | SetNTupleOutput (TList *output) |
Set the object list used for NTuple output. | |
virtual TList * | GetNTupleOutput () const |
Get the object list used for NTuple output. | |
template<typename T > | |
bool | ConnectVariable (const char *treeName, const char *branchName, T &variable) throw ( SError ) |
Connect an input variable. | |
template<typename T , size_t size> | |
bool | ConnectVariable (const char *treeName, const char *branchName, T(&variable)[size]) throw ( SError ) |
Specialisation for primitive arrays. | |
template<typename T > | |
bool | ConnectVariable (const char *treeName, const char *branchName, T *&variable) throw ( SError ) |
Specialisation for object pointers. | |
template<class T > | |
TBranch * | DeclareVariable (T &obj, const char *name, const char *treeName=0) throw ( SError ) |
Declare an output variable. | |
virtual TTree * | GetMetadataTree (const char *name) const throw ( SError ) |
Access one of the metadata trees. | |
virtual TTree * | GetInputMetadataTree (const char *name) const throw ( SError ) |
Access one of the input metadata trees. | |
virtual TTree * | GetOutputMetadataTree (const char *name) const throw ( SError ) |
Access one of the output metadata trees. | |
virtual TTree * | GetInputTree (const char *treeName) const throw ( SError ) |
Access one of the input trees. | |
virtual TTree * | GetOutputTree (const char *treeName) const throw ( SError ) |
Access one of the output trees. | |
Protected Member Functions | |
void | CreateOutputTrees (const SInputData &id, std::vector< TTree * > &outTrees, TFile *outputFile=0) throw ( SError ) |
Create the output trees. | |
void | SaveOutputTrees (TDirectory *output) throw ( SError ) |
Save all the created output trees in the output. | |
void | LoadInputTrees (const SInputData &id, TTree *main_tree, TFile *&inputFile) throw ( SError ) |
Load the input trees. | |
void | GetEvent (Long64_t entry) throw ( SError ) |
Read in the event from the "normal" trees. | |
Double_t | CalculateWeight (const SInputData &inputData, Long64_t entry) |
Calculate the weight of the current event. | |
void | ClearCachedTrees () |
Forget about the internally cached TTree pointers. |
NTuple handling part of SCycleBase.
This is the most complex constituent of all the SCycleBase classes. It is responsible for handling input and output TTree-s. It has quite a number of protected functions which are used by SCycleBase, and are hidden from the user by that class. (A little C++ magic...)
Definition at line 47 of file SCycleBaseNTuple.h.
SCycleBaseNTuple::SCycleBaseNTuple | ( | ) |
Default constructor.
The constructor is only initialising the base class.
Definition at line 47 of file SCycleBaseNTuple.cxx.
References REPORT_VERBOSE.
SCycleBaseNTuple::~SCycleBaseNTuple | ( | ) | [virtual] |
Default destructor.
Another one of the "I don't do anything" destructors.
Definition at line 57 of file SCycleBaseNTuple.cxx.
References REPORT_VERBOSE.
Double_t SCycleBaseNTuple::CalculateWeight | ( | const SInputData & | inputData, |
Long64_t | entry | ||
) | [protected, virtual] |
Calculate the weight of the current event.
Function calculating the event weight for the MC event for each event.
The function is used internally by the framework!
inputData | The input data that we're processing at the moment |
entry | The event number |
Implements ISCycleBaseNTuple.
Definition at line 614 of file SCycleBaseNTuple.cxx.
References EPSILON, ISCycleBaseConfig::GetConfig(), SCycleConfig::GetInputData(), SCycleConfig::GetTargetLumi(), SInputData::GetType(), SInputData::GetVersion(), and REPORT_VERBOSE.
void SCycleBaseNTuple::ClearCachedTrees | ( | ) | [protected, virtual] |
Forget about the internally cached TTree pointers.
This function instructs the object to forget about all the TTree pointers that it collected at the beginning of executing the cycle. It's a security measure for when the cycle is run multiple times.
Implements ISCycleBaseNTuple.
Definition at line 673 of file SCycleBaseNTuple.cxx.
bool SCycleBaseNTuple::ConnectVariable | ( | const char * | treeName, |
const char * | branchName, | ||
T & | variable | ||
) | throw ( SError ) |
Connect an input variable.
To connect to "primitive" types in the input TTree (ints, doubles, etc.) you have to define the variable itself, then give this variable to this function. So this function is only supposed to handle primitive types. More complex types are are handled by the specialised functions.
For STL objects (vectors, maps, you name it) you have to define a pointer to such an object, and give this pointer to the function. You don't need to initialise the pointer to anything, the function will take care about that.
The function checks if the variable given to the function is of the right type. Unfortunately ROOT is not able to do this itself.
See the example cycles for some details.
treeName | Name of the TTree in the input file |
branchName | Name of the branch in the TTree |
variable | The variable that should be connected to the branch |
true
if the connection was made successfully, false
otherwise Definition at line 58 of file SCycleBaseNTuple.icc.
References DEBUG, SLogger::endmsg(), INFO, REPORT_ERROR, REPORT_VERBOSE, SError::SkipCycle, and SError::SkipFile.
bool SCycleBaseNTuple::ConnectVariable | ( | const char * | treeName, |
const char * | branchName, | ||
T(&) | variable[size] | ||
) | throw ( SError ) |
Specialisation for primitive arrays.
This is a tricky specialisation of the base function...
Although it's not too common these days, but older ROOT ntuples often contained simple C style arrays instead of STL collections. Unfortunately the standard version of this function can't work if you give it your array variable. Luckily C++ allows us to use a special function for array type arguments.
If one of the branches that you'd like to read is an array, you should write something like this in your code:
In the header: Int_t m_my_variable[ MAX_SIZE ];
In the source file: ConnectVariable( "MyTree", "MyVariable", m_my_variable );
Note, that the arrays always have to have a fixed size. (This is the size that was specified when the TTree was written.) It's important that the array would have memory allocated for it (as in this example), because ROOT doesn't do this automatically!
treeName | Name of the TTree in the input file |
branchName | Name of the branch in the TTree |
variable | The variable that should be connected to the branch |
true
if the connection was made successfully, false
otherwise Definition at line 204 of file SCycleBaseNTuple.icc.
References DEBUG, SLogger::endmsg(), REPORT_ERROR, and REPORT_VERBOSE.
bool SCycleBaseNTuple::ConnectVariable | ( | const char * | treeName, |
const char * | branchName, | ||
T *& | variable | ||
) | throw ( SError ) |
Specialisation for object pointers.
This is a specialisation of the base function for object pointers. If the input ntuple contains an object (like an std::vector of something), then the user should connect an object pointer to this branch. Something like this:
In the header: std::vector< double >* m_electron_p_T;
In the source file: ConnectVariable( "MyTree", "Electron_p_T", m_electron_p_T );
Note that you don't get ownership of the object created by this function! It will be deleted automatically! At the same time, you shouldn't create a new object before calling this function, as that will lead to a memory leak.
Note also that the code doesn't need to check the type of the pointer given to the function. ROOT does this for us.
treeName | Name of the TTree in the input file |
branchName | Name of the branch in the TTree |
variable | The variable that should be connected to the branch |
true
if the connection was made successfully, false
otherwise Definition at line 268 of file SCycleBaseNTuple.icc.
References DEBUG, SLogger::endmsg(), REPORT_ERROR, REPORT_VERBOSE, and SError::SkipCycle.
void SCycleBaseNTuple::CreateOutputTrees | ( | const SInputData & | iD, |
std::vector< TTree * > & | outTrees, | ||
TFile * | outputFile = 0 |
||
) | throw ( SError ) [protected, virtual] |
Create the output trees.
Function called first when starting to process an InputData object. It opens the output file and creates the output trees defined in the cycle configuration in it. Note, that the created trees are empty, no branches are added to them by default anymore.
The function is used internally by the framework!
iD | The input data that we're handling at the moment |
outTrees | The collection of output trees that will be created |
Implements ISCycleBaseNTuple.
Definition at line 292 of file SCycleBaseNTuple.cxx.
References DEBUG, SLogger::endmsg(), STreeType::OutputMetaTree, STreeType::OutputSimpleTree, REPORT_VERBOSE, and WARNING.
TBranch * SCycleBaseNTuple::DeclareVariable | ( | T & | obj, |
const char * | name, | ||
const char * | treeName = 0 |
||
) | throw ( SError ) |
Declare an output variable.
Function putting an output variable in (one of) the output tree(s). The function is quite complicated, but it is for the reason for making it very easy to use. The user just has to give a reference to the output object, a name under which it should appear in the output tree, and the tree name if multiple output trees have been defined.
The function detects the type of the user supplied variable, and puts it in the output tree in a way depending on the object's type.
Example:
Double_t m_var1;
DeclareVariable( m_var1, "var1" );
...
std::vector< int > m_var2;
DeclareVariable( m_var2, "var2", "MyTree" );
obj | The object to write to the output ntuple |
name | The name of the branch to create from the object |
treeName | Optional TTree name, needed if multiple output trees are used |
Definition at line 346 of file SCycleBaseNTuple.icc.
References DEBUG, SLogger::endmsg(), REPORT_ERROR, REPORT_VERBOSE, SError::request(), SError::SkipFile, SError::SkipInputData, SError::StopExecution, WARNING, and SError::what().
void SCycleBaseNTuple::GetEvent | ( | Long64_t | entry | ) | throw ( SError ) [protected, virtual] |
Read in the event from the "normal" trees.
Function reading in the same entry for each of the connected branches. It is called first for each new event.
The function is used internally by the framework!
entry | The event number to read in |
Implements ISCycleBaseNTuple.
Definition at line 589 of file SCycleBaseNTuple.cxx.
TTree * SCycleBaseNTuple::GetInputMetadataTree | ( | const char * | name | ) | const throw ( SError ) [virtual] |
Access one of the input metadata trees.
This function can be used to retrieve input metadata trees. Input metadata trees are TTree-s that don't desribe event level information. The reading of these trees is completely up to the user at this point.
name | Name of the requested input metadata tree |
Definition at line 134 of file SCycleBaseNTuple.cxx.
References REPORT_VERBOSE, and SError::SkipFile.
TTree * SCycleBaseNTuple::GetInputTree | ( | const char * | treeName | ) | const throw ( SError ) [virtual] |
Access one of the input trees.
Function used by a few of the variable handling functions. It finds the tree with a given name among the input trees, or throws an exception if such tree doesn't exist.
Definition at line 227 of file SCycleBaseNTuple.cxx.
References REPORT_VERBOSE, and SError::SkipFile.
TTree * SCycleBaseNTuple::GetMetadataTree | ( | const char * | name | ) | const throw ( SError ) [virtual] |
Access one of the metadata trees.
This function can be used to retrieve both input and output metadata trees. Input metadata trees are TTree-s that don't desribe event level information. The reading of these trees is completely up to the user at this point.
Output metadata trees are also completely in the control of the user. Entries in them are only written out on the user's request.
name | Name of the requested metadata tree |
Definition at line 85 of file SCycleBaseNTuple.cxx.
References REPORT_ERROR, REPORT_VERBOSE, SError::request(), SError::SkipFile, and SError::what().
TList * SCycleBaseNTuple::GetNTupleOutput | ( | ) | const [virtual] |
Get the object list used for NTuple output.
Implements ISCycleBaseNTuple.
Definition at line 69 of file SCycleBaseNTuple.cxx.
TTree * SCycleBaseNTuple::GetOutputMetadataTree | ( | const char * | name | ) | const throw ( SError ) [virtual] |
Access one of the output metadata trees.
This function can be used to retrieve output metadata trees. Output metadata trees are completely in the control of the user. Entries in them are only written out on the user's request.
name | Name of the requested output metadata tree |
Definition at line 182 of file SCycleBaseNTuple.cxx.
References REPORT_VERBOSE, and SError::SkipFile.
TTree * SCycleBaseNTuple::GetOutputTree | ( | const char * | treeName | ) | const throw ( SError ) [virtual] |
Access one of the output trees.
Definition at line 254 of file SCycleBaseNTuple.cxx.
References REPORT_VERBOSE, and SError::SkipFile.
void SCycleBaseNTuple::LoadInputTrees | ( | const SInputData & | iD, |
TTree * | main_tree, | ||
TFile *& | inputFile | ||
) | throw ( SError ) [protected, virtual] |
Load the input trees.
Function called first for each new input file. It opens the file, and accesses the trees defined in the cycle configuration. It also starts the book-keeping for the EventView input trees, if such things are defined.
The function is used internally by the framework!
iD | The input data that we're handling at the moment |
filename | The full name of the input file |
file | Pointer to the input file that the function opens |
Implements ISCycleBaseNTuple.
Definition at line 459 of file SCycleBaseNTuple.cxx.
References DEBUG, SLogger::endmsg(), STreeType::InputMetaTree, STreeType::InputSimpleTree, SCycleConfig::LOCAL, SCycleConfig::PROOF, REPORT_VERBOSE, SError::SkipCycle, SError::SkipFile, and SError::StopExecution.
void SCycleBaseNTuple::SaveOutputTrees | ( | TDirectory * | output | ) | throw ( SError ) [protected, virtual] |
Save all the created output trees in the output.
This function is used to save all the output trees into the output file when the cycle finishes processing the events from the InputData. It also deletes the TTree objects, so it should really only be called by the framework at the end of processing.
output | The directory where the trees have to be written (Usually a TFile) |
Implements ISCycleBaseNTuple.
Definition at line 415 of file SCycleBaseNTuple.cxx.
void SCycleBaseNTuple::SetNTupleOutput | ( | TList * | output | ) | [virtual] |
Set the object list used for NTuple output.
Implements ISCycleBaseNTuple.
Definition at line 63 of file SCycleBaseNTuple.cxx.