CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Private Member Functions | Private Attributes
FWFileEntry Class Reference

#include <FWFileEntry.h>

Classes

struct  Filter
 

Public Member Functions

void closeFile ()
 
fwlite::Eventevent ()
 
TFile * file ()
 
std::list< Filter * > & filters ()
 
int firstSelectedEvent ()
 
 FWFileEntry (const std::string &name, bool checkVersion, bool checkGlobalTag)
 
FWTTreeCachefwTreeCache ()
 
const std::string & getGlobalTag () const
 
FWTEventListglobalSelection ()
 
bool hasActiveFilters ()
 
bool hasSelectedEvents ()
 
bool isEventSelected (int event)
 
int lastEvent ()
 
int lastSelectedEvent ()
 
void needUpdate ()
 
void NewEventItemCallIn (const FWEventItem *it)
 
int nextSelectedEvent (int event)
 
void openFile (bool, bool)
 
int previousSelectedEvent (int event)
 
void RemovingEventItemCallIn (const FWEventItem *it)
 
TTree * tree ()
 
void updateFilters (const FWEventItemsManager *eiMng, bool isOR)
 
virtual ~FWFileEntry ()
 

Private Member Functions

bool filterEventsWithCustomParser (Filter *filter)
 
 FWFileEntry (const FWFileEntry &)=delete
 
std::string getBranchName (const FWEventItem *it) const
 
const FWFileEntryoperator= (const FWFileEntry &)=delete
 
void runFilter (Filter *fe, const FWEventItemsManager *eiMng)
 

Private Attributes

fwlite::Eventm_event
 
TTree * m_eventTree
 
TFile * m_file
 
std::list< Filter * > m_filterEntries
 
FWTEventListm_globalEventList
 
std::string m_globalTag
 
std::string m_name
 
bool m_needUpdate
 

Detailed Description

Definition at line 36 of file FWFileEntry.h.

Constructor & Destructor Documentation

◆ FWFileEntry() [1/2]

FWFileEntry::FWFileEntry ( const std::string &  name,
bool  checkVersion,
bool  checkGlobalTag 
)

Definition at line 35 of file FWFileEntry.cc.

36  : m_name(name),
37  m_file(nullptr),
38  m_eventTree(nullptr),
39  m_event(nullptr),
40  m_needUpdate(true),
41  m_globalTag("gt_undef"),
42  m_globalEventList(nullptr) {
43  openFile(checkVersion, checkGT);
44 }

References openFile().

◆ ~FWFileEntry()

FWFileEntry::~FWFileEntry ( )
virtual

Definition at line 46 of file FWFileEntry.cc.

46  {
47  for (std::list<Filter*>::iterator i = m_filterEntries.begin(); i != m_filterEntries.end(); ++i)
48  delete (*i)->m_eventList;
49 
50  delete m_globalEventList;
51 }

References mps_fire::i, m_filterEntries, and m_globalEventList.

◆ FWFileEntry() [2/2]

FWFileEntry::FWFileEntry ( const FWFileEntry )
privatedelete

Member Function Documentation

◆ closeFile()

void FWFileEntry::closeFile ( )

Definition at line 214 of file FWFileEntry.cc.

214  {
215  if (m_file) {
216  printf("Reading %lld bytes in %d transactions.\n", m_file->GetBytesRead(), m_file->GetReadCalls());
217  delete m_file->GetCacheRead(m_eventTree);
218 
219  m_file->Close();
220  delete m_file;
221  }
222  if (m_event)
223  delete m_event;
224 }

References m_event, m_eventTree, and m_file.

◆ event()

fwlite::Event* FWFileEntry::event ( )
inline

Definition at line 53 of file FWFileEntry.h.

53 { return m_event; }

References m_event.

Referenced by Types.EventID::cppID().

◆ file()

TFile* FWFileEntry::file ( )
inline

Definition at line 52 of file FWFileEntry.h.

52 { return m_file; }

References m_file.

◆ filterEventsWithCustomParser()

bool FWFileEntry::filterEventsWithCustomParser ( Filter filter)
private

Definition at line 456 of file FWFileEntry.cc.

