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)
 
std::string processName ()
 
 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)
 
bool verifyBranchUniqueName (TTree &, std::string) const
 

Private Attributes

std::string m_baseName
 
UInt_t m_counter
 
unsigned long m_fills
 
long m_lastRun
 
std::string m_processName
 
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, and updateTriggerNames().

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

Member Function Documentation

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

Definition at line 81 of file TriggerOutputBranches.cc.

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

Referenced by TriggerOutputBranches().

82 {
84  iEvent.getByToken(m_token, handle);
85  const edm::TriggerResults & triggers = *handle;
86  const edm::TriggerNames &names = triggerNames(triggers);
87 
88  if(m_lastRun!=iEvent.id().run()) {
89  m_lastRun=iEvent.id().run();
90  updateTriggerNames(tree,names,triggers);
91  }
92  for (auto & pair : m_triggerBranches) fillColumn<uint8_t>(pair, triggers);
93  m_fills++;
94 }
RunNumber_t run() const
Definition: EventID.h:39
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  nb.buffer = (nb.idx >= 0) ? triggers.accept(nb.idx) : 0;
49  nb.branch->SetAddress(&(nb.buffer)); // Can be improved: this is not reallt needed at each event
50  //but we should be sure that resize of vectors of TriggerOutputBranches do not mess up things
51  }
bool accept() const
Has at least one path accepted the event?
std::string TriggerOutputBranches::processName ( )
inline

Definition at line 23 of file TriggerOutputBranches.h.

References m_processName, triggerNames(), and triggerResults.

Referenced by NanoAODOutputModule::write().

23 { return m_processName; }
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 processName().

58  {
60  edm::ParameterSet const* pset=nullptr;
61  if (nullptr!=(pset=psetRegistry->getMapped(triggerResults.parameterSetID()))) {
62 
63  if (pset->existsAs<std::vector<std::string> >("@trigger_paths", true)) {
65 
66  // This should never happen
67  if (triggerNames.size() != triggerResults.size()) {
68  throw cms::Exception("LogicError")
69  << "edm::EventBase::triggerNames_ Encountered vector\n"
70  "of trigger names and a TriggerResults object with\n"
71  "different sizes. This should be impossible.\n"
72  "Please send information to reproduce this problem to\n"
73  "the edm developers.\n";
74  }
75  return triggerNames;
76  }
77  }
78  return edm::TriggerNames();
79 }
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:161
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 9 of file TriggerOutputBranches.cc.

References TriggerOutputBranches::NamedBranchPtr::branch, runEdmFileComparison::found, edm::TriggerResults::getTriggerNames(), mps_fire::i, TriggerOutputBranches::NamedBranchPtr::idx, m_fills, m_processName, m_triggerBranches, TriggerOutputBranches::NamedBranchPtr::name, dataset::name, edm::HLTGlobalStatus::size(), AlCaHLTBitMon_QueryRunRegistry::string, TriggerOutputBranches::NamedBranchPtr::title, edm::TriggerNames::triggerName(), and verifyBranchUniqueName().

Referenced by fill(), and TriggerOutputBranches().

10 {
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  {
20  existing.idx = -1; // reset all triggers as not found and zero buffer
21  existing.buffer = 0; // reset all triggers as not found and zero buffer
22  for(unsigned int j=0;j<newNames.size();j++) {
23  std::string name=newNames[j]; // no const & as it will be modified below!
24  std::size_t vfound = name.rfind("_v");
25  if (vfound!=std::string::npos && (name.compare(0, 3, "HLT") == 0 || name.compare(0, 2, "L1") == 0)){
26  name.replace(vfound,name.size()-vfound,"");
27  }
28  if(name==existing.name) 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) {if(name==existing.name) found=true;}
41  if(!found){
42  NamedBranchPtr nb(name,
43  std::string("Trigger/flag bit (process: ") + m_processName +
44  ")"); //FIXME: If the title can be updated we can use it to list the versions _v* that were seen in this file
45  uint8_t backFillValue=0;
46  bool found_duplicate = verifyBranchUniqueName(tree, nb.name);
47  std::string brname = nb.name + (found_duplicate ? (std::string("_p") + m_processName) : "");
48  nb.branch = tree.Branch(brname.c_str(), &backFillValue, (brname + "/O").c_str());
49  nb.branch->SetTitle(nb.title.c_str());
50  nb.idx=j;
51  m_triggerBranches.push_back(nb);
52  for(size_t i=0;i<m_fills;i++) nb.branch->Fill(); // Back fill
53  }
54  }
55  }
56 }
bool verifyBranchUniqueName(TTree &, std::string) const
std::string const & triggerName(unsigned int index) const
Definition: TriggerNames.cc:22
Definition: tree.py:1
std::vector< NamedBranchPtr > m_triggerBranches
bool TriggerOutputBranches::verifyBranchUniqueName ( TTree &  tree,
std::string  name 
) const
private

Definition at line 96 of file TriggerOutputBranches.cc.

References mps_fire::i, m_processName, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by updateTriggerNames().

96  {
97  auto const branches = tree.GetListOfBranches();
98  for (int i = 0; i < branches->GetEntries(); i++) {
99  if (name == std::string(branches->At(i)->GetName())) {
100  edm::LogWarning("TriggerOutputBranches")
101  << "Found a branch with name " << std::string(branches->At(i)->GetName()) << " already present with title "
102  << std::string(branches->At(i)->GetTitle()) << ": will add suffix _p" << m_processName
103  << " to the new branch.\n";
104  return true;
105  }
106  }
107  return false;
108 }
Definition: tree.py:1

Member Data Documentation

std::string TriggerOutputBranches::m_baseName
private

Definition at line 29 of file TriggerOutputBranches.h.

UInt_t TriggerOutputBranches::m_counter
private

Definition at line 31 of file TriggerOutputBranches.h.

unsigned long TriggerOutputBranches::m_fills
private

Definition at line 42 of file TriggerOutputBranches.h.

Referenced by fill(), and updateTriggerNames().

long TriggerOutputBranches::m_lastRun
private

Definition at line 41 of file TriggerOutputBranches.h.

Referenced by fill().

std::string TriggerOutputBranches::m_processName
private

Definition at line 43 of file TriggerOutputBranches.h.

Referenced by processName(), updateTriggerNames(), and verifyBranchUniqueName().

bool TriggerOutputBranches::m_singleton
private

Definition at line 30 of file TriggerOutputBranches.h.

edm::EDGetToken TriggerOutputBranches::m_token
private

Definition at line 28 of file TriggerOutputBranches.h.

Referenced by fill().

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

Definition at line 40 of file TriggerOutputBranches.h.

Referenced by fill(), and updateTriggerNames().