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)
 
 FWFileEntry (const FWFileEntry &)=delete
 
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)
 
const FWFileEntryoperator= (const FWFileEntry &)=delete
 
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)
 
std::string getBranchName (const FWEventItem *it) const
 
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.

References openFile().

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 }
TFile * m_file
Definition: FWFileEntry.h:96
void openFile(bool, bool)
Definition: FWFileEntry.cc:53
bool m_needUpdate
Definition: FWFileEntry.h:100
TTree * m_eventTree
Definition: FWFileEntry.h:97
fwlite::Event * m_event
Definition: FWFileEntry.h:98
FWTEventList * m_globalEventList
Definition: FWFileEntry.h:104
std::string m_name
Definition: FWFileEntry.h:95
std::string m_globalTag
Definition: FWFileEntry.h:101

◆ ~FWFileEntry()

FWFileEntry::~FWFileEntry ( )
virtual

Definition at line 46 of file FWFileEntry.cc.

References mps_fire::i, m_filterEntries, and m_globalEventList.

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 }
std::list< Filter * > m_filterEntries
Definition: FWFileEntry.h:103
FWTEventList * m_globalEventList
Definition: FWFileEntry.h:104

◆ FWFileEntry() [2/2]

FWFileEntry::FWFileEntry ( const FWFileEntry )
delete

Member Function Documentation

◆ closeFile()

void FWFileEntry::closeFile ( )

Definition at line 214 of file FWFileEntry.cc.

References m_event, m_eventTree, and m_file.

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 }
TFile * m_file
Definition: FWFileEntry.h:96
TTree * m_eventTree
Definition: FWFileEntry.h:97
fwlite::Event * m_event
Definition: FWFileEntry.h:98

◆ event()

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

Definition at line 53 of file FWFileEntry.h.

References m_event.

Referenced by Types.EventID::cppID().

53 { return m_event; }
fwlite::Event * m_event
Definition: FWFileEntry.h:98

◆ file()

TFile* FWFileEntry::file ( )
inline

Definition at line 52 of file FWFileEntry.h.

References m_file.

52 { return m_file; }
TFile * m_file
Definition: FWFileEntry.h:96

◆ filterEventsWithCustomParser()

bool FWFileEntry::filterEventsWithCustomParser ( Filter filter)
private

Definition at line 456 of file FWFileEntry.cc.

References edm::HLTGlobalStatus::accept(), fwlite::Event::atEnd(), FWTEventList::Enter(), ALCARECOTkAlBeamHalo_cff::filter, filters(), RemoveAddSevLevel::flag, fwLog, fwlite::Handle< T >::getByLabel(), mps_fire::i, edm::EventBase::id(), iEvent, dqmiolumiharvest::j, fwlog::kDebug, fwlog::kWarning, 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().

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 }
bool accept() const
Has at least one path accepted the event?
edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const override
Definition: Event.cc:411
selection
main part
Definition: corrVsCorr.py:100
int iEvent
Definition: GenABIO.cc:224
bool to(Long64_t iIndex)
Go to the event at index iIndex.
Definition: Event.cc:208
edm::EventID id() const
Definition: EventBase.h:63
bool atEnd() const override
Definition: Event.cc:267
std::list< Filter * > & filters()
Definition: FWFileEntry.h:58
TFile * m_file
Definition: FWFileEntry.h:96
fwlite::Event * m_event
Definition: FWFileEntry.h:98
Event const & toBegin() override
Go to the very first Event.
Definition: Event.cc:230
#define fwLog(_level_)
Definition: fwLog.h:45
void getByLabel(const P &iP, const char *iModuleLabel, const char *iProductInstanceLabel=nullptr, const char *iProcessLabel=nullptr)
Definition: Handle.h:100
void Enter(Long64_t entry) override
Definition: FWTEventList.cc:57

◆ filters()

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

Definition at line 58 of file FWFileEntry.h.

References m_filterEntries.

Referenced by filterEventsWithCustomParser().

58 { return m_filterEntries; }
std::list< Filter * > m_filterEntries
Definition: FWFileEntry.h:103

◆ firstSelectedEvent()

int FWFileEntry::firstSelectedEvent ( )

Definition at line 235 of file FWFileEntry.cc.

References m_globalEventList.

235  {
236  if (m_globalEventList->GetN() > 0) {
237  return m_globalEventList->GetEntry(0);
238  } else {
239  return -1;
240  }
241 }
FWTEventList * m_globalEventList
Definition: FWFileEntry.h:104

◆ fwTreeCache()

FWTTreeCache * FWFileEntry::fwTreeCache ( )

Definition at line 547 of file FWFileEntry.cc.

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

Referenced by NewEventItemCallIn(), and RemovingEventItemCallIn().

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 }
assert(be >=bs)
TFile * m_file
Definition: FWFileEntry.h:96
TTree * m_eventTree
Definition: FWFileEntry.h:97

