CMS 3D CMS Logo

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

#include <TriggerOutputBranches.h>

Classes

struct  NamedBranchPtr
 

Public Member Functions

void fill (const edm::EventForOutput &iEvent, TTree &tree)
 
 TriggerOutputBranches (const edm::BranchDescription *desc, const edm::EDGetToken &token)
 
void updateTriggerNames (TTree &tree, const edm::TriggerNames &names, const edm::TriggerResults &ta)
 

Private Member Functions

template<typename T >
void fillColumn (NamedBranchPtr &nb, const edm::TriggerResults &triggers)
 
edm::TriggerNames triggerNames (const edm::TriggerResults triggerResults)
 

Private Attributes

std::string m_baseName
 
UInt_t m_counter
 
unsigned long m_fills
 
long m_lastRun
 
bool m_singleton
 
edm::EDGetToken m_token
 
std::vector< NamedBranchPtrm_triggerBranches
 

Detailed Description

Definition at line 13 of file TriggerOutputBranches.h.

Constructor & Destructor Documentation

TriggerOutputBranches::TriggerOutputBranches ( const edm::BranchDescription desc,
const edm::EDGetToken token 
)
inline

Definition at line 15 of file TriggerOutputBranches.h.

References edm::BranchDescription::className(), fill(), iEvent, names, triggerNames(), triggerResults, and updateTriggerNames().

16  : m_token(token), m_lastRun(-1), m_fills(0) {
17  if (desc->className() != "edm::TriggerResults")
18  throw cms::Exception("Configuration",
19  "NanoAODOutputModule/TriggerOutputBranches can only write out edm::TriggerResults objects");
20  }
std::string const & className() const

Member Function Documentation

void TriggerOutputBranches::fill ( const edm::EventForOutput iEvent,
TTree &  tree 
)

Definition at line 79 of file TriggerOutputBranches.cc.

References edm::OccurrenceForOutput::getByToken(), patZpeak::handle, edm::EventForOutput::id(), m_fills, m_lastRun, m_token, m_triggerBranches, names, edm::EventID::run(), triggerNames(), and updateTriggerNames().

Referenced by TriggerOutputBranches().

79  {
81  iEvent.getByToken(m_token, handle);
82  const edm::TriggerResults& triggers = *handle;
83  const edm::TriggerNames& names = triggerNames(triggers);
84 
85  if (m_lastRun != iEvent.id().run()) {
86  m_lastRun = iEvent.id().run();
87  updateTriggerNames(tree, names, triggers);
88  }
89  for (auto& pair : m_triggerBranches)
90  fillColumn<uint8_t>(pair, triggers);
91  m_fills++;
92 }
RunNumber_t run() const
Definition: EventID.h:38
EventID const & id() const
BasicHandle getByToken(EDGetToken token, TypeID const &typeID) const
const std::string names[nVars_]
edm::TriggerNames triggerNames(const edm::TriggerResults triggerResults)
Definition: tree.py:1
void updateTriggerNames(TTree &tree, const edm::TriggerNames &names, const edm::TriggerResults &ta)
std::vector< NamedBranchPtr > m_triggerBranches
template<typename T >
void TriggerOutputBranches::fillColumn ( NamedBranchPtr nb,
const edm::TriggerResults triggers 
)
inlineprivate

Definition at line 47 of file TriggerOutputBranches.h.

References edm::HLTGlobalStatus::accept(), TriggerOutputBranches::NamedBranchPtr::branch, TriggerOutputBranches::NamedBranchPtr::buffer, and TriggerOutputBranches::NamedBranchPtr::idx.

47  {
48  if (nb.idx >= 0)
49  nb.buffer = triggers.accept(nb.idx);
50  nb.branch->SetAddress(&(nb.buffer)); // Can be improved: this is not reallt needed at each event
51  //but we should be sure that resize of vectors of TriggerOutputBranches do not mess up things
52  }
bool accept() const
Has at least one path accepted the event?
edm::TriggerNames TriggerOutputBranches::triggerNames ( const edm::TriggerResults  triggerResults)
private

Definition at line 58 of file TriggerOutputBranches.cc.

References Exception, edm::ParameterSet::existsAs(), edm::pset::Registry::getMapped(), edm::pset::Registry::instance(), edm::TriggerResults::parameterSetID(), muonDTDigis_cfi::pset, edm::HLTGlobalStatus::size(), and edm::TriggerNames::size().

Referenced by fill(), and TriggerOutputBranches().

