1 #include <boost/regex.hpp>
4 #include "TEveTreeTools.h"
41 m_globalTag(
"gt_undef"),
42 m_globalEventList(nullptr) {
48 delete (*i)->m_eventList;
54 gErrorIgnoreLevel = 3000;
56 TFile* newFile = TFile::Open(
m_name.c_str());
58 if (newFile ==
nullptr || newFile->IsZombie() || !newFile->Get(
"Events")) {
61 throw std::runtime_error(
"Invalid file. Ignored.");
66 gErrorIgnoreLevel = -1;
69 typedef std::vector<edm::ProcessHistory> provList;
71 TTree* metaData =
dynamic_cast<TTree*
>(
m_file->Get(
"MetaData"));
72 TBranch*
b = metaData->GetBranch(
"ProcessHistory");
75 metaData->SetBranchAddress(
"ProcessHistory", &pPhv);
79 typedef std::map<edm::ParameterSetID, edm::ParameterSetBlob>
ParameterSetMap;
81 TTree* psetTree =
dynamic_cast<TTree*
>(newFile->Get(
"ParameterSets"));
82 typedef std::pair<edm::ParameterSetID, edm::ParameterSetBlob> IdToBlobs;
84 IdToBlobs* pIdToBlob = &idToBlob;
85 psetTree->SetBranchAddress(
"IdToParameterSetsBlobs", &pIdToBlob);
86 for (
long long i = 0;
i != psetTree->GetEntries(); ++
i) {
87 psetTree->GetEntry(
i);
88 psm_.insert(idToBlob);
92 for (
auto const&
item : psm_) {
99 int latestVersion = 0;
100 int currentVersionArr[] = {0, 0, 0};
101 for (
auto const& processHistory : phv_) {
106 int nvv = currentVersionArr[0] * 100 + currentVersionArr[1] * 10 + currentVersionArr[2];
107 if (nvv > latestVersion) {
115 if (checkGlobalTag) {
116 std::map<edm::ProcessConfigurationID, unsigned int> simpleIDs;
118 for (
auto const& ph : phv_) {
119 for (
auto const& pc : ph) {
120 unsigned int id = simpleIDs[pc.id()];
123 simpleIDs[pc.id()] =
id;
125 ParameterSetMap::const_iterator itFind = psm_.find(pc.parameterSetID());
126 if (itFind == psm_.end()) {
127 std::cout <<
"No ParameterSetID for " << pc.parameterSetID() << std::endl;
128 fwLog(
fwlog::kInfo) <<
"FWFileEntry::openFile no ParameterSetID for " << pc.parameterSetID() << std::endl;
131 std::vector<std::string> sourceStrings, moduleStrings;
132 std::vector<std::string> sources = processConfig.
getParameter<std::vector<std::string>>(
"@all_essources");
133 for (
auto& itM : sources) {
139 if (name !=
"GlobalTag")
142 for (
auto const&
item : pset.
tbl()) {
143 if (
item.first ==
"globaltag") {
163 b->SetAddress(
nullptr);
168 "incompatible data: Process version does not mactch major data formats version. File produced with %s. "
169 "Data formats version \"CMSSW_%d_%d_%d\".\n",
174 msg +=
"Use --no-version-check option if you still want to view the file.\n";
175 throw std::runtime_error(msg.Data());
178 TString
msg =
"No process history available\n";
179 msg +=
"Use --no-version-check option if you still want to view the file.\n";
180 throw std::runtime_error(msg.Data());
187 throw std::runtime_error(
"Cannot find TTree 'Events' in the data file");
192 printf(
"FWFileEntry::openFile enabling FWTTreeCache for file class '%s'.",
m_file->ClassName());
197 tc->SetLearnEntries(20);
198 tc->SetLearnPrefill(TTreeCache::kAllBranches);
199 tc->StartLearningPhase();
211 throw std::runtime_error(
"fwlite::Event size == 0");
216 printf(
"Reading %lld bytes in %d transactions.\n",
m_file->GetBytesRead(),
m_file->GetReadCalls());
256 Long64_t
val = tree_entry;
270 Long64_t
val = tree_entry;
272 if (list[idx] == val)
283 if ((*it)->m_selector->m_enabled)
301 if ((*it)->m_selector->m_enabled && (*it)->m_needsUpdate) {
306 if ((*it)->m_selector->m_enabled) {
307 if ((*it)->hasSelectedEvents()) {
313 }
else if (!globalOR) {
336 std::vector<std::string> branch_names;
349 boost::regex re(
std::string(
"\\$") + (*i)->name());
351 if (boost::regex_search(interpretedSelection, re)) {
359 interpretedSelection = boost::regex_replace(interpretedSelection, re, fullBranchName +
".obj");
361 branch_names.push_back(fullBranchName);
370 std::size_t
found = interpretedSelection.find(
'$');
371 if (found != std::string::npos) {
372 fwLog(
fwlog::kError) <<
"FWFileEntry::RunFilter invalid expression " << interpretedSelection << std::endl;
382 auto interCache =
new TTreeCache(
m_eventTree, 10 * 1024 * 1024);
386 for (
auto&
b : branch_names)
387 interCache->AddBranch(
b.c_str(),
true);
388 interCache->StopLearningPhase();
394 std::map<TBranch*, void*> prevAddrs;
397 TObjArray* branches =
m_eventTree->GetListOfBranches();
398 std::unique_ptr<TIterator> pIt(branches->MakeIterator());
399 while (TObject* branchObj = pIt->Next()) {
400 TBranch*
b =
dynamic_cast<TBranch*
>(branchObj);
402 const char*
name = b->GetName();
403 unsigned int length = strlen(name);
404 if (length > 1 && name[length - 1] !=
'.') {
408 if (
nullptr != b->GetAddress()) {
409 if (prevAddrs.find(b) != prevAddrs.end()) {
412 prevAddrs.insert(std::make_pair(b, b->GetAddress()));
415 b->SetAddress(
nullptr);
426 fwLog(
fwlog::kInfo) <<
"FWFileEntry::runFilter Running filter " << interpretedSelection <<
"' "
427 <<
"for file '" <<
m_file->GetName() <<
"'.\n";
429 TEveSelectorToEventList stoelist(filter->
m_eventList, interpretedSelection.c_str());
438 <<
"] events selected" << std::endl;
442 for (
auto i : prevAddrs) {
444 i.first->SetAddress(
i.second);
459 boost::regex re_spaces(
"\\s+");
460 selection = boost::regex_replace(selection, re_spaces,
"");
461 if (selection.find(
"&&") != std::string::npos && selection.find(
"||") != std::string::npos) {
482 bool junction_mode =
true;
483 if (selection.find(
"||") != std::string::npos)
484 junction_mode =
false;
486 boost::regex re(
"\\&\\&|\\|\\|");
488 boost::sregex_token_iterator
i(selection.begin(), selection.end(), re, -1);
489 boost::sregex_token_iterator
j;
492 std::vector<std::pair<unsigned int, bool>>
filters;
497 if (filter[0] ==
'!') {
499 filter.erase(filter.begin());
502 if (index == triggerNames->
size()) {
506 filters.push_back(std::make_pair(index, flag));
523 std::vector<std::pair<unsigned int, bool>>::const_iterator
filter = filters.begin();
524 bool passed = hTriggerResults->
accept(filter->first) == filter->second;
525 while (++filter != filters.end()) {
527 passed &= hTriggerResults->
accept(filter->first) == filter->second;
529 passed |= hTriggerResults->
accept(filter->first) == filter->second;
549 assert(tc !=
nullptr &&
"FWFileEntry::treeCache can not access TTreeCache");
564 printf(
"FWFileEntry:NewEventItemCallIn FWEventItem %s, learning=%d\n",
getBranchName(it).c_str(), tc->IsLearning());
573 printf(
"FWFileEntry:RemovingEventItemCallIn FWEventItem %s, learning=%d\n",
std::vector< ProcessHistory > ProcessHistoryVector
fireworks::Context * getContext()
FWEventSelector * m_selector
Event const & toBegin() override
Go to the very first Event.
FWFileEntry(const std::string &name, bool checkVersion, bool checkGlobalTag)
uint16_t *__restrict__ id
const FWEventItemsManager * eventItemsManager() const
void setEvent(const edm::EventBase *iEvent)
void RemovingEventItemCallIn(const FWEventItem *it)
bool accept() const
Has at least one path accepted the event?
std::string getBranchName(const FWEventItem *it) const
FWTEventList * m_eventList
void getPrimaryData() const
unsigned int triggerIndex(std::string_view name) const
std::string m_triggerProcess
void getDecomposedVersion(const TString &s, int *out)
const std::string & processName() const
Long64_t size() const
Returns number of events in the file.
bool isEventSelected(int event)
static TypeWithDict byName(std::string const &name)
std::string const & processName() const
const std::string & productInstanceLabel() const
std::list< Filter * > m_filterEntries
int * supportedDataFormatsVersion()
edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const override
const TClass * type() const
printf("params %d %f %f %f\n", minT, eps, errmax, chi2max)
static bool IsPrefetching()
sigc::signal< void, FWEventItem * > newItem_
bool filterEventsWithCustomParser(Filter *filter)
bool to(Long64_t iIndex)
Go to the event at index iIndex.
bool insertMapped(value_type const &v, bool forceUpdate=false)
std::type_info const & typeInfo() const
bool atEnd() const override
std::list< Filter * > & filters()
static int GetDefaultCacheSize()
void openFile(bool, bool)
std::string const getBranchNameFor(std::type_info const &, char const *iModuleLabel, char const *iProductInstanceLabel, char const *iProcessName) const override
Return the branch name in the TFile which contains the data.
const_iterator begin() const
NOTE: iterator is allowed to return a null object for items that have been removed.
static FWGUIManager * getGUIManager()
ReleaseVersion const & releaseVersion() const
std::string wrappedClassName(std::string const &iFullName)
T getParameter(std::string const &) const
void runFilter(Filter *fe, const FWEventItemsManager *eiMng)
void getByLabel(const P &iP, const char *iModuleLabel, const char *iProductInstanceLabel=nullptr, const char *iProcessLabel=nullptr)
std::map< ParameterSetID, ParameterSetBlob > ParameterSetMap
int nextSelectedEvent(int event)
bool acceptDataFormatsVersion(TString &n)
void updateFilters(const FWEventItemsManager *eiMng, bool isOR)
FWTTreeCache * fwTreeCache()
void Enter(Long64_t entry) override
FWTEventList * m_globalEventList
table const & tbl() const
int previousSelectedEvent(int event)
void Add(const TEventList *list) override
std::vector< FWEventItem * >::const_iterator const_iterator
void NewEventItemCallIn(const FWEventItem *it)
const std::string & moduleLabel() const
static Registry * instance()
const_iterator end() const