CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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)
 
FWTEventListglobalSelection ()
 
bool hasActiveFilters ()
 
bool hasSelectedEvents ()
 
bool isEventSelected (int event)
 
int lastEvent ()
 
int lastSelectedEvent ()
 
void needUpdate ()
 
int nextSelectedEvent (int event)
 
void openFile (bool)
 
int previousSelectedEvent (int event)
 
TTree * tree ()
 
void updateFilters (const FWEventItemsManager *eiMng, bool isOR)
 
virtual ~FWFileEntry ()
 

Private Member Functions

bool filterEventsWithCustomParser (Filter *filter)
 
 FWFileEntry (const FWFileEntry &)
 
const FWFileEntryoperator= (const FWFileEntry &)
 
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_name
 
bool m_needUpdate
 

Detailed Description

Definition at line 36 of file FWFileEntry.h.

Constructor & Destructor Documentation

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

Definition at line 27 of file FWFileEntry.cc.

References openFile().

27  :
28  m_name(name), m_file(0), m_eventTree(0), m_event(0),
30 {
31  openFile(checkVersion);
32 }
void openFile(bool)
Definition: FWFileEntry.cc:42
TFile * m_file
Definition: FWFileEntry.h:94
bool m_needUpdate
Definition: FWFileEntry.h:98
TTree * m_eventTree
Definition: FWFileEntry.h:95
fwlite::Event * m_event
Definition: FWFileEntry.h:96
FWTEventList * m_globalEventList
Definition: FWFileEntry.h:101
std::string m_name
Definition: FWFileEntry.h:93
FWFileEntry::~FWFileEntry ( )
virtual

Definition at line 34 of file FWFileEntry.cc.

References i, m_filterEntries, and m_globalEventList.

35 {
36  for(std::list<Filter*>::iterator i = m_filterEntries.begin(); i != m_filterEntries.end(); ++i)
37  delete (*i)->m_eventList;
38 
39  delete m_globalEventList;
40 }
int i
Definition: DBlmapReader.cc:9
std::list< Filter * > m_filterEntries
Definition: FWFileEntry.h:100
FWTEventList * m_globalEventList
Definition: FWFileEntry.h:101
FWFileEntry::FWFileEntry ( const FWFileEntry )
private

Member Function Documentation

void FWFileEntry::closeFile ( )

Definition at line 126 of file FWFileEntry.cc.

References m_event, and m_file.

Referenced by CmsShowNavigator::appendFile(), CmsShowNavigator::openFile(), and Vispa.Main.Application.Application::tabCloseRequest().

127 {
128  if (m_file) {
129  printf("Reading %lld bytes in %d transactions.\n",
130  m_file->GetBytesRead(), m_file->GetReadCalls());
131  m_file->Close();
132  delete m_file;
133  }
134  if (m_event) delete m_event;
135 }
TFile * m_file
Definition: FWFileEntry.h:94
fwlite::Event * m_event
Definition: FWFileEntry.h:96
fwlite::Event* FWFileEntry::event ( )
inline

Definition at line 60 of file FWFileEntry.h.

References m_event.

Referenced by Types.EventID::cppID(), core.AutoHandle.AutoHandle::Load(), and core.AutoHandle.AutoHandle::product().

60 { return m_event; }
fwlite::Event * m_event
Definition: FWFileEntry.h:96
TFile* FWFileEntry::file ( )
inline

Definition at line 59 of file FWFileEntry.h.

References m_file.

59 { return m_file; }
TFile * m_file
Definition: FWFileEntry.h:94
bool FWFileEntry::filterEventsWithCustomParser ( Filter filter)
private

Definition at line 382 of file FWFileEntry.cc.

References edm::HLTGlobalStatus::accept(), fwlite::Event::atEnd(), FWTEventList::Enter(), alcazmumu_cfi::filter, filters(), archive::flag, fwLog, fwlite::Handle< T >::getByLabel(), i, edm::EventBase::id(), iEvent, cmsHarvester::index, 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, corrVsCorr::selection, edm::TriggerNames::size(), AlCaHLTBitMon_QueryRunRegistry::string, fwlite::Event::to(), fwlite::Event::toBegin(), edm::TriggerNames::triggerIndex(), and fwlite::Event::triggerNames().