◆ getBranchName()

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

Definition at line 553 of file FWFileEntry.cc.

References edm::TypeWithDict::byName(), fwlite::Event::getBranchNameFor(), ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, m_event, edm::TypeWithDict::name(), edm::TypeWithDict::typeInfo(), and edm::wrappedClassName().

Referenced by NewEventItemCallIn(), and RemovingEventItemCallIn().

553  {
554  const edm::TypeWithDict elementType(const_cast<TClass*>(it->type()));
555  const edm::TypeWithDict wrapperType = edm::TypeWithDict::byName(edm::wrappedClassName(elementType.name()));
556  return m_event->getBranchNameFor(
557  wrapperType.typeInfo(), it->moduleLabel().c_str(), it->productInstanceLabel().c_str(), it->processName().c_str());
558 }
static TypeWithDict byName(std::string const &name)
Definition: TypeWithDict.cc:74
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.
Definition: Event.cc:281
fwlite::Event * m_event
Definition: FWFileEntry.h:98
std::type_info const & typeInfo() const
std::string wrappedClassName(std::string const &iFullName)

◆ getGlobalTag()

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

Definition at line 60 of file FWFileEntry.h.

References m_globalTag.

60 { return m_globalTag; }
std::string m_globalTag
Definition: FWFileEntry.h:101

◆ globalSelection()

FWTEventList* FWFileEntry::globalSelection ( )
inline

Definition at line 55 of file FWFileEntry.h.

References m_globalEventList.

55 { return m_globalEventList; }
FWTEventList * m_globalEventList
Definition: FWFileEntry.h:104

◆ hasActiveFilters()

bool FWFileEntry::hasActiveFilters ( )

Definition at line 281 of file FWFileEntry.cc.

References ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, and m_filterEntries.

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 }
std::list< Filter * > m_filterEntries
Definition: FWFileEntry.h:103

◆ hasSelectedEvents()

bool FWFileEntry::hasSelectedEvents ( )

Definition at line 233 of file FWFileEntry.cc.

References m_globalEventList.

233 { return m_globalEventList->GetN() > 0; }
FWTEventList * m_globalEventList
Definition: FWFileEntry.h:104

◆ isEventSelected()

bool FWFileEntry::isEventSelected ( int  event)

Definition at line 228 of file FWFileEntry.cc.

References heavyIonCSV_trainingSettings::idx, and m_globalEventList.

228  {
229  int idx = m_globalEventList->GetIndex(tree_entry);
230  return idx >= 0;
231 }
FWTEventList * m_globalEventList
Definition: FWFileEntry.h:104

◆ lastEvent()

int FWFileEntry::lastEvent ( )
inline

Definition at line 74 of file FWFileEntry.h.

References m_eventTree.

74 { return m_eventTree->GetEntries() - 1; }
TTree * m_eventTree
Definition: FWFileEntry.h:97

◆ lastSelectedEvent()

int FWFileEntry::lastSelectedEvent ( )

Definition at line 243 of file FWFileEntry.cc.

References m_globalEventList.

243  {
244  if (m_globalEventList->GetN() > 0)
245  return m_globalEventList->GetEntry(m_globalEventList->GetN() - 1);
246  else
247  return -1;
248 }
FWTEventList * m_globalEventList
Definition: FWFileEntry.h:104

◆ needUpdate()

void FWFileEntry::needUpdate ( )
inline

Definition at line 79 of file FWFileEntry.h.

References m_needUpdate.

79 { m_needUpdate = true; }
bool m_needUpdate
Definition: FWFileEntry.h:100

◆ NewEventItemCallIn()

void FWFileEntry::NewEventItemCallIn ( const FWEventItem it)

Definition at line 560 of file FWFileEntry.cc.

References fwTreeCache(), getBranchName(), FWTTreeCache::IsLogging(), and ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it.

Referenced by openFile().

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 }
static bool IsLogging()
Definition: FWTTreeCache.cc:23
std::string getBranchName(const FWEventItem *it) const
Definition: FWFileEntry.cc:553
FWTTreeCache * fwTreeCache()
Definition: FWFileEntry.cc:547

◆ nextSelectedEvent()

int FWFileEntry::nextSelectedEvent ( int  event)

Definition at line 250 of file FWFileEntry.cc.

References heavyIonCSV_trainingSettings::idx, m_globalEventList, and heppy_batch::val.

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 }
FWTEventList * m_globalEventList
Definition: FWFileEntry.h:104

◆ openFile()

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

