8 #include <framework/io/RootIOUtilities.h> 
   10 #include <framework/datastore/DataStore.h> 
   11 #include <framework/dataobjects/FileMetaData.h> 
   12 #include <framework/logging/Logger.h> 
   18 #include <TBaseClass.h> 
   33                                                       const std::vector<std::string>& branches,
 
   34                                                       const std::vector<std::string>& excludeBranches, 
int durability, 
bool quiet)
 
   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)
 
   43   for (
const std::string& b : excludeBranches) {
 
   46     if (branchesToFilter.count(b) == 0 and not quiet and b != 
"ProcessStatistics")
 
   48     if (!excludeBranchSet.insert(b).second and not quiet)
 
   52   std::set<std::string> out, relations, excluderelations;
 
   53   for (
const std::string& branch : branchesToFilter) {
 
   54     if (excludeBranchSet.count(branch))
 
   56     if (branchSet.empty() or branchSet.count(branch))
 
   59   if (!excludeBranchSet.empty()) {
 
   61     for (
const std::string& from : branchesToFilter) {
 
   62       for (
const std::string& to : branchesToFilter) {
 
   64         if (out.count(branch) == 0)
 
   66         if (excludeBranchSet.count(from) == 0 and excludeBranchSet.count(to) == 0)
 
   68         if (branchSet.count(branch) != 0)
 
   70         excluderelations.insert(branch);
 
   73     for (
const std::string& rel : excluderelations) {
 
   78   for (
const std::string& from : out) {
 
   79     for (
const std::string& to : out) {
 
   81       if (branchesToFilter.count(branch) == 0)
 
   83       if (excludeBranchSet.count(branch))
 
   85       relations.insert(branch);
 
   88   out.insert(relations.begin(), relations.end());
 
   95   std::queue<TBranch*> branches;
 
   96   branches.emplace(branch);
 
   97   while (!branches.empty()) {
 
   99     auto* current = branches.front();
 
  102     if (process) current->ResetBit(kDoNotProcess);
 
  103     else current->SetBit(kDoNotProcess);
 
  105     auto* children = current->GetListOfBranches();
 
  106     const auto nchildren = children->GetEntriesFast();
 
  107     for (
int i = 0; i < nchildren; ++i) {
 
  108       branches.emplace(
dynamic_cast<TBranch*
>(children->UncheckedAt(i)));
 
  116   std::vector<std::string> out;
 
  117   wordexp_t expansions;
 
  118   wordexp(
"", &expansions, 0);
 
  119   for (
const std::string& pattern : filenames) {
 
  120     if (wordexp(pattern.c_str(), &expansions, WRDE_APPEND | WRDE_NOCMD | WRDE_UNDEF) != 0) {
 
  121       B2ERROR(
"Failed to expand pattern '" << pattern << 
"'!");
 
  124   out.resize(expansions.we_wordc);
 
  125   for (
unsigned int i = 0; i < expansions.we_wordc; i++) {
 
  126     out[i] = expansions.we_wordv[i];
 
  128   wordfree(&expansions);
 
  135   const long major = 1000000 * experiment + run;
 
  136   const long minor = event;
 
  138   if (!tree->GetTreeIndex()) {
 
  139     B2DEBUG(100, 
"No TTreeIndex found, rebuild it...");
 
  142   long entry = tree->GetEntryNumberWithIndex(major, minor);
 
  146     B2DEBUG(100, 
"Couldn't find entry (" << event << 
", " << run << 
", " << experiment << 
") in file! (major index: " << major <<
 
  147             ", minor index: " << minor << 
")");
 
  154   tree->BuildIndex(
"1000000*EventMetaData.m_experiment+EventMetaData.m_run", 
"EventMetaData.m_event");
 
  159   if (cl == TObject::Class())
 
  162   if (cl->GetClassVersion() <= 0) {
 
  164     TList* baseClasses = 
const_cast<TClass*
>(cl)->GetListOfBases(); 
 
  165     TIter it(baseClasses);
 
  166     while (
auto* base = 
static_cast<TBaseClass*
>(it())) {
 
  181   return cl->TestBit(TClass::kHasCustomStreamerMember);
 
  188   auto now = time(
nullptr);
 
  189   strftime(date, 100, 
"%Y-%m-%d %H:%M:%S", gmtime(&now));
 
  190   const char* belle2_site = getenv(
"BELLE2_SITE");
 
  195     gethostname(hostname, 1023); 
 
  196     hostname[1023] = 
'\0'; 
 
  199   const char* user = getenv(
"BELLE2_USER");
 
  200   if (!user) user = getenv(
"USER");
 
  201   if (!user) user = getlogin();
 
  202   if (!user) user = 
"unknown";
 
  204   metadata.setCreationData(date, site, user, commitid);
 
static std::string relationName(const std::string &fromName, const std::string &toName, std::string const &namedRelation="")
Return storage name for a relation between two arrays of the given names.
bool hasCustomStreamer(const TClass *cl)
Returns true if and only if 'cl' has a user-defined streamer.
const std::string c_treeNames[]
Names of trees.
const std::string c_SteerExcludeBranchNames[]
Steering parameter names for m_excludeBranchNames.
std::string getCommitID()
Return git SHA1 hashes taking into account local & central release.
std::vector< std::string > expandWordExpansions(const std::vector< std::string > &filenames)
Performs wildcard expansion using wordexp(), returns matches.
const std::string c_SteerBranchNames[]
Steering parameter names for m_branchNames.
void setCreationData(FileMetaData &metadata)
Fill the creation info of a file meta data: site, user, data.
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 t...
const std::string c_SteerAdditionalBranchNames[]
Steering parameter names for m_additionalBranchNames.
long getEntryNumberWithEvtRunExp(TTree *tree, long event, long run, long experiment)
return entry number with given (event, run, experiment) from tree.
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.
size_t setBranchStatus(TBranch *branch, bool process)
Set Branch to be read or not.
Abstract base class for different kinds of events.