CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Registry.cc
Go to the documentation of this file.
1 // ----------------------------------------------------------------------
2 // ----------------------------------------------------------------------
3 
4 #include <ostream>
5 #include <mutex>
6 
9 
10 namespace edm {
11  namespace pset {
13  [[cms::thread_guard("s_mutex")]] static ParameterSetID s_ProcessParameterSetID;
14 
15  Registry*
17  [[cms::thread_safe]] static Registry s_reg;
18  return &s_reg;
19  }
20 
21  bool
23  auto it = m_map.find(k);
24  bool found = it != m_map.end();
25  if(found) {
26  result = it->second;
27  }
28  return found;
29  }
30 
32  Registry::getMapped(key_type const& k) const {
33  auto it = m_map.find(k);
34  bool found = it != m_map.end();
35  return found? &(it->second) : static_cast<value_type const*>(nullptr);
36  }
37 
38  bool
40  return m_map.insert(std::make_pair(v.id(),v)).second;
41  }
42 
43  void
45  m_map.clear();
46  }
47 
48  void
49  Registry::fillMap(regmap_type& fillme) const {
50  fillme.clear();
51  // Note: The tracked part is in the registry.
52  for (auto const& item : m_map) {
53  fillme[item.first].pset() = item.second.toString();
54  }
55  }
56 
57  void
58  Registry::print(std::ostream& os) const {
59  os << "Registry with " << size() << " entries\n";
60  for(auto const& item : *this) {
61  os << item.first << " " << item.second << '\n';
62  }
63  }
64 
67  std::lock_guard<std::mutex> guard(s_mutex);
70  << "Illegal attempt to access the process top level parameter set ID\n"
71  << "before that parameter set has been frozen and registered.\n"
72  << "The parameter set can be changed during module validation,\n"
73  << "which occurs concurrently with module construction.\n"
74  << "It is illegal to access the parameter set before it is frozen.\n";
75  }
77  }
78 
81  }
82 
83  } // namespace pset
84 
87  {
88  std::lock_guard<std::mutex> guard(pset::s_mutex);
90  }
91 
92  if (!p.isValid()) {
94  << "Illegal attempt to access the process top level parameter set ID\n"
95  << "before that parameter set has been frozen and registered.\n"
96  << "The parameter set can be changed during module validation,\n"
97  << "which occurs concurrently with module construction.\n"
98  << "It is illegal to access the parameter set before it is frozen.\n";
99  }
100 
102  ParameterSet const* result;
103  if (nullptr == (result = reg.getMapped(p))) {
104  throw edm::Exception(errors::EventCorruption, "Unknown ParameterSetID")
105  << "Unable to find the ParameterSet for id: "
106  << p
107  << ";\nthis was supposed to be the process ParameterSet\n";
108  }
109  return *result;
110  }
111 
112 } // namespace edm
ParameterSetID getProcessParameterSetID()
Definition: Registry.cc:66
size_t size() const
Definition: Registry.h:77
static boost::mutex mutex
Definition: LHEProxy.cc:11
ParameterSetID id() const
std::map< ParameterSetID, ParameterSetBlob > regmap_type
Definition: Registry.h:83
static std::mutex s_mutex
Definition: Registry.cc:12
tuple result
Definition: query.py:137
void clear()
Not thread safe.
Definition: Registry.cc:44
bool getMapped(key_type const &k, value_type &result) const
Definition: Registry.cc:22
void setProcessParameterSetID(ParameterSetID const &id)
Associated free functions.
Definition: Registry.cc:79
static ParameterSetID s_ProcessParameterSetID
Definition: Registry.cc:13
ParameterSet const & getProcessParameterSet()
Definition: Registry.cc:85
bool isValid() const
Definition: Hash.h:150
void print(std::ostream &os) const
Definition: Registry.cc:58
map_type m_map
Definition: Registry.h:89
bool insertMapped(value_type const &v)
Definition: Registry.cc:39
void fillMap(regmap_type &fillme) const
Definition: Registry.cc:49
static Registry * instance()
Definition: Registry.cc:16