456  {
457  std::string selection(filterEntry->m_selector->m_expression);
458 
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) {
462  // Combination of && and || operators not supported.
463  return false;
464  }
465 
466  fwlite::Handle<edm::TriggerResults> hTriggerResults;
467  edm::TriggerNames const* triggerNames(nullptr);
468  try {
469  hTriggerResults.getByLabel(*m_event, "TriggerResults", "", filterEntry->m_selector->m_triggerProcess.c_str());
470  triggerNames = &(m_event->triggerNames(*hTriggerResults));
471  } catch (...) {
472  fwLog(fwlog::kWarning) << " failed to get trigger results with process name "
473  << filterEntry->m_selector->m_triggerProcess << std::endl;
474  return false;
475  }
476 
477  // std::cout << "Number of trigger names: " << triggerNames->size() << std::endl;
478  // for (unsigned int i=0; i<triggerNames->size(); ++i)
479  // std::cout << " " << triggerNames->triggerName(i);
480  //std::cout << std::endl;
481 
482  bool junction_mode = true; // AND
483  if (selection.find("||") != std::string::npos)
484  junction_mode = false; // OR
485 
486  boost::regex re("\\&\\&|\\|\\|");
487 
488  boost::sregex_token_iterator i(selection.begin(), selection.end(), re, -1);
489  boost::sregex_token_iterator j;
490 
491  // filters and how they enter in the logical expression
492  std::vector<std::pair<unsigned int, bool>> filters;
493 
494  while (i != j) {
495  std::string filter = *i++;
496  bool flag = true;
497  if (filter[0] == '!') {
498  flag = false;
499  filter.erase(filter.begin());
500  }
501  unsigned int index = triggerNames->triggerIndex(filter);
502  if (index == triggerNames->size()) {
503  // Trigger name not found.
504  return false;
505  }
506  filters.push_back(std::make_pair(index, flag));
507  }
508  if (filters.empty())
509  return false;
510 
511  if (filterEntry->m_eventList)
512  filterEntry->m_eventList->Reset();
513  else
514  filterEntry->m_eventList = new FWTEventList();
515  FWTEventList* list = filterEntry->m_eventList;
516 
517  // loop over events
518  edm::EventID currentEvent = m_event->id();
519  unsigned int iEvent = 0;
520 
521  for (m_event->toBegin(); !m_event->atEnd(); ++(*m_event)) {
522  hTriggerResults.getByLabel(*m_event, "TriggerResults", "", filterEntry->m_selector->m_triggerProcess.c_str());
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()) {
526  if (junction_mode)
527  passed &= hTriggerResults->accept(filter->first) == filter->second;
528  else
529  passed |= hTriggerResults->accept(filter->first) == filter->second;
530  }
531  if (passed)
532  list->Enter(iEvent);
533  ++iEvent;
534  }
535  m_event->to(currentEvent);
536 
537  filterEntry->m_needsUpdate = false;
538 
539  fwLog(fwlog::kDebug) << "FWFile::filterEventsWithCustomParser file [" << m_file->GetName() << "], filter ["
540  << filterEntry->m_selector->m_expression << "], selected [" << list->GetN() << "]" << std::endl;
541 
542  return true;
543 }

References edm::HLTGlobalStatus::accept(), fwlite::Event::atEnd(), ALCARECOTkAlBeamHalo_cff::filter, filters(), RemoveAddSevLevel::flag, fwLog, fwlite::Handle< T >::getByLabel(), mps_fire::i, edm::EventBase::id(), iEvent, dqmiolumiharvest::j, fwlog::kDebug, fwlog::kWarning, list(), m_event, FWFileEntry::Filter::m_eventList, FWEventSelector::m_expression, m_file, FWFileEntry::Filter::m_needsUpdate, FWFileEntry::Filter::m_selector, FWEventSelector::m_triggerProcess, TriggerAnalyzer::passed, corrVsCorr::selection, AlCaHLTBitMon_QueryRunRegistry::string, fwlite::Event::to(), fwlite::Event::toBegin(), L1TEGammaOffline_cfi::triggerNames, and fwlite::Event::triggerNames().

Referenced by runFilter().

◆ filters()

std::list<Filter*>& FWFileEntry::filters ( )
inline

Definition at line 58 of file FWFileEntry.h.

58 { return m_filterEntries; }

References m_filterEntries.

Referenced by filterEventsWithCustomParser().

◆ firstSelectedEvent()

int FWFileEntry::firstSelectedEvent ( )

Definition at line 235 of file FWFileEntry.cc.

235  {
236  if (m_globalEventList->GetN() > 0) {
237  return m_globalEventList->GetEntry(0);
238  } else {
239  return -1;
240  }
241 }

References m_globalEventList.

◆ fwTreeCache()

FWTTreeCache * FWFileEntry::fwTreeCache ( )

Definition at line 547 of file FWFileEntry.cc.

547  {
548  FWTTreeCache* tc = dynamic_cast<FWTTreeCache*>(m_file->GetCacheRead(m_eventTree));
549  assert(tc != nullptr && "FWFileEntry::treeCache can not access TTreeCache");
550  return tc;
551 }

References cms::cuda::assert(), m_eventTree, and m_file.

Referenced by NewEventItemCallIn(), and RemovingEventItemCallIn().

◆ getBranchName()

std::string FWFileEntry::getBranchName ( const FWEventItem it) const
private

◆ getGlobalTag()

const std::string& FWFileEntry::getGlobalTag ( ) const
inline

Definition at line 60 of file FWFileEntry.h.

60 { return m_globalTag; }

References m_globalTag.

◆ globalSelection()

