CMS 3D CMS Logo

TriggerOutputBranches.cc
Go to the documentation of this file.
5 
6 #include <iostream>
7 
10  const edm::TriggerResults& triggers) {
11  std::vector<std::string> newNames(triggers.getTriggerNames());
12  if (newNames.empty()) {
13  for (unsigned int j = 0; j < triggers.size(); j++) {
14  newNames.push_back(names.triggerName(j));
15  }
16  }
17 
18  for (auto& existing : m_triggerBranches) {
19  existing.idx = -1; // reset all triggers as not found and zero buffer
20  existing.buffer = 0; // reset all triggers as not found and zero buffer
21  for (unsigned int j = 0; j < newNames.size(); j++) {
22  std::string name = newNames[j]; // no const & as it will be modified below!
23  std::size_t vfound = name.rfind("_v");
24  if (vfound != std::string::npos && (name.compare(0, 3, "HLT") == 0 || name.compare(0, 2, "L1") == 0 ||
25  name.find("Scouting") != std::string::npos)) {
26  name.replace(vfound, name.size() - vfound, "");
27  }
28  if (name == existing.name)
29  existing.idx = j;
30  }
31  }
32  // Find new ones
33  for (unsigned int j = 0; j < newNames.size(); j++) {
34  std::string name = newNames[j]; // no const & as it will be modified below!
35  std::size_t vfound = name.rfind("_v");
36  if (vfound != std::string::npos && (name.compare(0, 3, "HLT") == 0 || name.compare(0, 2, "L1") == 0 ||
37  name.find("Scouting") != std::string::npos)) {
38  name.replace(vfound, name.size() - vfound, "");
39  }
40  bool found = false;
41  if (name.compare(0, 3, "HLT") == 0 || name.compare(0, 4, "Flag") == 0 || name.compare(0, 2, "L1") == 0 ||
42  name.find("Scouting") != std::string::npos) {
43  for (auto& existing : m_triggerBranches) {
44  if (name == existing.name)
45  found = true;
46  }
47  if (!found) {
48  NamedBranchPtr nb(
49  name,
50  std::string("Trigger/flag bit (process: ") + m_processName +
51  ")"); //FIXME: If the title can be updated we can use it to list the versions _v* that were seen in this file
52  uint8_t backFillValue = 0;
53  bool found_duplicate = verifyBranchUniqueName(tree, nb.name);
54  std::string brname = nb.name + (found_duplicate ? (std::string("_p") + m_processName) : "");
55  nb.branch = tree.Branch(brname.c_str(), &backFillValue, (brname + "/O").c_str());
56  nb.branch->SetTitle(nb.title.c_str());
57  nb.idx = j;
58  m_triggerBranches.push_back(nb);
59  for (size_t i = 0; i < m_fills; i++)
60  nb.branch->Fill(); // Back fill
61  }
62  }
63  }
64 }
65 
68  edm::ParameterSet const* pset = nullptr;
69  if (nullptr != (pset = psetRegistry->getMapped(triggerResults.parameterSetID()))) {
70  if (pset->existsAs<std::vector<std::string> >("@trigger_paths", true)) {
72 
73  // This should never happen
74  if (triggerNames.size() != triggerResults.size()) {
75  throw cms::Exception("LogicError") << "edm::EventBase::triggerNames_ Encountered vector\n"
76  "of trigger names and a TriggerResults object with\n"
77  "different sizes. This should be impossible.\n"
78  "Please send information to reproduce this problem to\n"
79  "the edm developers.\n";
80  }
81  return triggerNames;
82  }
83  }
84  return edm::TriggerNames();
85 }
86 
89  iEvent.getByToken(m_token, handle);
90  const edm::TriggerResults& triggers = *handle;
91  const edm::TriggerNames& names = triggerNames(triggers);
92 
93  if (m_lastRun != iEvent.id().run()) {
94  m_lastRun = iEvent.id().run();
95  updateTriggerNames(tree, names, triggers);
96  }
97  for (auto& pair : m_triggerBranches)
98  fillColumn<uint8_t>(pair, triggers);
99  m_fills++;
100 }
101 
103  auto const branches = tree.GetListOfBranches();
104  for (int i = 0; i < branches->GetEntries(); i++) {
105  if (name == std::string(branches->At(i)->GetName())) {
106  edm::LogWarning("TriggerOutputBranches")
107  << "Found a branch with name " << std::string(branches->At(i)->GetName()) << " already present with title "
108  << std::string(branches->At(i)->GetTitle()) << ": will add suffix _p" << m_processName
109  << " to the new branch.\n";
110  return true;
111  }
112  }
113  return false;
114 }
bool getMapped(key_type const &k, value_type &result) const
Definition: Registry.cc:17
bool verifyBranchUniqueName(TTree &, std::string) const
const std::string names[nVars_]
unsigned int size() const
Get number of paths stored.
int iEvent
Definition: GenABIO.cc:224
const std::vector< std::string > & getTriggerNames() const
Obsolete.
static std::string const triggerResults
Definition: EdmProvDump.cc:47
edm::TriggerNames triggerNames(const edm::TriggerResults triggerResults)
std::size_t size() const
Definition: TriggerNames.cc:59
Definition: tree.py:1
Log< level::Warning, false > LogWarning
void fill(const edm::EventForOutput &iEvent, TTree &tree)
void updateTriggerNames(TTree &tree, const edm::TriggerNames &names, const edm::TriggerResults &ta)
std::vector< NamedBranchPtr > m_triggerBranches
static Registry * instance()
Definition: Registry.cc:12