All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Public Attributes | List of all members
icarus::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 584 of file icaruscode/icaruscode/Analysis/AnalysisTree_module.cc.

Constructor & Destructor Documentation

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

Member Function Documentation

void icarus::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 592 of file icaruscode/icaruscode/Analysis/AnalysisTree_module.cc.

593  {
594  if (!pTree) return;
595  TBranch* pBranch = pTree->GetBranch(name.c_str());
596  if (!pBranch) {
597  pTree->Branch(name.c_str(), address, leaflist.c_str() /*, bufsize */);
598  MF_LOG_DEBUG("AnalysisTreeStructure")
599  << "Creating branch '" << name << " with leaf '" << leaflist << "'";
600  }
601  else if (pBranch->GetAddress() != address) {
602  pBranch->SetAddress(address);
603  MF_LOG_DEBUG("AnalysisTreeStructure")
604  << "Reassigning address to branch '" << name << "'";
605  }
606  else {
607  MF_LOG_DEBUG("AnalysisTreeStructure")
608  << "Branch '" << name << "' is fine";
609  }
610  } // operator()
then echo fcl name
void icarus::AnalysisTreeDataStruct::BranchCreator::operator() ( std::string  name,
void *  address,
const std::stringstream &  leaflist 
)
inline

Definition at line 612 of file icaruscode/icaruscode/Analysis/AnalysisTree_module.cc.

613  { return this->operator() (name, address, leaflist.str() /*, int bufsize = 32000 */); }
void operator()(std::string name, void *address, std::string leaflist)
Create a branch if it does not exist, and set its address.
then echo fcl name
template<typename T >
void icarus::AnalysisTreeDataStruct::BranchCreator::operator() ( std::string  name,
std::vector< T > &  data,
std::string  leaflist 
)
inline

Definition at line 616 of file icaruscode/icaruscode/Analysis/AnalysisTree_module.cc.

617  { return this->operator() (name, (void*) data.data(), leaflist /*, int bufsize = 32000 */); }
void operator()(std::string name, void *address, std::string leaflist)
Create a branch if it does not exist, and set its address.
then echo fcl name
template<typename T >
void icarus::AnalysisTreeDataStruct::BranchCreator::operator() ( std::string  name,
std::vector< T > &  data 
)
inline

Definition at line 620 of file icaruscode/icaruscode/Analysis/AnalysisTree_module.cc.

621  {
622  // overload for a generic object expressed directly by reference
623  // (as opposed to a generic object expressed by a pointer or
624  // to a simple leaf sequence specification);
625  // TTree::Branch(name, T* obj, Int_t bufsize, splitlevel) and
626  // TTree::SetObject() are used.
627  if (!pTree) return;
628  TBranch* pBranch = pTree->GetBranch(name.c_str());
629  if (!pBranch) {
630  pTree->Branch(name.c_str(), &data);
631  // ROOT needs a TClass definition for T in order to create a branch,
632  // se we are sure that at this point the TClass exists
633  MF_LOG_DEBUG("AnalysisTreeStructure")
634  << "Creating object branch '" << name
635  << " with " << TClass::GetClass(typeid(T))->ClassName();
636  }
637  else if
638  (*(reinterpret_cast<std::vector<T>**>(pBranch->GetAddress())) != &data)
639  {
640  // when an object is provided directly, the address of the object
641  // is assigned in TBranchElement::fObject (via TObject::SetObject())
642  // and the address itself is set to the address of the fObject
643  // member. Here we check that the address of the object in fObject
644  // is the same as the address of our current data type
645  pBranch->SetObject(&data);
646  MF_LOG_DEBUG("AnalysisTreeStructure")
647  << "Reassigning object to branch '" << name << "'";
648  }
649  else {
650  MF_LOG_DEBUG("AnalysisTreeStructure")
651  << "Branch '" << name << "' is fine";
652  }
653  } // operator()
then echo fcl name

Member Data Documentation

TTree* icarus::AnalysisTreeDataStruct::BranchCreator::pTree

the tree to be worked on

Definition at line 586 of file icaruscode/icaruscode/Analysis/AnalysisTree_module.cc.


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