FWTEventList* FWFileEntry::globalSelection ( )
inline

Definition at line 55 of file FWFileEntry.h.

55 { return m_globalEventList; }

References m_globalEventList.

◆ hasActiveFilters()

bool FWFileEntry::hasActiveFilters ( )

Definition at line 281 of file FWFileEntry.cc.

281  {
282  for (std::list<Filter*>::iterator it = m_filterEntries.begin(); it != m_filterEntries.end(); ++it) {
283  if ((*it)->m_selector->m_enabled)
284  return true;
285  }
286 
287  return false;
288 }

References m_filterEntries.

◆ hasSelectedEvents()

bool FWFileEntry::hasSelectedEvents ( )

Definition at line 233 of file FWFileEntry.cc.

233 { return m_globalEventList->GetN() > 0; }

References m_globalEventList.

◆ isEventSelected()

bool FWFileEntry::isEventSelected ( int  event)

Definition at line 228 of file FWFileEntry.cc.

228  {
229  int idx = m_globalEventList->GetIndex(tree_entry);
230  return idx >= 0;
231 }

References training_settings::idx, and m_globalEventList.

◆ lastEvent()

int FWFileEntry::lastEvent ( )
inline

Definition at line 74 of file FWFileEntry.h.

74 { return m_eventTree->GetEntries() - 1; }

References m_eventTree.

◆ lastSelectedEvent()

int FWFileEntry::lastSelectedEvent ( )

Definition at line 243 of file FWFileEntry.cc.

243  {
244  if (m_globalEventList->GetN() > 0)
245  return m_globalEventList->GetEntry(m_globalEventList->GetN() - 1);
246  else
247  return -1;
248 }

References m_globalEventList.

◆ needUpdate()

void FWFileEntry::needUpdate ( )
inline

Definition at line 79 of file FWFileEntry.h.

79 { m_needUpdate = true; }

References m_needUpdate.

◆ NewEventItemCallIn()

void FWFileEntry::NewEventItemCallIn ( const FWEventItem it)

Definition at line 560 of file FWFileEntry.cc.

560  {
561  auto tc = fwTreeCache();
562 
564  printf("FWFileEntry:NewEventItemCallIn FWEventItem %s, learning=%d\n", getBranchName(it).c_str(), tc->IsLearning());
565 
566  tc->AddBranchTopLevel(getBranchName(it).c_str());
567 }

References fwTreeCache(), getBranchName(), and FWTTreeCache::IsLogging().

Referenced by openFile().

◆ nextSelectedEvent()

int FWFileEntry::nextSelectedEvent ( int  event)

Definition at line 250 of file FWFileEntry.cc.

250  {
251  // Find next selected event after the current one.
252  // This returns the index in the selected event list.
253  // If none exists -1 is returned.
254 
255  const Long64_t* list = m_globalEventList->GetList();
256  Long64_t val = tree_entry;
257  Long64_t idx = TMath::BinarySearch(m_globalEventList->GetN(), list, val);
258  ++idx;
259  if (idx >= m_globalEventList->GetN() || idx < 0)
260  return -1;
261  return list[idx];
262 }

References training_settings::idx, list(), m_globalEventList, and heppy_batch::val.

◆ openFile()

void FWFileEntry::openFile ( bool  checkVersion,
bool  checkGlobalTag 
)

Definition at line 53 of file FWFileEntry.cc.