Referenced by runFilter().

383 {
384  std::string selection(filterEntry->m_selector->m_expression);
385 
386  boost::regex re_spaces("\\s+");
387  selection = boost::regex_replace(selection,re_spaces,"");
388  if (selection.find("&&") != std::string::npos &&
389  selection.find("||") != std::string::npos )
390  {
391  // Combination of && and || operators not supported.
392  return false;
393  }
394 
395  fwlite::Handle<edm::TriggerResults> hTriggerResults;
396  edm::TriggerNames const* triggerNames(0);
397  try
398  {
399  hTriggerResults.getByLabel(*m_event,"TriggerResults","", filterEntry->m_selector->m_triggerProcess.c_str());
400  triggerNames = &(m_event->triggerNames(*hTriggerResults));
401  }
402  catch(...)
403  {
404  fwLog(fwlog::kWarning) << " failed to get trigger results with process name "<< filterEntry->m_selector->m_triggerProcess << std::endl;
405  return false;
406  }
407 
408  // std::cout << "Number of trigger names: " << triggerNames->size() << std::endl;
409  // for (unsigned int i=0; i<triggerNames->size(); ++i)
410  // std::cout << " " << triggerNames->triggerName(i);
411  //std::cout << std::endl;
412 
413  bool junction_mode = true; // AND
414  if (selection.find("||")!=std::string::npos)
415  junction_mode = false; // OR
416 
417  boost::regex re("\\&\\&|\\|\\|");
418 
419  boost::sregex_token_iterator i(selection.begin(), selection.end(), re, -1);
420  boost::sregex_token_iterator j;
421 
422  // filters and how they enter in the logical expression
423  std::vector<std::pair<unsigned int,bool> > filters;
424 
425  while (i != j)
426  {
427  std::string filter = *i++;
428  bool flag = true;
429  if (filter[0] == '!')
430  {
431  flag = false;
432  filter.erase(filter.begin());
433  }
434  unsigned int index = triggerNames->triggerIndex(filter);
435  if (index == triggerNames->size())
436  {
437  // Trigger name not found.
438  return false;
439  }
440  filters.push_back(std::make_pair(index, flag));
441  }
442  if (filters.empty())
443  return false;
444 
445  if (filterEntry->m_eventList)
446  filterEntry->m_eventList->Reset();
447  else
448  filterEntry->m_eventList = new FWTEventList();
449  FWTEventList* list = filterEntry->m_eventList;
450 
451  // loop over events
452  edm::EventID currentEvent = m_event->id();
453  unsigned int iEvent = 0;
454 
455  for (m_event->toBegin(); !m_event->atEnd(); ++(*m_event))
456  {
457  hTriggerResults.getByLabel(*m_event,"TriggerResults","", filterEntry->m_selector->m_triggerProcess.c_str());
458  std::vector<std::pair<unsigned int,bool> >::const_iterator filter = filters.begin();
459  bool passed = hTriggerResults->accept(filter->first) == filter->second;
460  while (++filter != filters.end())
461  {
462  if (junction_mode)
463  passed &= hTriggerResults->accept(filter->first) == filter->second;
464  else
465  passed |= hTriggerResults->accept(filter->first) == filter->second;
466  }
467  if (passed)
468  list->Enter(iEvent);
469  ++iEvent;
470  }
471  m_event->to(currentEvent);
472 
473  filterEntry->m_needsUpdate = false;
474 
475  fwLog(fwlog::kDebug) << "FWFile::filterEventsWithCustomParser file [" << m_file->GetName() << "], filter [" << filterEntry->m_selector->m_expression << "], selected [" << list->GetN() << "]" << std::endl;
476 
477  return true;
478 }
int i
Definition: DBlmapReader.cc:9
virtual void Enter(Long64_t entry)
Definition: FWTEventList.cc:55
virtual edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const
Definition: Event.cc:429
bool accept() const
Has at least one path accepted the event?
selection
main part
Definition: corrVsCorr.py:98
void getByLabel(const P &iP, const char *iModuleLabel, const char *iProductInstanceLabel=0, const char *iProcessLabel=0)
Definition: Handle.h:94
Event const & toBegin()
Go to the very first Event.
Definition: Event.cc:242
int iEvent
Definition: GenABIO.cc:230
int j
Definition: DBlmapReader.cc:9
bool to(Long64_t iIndex)
Go to the event at index iIndex.
Definition: Event.cc:212
std::list< Filter * > & filters()
Definition: FWFileEntry.h:64
TFile * m_file
Definition: FWFileEntry.h:94
virtual bool atEnd() const
Definition: Event.cc:285
fwlite::Event * m_event
Definition: FWFileEntry.h:96
#define fwLog(_level_)
Definition: fwLog.h:50
edm::EventID id() const
Definition: EventBase.h:56
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
std::list<Filter*>& FWFileEntry::filters ( )
inline

