Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:09:25

0001 #ifndef TTREE_FOREACH_ENTRY_H
0002 #define TTREE_FOREACH_ENTRY_H
0003 
0004 #include <cassert>
0005 #include <string>
0006 #include <algorithm>
0007 #include <iomanip>
0008 #include "TTree.h"
0009 
0010 #define LEAF(leaf, tree)                        \
0011   leaf = 0;                             \
0012   { TBranch* branch = tree->GetBranch( #leaf ); assert(branch);     \
0013     branch->SetAddress( &(leaf) );                  \
0014     branch->GetEntry( TFE_local_index,1); }             \
0015 
0016 #define PLEAF(leaf, tree)                       \
0017   leaf;                                 \
0018   { TBranch* branch = tree->GetBranch( #leaf ); assert(branch);     \
0019     void* pt = &(leaf);                         \
0020     branch->SetAddress( &pt );                      \
0021     branch->GetEntry( TFE_local_index,1); }             \
0022 
0023 #define RENAMED_LEAF(var,leafname, tree)                \
0024   var = 0;                              \
0025   { std::string n=leafname;                     \
0026     TBranch* branch = tree->GetBranch( n.c_str() ); assert(branch); \
0027     branch->SetAddress( &(var) );                   \
0028     branch->GetEntry( TFE_local_index,1); }             \
0029 
0030 #define RENAMED_PLEAF(var,leafname, tree)               \
0031   var;                                  \
0032   { std::string n=leafname;                     \
0033     TBranch* branch = tree->GetBranch( n.c_str() ); assert(branch); \
0034     void* pt = &(var);                          \
0035     branch->SetAddress( &pt );                      \
0036     branch->GetEntry( TFE_local_index,1); }             \
0037 
0038   
0039 #define TTREE_FOREACH_ENTRY(tree)                   \
0040   for ( Long64_t                            \
0041       TFE_index=0,                          \
0042       TFE_total=tree->GetEntries(),                 \
0043       TFE_local_index=0,                        \
0044       TFE_local_total=0,                        \
0045       TFE_freq=TFE_total/100;                   \
0046     TFE_index < TFE_total &&                    \
0047       ( TFE_local_index < TFE_local_total ||            \
0048         (-1 < tree->LoadTree(TFE_index) &&              \
0049          -1 < ( TFE_local_index = 0) &&             \
0050          -1 < ( TFE_local_total = tree->GetTree()->GetEntries())    \
0051          ));                            \
0052     TFE_index++, TFE_local_index++ )                \
0053 
0054     
0055 #define TFE_MAX(max) if(TFE_index && max) { TFE_total = std::min(Long64_t(max),TFE_total); TFE_freq=TFE_total/100;}
0056 
0057 #define TFE_PRINTSTATUS {                       \
0058     if ( TFE_freq && !(TFE_index%TFE_freq) ) {              \
0059       std::cout << "\b\b\b\b\b" << std::setw(3) << std::fixed       \
0060         << (100*TFE_index)/TFE_total << "% " << std::flush; \
0061     }                                   \
0062   }                                 \
0063     
0064 #endif