53  {
54  gErrorIgnoreLevel = 3000; // suppress warnings about missing dictionaries
55 
56  TFile* newFile = TFile::Open(m_name.c_str());
57 
58  if (newFile == nullptr || newFile->IsZombie() || !newFile->Get("Events")) {
59  // std::cout << "Invalid file. Ignored." << std::endl;
60  // return false;
61  throw std::runtime_error("Invalid file. Ignored.");
62  }
63 
64  m_file = newFile;
65 
66  gErrorIgnoreLevel = -1;
67 
68  // check CMSSW relese version for compatibility
69  typedef std::vector<edm::ProcessHistory> provList;
70 
71  TTree* metaData = dynamic_cast<TTree*>(m_file->Get("MetaData"));
72  TBranch* b = metaData->GetBranch("ProcessHistory");
74  edm::ProcessHistoryVector* pPhv = &phv_;
75  metaData->SetBranchAddress("ProcessHistory", &pPhv);
76 
77  b->GetEntry(0);
78 
79  typedef std::map<edm::ParameterSetID, edm::ParameterSetBlob> ParameterSetMap;
80  ParameterSetMap psm_;
81  TTree* psetTree = dynamic_cast<TTree*>(newFile->Get("ParameterSets"));
82  typedef std::pair<edm::ParameterSetID, edm::ParameterSetBlob> IdToBlobs;
83  IdToBlobs idToBlob;
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);
89  }
90 
92  for (auto const& item : psm_) {
93  edm::ParameterSet pset(item.second.pset());
94  pset.setID(item.first);
95  psetRegistry.insertMapped(pset);
96  }
97 
98  const edm::ProcessConfiguration* dd = nullptr;
99  int latestVersion = 0;
100  int currentVersionArr[] = {0, 0, 0};
101  for (auto const& processHistory : phv_) {
102  for (auto const& processConfiguration : processHistory) {
103  // std::cout << processConfiguration.releaseVersion() << " " << processConfiguration.processName() << std::endl;
104  TString dcv = processConfiguration.releaseVersion();
105  fireworks::getDecomposedVersion(dcv, currentVersionArr);
106  int nvv = currentVersionArr[0] * 100 + currentVersionArr[1] * 10 + currentVersionArr[2];
107  if (nvv > latestVersion) {
108  latestVersion = nvv;
109  dd = &processConfiguration;
110  }
111  }
112  }
113 
114  // read first global tag for auto detect of geomtery version
115  if (checkGlobalTag) {
116  std::map<edm::ProcessConfigurationID, unsigned int> simpleIDs;
117  m_globalTag = "";
118  for (auto const& ph : phv_) {
119  for (auto const& pc : ph) {
120  unsigned int id = simpleIDs[pc.id()];
121  if (0 == id) {
122  id = 1;
123  simpleIDs[pc.id()] = id;
124  }
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;
129  } else {
130  edm::ParameterSet processConfig(itFind->second.pset());
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) {
134  edm::ParameterSet const& pset = processConfig.getParameterSet(itM);
135  std::string name(pset.getParameter<std::string>("@module_label"));
136  if (name.empty()) {
137  name = pset.getParameter<std::string>("@module_type");
138  }
139  if (name != "GlobalTag")
140  continue;
141 
142  for (auto const& item : pset.tbl()) {
143  if (item.first == "globaltag") {
144  m_globalTag = item.second.getString();
145  goto gtEnd;
146  }
147  }
148  }
149  }
150  }
151  }
152 
153  gtEnd:
154  fwLog(fwlog::kDebug) << "FWFileEntry::openFile detected global tag " << m_globalTag << "\n";
155  }
156 
157  // test compatibility of data with CMSSW
158  if (checkVersion) {
159  if (latestVersion) {
160  fwLog(fwlog::kInfo) << "Checking process history. " << m_name.c_str() << " latest process \"" << dd->processName()
161  << "\", version " << dd->releaseVersion() << std::endl;
162 
163  b->SetAddress(nullptr);
164  TString v = dd->releaseVersion();
167  TString msg = Form(
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(),
171  di[0],
172  di[1],
173  di[2]);
174  msg += "Use --no-version-check option if you still want to view the file.\n";
175  throw std::runtime_error(msg.Data());
176  }
177  } else {
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());
181  }
182  }
183 
184  m_eventTree = dynamic_cast<TTree*>(m_file->Get("Events"));
185 
186  if (m_eventTree == nullptr) {
187  throw std::runtime_error("Cannot find TTree 'Events' in the data file");
188  }
189 
190  // Initialize caching, this helps also in the case of local file.
192  printf("FWFileEntry::openFile enabling FWTTreeCache for file class '%s'.", m_file->ClassName());
193 
195  m_file->SetCacheRead(tc, m_eventTree);
196  tc->SetEnablePrefetching(FWTTreeCache::IsPrefetching());
197  tc->SetLearnEntries(20);
198  tc->SetLearnPrefill(TTreeCache::kAllBranches);
199  tc->StartLearningPhase();
200 
201  // load event, set DataGetterHelper callback for branch access
202  m_event = new fwlite::Event(m_file, false, [tc](TBranch const& b) { tc->BranchAccessCallIn(&b); });
203 
204  // Connect to collection add/remove signals
206  eiMng->newItem_.connect(boost::bind(&FWFileEntry::NewEventItemCallIn, this, _1));
207  eiMng->removingItem_.connect(boost::bind(&FWFileEntry::RemovingEventItemCallIn, this, _1));
208  // no need to connect to goingToClearItems_ ... individual removes are emitted.
209 
210  if (m_event->size() == 0)
211  throw std::runtime_error("fwlite::Event size == 0");
212 }

References fireworks::acceptDataFormatsVersion(), b, gather_cfg::cout, createTree::dd, fireworks::Context::eventItemsManager(), fwLog, utils::gErrorIgnoreLevel, FWGUIManager::getContext(), fireworks::getDecomposedVersion(), FWTTreeCache::GetDefaultCacheSize(), FWGUIManager::getGUIManager(), mps_fire::i, triggerObjects_cff::id, edm::pset::Registry::insertMapped(), edm::pset::Registry::instance(), FWTTreeCache::IsLogging(), FWTTreeCache::IsPrefetching(), B2GTnPMonitor_cfi::item, fwlog::kDebug, fwlog::kInfo, m_event, m_eventTree, m_file, m_globalTag, m_name, mps_check::msg, Skims_PA_cff::name, NewEventItemCallIn(), FWEventItemsManager::newItem_, muonDTDigis_cfi::pset, RemovingEventItemCallIn(), fwlite::Event::size(), CalibrationSummaryClient_cfi::sources, AlCaHLTBitMon_QueryRunRegistry::string, fireworks::supportedDataFormatsVersion(), and findQualityFiles::v.