Definition at line 64 of file FWFileEntry.h.

References m_filterEntries.

Referenced by CmsShowNavigator::appendFile(), filterEventsWithCustomParser(), and CmsShowNavigator::openFile().

64 { return m_filterEntries; }
std::list< Filter * > m_filterEntries
Definition: FWFileEntry.h:100
int FWFileEntry::firstSelectedEvent ( )

Definition at line 150 of file FWFileEntry.cc.

References m_globalEventList.

151 {
152  if (m_globalEventList->GetN() > 0)
153  {
154  return m_globalEventList->GetEntry(0);
155  }
156  else
157  {
158  return -1;
159  }
160 }
FWTEventList * m_globalEventList
Definition: FWFileEntry.h:101
FWTEventList* FWFileEntry::globalSelection ( )
inline

Definition at line 62 of file FWFileEntry.h.

References m_globalEventList.

62 { return m_globalEventList; }
FWTEventList * m_globalEventList
Definition: FWFileEntry.h:101
bool FWFileEntry::hasActiveFilters ( )

Definition at line 203 of file FWFileEntry.cc.

References m_filterEntries.

204 {
205  for (std::list<Filter*>::iterator it = m_filterEntries.begin(); it != m_filterEntries.end(); ++it)
206  {
207  if ((*it)->m_selector->m_enabled)
208  return true;
209  }
210 
211  return false;
212 }
std::list< Filter * > m_filterEntries
Definition: FWFileEntry.h:100
bool FWFileEntry::hasSelectedEvents ( )

Definition at line 145 of file FWFileEntry.cc.

References m_globalEventList.

146 {
147  return m_globalEventList->GetN() > 0;
148 }
FWTEventList * m_globalEventList
Definition: FWFileEntry.h:101
bool FWFileEntry::isEventSelected ( int  event)

Definition at line 139 of file FWFileEntry.cc.

References customizeTrackingMonitorSeedNumber::idx, and m_globalEventList.

140 {
141  int idx = m_globalEventList->GetIndex(tree_entry);
142  return idx >= 0;
143 }
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
FWTEventList * m_globalEventList
Definition: FWFileEntry.h:101
int FWFileEntry::lastEvent ( )
inline

Definition at line 78 of file FWFileEntry.h.

References m_eventTree.

78 { return m_eventTree->GetEntries() -1; }
TTree * m_eventTree
Definition: FWFileEntry.h:95
int FWFileEntry::lastSelectedEvent ( )

Definition at line 162 of file FWFileEntry.cc.

References m_globalEventList.

163 {
164  if (m_globalEventList->GetN() > 0)
165  return m_globalEventList->GetEntry(m_globalEventList->GetN() - 1);
166  else
167  return -1;
168 }
FWTEventList * m_globalEventList
Definition: FWFileEntry.h:101
void FWFileEntry::needUpdate ( )
inline

Definition at line 83 of file FWFileEntry.h.

References m_needUpdate.

83 { m_needUpdate = true; }
bool m_needUpdate
Definition: FWFileEntry.h:98
int FWFileEntry::nextSelectedEvent ( int  event)

Definition at line 170 of file FWFileEntry.cc.

References customizeTrackingMonitorSeedNumber::idx, list(), and m_globalEventList.

