CMS 3D CMS Logo

TriggerOutputBranches.cc
Go to the documentation of this file.
4 
5 #include <iostream>
6 
9  const edm::TriggerResults& triggers) {
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 }
57 
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 }
78 
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
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:160
BasicHandle getByToken(EDGetToken token, TypeID const &typeID) const
Strings::size_type size() const
Definition: TriggerNames.cc:31
const std::string names[nVars_]
const std::vector< std::string > & getTriggerNames() const
Obsolete.
int iEvent
Definition: GenABIO.cc:224
unsigned int size() const
Get number of paths stored.
bool getMapped(key_type const &k, value_type &result) const
Definition: Registry.cc:17
static std::string const triggerResults
Definition: EdmProvDump.cc:45
edm::TriggerNames triggerNames(const edm::TriggerResults triggerResults)
std::string const & triggerName(unsigned int index) const
Definition: TriggerNames.cc:22
Definition: tree.py:1
void fill(const edm::EventForOutput &iEvent, TTree &tree)
const ParameterSetID & parameterSetID() const
Get stored parameter set id.
void updateTriggerNames(TTree &tree, const edm::TriggerNames &names, const edm::TriggerResults &ta)
std::vector< NamedBranchPtr > m_triggerBranches
static Registry * instance()
Definition: Registry.cc:12