Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:59:46

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   {                                           \
0013     TBranch* branch = tree->GetBranch(#leaf); \
0014     assert(branch);                           \
0015     branch->SetAddress(&(leaf));              \
0016     branch->GetEntry(TFE_local_index, 1);     \
0017   }
0018 
0019 #define PLEAF(leaf, tree)                     \
0020   leaf;                                       \
0021   {                                           \
0022     TBranch* branch = tree->GetBranch(#leaf); \
0023     assert(branch);                           \
0024     void* pt = &(leaf);                       \
0025     branch->SetAddress(&pt);                  \
0026     branch->GetEntry(TFE_local_index, 1);     \
0027   }
0028 
0029 #define RENAMED_LEAF(var, leafname, tree)         \
0030   var = 0;                                        \
0031   {                                               \
0032     std::string n = leafname;                     \
0033     TBranch* branch = tree->GetBranch(n.c_str()); \
0034     assert(branch);                               \
0035     branch->SetAddress(&(var));                   \
0036     branch->GetEntry(TFE_local_index, 1);         \
0037   }
0038 
0039 #define RENAMED_PLEAF(var, leafname, tree)        \
0040   var;                                            \
0041   {                                               \
0042     std::string n = leafname;                     \
0043     TBranch* branch = tree->GetBranch(n.c_str()); \
0044     assert(branch);                               \
0045     void* pt = &(var);                            \
0046     branch->SetAddress(&pt);                      \
0047     branch->GetEntry(TFE_local_index, 1);         \
0048   }
0049 
0050 #define TTREE_FOREACH_ENTRY(tree)                                                                             \
0051   for (Long64_t TFE_index = 0,                                                                                \
0052                 TFE_total = tree->GetEntries(),                                                               \
0053                 TFE_local_index = 0,                                                                          \
0054                 TFE_local_total = 0,                                                                          \
0055                 TFE_freq = TFE_total / 100;                                                                   \
0056        TFE_index < TFE_total &&                                                                               \
0057        (TFE_local_index < TFE_local_total || (-1 < tree->LoadTree(TFE_index) && -1 < (TFE_local_index = 0) && \
0058                                               -1 < (TFE_local_total = tree->GetTree()->GetEntries())));       \
0059        TFE_index++, TFE_local_index++)
0060 
0061 #define TFE_MAX(max)                                \
0062   if (TFE_index && max) {                           \
0063     TFE_total = std::min(Long64_t(max), TFE_total); \
0064     TFE_freq = TFE_total / 100;                     \
0065   }
0066 
0067 #define TFE_PRINTSTATUS                                                                                               \
0068   {                                                                                                                   \
0069     if (TFE_freq && !(TFE_index % TFE_freq)) {                                                                        \
0070       std::cout << "\b\b\b\b\b" << std::setw(3) << std::fixed << (100 * TFE_index) / TFE_total << "% " << std::flush; \
0071     }                                                                                                                 \
0072   }
0073 
0074 #endif