CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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
25 
26 namespace {
27  struct key_hash {
28  std::size_t operator()(edm::ParameterSetID const& iKey) const{
29  return iKey.smallHash();
30  }
31  };
32  typedef tbb::concurrent_unordered_map<edm::ParameterSetID, edm::TriggerNames, key_hash> TriggerNamesMap;
33  [[cms::thread_safe]] static TriggerNamesMap triggerNamesMap;
34 }
35 
36 namespace edm
37 {
38 
40  {
41  }
42 
44  {
45  }
46 
47  TriggerNames const*
49 
50  // If TriggerNames was already created and cached here in the map,
51  // then look it up and return that one
52  TriggerNamesMap::const_iterator iter =
53  triggerNamesMap.find(triggerResults.parameterSetID());
54  if (iter != triggerNamesMap.end()) {
55  return &iter->second;
56  }
57 
58  // Look for the parameter set containing the trigger names in the parameter
59  // set registry using the ID from TriggerResults as the key used to find it.
61  edm::ParameterSet const* pset=0;
62  if (0!=(pset=psetRegistry->getMapped(triggerResults.parameterSetID()))) {
63 
64  if (pset->existsAs<std::vector<std::string> >("@trigger_paths", true)) {
66 
67  // This should never happen
68  if (triggerNames.size() != triggerResults.size()) {
69  throw cms::Exception("LogicError")
70  << "edm::EventBase::triggerNames_ Encountered vector\n"
71  "of trigger names and a TriggerResults object with\n"
72  "different sizes. This should be impossible.\n"
73  "Please send information to reproduce this problem to\n"
74  "the edm developers.\n";
75  }
76 
77  std::pair<TriggerNamesMap::iterator, bool> ret =
78  triggerNamesMap.insert(std::pair<edm::ParameterSetID, edm::TriggerNames>(triggerResults.parameterSetID(), triggerNames));
79  return &(ret.first->second);
80  }
81  }
82  // For backward compatibility to very old data
83  if (triggerResults.getTriggerNames().size() > 0U) {
84  edm::ParameterSet fakePset;
85  fakePset.addParameter<std::vector<std::string> >("@trigger_paths", triggerResults.getTriggerNames());
86  fakePset.registerIt();
87  TriggerNames triggerNames(fakePset);
88 
89  // This should never happen
90  if (triggerNames.size() != triggerResults.size()) {
91  throw cms::Exception("LogicError")
92  << "edm::EventBase::triggerNames_ Encountered vector\n"
93  "of trigger names and a TriggerResults object with\n"
94  "different sizes. This should be impossible.\n"
95  "Please send information to reproduce this problem to\n"
96  "the edm developers (2).\n";
97  }
98 
99  std::pair<TriggerNamesMap::iterator, bool> ret =
100  triggerNamesMap.insert(std::pair<edm::ParameterSetID, edm::TriggerNames>(fakePset.id(), triggerNames));
101  return &(ret.first->second);
102  }
103  return 0;
104  }
105 }
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:186
ParameterSetID id() const
Strings::size_type size() const
Definition: TriggerNames.cc:39
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:144
bool getMapped(key_type const &k, value_type &result) const
Definition: Registry.cc:18
static TriggerNames const * triggerNames_(edm::TriggerResults const &triggerResults)
Definition: EventBase.cc:48
static std::string const triggerResults("TriggerResults")
size_t smallHash() const
returns a short hash which can be used with hashing containers
Definition: Hash.h:220
virtual TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const =0
virtual ~EventBase()
Definition: EventBase.cc:43
ParameterSet const & registerIt()
const ParameterSetID & parameterSetID() const
Get stored parameter set id.
static Registry * instance()
Definition: Registry.cc:12