CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes
TriggerOutputFields Class Reference

#include <TriggerOutputFields.h>

Public Member Functions

void createFields (const edm::EventForOutput &event, RNTupleModel &model)
 
void fill (const edm::EventForOutput &event)
 
 TriggerOutputFields ()=default
 
 TriggerOutputFields (const std::string &processName, const edm::EDGetToken &token)
 

Private Member Functions

void makeUniqueFieldName (RNTupleModel &model, std::string &name)
 
void updateTriggerFields (const edm::TriggerResults &triggerResults)
 

Static Private Member Functions

static std::vector< std::string > getTriggerNames (const edm::TriggerResults &triggerResults)
 

Private Attributes

long m_lastRun
 
std::string m_processName
 
edm::EDGetToken m_token
 
std::vector< TriggerFieldPtrm_triggerFields
 

Detailed Description

Definition at line 28 of file TriggerOutputFields.h.

Constructor & Destructor Documentation

◆ TriggerOutputFields() [1/2]

TriggerOutputFields::TriggerOutputFields ( )
default

◆ TriggerOutputFields() [2/2]

TriggerOutputFields::TriggerOutputFields ( const std::string &  processName,
const edm::EDGetToken token 
)
inlineexplicit

Member Function Documentation

◆ createFields()

void TriggerOutputFields::createFields ( const edm::EventForOutput event,
RNTupleModel &  model 
)

Definition at line 71 of file TriggerOutputFields.cc.

References submitPVResolutionJobs::desc, getTriggerNames(), patZpeak::handle, mps_fire::i, m_lastRun, m_processName, m_token, m_triggerFields, makeUniqueFieldName(), ReggeGribovPartonMC_EposLHC_2760GeV_PbPb_cfi::model, hltEcalBarrelClusterFastTimer_cfi::modelName, Skims_PA_cff::name, AlCaHLTBitMon_QueryRunRegistry::string, L1TEGammaOffline_cfi::triggerNames, and triggerResults.

71  {
72  m_lastRun = event.id().run();
74  event.getByToken(m_token, handle);
77  m_triggerFields.reserve(triggerNames.size());
78  for (std::size_t i = 0; i < triggerNames.size(); i++) {
79  auto& name = triggerNames[i];
80  if (!isNanoaodTrigger(name)) {
81  continue;
82  }
83  trimVersionSuffix(name);
86  std::string desc = std::string("Trigger/flag bit (process: ") + m_processName + ")";
88  }
89 }
void makeUniqueFieldName(RNTupleModel &model, std::string &name)
std::vector< TriggerFieldPtr > m_triggerFields
static std::string const triggerResults
Definition: EdmProvDump.cc:47
static std::vector< std::string > getTriggerNames(const edm::TriggerResults &triggerResults)
edm::EDGetToken m_token

◆ fill()

void TriggerOutputFields::fill ( const edm::EventForOutput event)

Definition at line 140 of file TriggerOutputFields.cc.

References patZpeak::handle, m_lastRun, m_token, m_triggerFields, submitPVValidationJobs::t, and updateTriggerFields().

140  {
142  event.getByToken(m_token, handle);
143  const edm::TriggerResults& triggers = *handle;
144  if (m_lastRun != event.id().run()) {
145  m_lastRun = event.id().run();
146  updateTriggerFields(triggers);
147  }
148  for (auto& t : m_triggerFields) {
149  t.fill(triggers);
150  }
151 }
void updateTriggerFields(const edm::TriggerResults &triggerResults)
std::vector< TriggerFieldPtr > m_triggerFields
edm::EDGetToken m_token
Definition: event.py:1

◆ getTriggerNames()

std::vector< std::string > TriggerOutputFields::getTriggerNames ( const edm::TriggerResults triggerResults)
staticprivate

Definition at line 49 of file TriggerOutputFields.cc.

References Exception, edm::pset::Registry::getMapped(), edm::pset::Registry::instance(), names, muonDTDigis_cfi::pset, L1TEGammaOffline_cfi::triggerNames, and triggerResults.

Referenced by createFields(), and updateTriggerFields().