171 {
172  // Find next selected event after the current one.
173  // This returns the index in the selected event list.
174  // If none exists -1 is returned.
175 
176  const Long64_t *list = m_globalEventList->GetList();
177  Long64_t val = tree_entry;
178  Long64_t idx = TMath::BinarySearch(m_globalEventList->GetN(), list, val);
179  ++idx;
180  if (idx >= m_globalEventList->GetN() || idx < 0)
181  return -1;
182  return list[idx];
183 }
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
FWTEventList * m_globalEventList
Definition: FWFileEntry.h:101
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
void FWFileEntry::openFile ( bool  checkVersion)

Definition at line 42 of file FWFileEntry.cc.

References fireworks::acceptDataFormatsVersion(), b, createTree::dd, fwLog, fireworks::getDecomposedVersion(), fwlog::kInfo, m_event, m_eventTree, m_file, m_name, producerFileCleanner::msg, edm::processConfiguration, edm::ProcessConfiguration::processName(), edm::ProcessConfiguration::releaseVersion(), fwlite::Event::size(), fireworks::supportedDataFormatsVersion(), findQualityFiles::v, and x.

Referenced by Vispa.Main.Application.Application::_readCommandLineAttributes(), Vispa.Main.Application.Application::doubleClickOnFile(), FWFileEntry(), Vispa.Main.Application.Application::openFileDialog(), and Vispa.Main.Application.Application::openRecentFileSlot().

43 {
44  gErrorIgnoreLevel = 3000; // suppress warnings about missing dictionaries
45  TFile *newFile = TFile::Open(m_name.c_str());
46  if (newFile == 0 || newFile->IsZombie() || !newFile->Get("Events")) {
47  // std::cout << "Invalid file. Ignored." << std::endl;
48  // return false;
49  throw std::runtime_error("Invalid file. Ignored.");
50  }
51  gErrorIgnoreLevel = -1;
52  m_file = newFile;
53 
54 
55  // check CMSSW relese version for compatibility
56  if (checkVersion) {
57  typedef std::vector<edm::ProcessHistory> provList;
58 
59  TTree *metaData = dynamic_cast<TTree*>(m_file->Get("MetaData"));
60  TBranch *b = metaData->GetBranch("ProcessHistory");
61  provList *x = 0;
62  b->SetAddress(&x);
63  b->GetEntry(0);
64 
65  const edm::ProcessConfiguration* dd = 0;
66  int latestVersion =0;
67  int currentVersionArr[] = {0, 0, 0};
68  for (auto const& processHistory : *x)
69  {
70  for (auto const& processConfiguration : processHistory)
71  {
72  // std::cout << processConfiguration.releaseVersion() << " " << processConfiguration.processName() << std::endl;
73  TString dcv = processConfiguration.releaseVersion();
74  fireworks::getDecomposedVersion(dcv, currentVersionArr);
75  int nvv = currentVersionArr[0]*100 + currentVersionArr[1]*10 + currentVersionArr[2];
76  if (nvv > latestVersion) {
77  latestVersion = nvv;
79  }
80  }
81  }
82 
83  if (latestVersion) {
84  fwLog(fwlog::kInfo) << "Checking process history. " << m_name.c_str() << " latest process \"" << dd->processName() << "\", version " << dd->releaseVersion() << std::endl;
85 
86  b->SetAddress(0);
87  TString v = dd->releaseVersion();
89  {
91  TString msg = Form("incompatible data: Process version does not mactch major data formats version. File produced with %s. Data formats version \"CMSSW_%d_%d_%d\".\n",
92  dd->releaseVersion().c_str(), di[0], di[1], di[2]);
93  msg += "Use --no-version-check option if you still want to view the file.\n";
94  throw std::runtime_error(msg.Data());
95  }
96  }
97  else {
98  TString msg = "No process history available\n";
99  msg += "Use --no-version-check option if you still want to view the file.\n";
100  throw std::runtime_error(msg.Data());
101  }
102  }
103 
104  // load event
106 
107  if (m_event->size() == 0)
108  throw std::runtime_error("fwlite::Event size == 0");
109 
110 
111  m_eventTree = dynamic_cast<TTree*>(m_file->Get("Events"));
112 
113  if (m_eventTree == 0)
114  {
115  throw std::runtime_error("Cannot find TTree 'Events' in the data file");
116  }
117 
118  // This now set in DataHelper
119  //TTreeCache::SetLearnEntries(2);
120  //m_eventTree->SetCacheSize(10*1024*1024);
121  //TTreeCache *tc = (TTreeCache*) m_file->GetCacheRead();
122  //tc->AddBranch(m_event->auxBranch_,kTRUE);
123  //tc->StartLearningPhase();
124 }
processConfiguration
Definition: Schedule.cc:370
void getDecomposedVersion(const TString &s, int *out)
Definition: fwPaths.cc:30
Long64_t size() const
Returns number of events in the file.
Definition: Event.cc:269
std::string const & processName() const
int * supportedDataFormatsVersion()
Definition: fwPaths.cc:43
TFile * m_file
Definition: FWFileEntry.h:94
TTree * m_eventTree
Definition: FWFileEntry.h:95
fwlite::Event * m_event
Definition: FWFileEntry.h:96
#define fwLog(_level_)
Definition: fwLog.h:50
ReleaseVersion const & releaseVersion() const
double b
Definition: hdecay.h:120
bool acceptDataFormatsVersion(TString &n)
Definition: fwPaths.cc:71
std::string m_name
Definition: FWFileEntry.h:93
Definition: DDAxes.h:10
const FWFileEntry& FWFileEntry::operator= ( const FWFileEntry )
private
int FWFileEntry::previousSelectedEvent ( int  event)