Definition at line 53 of file FWFileEntry.cc.

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, l1ctLayer2EG_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().

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(std::bind(&FWFileEntry::NewEventItemCallIn, this, std::placeholders::_1));
207  eiMng->removingItem_.connect(std::bind(&FWFileEntry::RemovingEventItemCallIn, this, std::placeholders::_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 }
std::vector< ProcessHistory > ProcessHistoryVector
fireworks::Context * getContext()
Definition: FWGUIManager.h:153
sigc::signal< void(FWEventItem *)> newItem_
const FWEventItemsManager * eventItemsManager() const
Definition: Context.h:56
void RemovingEventItemCallIn(const FWEventItem *it)
Definition: FWFileEntry.cc:569
void getDecomposedVersion(const TString &s, int *out)
Definition: fwPaths.cc:26
string dd
Definition: createTree.py:154
int * supportedDataFormatsVersion()
Definition: fwPaths.cc:35
static bool IsLogging()
Definition: FWTTreeCache.cc:23
static bool IsPrefetching()
Definition: FWTTreeCache.cc:27
bool insertMapped(value_type const &v, bool forceUpdate=false)
Definition: Registry.cc:32
static int GetDefaultCacheSize()
Definition: FWTTreeCache.cc:30
TFile * m_file
Definition: FWFileEntry.h:96
TTree * m_eventTree
Definition: FWFileEntry.h:97
fwlite::Event * m_event
Definition: FWFileEntry.h:98
static FWGUIManager * getGUIManager()
#define fwLog(_level_)
Definition: fwLog.h:45
double b
Definition: hdecay.h:120
tuple msg
Definition: mps_check.py:286
gErrorIgnoreLevel
Definition: utils.py:27
std::map< ParameterSetID, ParameterSetBlob > ParameterSetMap
bool acceptDataFormatsVersion(TString &n)
Definition: fwPaths.cc:60
std::string m_name
Definition: FWFileEntry.h:95
std::string m_globalTag
Definition: FWFileEntry.h:101
Long64_t size() const
Returns number of events in the file.
Definition: Event.cc:258
void NewEventItemCallIn(const FWEventItem *it)
Definition: FWFileEntry.cc:560
static Registry * instance()
Definition: Registry.cc:12

◆ operator=()

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

◆ previousSelectedEvent()

int FWFileEntry::previousSelectedEvent ( int  event)

Definition at line 264 of file FWFileEntry.cc.

References heavyIonCSV_trainingSettings::idx, m_globalEventList, and heppy_batch::val.

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 }
FWTEventList * m_globalEventList
Definition: FWFileEntry.h:104

◆ RemovingEventItemCallIn()

void FWFileEntry::RemovingEventItemCallIn ( const FWEventItem it)

Definition at line 569 of file FWFileEntry.cc.

References fwTreeCache(), getBranchName(), FWTTreeCache::IsLogging(), and ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it.

Referenced by openFile().

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 }
static bool IsLogging()
Definition: FWTTreeCache.cc:23
std::string getBranchName(const FWEventItem *it) const
Definition: FWFileEntry.cc:553
FWTTreeCache * fwTreeCache()
Definition: FWFileEntry.cc:547

◆ runFilter()

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

Definition at line 327 of file FWFileEntry.cc.

References b, FWEventItemsManager::begin(), edm::TypeWithDict::byName(), FWEventItemsManager::end(), mps_fire::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().

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 }
static TypeWithDict byName(std::string const &name)
Definition: TypeWithDict.cc:74
static bool IsPrefetching()
Definition: FWTTreeCache.cc:27
bool filterEventsWithCustomParser(Filter *filter)
Definition: FWFileEntry.cc:456
TFile * m_file
Definition: FWFileEntry.h:96
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.
Definition: Event.cc:281
TTree * m_eventTree
Definition: FWFileEntry.h:97
fwlite::Event * m_event
Definition: FWFileEntry.h:98
#define fwLog(_level_)
Definition: fwLog.h:45
std::type_info const & typeInfo() const
std::string wrappedClassName(std::string const &iFullName)
double b
Definition: hdecay.h:120
const_iterator begin() const
NOTE: iterator is allowed to return a null object for items that have been removed.
const_iterator end() const
std::vector< FWEventItem * >::const_iterator const_iterator

◆ tree()

TTree* FWFileEntry::tree ( )
inline

◆ updateFilters()

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

Definition at line 291 of file FWFileEntry.cc.

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

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 }
std::list< Filter * > m_filterEntries
Definition: FWFileEntry.h:103
TFile * m_file
Definition: FWFileEntry.h:96
bool m_needUpdate
Definition: FWFileEntry.h:100
TTree * m_eventTree
Definition: FWFileEntry.h:97
#define fwLog(_level_)
Definition: fwLog.h:45
void runFilter(Filter *fe, const FWEventItemsManager *eiMng)
Definition: FWFileEntry.cc:327
FWTEventList * m_globalEventList
Definition: FWFileEntry.h:104
void Add(const TEventList *list) override
Definition: FWTEventList.cc:7

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().