58  {
60  edm::ParameterSet const* pset = nullptr;
61  if (nullptr != (pset = psetRegistry->getMapped(triggerResults.parameterSetID()))) {
62  if (pset->existsAs<std::vector<std::string> >("@trigger_paths", true)) {
64 
65  // This should never happen
66  if (triggerNames.size() != triggerResults.size()) {
67  throw cms::Exception("LogicError") << "edm::EventBase::triggerNames_ Encountered vector\n"
68  "of trigger names and a TriggerResults object with\n"
69  "different sizes. This should be impossible.\n"
70  "Please send information to reproduce this problem to\n"
71  "the edm developers.\n";
72  }
73  return triggerNames;
74  }
75  }
76  return edm::TriggerNames();
77 }
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:160
Strings::size_type size() const
Definition: TriggerNames.cc:31
unsigned int size() const
Get number of paths stored.
bool getMapped(key_type const &k, value_type &result) const
Definition: Registry.cc:17
edm::TriggerNames triggerNames(const edm::TriggerResults triggerResults)
const ParameterSetID & parameterSetID() const
Get stored parameter set id.
static Registry * instance()
Definition: Registry.cc:12
void TriggerOutputBranches::updateTriggerNames ( TTree &  tree,
const edm::TriggerNames names,
const edm::TriggerResults ta 
)

Definition at line 7 of file TriggerOutputBranches.cc.

References TriggerOutputBranches::NamedBranchPtr::branch, dqmPostProcessing_online::existing, newFWLiteAna::found, edm::TriggerResults::getTriggerNames(), mps_fire::i, TriggerOutputBranches::NamedBranchPtr::idx, dqmiolumiharvest::j, m_fills, m_triggerBranches, Skims_PA_cff::name, TriggerOutputBranches::NamedBranchPtr::name, edm::HLTGlobalStatus::size(), AlCaHLTBitMon_QueryRunRegistry::string, TriggerOutputBranches::NamedBranchPtr::title, and edm::TriggerNames::triggerName().

Referenced by fill(), and TriggerOutputBranches().

9  {
10  std::vector<std::string> newNames(triggers.getTriggerNames());
11  if (newNames.empty()) {
12  for (unsigned int j = 0; j < triggers.size(); j++) {
13  newNames.push_back(names.triggerName(j));
14  }
15  }
16 
17  for (auto& existing : m_triggerBranches) {
18  existing.idx = -1; // reset all triggers as not found
19  for (unsigned int j = 0; j < newNames.size(); j++) {
20  std::string name = newNames[j]; // no const & as it will be modified below!
21  std::size_t vfound = name.rfind("_v");
22  if (vfound != std::string::npos) {
23  name.replace(vfound, name.size() - vfound, "");
24  }
25  if (name == existing.name)
26  existing.idx = j;
27  }
28  }
29  // Find new ones
30  for (unsigned int j = 0; j < newNames.size(); j++) {
31  std::string name = newNames[j]; // no const & as it will be modified below!
32  std::size_t vfound = name.rfind("_v");
33  if (vfound != std::string::npos) {
34  name.replace(vfound, name.size() - vfound, "");
35  }
36  bool found = false;
37  if (name.compare(0, 3, "HLT") == 0 || name.compare(0, 4, "Flag") == 0 || name.compare(0, 2, "L1") == 0) {
38  for (auto& existing : m_triggerBranches) {
39  if (name == existing.name)
40  found = true;
41  }
42  if (!found) {
43  NamedBranchPtr nb(
44  name,
45  "Trigger/flag bit"); //FIXME: If the title can be updated we can use it to list the versions _v* that were seen in this file
46  uint8_t backFillValue = 0;
47  nb.branch = tree.Branch(nb.name.c_str(), &backFillValue, (name + "/O").c_str());
48  nb.branch->SetTitle(nb.title.c_str());
49  nb.idx = j;
50  m_triggerBranches.push_back(nb);
51  for (size_t i = 0; i < m_fills; i++)
52  nb.branch->Fill(); // Back fill
53  }
54  }
55  }
56 }
std::string const & triggerName(unsigned int index) const
Definition: TriggerNames.cc:22
Definition: tree.py:1
std::vector< NamedBranchPtr > m_triggerBranches

Member Data Documentation

std::string TriggerOutputBranches::m_baseName
private

Definition at line 31 of file TriggerOutputBranches.h.

UInt_t TriggerOutputBranches::m_counter
private

Definition at line 33 of file TriggerOutputBranches.h.

unsigned long TriggerOutputBranches::m_fills
private

Definition at line 44 of file TriggerOutputBranches.h.

Referenced by fill(), and updateTriggerNames().

long TriggerOutputBranches::m_lastRun
private

Definition at line 43 of file TriggerOutputBranches.h.

Referenced by fill().

bool TriggerOutputBranches::m_singleton
private

Definition at line 32 of file TriggerOutputBranches.h.

edm::EDGetToken TriggerOutputBranches::m_token
private

Definition at line 30 of file TriggerOutputBranches.h.

Referenced by fill().

std::vector<NamedBranchPtr> TriggerOutputBranches::m_triggerBranches
private

Definition at line 42 of file TriggerOutputBranches.h.

Referenced by fill(), and updateTriggerNames().