Belle II Software  release-08-01-10
Belle2::RootIOUtilities Namespace Reference

Some constants and helpers common to the RootInput and RootOutput modules. More...

Classes

class  RootFileInfo
 Helper class to factorize some necessary tasks when working with Belle2 output files. More...
 

Functions

std::set< std::string > filterBranches (const std::set< std::string > &branchesToFilter, const std::vector< std::string > &branches, const std::vector< std::string > &excludeBranches, int durability, bool quiet=false)
 Given a list of input branches and lists of branches to include/exclude, returns a list of branches that are accepted. More...
 
size_t setBranchStatus (TBranch *branch, bool process)
 Set Branch to be read or not. More...
 
std::vector< std::string > expandWordExpansions (const std::vector< std::string > &filenames)
 Performs wildcard expansion using wordexp(), returns matches.
 
long getEntryNumberWithEvtRunExp (TTree *tree, long event, long run, long experiment)
 return entry number with given (event, run, experiment) from tree. More...
 
void buildIndex (TTree *tree)
 Build TTreeIndex on tree (assumes EventMetaData branch exists there).
 
bool hasStreamer (const TClass *cl)
 Returns true if and only if 'cl' or one of its bases has I/O streamers. More...
 
bool hasCustomStreamer (const TClass *cl)
 Returns true if and only if 'cl' has a user-defined streamer. More...
 
void setCreationData (FileMetaData &metadata)
 Fill the creation info of a file meta data: site, user, data.
 
std::string getCommitID ()
 Return git SHA1 hashes taking into account local & central release. More...
 

Variables

const std::string c_treeNames [] = { "tree", "persistent" }
 Names of trees.
 
const std::string c_SteerBranchNames [] = { "branchNames", "branchNamesPersistent" }
 Steering parameter names for m_branchNames.
 
const std::string c_SteerExcludeBranchNames [] = { "excludeBranchNames", "excludeBranchNamesPersistent" }
 Steering parameter names for m_excludeBranchNames.
 
const std::string c_SteerAdditionalBranchNames [] = { "additionalBranchNames", "additionalBranchNamesPersistent" }
 Steering parameter names for m_additionalBranchNames.
 

Detailed Description

Some constants and helpers common to the RootInput and RootOutput modules.

Function Documentation

◆ filterBranches()

std::set< std::string > filterBranches ( const std::set< std::string > &  branchesToFilter,
const std::vector< std::string > &  branches,
const std::vector< std::string > &  excludeBranches,
int  durability,
bool  quiet = false 
)

Given a list of input branches and lists of branches to include/exclude, returns a list of branches that are accepted.

More precisely, an item b from 'branchesToFilter' will be in the returned set if b not in excludeBranches and (b in branches or empty(branches) or b in relationsBetweenAcceptedBranches) and b not in relationsInvolvingExcludedBranches

Parameters
branchesToFilterinput
branchesif not empty, the list of branches to be accepted
excludeBranchesbranches that should never end up in output (takes precedence over everything else)
durabilityDurability being filtered (used for messages only)
quietIf true don't warn about branches which are missing/extra/duplicate in the lists

Definition at line 32 of file RootIOUtilities.cc.

35 {
36  std::set<std::string> branchSet, excludeBranchSet;
37  for (const std::string& b : branches) {
38  if (branchesToFilter.count(b) == 0 and not quiet)
39  B2WARNING("The branch " << b << " given in " << c_SteerBranchNames[durability] << " does not exist.");
40  if (!branchSet.insert(b).second and not quiet)
41  B2WARNING(c_SteerBranchNames[durability] << " has duplicate entry " << b);
42  }
43  for (const std::string& b : excludeBranches) {
44  // FIXME: ProcessStatistics is excluded by default but not always present. We should switch that to not write it out
45  // in the first place but the info message is meaningless for almost everyone
46  if (branchesToFilter.count(b) == 0 and not quiet and b != "ProcessStatistics")
47  B2INFO("The branch " << b << " given in " << c_SteerExcludeBranchNames[durability] << " does not exist.");
48  if (!excludeBranchSet.insert(b).second and not quiet)
49  B2WARNING(c_SteerExcludeBranchNames[durability] << " has duplicate entry " << b);
50  }
51 
52  std::set<std::string> out, relations, excluderelations;
53  for (const std::string& branch : branchesToFilter) {
54  if (excludeBranchSet.count(branch))
55  continue;
56  if (branchSet.empty() or branchSet.count(branch))
57  out.insert(branch);
58  }
59  if (!excludeBranchSet.empty()) {
60  //remove relations for excluded things
61  for (const std::string& from : branchesToFilter) {
62  for (const std::string& to : branchesToFilter) {
63  std::string branch = DataStore::relationName(from, to);
64  if (out.count(branch) == 0)
65  continue; //not selected
66  if (excludeBranchSet.count(from) == 0 and excludeBranchSet.count(to) == 0)
67  continue; //at least one side should be excluded
68  if (branchSet.count(branch) != 0)
69  continue; //specifically included
70  excluderelations.insert(branch);
71  }
72  }
73  for (const std::string& rel : excluderelations) {
74  out.erase(rel);
75  }
76  }
77  //add relations between accepted branches
78  for (const std::string& from : out) {
79  for (const std::string& to : out) {
80  std::string branch = DataStore::relationName(from, to);
81  if (branchesToFilter.count(branch) == 0)
82  continue; //not in input
83  if (excludeBranchSet.count(branch))
84  continue;
85  relations.insert(branch);
86  }
87  }
88  out.insert(relations.begin(), relations.end());
89  return out;
90 }

◆ getCommitID()

std::string getCommitID ( )

Return git SHA1 hashes taking into account local & central release.

ID is a combined hash $CENTRAL_SHA1[+$LOCAL_SHA1][-modified], or just SHA1[-modified] if only one release or they are on the same revision. Empty string denotes at least one untracked release directory.

Definition at line 207 of file RootIOUtilities.cc.

◆ getEntryNumberWithEvtRunExp()

long getEntryNumberWithEvtRunExp ( TTree *  tree,
long  event,
long  run,
long  experiment 
)

return entry number with given (event, run, experiment) from tree.

Returns -1 if not found.

Definition at line 133 of file RootIOUtilities.cc.

◆ hasCustomStreamer()

bool hasCustomStreamer ( const TClass *  cl)

Returns true if and only if 'cl' has a user-defined streamer.

In that case, TClonesArrays of this type should be written with BypassStreamer(false) and split-level -1 (no splitting).

Definition at line 178 of file RootIOUtilities.cc.

◆ hasStreamer()

bool hasStreamer ( const TClass *  cl)

Returns true if and only if 'cl' or one of its bases has I/O streamers.

TObject is not considered to have any.

Definition at line 157 of file RootIOUtilities.cc.

◆ setBranchStatus()

size_t setBranchStatus ( TBranch *  branch,
bool  process 
)

Set Branch to be read or not.

TTree::SetBranchAddress doesn't do what we want it to do because our branch names seem to not be conform to their expectations. But we don't need to use name matching, we know our structure and it's simple enough so we just recursively go through the branch and all children and set processing on or off.

Parameters
branchThe branch to change the status for
processWhether or not to read/process this branch
Returns
the number of branches enabled/disabled

Definition at line 92 of file RootIOUtilities.cc.