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

Constructor & Destructor Documentation

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

Member Function Documentation

void sbnd::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 741 of file sbndcode/sbndcode/AnalysisTree/AnalysisTree_module.cc.

742  {
743  if (!pTree) return;
744  TBranch* pBranch = pTree->GetBranch(name.c_str());
745  if (!pBranch) {
746  pTree->Branch(name.c_str(), address, leaflist.c_str() /*, bufsize */);
747  MF_LOG_DEBUG("AnalysisTreeStructure")
748  << "Creating branch '" << name << " with leaf '" << leaflist << "'";
749  }
750  else if (pBranch->GetAddress() != address) {
751  pBranch->SetAddress(address);
752  MF_LOG_DEBUG("AnalysisTreeStructure")
753  << "Reassigning address to branch '" << name << "'";
754  }
755  else {
756  MF_LOG_DEBUG("AnalysisTreeStructure")
757  << "Branch '" << name << "' is fine";
758  }
759  } // operator()
then echo fcl name
void sbnd::AnalysisTreeDataStruct::BranchCreator::operator() ( std::string  name,
void *  address,
const std::stringstream &  leaflist 
)
inline

Definition at line 761 of file sbndcode/sbndcode/AnalysisTree/AnalysisTree_module.cc.

762  { 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 sbnd::AnalysisTreeDataStruct::BranchCreator::operator() ( std::string  name,
std::vector< T > &  data,
std::string  leaflist 
)
inline

Definition at line 765 of file sbndcode/sbndcode/AnalysisTree/AnalysisTree_module.cc.

766  { 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 sbnd::AnalysisTreeDataStruct::BranchCreator::operator() ( std::string  name,
std::vector< T > &  data 
)
inline

Definition at line 769 of file sbndcode/sbndcode/AnalysisTree/AnalysisTree_module.cc.

770  {
771  // overload for a generic object expressed directly by reference
772  // (as opposed to a generic object expressed by a pointer or
773  // to a simple leaf sequence specification);
774  // TTree::Branch(name, T* obj, Int_t bufsize, splitlevel) and
775  // TTree::SetObject() are used.
776  if (!pTree) return;
777  TBranch* pBranch = pTree->GetBranch(name.c_str());
778  if (!pBranch) {
779  pTree->Branch(name.c_str(), &data);
780  // ROOT needs a TClass definition for T in order to create a branch,
781  // se we are sure that at this point the TClass exists
782  MF_LOG_DEBUG("AnalysisTreeStructure")
783  << "Creating object branch '" << name
784  << " with " << TClass::GetClass(typeid(T))->ClassName();
785  }
786  else if
787  (*(reinterpret_cast<std::vector<T>**>(pBranch->GetAddress())) != &data)
788  {
789  // when an object is provided directly, the address of the object
790  // is assigned in TBranchElement::fObject (via TObject::SetObject())
791  // and the address itself is set to the address of the fObject
792  // member. Here we check that the address of the object in fObject
793  // is the same as the address of our current data type
794  pBranch->SetObject(&data);
795  MF_LOG_DEBUG("AnalysisTreeStructure")
796  << "Reassigning object to branch '" << name << "'";
797  }
798  else {
799  MF_LOG_DEBUG("AnalysisTreeStructure")
800  << "Branch '" << name << "' is fine";
801  }
802  } // operator()
then echo fcl name

Member Data Documentation

TTree* sbnd::AnalysisTreeDataStruct::BranchCreator::pTree

the tree to be worked on

Definition at line 735 of file sbndcode/sbndcode/AnalysisTree/AnalysisTree_module.cc.


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