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.replace(vfound, name.size() - vfound, "");
26  }
27  if (name == existing.name)
28  existing.idx = j;
29  }
30  }
31  // Find new ones
32  for (unsigned int j = 0; j < newNames.size(); j++) {
33  std::string name = newNames[j]; // no const & as it will be modified below!
34  std::size_t vfound = name.rfind("_v");
35  if (vfound != std::string::npos && (name.compare(0, 3, "HLT") == 0 || name.compare(0, 2, "L1") == 0)) {
36  name.replace(vfound, name.size() - vfound, "");
37  }
38  bool found = false;
39  if (name.compare(0, 3, "HLT") == 0 || name.compare(0, 4, "Flag") == 0 || name.compare(0, 2, "L1") == 0) {
40  for (auto& existing : m_triggerBranches) {
41  if (name == existing.name)
42  found = true;
43  }
44  if (!found) {
45  NamedBranchPtr nb(
46  name,
47  std::string("Trigger/flag bit (process: ") + m_processName +
48  ")"); //FIXME: If the title can be updated we can use it to list the versions _v* that were seen in this file
49  uint8_t backFillValue = 0;
50  bool found_duplicate = verifyBranchUniqueName(tree, nb.name);
51  std::string brname = nb.name + (found_duplicate ? (std::string("_p") + m_processName) : "");
52  nb.branch = tree.Branch(brname.c_str(), &backFillValue, (brname + "/O").c_str());
53  nb.branch->SetTitle(nb.title.c_str());
54  nb.idx = j;
55  m_triggerBranches.push_back(nb);
56  for (size_t i = 0; i < m_fills; i++)
57  nb.branch->Fill(); // Back fill
58  }
59  }
60  }
61 }
62 
65  edm::ParameterSet const* pset = nullptr;
66  if (nullptr != (pset = psetRegistry->getMapped(triggerResults.parameterSetID()))) {
67  if (pset->existsAs<std::vector<std::string> >("@trigger_paths", true)) {
69 
70  // This should never happen
71  if (triggerNames.size() != triggerResults.size()) {
72  throw cms::Exception("LogicError") << "edm::EventBase::triggerNames_ Encountered vector\n"
73  "of trigger names and a TriggerResults object with\n"
74  "different sizes. This should be impossible.\n"
75  "Please send information to reproduce this problem to\n"
76  "the edm developers.\n";
77  }
78  return triggerNames;
79  }
80  }
81  return edm::TriggerNames();
82 }
83 
86  iEvent.getByToken(m_token, handle);
87  const edm::TriggerResults& triggers = *handle;
88  const edm::TriggerNames& names = triggerNames(triggers);
89 
90  if (m_lastRun != iEvent.id().run()) {
91  m_lastRun = iEvent.id().run();
92  updateTriggerNames(tree, names, triggers);
93  }
94  for (auto& pair : m_triggerBranches)
95  fillColumn<uint8_t>(pair, triggers);
96  m_fills++;
97 }
98 
100  auto const branches = tree.GetListOfBranches();
101  for (int i = 0; i < branches->GetEntries(); i++) {
102  if (name == std::string(branches->At(i)->GetName())) {
103  edm::LogWarning("TriggerOutputBranches")
104  << "Found a branch with name " << std::string(branches->At(i)->GetName()) << " already present with title "
105  << std::string(branches->At(i)->GetTitle()) << ": will add suffix _p" << m_processName
106  << " to the new branch.\n";
107  return true;
108  }
109  }
110  return false;
111 }
edm::pset::Registry::instance
static Registry * instance()
Definition: Registry.cc:12
TriggerOutputBranches::verifyBranchUniqueName
bool verifyBranchUniqueName(TTree &, std::string) const
Definition: TriggerOutputBranches.cc:99
TriggerOutputBranches::NamedBranchPtr::branch
TBranch * branch
Definition: TriggerOutputBranches.h:38
mps_fire.i
i
Definition: mps_fire.py:355
TriggerOutputBranches::NamedBranchPtr::name
std::string name
Definition: TriggerOutputBranches.h:36
edm::TriggerResults::getTriggerNames
const std::vector< std::string > & getTriggerNames() const
Obsolete.
Definition: TriggerResults.h:78
patZpeak.handle
handle
Definition: patZpeak.py:23
TriggerOutputBranches::m_triggerBranches
std::vector< NamedBranchPtr > m_triggerBranches
Definition: TriggerOutputBranches.h:43
tree
Definition: tree.py:1
TriggerOutputBranches::triggerNames
edm::TriggerNames triggerNames(const edm::TriggerResults triggerResults)
Definition: TriggerOutputBranches.cc:63
TriggerOutputBranches::NamedBranchPtr::title
std::string title
Definition: TriggerOutputBranches.h:36
triggerResults
static const std::string triggerResults
Definition: EdmProvDump.cc:45
dqmPostProcessing_online.existing
existing
Definition: dqmPostProcessing_online.py:126
newFWLiteAna.found
found
Definition: newFWLiteAna.py:118
edm::Handle< edm::TriggerResults >
TriggerOutputBranches::m_lastRun
long m_lastRun
Definition: TriggerOutputBranches.h:44
MakerMacros.h
names
const std::string names[nVars_]
Definition: PhotonIDValueMapProducer.cc:122
edm::HLTGlobalStatus::size
unsigned int size() const
Get number of paths stored.
Definition: HLTGlobalStatus.h:35
TriggerOutputBranches::updateTriggerNames
void updateTriggerNames(TTree &tree, const edm::TriggerNames &names, const edm::TriggerResults &ta)
Definition: TriggerOutputBranches.cc:8
TriggerOutputBranches::m_token
edm::EDGetToken m_token
Definition: TriggerOutputBranches.h:31
TriggerOutputBranches::m_fills
unsigned long m_fills
Definition: TriggerOutputBranches.h:45
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
TriggerOutputBranches::NamedBranchPtr
Definition: TriggerOutputBranches.h:35
edm::LogWarning
Definition: MessageLogger.h:141
edm::ParameterSet
Definition: ParameterSet.h:36
iEvent
int iEvent
Definition: GenABIO.cc:224
TriggerOutputBranches::fill
void fill(const edm::EventForOutput &iEvent, TTree &tree)
Definition: TriggerOutputBranches.cc:84
Registry.h
edm::EventForOutput
Definition: EventForOutput.h:50
TriggerOutputBranches::NamedBranchPtr::idx
int idx
Definition: TriggerOutputBranches.h:37
edm::TriggerNames::size
Strings::size_type size() const
Definition: TriggerNames.cc:31
Exception
Definition: hltDiff.cc:246
TriggerOutputBranches.h
edm::TriggerNames
Definition: TriggerNames.h:55
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
ParameterSet.h
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
TriggerOutputBranches::m_processName
std::string m_processName
Definition: TriggerOutputBranches.h:46
edm::pset::Registry::getMapped
bool getMapped(key_type const &k, value_type &result) const
Definition: Registry.cc:17
edm::TriggerResults
Definition: TriggerResults.h:35
edm::pset::Registry
Definition: Registry.h:26
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27