Definition at line 185 of file FWFileEntry.cc.

References customizeTrackingMonitorSeedNumber::idx, list(), and m_globalEventList.

186 {
187  // Find first selected event before current one.
188  // This returns the index in the selected event list.
189  // If none exists -1 is returned.
190 
191  const Long64_t *list = m_globalEventList->GetList();
192  Long64_t val = tree_entry;
193  Long64_t idx = TMath::BinarySearch(m_globalEventList->GetN(), list, val);
194  if (list[idx] == val)
195  --idx;
196  if (idx >= 0)
197  return list[idx];
198  else
199  return -1;
200 }
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
FWTEventList * m_globalEventList
Definition: FWFileEntry.h:101
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
void FWFileEntry::runFilter ( Filter fe,
const FWEventItemsManager eiMng 
)
private

Definition at line 260 of file FWFileEntry.cc.

References b, FWEventItemsManager::begin(), edm::TypeWithDict::byName(), end, FWEventItemsManager::end(), filterEventsWithCustomParser(), newFWLiteAna::found, fwLog, fwlite::Event::getBranchNameFor(), FWEventItem::getPrimaryData(), i, fwlog::kDebug, fwlog::kError, fwlog::kWarning, m_event, FWEventItem::m_event, FWFileEntry::Filter::m_eventList, m_eventTree, FWEventSelector::m_expression, m_file, FWFileEntry::Filter::m_needsUpdate, FWFileEntry::Filter::m_selector, FWEventSelector::m_triggerProcess, FWEventItem::moduleLabel(), edm::TypeWithDict::name(), mergeVDriftHistosByStation::name, FWEventItem::processName(), FWEventItem::productInstanceLabel(), query::result, AlCaHLTBitMon_QueryRunRegistry::string, FWEventItem::type(), edm::TypeWithDict::typeInfo(), and edm::wrappedClassName().

Referenced by updateFilters().

