CMS 3D CMS Logo

EventBase.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: FWCore/Common
4 // Class : EventBase
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Chris Jones
10 // Created: Thu Aug 27 11:20:06 CDT 2009
11 //
12 
13 // system include files
14 #include <vector>
15 #include "tbb/concurrent_unordered_map.h"
16 
17 // user include files
26 
27 namespace {
28  struct key_hash {
29  std::size_t operator()(edm::ParameterSetID const& iKey) const { return iKey.smallHash(); }
30  };
31  typedef tbb::concurrent_unordered_map<edm::ParameterSetID, edm::TriggerNames, key_hash> TriggerNamesMap;
32  CMS_THREAD_SAFE TriggerNamesMap triggerNamesMap;
33 } // namespace
34 
35 namespace edm {
36 
37  EventBase::EventBase() {}
38 
39  EventBase::~EventBase() {}
40 
41  edm::ParameterSet const* EventBase::parameterSetForID_(edm::ParameterSetID const& iPSID) {
43  }
44 
45  TriggerNames const* EventBase::triggerNames_(edm::TriggerResults const& triggerResults) {
46  // If TriggerNames was already created and cached here in the map,
47  // then look it up and return that one
48  TriggerNamesMap::const_iterator iter = triggerNamesMap.find(triggerResults.parameterSetID());
49  if (iter != triggerNamesMap.end()) {
50  return &iter->second;
51  }
52 
53  // Look for the parameter set containing the trigger names in the parameter
54  // set registry using the ID from TriggerResults as the key used to find it.
56  edm::ParameterSet const* pset = nullptr;
57  if (nullptr != (pset = psetRegistry->getMapped(triggerResults.parameterSetID()))) {
58  if (pset->existsAs<std::vector<std::string> >("@trigger_paths", true)) {
59  TriggerNames triggerNames(*pset);
60 
61  // This should never happen
62  if (triggerNames.size() != triggerResults.size()) {
63  throw cms::Exception("LogicError") << "edm::EventBase::triggerNames_ Encountered vector\n"
64  "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\n"
67  "the edm developers.\n";
68  }
69 
70  std::pair<TriggerNamesMap::iterator, bool> ret = triggerNamesMap.insert(
71  std::pair<edm::ParameterSetID, edm::TriggerNames>(triggerResults.parameterSetID(), triggerNames));
72  return &(ret.first->second);
73  }
74  }
75  // For backward compatibility to very old data
76  if (!triggerResults.getTriggerNames().empty()) {
77  edm::ParameterSet fakePset;
78  fakePset.addParameter<std::vector<std::string> >("@trigger_paths", triggerResults.getTriggerNames());
79  fakePset.registerIt();
80  TriggerNames triggerNames(fakePset);
81 
82  // This should never happen
83  if (triggerNames.size() != triggerResults.size()) {
84  throw cms::Exception("LogicError") << "edm::EventBase::triggerNames_ Encountered vector\n"
85  "of trigger names and a TriggerResults object with\n"
86  "different sizes. This should be impossible.\n"
87  "Please send information to reproduce this problem to\n"
88  "the edm developers (2).\n";
89  }
90 
91  std::pair<TriggerNamesMap::iterator, bool> ret =
92  triggerNamesMap.insert(std::pair<edm::ParameterSetID, edm::TriggerNames>(fakePset.id(), triggerNames));
93  return &(ret.first->second);
94  }
95  return nullptr;
96  }
97 } // namespace edm
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:161
ParameterSetID id() const
Strings::size_type size() const
Definition: TriggerNames.cc:31
const std::vector< std::string > & getTriggerNames() const
Obsolete.
unsigned int size() const
Get number of paths stored.
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:125
bool getMapped(key_type const &k, value_type &result) const
Definition: Registry.cc:17
#define CMS_THREAD_SAFE
static std::string const triggerResults
Definition: EdmProvDump.cc:45
size_t smallHash() const
returns a short hash which can be used with hashing containers
Definition: Hash.h:224
HLT enums.
ParameterSet const & registerIt()
const ParameterSetID & parameterSetID() const
Get stored parameter set id.
static Registry * instance()
Definition: Registry.cc:12