Referenced by FWFileEntry().

◆ operator=()

const FWFileEntry& FWFileEntry::operator= ( const FWFileEntry )
privatedelete

◆ previousSelectedEvent()

int FWFileEntry::previousSelectedEvent ( int  event)

Definition at line 264 of file FWFileEntry.cc.

264  {
265  // Find first selected event before current one.
266  // This returns the index in the selected event list.
267  // If none exists -1 is returned.
268 
269  const Long64_t* list = m_globalEventList->GetList();
270  Long64_t val = tree_entry;
271  Long64_t idx = TMath::BinarySearch(m_globalEventList->GetN(), list, val);
272  if (list[idx] == val)
273  --idx;
274  if (idx >= 0)
275  return list[idx];
276  else
277  return -1;
278 }

References training_settings::idx, list(), m_globalEventList, and heppy_batch::val.

◆ RemovingEventItemCallIn()

void FWFileEntry::RemovingEventItemCallIn ( const FWEventItem it)

Definition at line 569 of file FWFileEntry.cc.

569  {
570  auto tc = fwTreeCache();
571 
573  printf("FWFileEntry:RemovingEventItemCallIn FWEventItem %s, learning=%d\n",
574  getBranchName(it).c_str(),
575  tc->IsLearning());
576 
577  tc->DropBranchTopLevel(getBranchName(it).c_str());
578 }

References fwTreeCache(), getBranchName(), and FWTTreeCache::IsLogging().

Referenced by openFile().

◆ runFilter()

void FWFileEntry::runFilter ( Filter fe,
const FWEventItemsManager eiMng 
)
private

Definition at line 327 of file FWFileEntry.cc.

327  {
328  if (!filter->m_selector->m_triggerProcess.empty()) {
330  return;
331  }
332 
333  // parse selection for known Fireworks expressions
334  std::string interpretedSelection = filter->m_selector->m_expression;
335  // list of branch names to be added to tree-cache
336  std::vector<std::string> branch_names;
337 
338  for (FWEventItemsManager::const_iterator i = eiMng->begin(), end = eiMng->end(); i != end; ++i) {
339  FWEventItem* item = *i;
340  if (item == nullptr)
341  continue;
342  // FIXME: hack to get full branch name filled
343  if (!item->hasEvent()) {
344  item->setEvent(m_event);
345  item->getPrimaryData();
346  item->setEvent(nullptr);
347  }
348 
349  boost::regex re(std::string("\\$") + (*i)->name());
350 
351  if (boost::regex_search(interpretedSelection, re)) {
352  const edm::TypeWithDict elementType(const_cast<TClass*>(item->type()));
353  const edm::TypeWithDict wrapperType = edm::TypeWithDict::byName(edm::wrappedClassName(elementType.name()));
354  std::string fullBranchName = m_event->getBranchNameFor(wrapperType.typeInfo(),
355  item->moduleLabel().c_str(),
356  item->productInstanceLabel().c_str(),
357  item->processName().c_str());
358 
359  interpretedSelection = boost::regex_replace(interpretedSelection, re, fullBranchName + ".obj");
360 
361  branch_names.push_back(fullBranchName);
362 
363  // printf("selection after applying s/%s/%s/: %s\n",
364  // (std::string("\\$") + (*i)->name()).c_str(),
365  // ((*i)->m_fullBranchName + ".obj").c_str(),
366  // interpretedSelection.c_str());
367  }
368  }
369 
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;
374  return;
375  }
376 
377  m_file->cd();
378  m_eventTree->SetEventList(nullptr);
379 
380  auto prevCache = m_file->GetCacheRead(m_eventTree);
381 
382  auto interCache = new TTreeCache(m_eventTree, 10 * 1024 * 1024);
383  // Do not disconnect the cache, it will be reattached after filtering.
384  m_file->SetCacheRead(interCache, m_eventTree, TFile::kDoNotDisconnect);
385  interCache->SetEnablePrefetching(FWTTreeCache::IsPrefetching());
386  for (auto& b : branch_names)
387  interCache->AddBranch(b.c_str(), true);
388  interCache->StopLearningPhase();
389 
390  // Since ROOT will leave any TBranches used in the filtering at the last event,
391  // we need to be able to reset them to what fwlite::Event expects them to be.
392  // We do this by holding onto the old buffers and create temporary new ones.
393 
394  std::map<TBranch*, void*> prevAddrs;
395 
396  {
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);
401  if (nullptr != b) {
402  const char* name = b->GetName();
403  unsigned int length = strlen(name);
404  if (length > 1 && name[length - 1] != '.') {
405  // This is not a data branch so we should ignore it.
406  continue;
407  }
408  if (nullptr != b->GetAddress()) {
409  if (prevAddrs.find(b) != prevAddrs.end()) {
410  fwLog(fwlog::kWarning) << "FWFileEntry::runFilter branch is already in the map!\n";
411  }
412  prevAddrs.insert(std::make_pair(b, b->GetAddress()));
413 
414  // std::cout <<"Zeroing branch: "<< b->GetName() <<" "<< (void*) b->GetAddress() <<std::endl;
415  b->SetAddress(nullptr);
416  }
417  }
418  }
419  }
420 
421  if (filter->m_eventList)
422  filter->m_eventList->Reset();
423  else
424  filter->m_eventList = new FWTEventList;
425 
426  fwLog(fwlog::kInfo) << "FWFileEntry::runFilter Running filter " << interpretedSelection << "' "
427  << "for file '" << m_file->GetName() << "'.\n";
428 
429  TEveSelectorToEventList stoelist(filter->m_eventList, interpretedSelection.c_str());
430  Long64_t result = m_eventTree->Process(&stoelist);
431 
432  if (result < 0)
433  fwLog(fwlog::kWarning) << "FWFileEntry::runFilter in file [" << m_file->GetName() << "] filter ["
434  << filter->m_selector->m_expression << "] is invalid." << std::endl;
435  else
436  fwLog(fwlog::kDebug) << "FWFileEntry::runFilter is file [" << m_file->GetName() << "], filter ["
437  << filter->m_selector->m_expression << "] has [" << filter->m_eventList->GetN()
438  << "] events selected" << std::endl;
439 
440  // Set back the old branch buffers.
441  {
442  for (auto i : prevAddrs) {
443  // std::cout <<"Resetting branch: "<< i.first->GetName() <<" "<< i.second <<std::endl;
444  i.first->SetAddress(i.second);
445  }
446  }
447 
448  m_file->SetCacheRead(prevCache, m_eventTree);
449  delete interCache;
450 
451  filter->m_needsUpdate = false;
452 }

