Public Member Functions | Public Attributes | List of all members
dune::AnalysisTreeDataStruct::BranchCreator Class Reference

Little helper functor class to create or reset branches in a tree. More...

Public Member Functions

 BranchCreator (TTree *tree)
 
void operator() (std::string name, void *address, std::string leaflist)
 Create a branch if it does not exist, and set its address. More...
 
void operator() (std::string name, void *address, const std::stringstream &leaflist)
 
template<typename T >
void operator() (std::string name, std::vector< T > &data, std::string leaflist)
 
template<typename T >
void operator() (std::string name, std::vector< T > &data)
 

Public Attributes

TTree * pTree
 the tree to be worked on More...
 

Detailed Description

Little helper functor class to create or reset branches in a tree.

Definition at line 1107 of file AnalysisTree_module.cc.

Constructor & Destructor Documentation

dune::AnalysisTreeDataStruct::BranchCreator::BranchCreator ( TTree *  tree)
inline

Definition at line 1110 of file AnalysisTree_module.cc.

Member Function Documentation

void dune::AnalysisTreeDataStruct::BranchCreator::operator() ( std::string  name,
void *  address,
std::string  leaflist 
)
inline

Create a branch if it does not exist, and set its address.

Definition at line 1115 of file AnalysisTree_module.cc.

1116  {
1117  if (!pTree) return;
1118  TBranch* pBranch = pTree->GetBranch(name.c_str());
1119  if (!pBranch) {
1120  pTree->Branch(name.c_str(), address, leaflist.c_str() /*, bufsize */);
1121  MF_LOG_DEBUG("AnalysisTreeStructure")
1122  << "Creating branch '" << name << " with leaf '" << leaflist << "'";
1123  }
1124  else if (pBranch->GetAddress() != address) {
1125  pBranch->SetAddress(address);
1126  MF_LOG_DEBUG("AnalysisTreeStructure")
1127  << "Reassigning address to branch '" << name << "'";
1128  }
1129  else {
1130  MF_LOG_DEBUG("AnalysisTreeStructure")
1131  << "Branch '" << name << "' is fine";
1132  }
1133  } // operator()
static QCString name
Definition: declinfo.cpp:673
#define MF_LOG_DEBUG(id)
void dune::AnalysisTreeDataStruct::BranchCreator::operator() ( std::string  name,
void *  address,
const std::stringstream &  leaflist 
)
inline

Definition at line 1135 of file AnalysisTree_module.cc.

1136  { return this->operator() (name, address, leaflist.str() /*, int bufsize = 32000 */); }
static QCString name
Definition: declinfo.cpp:673
void operator()(std::string name, void *address, std::string leaflist)
Create a branch if it does not exist, and set its address.
template<typename T >
void dune::AnalysisTreeDataStruct::BranchCreator::operator() ( std::string  name,
std::vector< T > &  data,
std::string  leaflist 
)
inline

Definition at line 1139 of file AnalysisTree_module.cc.

1140  { return this->operator() (name, (void*) data.data(), leaflist /*, int bufsize = 32000 */); }
static QCString name
Definition: declinfo.cpp:673
void operator()(std::string name, void *address, std::string leaflist)
Create a branch if it does not exist, and set its address.
template<typename T >
void dune::AnalysisTreeDataStruct::BranchCreator::operator() ( std::string  name,
std::vector< T > &  data 
)
inline

Definition at line 1143 of file AnalysisTree_module.cc.

1144  {
1145  // overload for a generic object expressed directly by reference
1146  // (as opposed to a generic object expressed by a pointer or
1147  // to a simple leaf sequence specification);
1148  // TTree::Branch(name, T* obj, Int_t bufsize, splitlevel) and
1149  // TTree::SetObject() are used.
1150  if (!pTree) return;
1151  TBranch* pBranch = pTree->GetBranch(name.c_str());
1152  if (!pBranch) {
1153  pTree->Branch(name.c_str(), &data);
1154  // ROOT needs a TClass definition for T in order to create a branch,
1155  // se we are sure that at this point the TClass exists
1156  MF_LOG_DEBUG("AnalysisTreeStructure")
1157  << "Creating object branch '" << name
1158  << " with " << TClass::GetClass(typeid(T))->ClassName();
1159  }
1160  else if
1161  (*(reinterpret_cast<std::vector<T>**>(pBranch->GetAddress())) != &data)
1162  {
1163  // when an object is provided directly, the address of the object
1164  // is assigned in TBranchElement::fObject (via TObject::SetObject())
1165  // and the address itself is set to the address of the fObject
1166  // member. Here we check that the address of the object in fObject
1167  // is the same as the address of our current data type
1168  pBranch->SetObject(&data);
1169  MF_LOG_DEBUG("AnalysisTreeStructure")
1170  << "Reassigning object to branch '" << name << "'";
1171  }
1172  else {
1173  MF_LOG_DEBUG("AnalysisTreeStructure")
1174  << "Branch '" << name << "' is fine";
1175  }
1176  } // operator()
static QCString name
Definition: declinfo.cpp:673
#define MF_LOG_DEBUG(id)

Member Data Documentation

TTree* dune::AnalysisTreeDataStruct::BranchCreator::pTree

the tree to be worked on

Definition at line 1109 of file AnalysisTree_module.cc.


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