1 #include <boost/regex.hpp> 4 #include "TEveTreeTools.h" 41 m_globalTag(
"gt_undef"),
42 m_globalEventList(nullptr) {
48 delete (*i)->m_eventList;
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.");
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_) {
102 for (
auto const& processConfiguration : processHistory) {
104 TString dcv = processConfiguration.releaseVersion();
106 int nvv = currentVersionArr[0] * 100 + currentVersionArr[1] * 10 + currentVersionArr[2];
107 if (nvv > latestVersion) {
109 dd = &processConfiguration;
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");
139 if (
name !=
"GlobalTag")
142 for (
auto const&
item :
pset.tbl()) {
143 if (
item.first ==
"globaltag") {
161 <<
"\", version " <<
dd->releaseVersion() << std::endl;
163 b->SetAddress(
nullptr);
164 TString
v =
dd->releaseVersion();
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",
170 dd->releaseVersion().c_str(),
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;
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) {
328 if (!
filter->m_selector->m_triggerProcess.empty()) {
336 std::vector<std::string> branch_names;
343 if (!
item->hasEvent()) {
345 item->getPrimaryData();
346 item->setEvent(
nullptr);
349 boost::regex re(
std::string(
"\\$") + (*i)->name());
351 if (boost::regex_search(interpretedSelection, re)) {
355 item->moduleLabel().c_str(),
356 item->productInstanceLabel().c_str(),
357 item->processName().c_str());
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;
373 filter->m_needsUpdate =
false;
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);
422 filter->m_eventList->Reset();
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());
434 <<
filter->m_selector->m_expression <<
"] is invalid." << std::endl;
437 <<
filter->m_selector->m_expression <<
"] has [" <<
filter->m_eventList->GetN()
438 <<
"] events selected" << std::endl;
442 for (
auto i : prevAddrs) {
444 i.first->SetAddress(
i.second);
451 filter->m_needsUpdate =
false;
459 boost::regex re_spaces(
"\\s+");
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(
"\\&\\&|\\|\\|");
489 boost::sregex_token_iterator
j;
492 std::vector<std::pair<unsigned int, bool>>
filters;
523 std::vector<std::pair<unsigned int, bool>>::const_iterator
filter =
filters.begin();
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
bool accept() const
Has at least one path accepted the event?
fireworks::Context * getContext()
FWEventSelector * m_selector
FWFileEntry(const std::string &name, bool checkVersion, bool checkGlobalTag)
sigc::signal< void(FWEventItem *)> newItem_
const FWEventItemsManager * eventItemsManager() const
edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const override
void RemovingEventItemCallIn(const FWEventItem *it)
FWTEventList * m_eventList
std::string m_triggerProcess
const std::string & processName() const
void getDecomposedVersion(const TString &s, int *out)
const std::string & moduleLabel() const
bool isEventSelected(int event)
static TypeWithDict byName(std::string const &name)
std::list< Filter * > m_filterEntries
int * supportedDataFormatsVersion()
static bool IsPrefetching()
std::string getBranchName(const FWEventItem *it) const
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)
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.
Event const & toBegin() override
Go to the very first Event.
static FWGUIManager * getGUIManager()
std::type_info const & typeInfo() const
const TClass * type() const
std::string wrappedClassName(std::string const &iFullName)
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()
const_iterator begin() const
NOTE: iterator is allowed to return a null object for items that have been removed.
void Enter(Long64_t entry) override
FWTEventList * m_globalEventList
const_iterator end() const
const std::string & productInstanceLabel() const
int previousSelectedEvent(int event)
Long64_t size() const
Returns number of events in the file.
void Add(const TEventList *list) override
std::vector< FWEventItem * >::const_iterator const_iterator
void NewEventItemCallIn(const FWEventItem *it)
static Registry * instance()