261 {
262  if (!filter->m_selector->m_triggerProcess.empty())
263  {
265  return;
266  }
267 
268  // parse selection for known Fireworks expressions
269  std::string interpretedSelection = filter->m_selector->m_expression;
270 
272  end = eiMng->end(); i != end; ++i)
273  {
274  FWEventItem *item = *i;
275  if (item == 0)
276  continue;
277  // FIXME: hack to get full branch name filled
278  if (item->m_event == 0)
279  {
280  item->m_event = m_event;
281  item->getPrimaryData();
282  item->m_event = 0;
283  }
284 
285  boost::regex re(std::string("\\$") + (*i)->name());
286 
287  if (boost::regex_search(interpretedSelection, re))
288  {
289  const edm::TypeWithDict elementType(const_cast<TClass*>(item->type()));
290  const edm::TypeWithDict wrapperType = edm::TypeWithDict::byName(edm::wrappedClassName(elementType.name()));
291  std::string fullBranchName = m_event->getBranchNameFor(wrapperType.typeInfo(),
292  item->moduleLabel().c_str(),
293  item->productInstanceLabel().c_str(),
294  item->processName().c_str());
295 
296  interpretedSelection = boost::regex_replace(interpretedSelection, re,
297  fullBranchName + ".obj");
298 
299  // printf("selection after applying s/%s/%s/: %s\n",
300  // (std::string("\\$") + (*i)->name()).c_str(),
301  // ((*i)->m_fullBranchName + ".obj").c_str(),
302  // interpretedSelection.c_str());
303  }
304  }
305 
306 
307  std::size_t found = interpretedSelection.find('$');
308  if (found!=std::string::npos)
309  {
310  fwLog(fwlog::kError) << "FWFileEntry::RunFilter invalid expression " << interpretedSelection << std::endl;
311  filter->m_needsUpdate = false;
312  return;
313  }
314 
315  m_file->cd();
316  m_eventTree->SetEventList(0);
317 
318  // Since ROOT will leave any TBranches used in the filtering at the last event,
319  // we need to be able to reset them to what fwlite::Event expects them to be
320  // we do this by holding onto the old buffers and create temporary new ones.
321 
322  std::map<TBranch*, void*> prevAddrs;
323 
324  {
325  TObjArray* branches = m_eventTree->GetListOfBranches();
326  std::auto_ptr<TIterator> pIt( branches->MakeIterator());
327  while (TObject* branchObj = pIt->Next())
328  {
329  TBranch* b = dynamic_cast<TBranch*> (branchObj);
330  if (0!=b)
331  {
332  const char * name = b->GetName();
333  unsigned int length = strlen(name);
334  if (length > 1 && name[length-1] != '.')
335  {
336  // This is not a data branch so we should ignore it.
337  continue;
338  }
339  if (0 != b->GetAddress())
340  {
341  if (prevAddrs.find(b) != prevAddrs.end())
342  {
343  fwLog(fwlog::kWarning) << "FWFileEntry::runFilter branch is already in the map!\n";
344  }
345  prevAddrs.insert(std::make_pair(b, b->GetAddress()));
346 
347  // std::cout <<"Zeroing branch: "<< b->GetName() <<" "<< (void*) b->GetAddress() <<std::endl;
348  b->SetAddress(0);
349  }
350  }
351  }
352  }
353 
354  if (filter->m_eventList)
355  filter->m_eventList->Reset();
356  else
357  filter->m_eventList = new FWTEventList;
358 
359  TEveSelectorToEventList stoelist(filter->m_eventList, interpretedSelection.c_str());
360  Long64_t result = m_eventTree->Process(&stoelist);
361 
362  if (result < 0)
363  fwLog(fwlog::kWarning) << "FWFileEntry::runFilter in file [" << m_file->GetName() << "] filter [" << filter->m_selector->m_expression << "] is invalid." << std::endl;
364  else
365  fwLog(fwlog::kDebug) << "FWFileEntry::runFilter is file [" << m_file->GetName() << "], filter [" << filter->m_selector->m_expression << "] has [" << filter->m_eventList->GetN() << "] events selected" << std::endl;
366 
367  // Set back the old branch buffers.
368  {
369  for (auto i : prevAddrs)
370  {
371  // std::cout <<"Resetting branch: "<< i.first->GetName() <<" "<< i.second <<std::endl;
372  i.first->SetAddress(i.second);
373  }
374  }
375 
376  filter->m_needsUpdate = false;
377 }
int i
Definition: DBlmapReader.cc:9
static TypeWithDict byName(std::string const &className)
void getPrimaryData() const
Definition: FWEventItem.cc:443
const std::string & processName() const
Definition: FWEventItem.cc:529
virtual std::string const getBranchNameFor(std::type_info const &, char const *iModuleLabel, char const *iProductInstanceLabel, char const *iProcessName) const
Return the branch name in the TFile which contains the data.
Definition: Event.cc:305
const std::string & productInstanceLabel() const
Definition: FWEventItem.cc:523
const TClass * type() const
Definition: FWEventItem.cc:506
tuple result
Definition: query.py:137
bool filterEventsWithCustomParser(Filter *filter)
Definition: FWFileEntry.cc:382
std::type_info const & typeInfo() const
#define end
Definition: vmac.h:37
TFile * m_file
Definition: FWFileEntry.h:94
TTree * m_eventTree
Definition: FWFileEntry.h:95
fwlite::Event * m_event
Definition: FWFileEntry.h:96
const_iterator begin() const
NOTE: iterator is allowed to return a null object for items that have been removed.
#define fwLog(_level_)
Definition: fwLog.h:50
std::string wrappedClassName(std::string const &iFullName)
double b
Definition: hdecay.h:120
const edm::EventBase * m_event
Definition: FWEventItem.h:239
std::vector< FWEventItem * >::const_iterator const_iterator
const std::string & moduleLabel() const
Definition: FWEventItem.cc:518
const_iterator end() const
TTree* FWFileEntry::tree ( )
inline
void FWFileEntry::updateFilters ( const FWEventItemsManager eiMng,
bool  isOR 
)

