Public Member Functions | Public Attributes | List of all members
dune::AnaRootParserDataStruct::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 1264 of file AnaRootParser_module.cc.

Constructor & Destructor Documentation

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

Definition at line 1267 of file AnaRootParser_module.cc.

Member Function Documentation

void dune::AnaRootParserDataStruct::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 1272 of file AnaRootParser_module.cc.

1273  {
1274 
1275  if (!pTree) return;
1276  TBranch* pBranch = pTree->GetBranch(name.c_str());
1277 
1278  if (!pBranch) {
1279  pTree->Branch(name.c_str(), address, leaflist.c_str() /*, bufsize */);
1280 
1281  MF_LOG_DEBUG("AnaRootParserStructure")
1282  << "Creating branch '" << name << " with leaf '" << leaflist << "'";
1283 
1284  }
1285  else if (pBranch->GetAddress() != address) {
1286  pBranch->SetAddress(address);
1287  MF_LOG_DEBUG("AnaRootParserStructure")
1288  << "Reassigning address to branch '" << name << "'";
1289  }
1290  else {
1291  MF_LOG_DEBUG("AnaRootParserStructure")
1292  << "Branch '" << name << "' is fine";
1293  }
1294  } // operator()
static QCString name
Definition: declinfo.cpp:673
#define MF_LOG_DEBUG(id)
void dune::AnaRootParserDataStruct::BranchCreator::operator() ( std::string  name,
void *  address,
const std::stringstream &  leaflist 
)
inline

Definition at line 1296 of file AnaRootParser_module.cc.

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

Definition at line 1300 of file AnaRootParser_module.cc.

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

Definition at line 1304 of file AnaRootParser_module.cc.

1305  {
1306  // overload for a generic object expressed directly by reference
1307  // (as opposed to a generic object expressed by a pointer or
1308  // to a simple leaf sequence specification);
1309  // TTree::Branch(name, T* obj, Int_t bufsize, splitlevel) and
1310  // TTree::SetObject() are used.
1311  if (!pTree) return;
1312  TBranch* pBranch = pTree->GetBranch(name.c_str());
1313  if (!pBranch) {
1314  pTree->Branch(name.c_str(), &data);
1315  // ROOT needs a TClass definition for T in order to create a branch,
1316  // se we are sure that at this point the TClass exists
1317  MF_LOG_DEBUG("AnaRootParserStructure")
1318  << "Creating object branch '" << name
1319  << " with " << TClass::GetClass(typeid(T))->ClassName();
1320  }
1321  else if
1322  (*(reinterpret_cast<std::vector<T>**>(pBranch->GetAddress())) != &data)
1323  {
1324  // when an object is provided directly, the address of the object
1325  // is assigned in TBranchElement::fObject (via TObject::SetObject())
1326  // and the address itself is set to the address of the fObject
1327  // member. Here we check that the address of the object in fObject
1328  // is the same as the address of our current data type
1329  pBranch->SetObject(&data);
1330  MF_LOG_DEBUG("AnaRootParserStructure")
1331  << "Reassigning object to branch '" << name << "'";
1332  }
1333  else {
1334  MF_LOG_DEBUG("AnaRootParserStructure")
1335  << "Branch '" << name << "' is fine";
1336  }
1337  } // operator()
static QCString name
Definition: declinfo.cpp:673
#define MF_LOG_DEBUG(id)

Member Data Documentation

TTree* dune::AnaRootParserDataStruct::BranchCreator::pTree

the tree to be worked on

Definition at line 1266 of file AnaRootParser_module.cc.


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