References b, FWEventItemsManager::begin(), edm::TypeWithDict::byName(), end, FWEventItemsManager::end(), ALCARECOTkAlBeamHalo_cff::filter, filterEventsWithCustomParser(), newFWLiteAna::found, fwLog, fwlite::Event::getBranchNameFor(), mps_fire::i, FWTTreeCache::IsPrefetching(), B2GTnPMonitor_cfi::item, fwlog::kDebug, fwlog::kError, fwlog::kInfo, fwlog::kWarning, m_event, m_eventTree, m_file, Skims_PA_cff::name, edm::TypeWithDict::name(), mps_fire::result, AlCaHLTBitMon_QueryRunRegistry::string, edm::TypeWithDict::typeInfo(), and edm::wrappedClassName().

Referenced by updateFilters().

◆ tree()

TTree* FWFileEntry::tree ( )
inline

◆ updateFilters()

void FWFileEntry::updateFilters ( const FWEventItemsManager eiMng,
bool  isOR 
)

Definition at line 291 of file FWFileEntry.cc.

291  {
292  if (!m_needUpdate)
293  return;
294 
295  if (m_globalEventList)
296  m_globalEventList->Reset();
297  else
299 
300  for (std::list<Filter*>::iterator it = m_filterEntries.begin(); it != m_filterEntries.end(); ++it) {
301  if ((*it)->m_selector->m_enabled && (*it)->m_needsUpdate) {
302  runFilter(*it, eiMng);
303  }
304  // Need to re-check if enabled after filtering as it can be set to false
305  // in runFilter().
306  if ((*it)->m_selector->m_enabled) {
307  if ((*it)->hasSelectedEvents()) {
308  if (globalOR || m_globalEventList->GetN() == 0) {
309  m_globalEventList->Add((*it)->m_eventList);
310  } else {
311  m_globalEventList->Intersect((*it)->m_eventList);
312  }
313  } else if (!globalOR) {
314  m_globalEventList->Reset();
315  break;
316  }
317  }
318  }
319 
320  fwLog(fwlog::kDebug) << "FWFileEntry::updateFilters in [" << m_file->GetName() << "] global selection ["
321  << m_globalEventList->GetN() << "/" << m_eventTree->GetEntries() << "]" << std::endl;
322 
323  m_needUpdate = false;
324 }

References FWTEventList::Add(), fwLog, fwlog::kDebug, m_eventTree, m_file, m_filterEntries, m_globalEventList, m_needUpdate, and runFilter().

Member Data Documentation

◆ m_event

fwlite::Event* FWFileEntry::m_event
private

◆ m_eventTree

TTree* FWFileEntry::m_eventTree
private