Definition at line 215 of file FWFileEntry.cc.

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

216 {
217  if (!m_needUpdate)
218  return;
219 
220  if (m_globalEventList)
221  m_globalEventList->Reset();
222  else
224 
225  for (std::list<Filter*>::iterator it = m_filterEntries.begin(); it != m_filterEntries.end(); ++it)
226  {
227  if ((*it)->m_selector->m_enabled && (*it)->m_needsUpdate)
228  {
229  runFilter(*it, eiMng);
230  }
231  // Need to re-check if enabled after filtering as it can be set to false
232  // in runFilter().
233  if ((*it)->m_selector->m_enabled)
234  {
235  if ((*it)->hasSelectedEvents())
236  {
237  if (globalOR || m_globalEventList->GetN() == 0)
238  {
239  m_globalEventList->Add((*it)->m_eventList);
240  }
241  else
242  {
243  m_globalEventList->Intersect((*it)->m_eventList);
244  }
245  }
246  else if (!globalOR)
247  {
248  m_globalEventList->Reset();
249  break;
250  }
251  }
252  }
253 
254  fwLog(fwlog::kDebug) << "FWFileEntry::updateFilters in [" << m_file->GetName() << "] global selection [" << m_globalEventList->GetN() << "/" << m_eventTree->GetEntries() << "]" << std::endl;
255 
256  m_needUpdate = false;
257 }
std::list< Filter * > m_filterEntries
Definition: FWFileEntry.h:100
virtual void Add(const TEventList *list)
Definition: FWTEventList.cc:7
TFile * m_file
Definition: FWFileEntry.h:94
bool m_needUpdate
Definition: FWFileEntry.h:98
TTree * m_eventTree
Definition: FWFileEntry.h:95
#define fwLog(_level_)
Definition: fwLog.h:50
void runFilter(Filter *fe, const FWEventItemsManager *eiMng)
Definition: FWFileEntry.cc:260
FWTEventList * m_globalEventList
Definition: FWFileEntry.h:101

Member Data Documentation

fwlite::Event* FWFileEntry::m_event
private

Definition at line 96 of file FWFileEntry.h.

Referenced by closeFile(), event(), filterEventsWithCustomParser(), openFile(), and runFilter().

TTree* FWFileEntry::m_eventTree
private

Definition at line 95 of file FWFileEntry.h.

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

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

Definition at line 100 of file FWFileEntry.h.

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

FWTEventList* FWFileEntry::m_globalEventList
private
std::string FWFileEntry::m_name
private

Definition at line 93 of file FWFileEntry.h.

Referenced by openFile().

bool FWFileEntry::m_needUpdate
private

Definition at line 98 of file FWFileEntry.h.

Referenced by needUpdate(), and updateFilters().