49  {
50  // Trigger names are either stored in the TriggerResults object (e.g. L1) or
51  // need to be looked up in the registry (e.g. HLT)
52  auto triggerNames = triggerResults.getTriggerNames();
53  if (!triggerNames.empty()) {
54  return triggerNames;
55  }
57  edm::ParameterSet const* pset = psetRegistry->getMapped(triggerResults.parameterSetID());
58  if (nullptr == pset || !pset->existsAs<std::vector<std::string>>("@trigger_paths", true)) {
59  return {};
60  }
62  if (names.size() != triggerResults.size()) {
63  throw cms::Exception("LogicError") << "TriggerOutputFields::getTriggerNames "
64  "Encountered vector\n of trigger names and a TriggerResults object with\n"
65  "different sizes. This should be impossible.\n"
66  "Please send information to reproduce this problem to\nthe edm developers.\n";
67  }
68  return names.triggerNames();
69 }
bool getMapped(key_type const &k, value_type &result) const
Definition: Registry.cc:17
const std::string names[nVars_]
static std::string const triggerResults
Definition: EdmProvDump.cc:47
static Registry * instance()
Definition: Registry.cc:12

◆ makeUniqueFieldName()

void TriggerOutputFields::makeUniqueFieldName ( RNTupleModel &  model,
std::string &  name 
)
private

Definition at line 124 of file TriggerOutputFields.cc.

References m_processName, ReggeGribovPartonMC_EposLHC_2760GeV_PbPb_cfi::model, Skims_PA_cff::name, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by createFields().

124  {
125  // Could also use a cache of names in a higher-level object, don't ask the RNTupleModel each time
126 #if ROOT_VERSION_CODE < ROOT_VERSION(6, 31, 0)
127  auto existing_field = model.Get<bool>(name);
128 #else
129  auto existing_field = model.GetDefaultEntry().GetPtr<bool>(name);
130 #endif
131  if (!existing_field) {
132  return;
133  }
134  edm::LogWarning("TriggerOutputFields") << "Found a branch with name " << name
135  << " already present. Will add suffix _p" << m_processName
136  << " to the new branch.\n";
137  name += std::string("_p") + m_processName;
138 }
Log< level::Warning, false > LogWarning

◆ updateTriggerFields()

void TriggerOutputFields::updateTriggerFields ( const edm::TriggerResults triggerResults)
private

Definition at line 92 of file TriggerOutputFields.cc.

References getTriggerNames(), dqmiolumiharvest::j, m_triggerFields, Skims_PA_cff::name, and submitPVValidationJobs::t.

Referenced by fill().

92  {
93  std::vector<std::string> newNames(TriggerOutputFields::getTriggerNames(triggers));
94  // adjust existing trigger indices
95  for (auto& t : m_triggerFields) {
96  t.setIndex(-1);
97  for (std::size_t j = 0; j < newNames.size(); j++) {
98  auto& name = newNames[j];
99  if (!isNanoaodTrigger(name)) {
100  continue;
101  }
102  trimVersionSuffix(name);
103  if (name == t.getTriggerName()) {
104  t.setIndex(j);
105  }
106  }
107  }
108  // find new triggers
109  for (std::size_t j = 0; j < newNames.size(); j++) {
110  auto& name = newNames[j];
111  if (!isNanoaodTrigger(name)) {
112  continue;
113  }
114  trimVersionSuffix(name);
115  if (std::none_of(m_triggerFields.cbegin(), m_triggerFields.cend(), [&](const TriggerFieldPtr& t) {
116  return t.getTriggerName() == name;
117  })) {
118  // TODO backfill / friend ntuples
119  edm::LogWarning("TriggerOutputFields") << "Skipping output of TriggerField " << name << "\n";
120  }
121  }
122 }
std::vector< TriggerFieldPtr > m_triggerFields
static std::vector< std::string > getTriggerNames(const edm::TriggerResults &triggerResults)
Log< level::Warning, false > LogWarning

Member Data Documentation

◆ m_lastRun

long TriggerOutputFields::m_lastRun
private

Definition at line 43 of file TriggerOutputFields.h.

Referenced by createFields(), and fill().

◆ m_processName

std::string TriggerOutputFields::m_processName
private

Definition at line 44 of file TriggerOutputFields.h.

Referenced by createFields(), and makeUniqueFieldName().

◆ m_token

edm::EDGetToken TriggerOutputFields::m_token
private

Definition at line 42 of file TriggerOutputFields.h.

Referenced by createFields(), and fill().

◆ m_triggerFields

std::vector<TriggerFieldPtr> TriggerOutputFields::m_triggerFields
private

Definition at line 45 of file TriggerOutputFields.h.

Referenced by createFields(), fill(), and updateTriggerFields().