Definition at line 97 of file FWFileEntry.h.

Referenced by closeFile(), fwTreeCache(), lastEvent(), openFile(), runFilter(), tree(), and updateFilters().

◆ m_file

TFile* FWFileEntry::m_file
private

◆ m_filterEntries

std::list<Filter*> FWFileEntry::m_filterEntries
private

Definition at line 103 of file FWFileEntry.h.

Referenced by filters(), hasActiveFilters(), updateFilters(), and ~FWFileEntry().

◆ m_globalEventList

FWTEventList* FWFileEntry::m_globalEventList
private

◆ m_globalTag

std::string FWFileEntry::m_globalTag
private

Definition at line 101 of file FWFileEntry.h.

Referenced by getGlobalTag(), and openFile().

◆ m_name

std::string FWFileEntry::m_name
private

Definition at line 95 of file FWFileEntry.h.

Referenced by openFile().

◆ m_needUpdate

bool FWFileEntry::m_needUpdate
private

Definition at line 100 of file FWFileEntry.h.

Referenced by needUpdate(), and updateFilters().

edm::pset::Registry::instance
static Registry * instance()
Definition: Registry.cc:12
FWTTreeCache::IsLogging
static bool IsLogging()
Definition: FWTTreeCache.cc:23
edm::TypeWithDict::byName
static TypeWithDict byName(std::string const &name)
Definition: TypeWithDict.cc:74
fwLog
#define fwLog(_level_)
Definition: fwLog.h:45
FWFileEntry::m_name
std::string m_name
Definition: FWFileEntry.h:95
mps_fire.i
i
Definition: mps_fire.py:355
FWTTreeCache::GetDefaultCacheSize
static int GetDefaultCacheSize()
Definition: FWTTreeCache.cc:30
FWEventItem::productInstanceLabel
const std::string & productInstanceLabel() const
Definition: FWEventItem.cc:442
fwlite::Event::toBegin
Event const & toBegin() override
Go to the very first Event.
Definition: Event.cc:217
fireworks::getDecomposedVersion
void getDecomposedVersion(const TString &s, int *out)
Definition: fwPaths.cc:26
FWEventItem::processName
const std::string & processName() const
Definition: FWEventItem.cc:444
FWFileEntry::NewEventItemCallIn
void NewEventItemCallIn(const FWEventItem *it)
Definition: FWFileEntry.cc:560
fwlite::Event::to
bool to(Long64_t iIndex)
Go to the event at index iIndex.
Definition: Event.cc:195
FWEventItemsManager
Definition: FWEventItemsManager.h:44
gather_cfg.cout
cout
Definition: gather_cfg.py:144
FWFileEntry::RemovingEventItemCallIn
void RemovingEventItemCallIn(const FWEventItem *it)
Definition: FWFileEntry.cc:569
cms::cuda::assert
assert(be >=bs)
CalibrationSummaryClient_cfi.sources
sources
Definition: CalibrationSummaryClient_cfi.py:23
mps_check.msg
tuple msg
Definition: mps_check.py:285
FWEventItem::moduleLabel
const std::string & moduleLabel() const
Definition: FWEventItem.cc:441
findQualityFiles.v
v
Definition: findQualityFiles.py:179
newFWLiteAna.found
found
Definition: newFWLiteAna.py:118
training_settings.idx
idx
Definition: training_settings.py:16
fireworks::supportedDataFormatsVersion
int * supportedDataFormatsVersion()
Definition: fwPaths.cc:35
FWTTreeCache::IsPrefetching
static bool IsPrefetching()
Definition: FWTTreeCache.cc:27
end
#define end
Definition: vmac.h:39
fwlite::Event::size
Long64_t size() const
Returns number of events in the file.
Definition: Event.cc:245
edm::ParameterSetMap
std::map< ParameterSetID, ParameterSetBlob > ParameterSetMap
Definition: ParameterSetConverter.h:40
FWTEventList::Add
void Add(const TEventList *list) override
Definition: FWTEventList.cc:7
FWFileEntry::getBranchName
std::string getBranchName(const FWEventItem *it) const
Definition: FWFileEntry.cc:553
fwlite::Handle
Definition: Handle.h:39
fireworks::Context::eventItemsManager
const FWEventItemsManager * eventItemsManager() const
Definition: Context.h:56
L1TEGammaOffline_cfi.triggerNames
triggerNames
Definition: L1TEGammaOffline_cfi.py:40
corrVsCorr.selection
selection
main part
Definition: corrVsCorr.py:100
fireworks::acceptDataFormatsVersion
bool acceptDataFormatsVersion(TString &n)
Definition: fwPaths.cc:60
b
double b
Definition: hdecay.h:118
ALCARECOTkAlBeamHalo_cff.filter
filter
Definition: ALCARECOTkAlBeamHalo_cff.py:27
FWFileEntry::m_filterEntries
std::list< Filter * > m_filterEntries
Definition: FWFileEntry.h:103
createTree.dd
string dd
Definition: createTree.py:154
utils.gErrorIgnoreLevel
gErrorIgnoreLevel
Definition: utils.py:27
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::TypeWithDict
Definition: TypeWithDict.h:38
FWFileEntry::filters
std::list< Filter * > & filters()
Definition: FWFileEntry.h:58
FWFileEntry::m_file
TFile * m_file
Definition: FWFileEntry.h:96
edm::ParameterSet
Definition: ParameterSet.h:36
FWFileEntry::runFilter
void runFilter(Filter *fe, const FWEventItemsManager *eiMng)
Definition: FWFileEntry.cc:327
FWTTreeCache
Definition: FWTTreeCache.h:9
edm::TypeWithDict::typeInfo
std::type_info const & typeInfo() const
Definition: TypeWithDict.cc:357
fwlite::Event::getBranchNameFor
const std::string 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.
Definition: Event.cc:268
FWEventItemsManager::end
const_iterator end() const
Definition: FWEventItemsManager.cc:300
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::ProcessHistoryVector
std::vector< ProcessHistory > ProcessHistoryVector
Definition: ProcessHistoryRegistry.h:16
FWTEventList
Definition: FWTEventList.h:12
FWEventItemsManager::const_iterator
std::vector< FWEventItem * >::const_iterator const_iterator
Definition: FWEventItemsManager.h:50
FWFileEntry::filterEventsWithCustomParser
bool filterEventsWithCustomParser(Filter *filter)
Definition: FWFileEntry.cc:456
FWEventItem::type
const TClass * type() const
Definition: FWEventItem.cc:437
fwlog::kWarning
Definition: fwLog.h:35
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
edm::wrappedClassName
std::string wrappedClassName(std::string const &iFullName)
Definition: WrappedClassName.cc:4
FWFileEntry::openFile
void openFile(bool, bool)
Definition: FWFileEntry.cc:53
FWGUIManager::getGUIManager
static FWGUIManager * getGUIManager()
Definition: FWGUIManager.cc:685
edm::pset::Registry::insertMapped
bool insertMapped(value_type const &v, bool forceUpdate=false)
Definition: Registry.cc:32
fwlite::Event::atEnd
bool atEnd() const override
Definition: Event.cc:254
FWGUIManager::getContext
fireworks::Context * getContext()
Definition: FWGUIManager.h:152
fwlite::Handle::getByLabel
void getByLabel(const P &iP, const char *iModuleLabel, const char *iProductInstanceLabel=nullptr, const char *iProcessLabel=nullptr)
Definition: Handle.h:100
fwlog::kInfo
Definition: fwLog.h:35
fwlite::Event::triggerNames
edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const override
Definition: Event.cc:381
FWEventItemsManager::begin
const_iterator begin() const
NOTE: iterator is allowed to return a null object for items that have been removed.
Definition: FWEventItemsManager.cc:299
FWEventItem
Definition: FWEventItem.h:56
heppy_batch.val
val
Definition: heppy_batch.py:351
fwlite::Event
Definition: Event.h:87
fwlog::kDebug
Definition: fwLog.h:35
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:31
FWFileEntry::m_globalEventList
FWTEventList * m_globalEventList
Definition: FWFileEntry.h:104
FWFileEntry::m_eventTree
TTree * m_eventTree
Definition: FWFileEntry.h:97
edm::EventBase::id
edm::EventID id() const
Definition: EventBase.h:59
edm::TriggerNames
Definition: TriggerNames.h:55
FWEventItemsManager::newItem_
sigc::signal< void, FWEventItem * > newItem_
Definition: FWEventItemsManager.h:73
TriggerAnalyzer.passed
passed
Definition: TriggerAnalyzer.py:62
FWFileEntry::m_event
fwlite::Event * m_event
Definition: FWFileEntry.h:98
FWFileEntry::m_globalTag
std::string m_globalTag
Definition: FWFileEntry.h:101
FWFileEntry::m_needUpdate
bool m_needUpdate
Definition: FWFileEntry.h:100
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
edm::HLTGlobalStatus::accept
bool accept() const
Has at least one path accepted the event?
Definition: HLTGlobalStatus.h:49
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
fwlog::kError
Definition: fwLog.h:35
FWFileEntry::fwTreeCache
FWTTreeCache * fwTreeCache()
Definition: FWFileEntry.cc:547
mps_fire.result
result
Definition: mps_fire.py:303
list
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*", "!HLTx*" if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL. It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of "!*" before the partial wildcard feature was incorporated). Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
edm::EventID
Definition: EventID.h:31
edm::ProcessConfiguration
Definition: ProcessConfiguration.h:14
edm::pset::Registry
Definition: Registry.h:26
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
RemoveAddSevLevel.flag
flag
Definition: RemoveAddSevLevel.py:116