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;
53 for (
const std::string& branch : branchesToFilter) {
54 if (excludeBranchSet.count(branch))
56 if (branchSet.empty() or branchSet.count(branch))
59 std::set<std::string> excluderelations;
60 if (!excludeBranchSet.empty()) {
62 for (
const std::string& from : branchesToFilter) {
63 for (
const std::string& to : branchesToFilter) {
65 if (out.count(branch) == 0)
67 if (excludeBranchSet.count(from) == 0 and excludeBranchSet.count(to) == 0)
69 if (branchSet.count(branch) != 0)
71 excluderelations.insert(branch);
74 for (
const std::string& rel : excluderelations) {
79 std::set<std::string> relations;
80 for (
const std::string& from : out) {
81 for (
const std::string& to : out) {
83 if (branchesToFilter.count(branch) == 0)
85 if (excludeBranchSet.count(branch))
87 relations.insert(branch);
90 out.insert(relations.begin(), relations.end());
97 std::queue<TBranch*> branches;
98 branches.emplace(branch);
99 while (!branches.empty()) {
101 auto* current = branches.front();
104 if (process) current->ResetBit(kDoNotProcess);
105 else current->SetBit(kDoNotProcess);
107 auto* children = current->GetListOfBranches();
108 const auto nchildren = children->GetEntriesFast();
109 for (
int i = 0; i < nchildren; ++i) {
110 branches.emplace(
dynamic_cast<TBranch*
>(children->UncheckedAt(i)));
118 std::vector<std::string> out;
119 wordexp_t expansions;
120 wordexp(
"", &expansions, 0);
121 for (
const std::string& pattern : filenames) {
122 if (wordexp(pattern.c_str(), &expansions, WRDE_APPEND | WRDE_NOCMD | WRDE_UNDEF) != 0) {
123 B2ERROR(
"Failed to expand pattern '" << pattern <<
"'!");
126 out.resize(expansions.we_wordc);
127 for (
unsigned int i = 0; i < expansions.we_wordc; i++) {
128 out[i] = expansions.we_wordv[i];
130 wordfree(&expansions);
137 const long major = 1000000 * experiment + run;
138 const long minor = event;
140 if (!tree->GetTreeIndex()) {
141 B2DEBUG(100,
"No TTreeIndex found, rebuild it...");
144 long entry = tree->GetEntryNumberWithIndex(major, minor);
148 B2DEBUG(100,
"Couldn't find entry (" << event <<
", " << run <<
", " << experiment <<
") in file! (major index: " << major <<
149 ", minor index: " << minor <<
")");
156 std::string treeName = tree->GetName();
157 TBranch*
const EventMetaDataBranch = tree->GetBranch(
"EventMetaData");
158 if ((strcmp(treeName.c_str(),
"tree") == 0) && EventMetaDataBranch) {
159 tree->BuildIndex(
"1000000*EventMetaData.m_experiment+EventMetaData.m_run",
"EventMetaData.m_event");
163 std::string key =
"1000000*" + treeName +
".__experiment__+" + treeName +
".__run__";
164 std::string
event = treeName +
".__event__";
165 tree->BuildIndex(key.c_str(), event.c_str());
171 if (cl == TObject::Class())
174 if (cl->GetClassVersion() <= 0) {
176 TList* baseClasses =
const_cast<TClass*
>(cl)->GetListOfBases();
177 TIter it(baseClasses);
178 while (
auto* base =
static_cast<TBaseClass*
>(it())) {
193 return cl->HasCustomStreamerMember();
200 auto now = time(
nullptr);
201 strftime(date, 100,
"%Y-%m-%d %H:%M:%S", gmtime(&now));
202 const char* belle2_site = getenv(
"BELLE2_SITE");
207 gethostname(hostname, 1023);
208 hostname[1023] =
'\0';
211 const char* user = getenv(
"BELLE2_USER");
212 if (!user) user = getenv(
"USER");
213 if (!user) user = getlogin();
214 if (!user) user =
"unknown";
228 [&name](
const std::string & s) {
return s == name; });
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.
bool isReservedTreeName(const std::string &name)
Check whether a tree name is a reserved basf2 tree name as defined in RootIOUtilities::c_treeNames.
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 either EventMetaData branch exists or is a ntuple tree).
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.