CMS 3D CMS Logo

EventSetupsController.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Framework
4 // Class : EventSetupsController
5 //
6 // Implementation:
7 // [Notes on implementation]
8 //
9 // Original Author: Chris Jones, W. David Dagenhart
10 // Created: Wed Jan 12 14:30:44 CST 2011
11 //
12 
21 
22 #include <algorithm>
23 #include <iostream>
24 
25 namespace edm {
26  namespace eventsetup {
27 
28  EventSetupsController::EventSetupsController() : mustFinishConfiguration_(true) {}
29 
30  std::shared_ptr<EventSetupProvider> EventSetupsController::makeProvider(ParameterSet& iPSet,
31  ActivityRegistry* activityRegistry) {
32  // Makes an EventSetupProvider
33  // Also parses the prefer information from ParameterSets and puts
34  // it in a map that is stored in the EventSetupProvider
35  std::shared_ptr<EventSetupProvider> returnValue(
36  makeEventSetupProvider(iPSet, providers_.size(), activityRegistry));
37 
38  // Construct the ESProducers and ESSources
39  // shared_ptrs to them are temporarily stored in this
40  // EventSetupsController and in the EventSetupProvider
41  fillEventSetupProvider(*this, *returnValue, iPSet);
42 
43  providers_.push_back(returnValue);
44  return returnValue;
45  }
46 
49  std::for_each(providers_.begin(), providers_.end(), [](std::shared_ptr<EventSetupProvider> const& esp) {
50  esp->finishConfiguration();
51  });
52  // When the ESSources and ESProducers were constructed a first pass was
53  // done which attempts to get component sharing between SubProcesses
54  // correct, but in this pass only the configuration of the components
55  // being shared are compared. This is not good enough for ESProducers.
56  // In the following function, all the other components that contribute
57  // to the same record and also the records that record depends on are
58  // also checked. The component sharing is appropriately fixed as necessary.
62  }
63  }
66  std::for_each(providers_.begin(), providers_.end(), [&syncValue](std::shared_ptr<EventSetupProvider> const& esp) {
67  esp->eventSetupForInstance(syncValue);
68  });
69  }
70 
72  std::for_each(providers_.begin(), providers_.end(), [](std::shared_ptr<EventSetupProvider> const& esp) {
73  esp->forceCacheClear();
74  });
75  }
76 
78  for (auto const& provider : providers_) {
79  if (not provider->isWithinValidityInterval(syncValue)) {
80  return false;
81  }
82  }
83  return true;
84  }
85 
86  std::shared_ptr<DataProxyProvider> EventSetupsController::getESProducerAndRegisterProcess(
87  ParameterSet const& pset, unsigned subProcessIndex) {
88  // Try to find a DataProxyProvider with a matching ParameterSet
89  auto elements = esproducers_.equal_range(pset.id());
90  for (auto it = elements.first; it != elements.second; ++it) {
91  // Untracked parameters must also match, do complete comparison if IDs match
92  if (isTransientEqual(pset, *it->second.pset())) {
93  // Register processes with an exact match
94  it->second.subProcessIndexes().push_back(subProcessIndex);
95  // Return the DataProxyProvider
96  return it->second.provider();
97  }
98  }
99  // Could not find it
100  return std::shared_ptr<DataProxyProvider>();
101  }
102 
104  std::shared_ptr<DataProxyProvider> const& component,
105  unsigned subProcessIndex) {
106  auto newElement =
107  esproducers_.insert(std::pair<ParameterSetID, ESProducerInfo>(pset.id(), ESProducerInfo(&pset, component)));
108  // Register processes with an exact match
109  newElement->second.subProcessIndexes().push_back(subProcessIndex);
110  }
111 
112  std::shared_ptr<EventSetupRecordIntervalFinder> EventSetupsController::getESSourceAndRegisterProcess(
113  ParameterSet const& pset, unsigned subProcessIndex) {
114  // Try to find a EventSetupRecordIntervalFinder with a matching ParameterSet
115  auto elements = essources_.equal_range(pset.id());
116  for (auto it = elements.first; it != elements.second; ++it) {
117  // Untracked parameters must also match, do complete comparison if IDs match
118  if (isTransientEqual(pset, *it->second.pset())) {
119  // Register processes with an exact match
120  it->second.subProcessIndexes().push_back(subProcessIndex);
121  // Return the EventSetupRecordIntervalFinder
122  return it->second.finder();
123  }
124  }
125  // Could not find it
126  return std::shared_ptr<EventSetupRecordIntervalFinder>();
127  }
128 
130  std::shared_ptr<EventSetupRecordIntervalFinder> const& component,
131  unsigned subProcessIndex) {
132  auto newElement =
133  essources_.insert(std::pair<ParameterSetID, ESSourceInfo>(pset.id(), ESSourceInfo(&pset, component)));
134  // Register processes with an exact match
135  newElement->second.subProcessIndexes().push_back(subProcessIndex);
136  }
137 
139  esproducers_.clear();
140  essources_.clear();
141  }
142 
144  unsigned subProcessIndex,
145  unsigned precedingProcessIndex,
146  bool& firstProcessWithThisPSet,
147  bool& precedingHasMatchingPSet) const {
148  auto elements = esproducers_.equal_range(psetID);
149  for (auto it = elements.first; it != elements.second; ++it) {
150  std::vector<unsigned> const& subProcessIndexes = it->second.subProcessIndexes();
151 
152  auto iFound = std::find(subProcessIndexes.begin(), subProcessIndexes.end(), subProcessIndex);
153  if (iFound == subProcessIndexes.end()) {
154  continue;
155  }
156 
157  if (iFound == subProcessIndexes.begin()) {
158  firstProcessWithThisPSet = true;
159  precedingHasMatchingPSet = false;
160  } else {
161  auto iFoundPreceding = std::find(subProcessIndexes.begin(), iFound, precedingProcessIndex);
162  if (iFoundPreceding == iFound) {
163  firstProcessWithThisPSet = false;
164  precedingHasMatchingPSet = false;
165  } else {
166  firstProcessWithThisPSet = false;
167  precedingHasMatchingPSet = true;
168  }
169  }
170  return;
171  }
172  throw edm::Exception(edm::errors::LogicError) << "EventSetupsController::lookForMatches\n"
173  << "Subprocess index not found. This should never happen\n"
174  << "Please report this to a Framework Developer\n";
175  }
176 
178  unsigned subProcessIndex,
179  unsigned precedingProcessIndex) const {
180  auto elements = esproducers_.equal_range(psetID);
181  for (auto it = elements.first; it != elements.second; ++it) {
182  std::vector<unsigned> const& subProcessIndexes = it->second.subProcessIndexes();
183 
184  auto iFound = std::find(subProcessIndexes.begin(), subProcessIndexes.end(), subProcessIndex);
185  if (iFound == subProcessIndexes.end()) {
186  continue;
187  }
188 
189  auto iFoundPreceding = std::find(subProcessIndexes.begin(), iFound, precedingProcessIndex);
190  if (iFoundPreceding == iFound) {
191  break;
192  } else {
193  return iFoundPreceding == subProcessIndexes.begin();
194  }
195  }
196  throw edm::Exception(edm::errors::LogicError) << "EventSetupsController::isFirstMatch\n"
197  << "Subprocess index not found. This should never happen\n"
198  << "Please report this to a Framework Developer\n";
199  return false;
200  }
201 
203  unsigned subProcessIndex,
204  unsigned precedingProcessIndex) const {
205  auto elements = esproducers_.equal_range(psetID);
206  for (auto it = elements.first; it != elements.second; ++it) {
207  std::vector<unsigned> const& subProcessIndexes = it->second.subProcessIndexes();
208 
209  auto iFound = std::find(subProcessIndexes.begin(), subProcessIndexes.end(), subProcessIndex);
210  if (iFound == subProcessIndexes.end()) {
211  continue;
212  }
213 
214  auto iFoundPreceding = std::find(subProcessIndexes.begin(), iFound, precedingProcessIndex);
215  if (iFoundPreceding == iFound) {
216  break;
217  } else {
218  return (++iFoundPreceding) == iFound;
219  }
220  }
221  throw edm::Exception(edm::errors::LogicError) << "EventSetupsController::isLastMatch\n"
222  << "Subprocess index not found. This should never happen\n"
223  << "Please report this to a Framework Developer\n";
224  return false;
225  }
226 
228  unsigned subProcessIndex,
229  unsigned precedingProcessIndex) const {
230  auto elements = essources_.equal_range(psetID);
231  for (auto it = elements.first; it != elements.second; ++it) {
232  std::vector<unsigned> const& subProcessIndexes = it->second.subProcessIndexes();
233 
234  auto iFound = std::find(subProcessIndexes.begin(), subProcessIndexes.end(), subProcessIndex);
235  if (iFound == subProcessIndexes.end()) {
236  continue;
237  }
238 
239  auto iFoundPreceding = std::find(subProcessIndexes.begin(), iFound, precedingProcessIndex);
240  if (iFoundPreceding == iFound) {
241  return false;
242  } else {
243  return true;
244  }
245  }
246  throw edm::Exception(edm::errors::LogicError) << "EventSetupsController::lookForMatchingESSource\n"
247  << "Subprocess index not found. This should never happen\n"
248  << "Please report this to a Framework Developer\n";
249  return false;
250  }
251 
253  unsigned subProcessIndex,
254  unsigned precedingProcessIndex) const {
255  auto elements = esproducers_.equal_range(psetID);
256  for (auto it = elements.first; it != elements.second; ++it) {
257  std::vector<unsigned> const& subProcessIndexes = it->second.subProcessIndexes();
258 
259  auto iFound = std::find(subProcessIndexes.begin(), subProcessIndexes.end(), subProcessIndex);
260  if (iFound == subProcessIndexes.end()) {
261  continue;
262  }
263 
264  auto iFoundPreceding = std::find(subProcessIndexes.begin(), iFound, precedingProcessIndex);
265  if (iFoundPreceding == iFound) {
266  return false;
267  } else {
268  return true;
269  }
270  }
271  throw edm::Exception(edm::errors::LogicError) << "EventSetupsController::lookForMatchingESSource\n"
272  << "Subprocess index not found. This should never happen\n"
273  << "Please report this to a Framework Developer\n";
274  return false;
275  }
276 
278  unsigned subProcessIndex) const {
279  auto elements = esproducers_.equal_range(psetID);
280  for (auto it = elements.first; it != elements.second; ++it) {
281  std::vector<unsigned> const& subProcessIndexes = it->second.subProcessIndexes();
282 
283  auto iFound = std::find(subProcessIndexes.begin(), subProcessIndexes.end(), subProcessIndex);
284  if (iFound == subProcessIndexes.end()) {
285  continue;
286  }
287  return it->second.pset();
288  }
289  throw edm::Exception(edm::errors::LogicError) << "EventSetupsController::getESProducerPSet\n"
290  << "Subprocess index not found. This should never happen\n"
291  << "Please report this to a Framework Developer\n";
292  return nullptr;
293  }
294 
296  // Loop over SubProcesses, skip the top level process.
297  auto esProvider = providers_.begin();
298  auto const esProviderEnd = providers_.end();
299  if (esProvider != esProviderEnd)
300  ++esProvider;
301  for (; esProvider != esProviderEnd; ++esProvider) {
302  // An element is added to this set for each ESProducer
303  // when we have determined which preceding process
304  // this process can share that ESProducer with or
305  // we have determined that it cannot be shared with
306  // any preceding process.
307  // Note the earliest possible preceding process
308  // will be the one selected if there is more than one.
309  std::set<ParameterSetIDHolder> sharingCheckDone;
310 
311  // This will hold an entry for DataProxy's that are
312  // referenced by an EventSetupRecord in this SubProcess.
313  // But only for DataProxy's that are associated with
314  // an ESProducer (not the ones associated with ESSource's
315  // or EDLooper's)
316  std::map<EventSetupRecordKey, std::vector<ComponentDescription const*> > referencedESProducers;
317 
318  // For each EventSetupProvider from a SubProcess, loop over the
319  // EventSetupProviders from the preceding processes (the first
320  // preceding process will be the top level process and the others
321  // SubProcess's)
322  for (auto precedingESProvider = providers_.begin(); precedingESProvider != esProvider; ++precedingESProvider) {
323  (*esProvider)->checkESProducerSharing(**precedingESProvider, sharingCheckDone, referencedESProducers, *this);
324  }
325 
326  (*esProvider)->resetRecordToProxyPointers();
327  }
328  esProvider = providers_.begin();
329  for (; esProvider != esProviderEnd; ++esProvider) {
330  (*esProvider)->clearInitializationData();
331  }
332  }
333  } // namespace eventsetup
334 } // namespace edm
void lookForMatches(ParameterSetID const &psetID, unsigned subProcessIndex, unsigned precedingProcessIndex, bool &firstProcessWithThisPSet, bool &precedingHasMatchingPSet) const
std::shared_ptr< EventSetupRecordIntervalFinder > getESSourceAndRegisterProcess(ParameterSet const &pset, unsigned subProcessIndex)
bool isFirstMatch(ParameterSetID const &psetID, unsigned subProcessIndex, unsigned precedingProcessIndex) const
bool isMatchingESProducer(ParameterSetID const &psetID, unsigned subProcessIndex, unsigned precedingProcessIndex) const
void putESSource(ParameterSet const &pset, std::shared_ptr< EventSetupRecordIntervalFinder > const &component, unsigned subProcessIndex)
Definition: Hash.h:43
ParameterSetID id() const
void putESProducer(ParameterSet const &pset, std::shared_ptr< DataProxyProvider > const &component, unsigned subProcessIndex)
std::multimap< ParameterSetID, ESProducerInfo > esproducers_
bool isLastMatch(ParameterSetID const &psetID, unsigned subProcessIndex, unsigned precedingProcessIndex) const
std::shared_ptr< EventSetupProvider > makeProvider(ParameterSet &, ActivityRegistry *)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
ParameterSet const * getESProducerPSet(ParameterSetID const &psetID, unsigned subProcessIndex) const
void eventSetupForInstance(IOVSyncValue const &syncValue)
std::shared_ptr< DataProxyProvider > getESProducerAndRegisterProcess(ParameterSet const &pset, unsigned subProcessIndex)
void fillEventSetupProvider(EventSetupsController &esController, EventSetupProvider &cp, ParameterSet &params)
std::multimap< ParameterSetID, ESSourceInfo > essources_
bool isWithinValidityInterval(IOVSyncValue const &syncValue) const
HLT enums.
std::unique_ptr< EventSetupProvider > makeEventSetupProvider(ParameterSet const &params, unsigned subProcessIndex, ActivityRegistry *)
bool isMatchingESSource(ParameterSetID const &psetID, unsigned subProcessIndex, unsigned precedingProcessIndex) const
std::vector< std::shared_ptr< EventSetupProvider > > providers_
bool isTransientEqual(ParameterSet const &a, ParameterSet const &b)