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 
31  std::shared_ptr<EventSetupProvider>
33 
34  // Makes an EventSetupProvider
35  // Also parses the prefer information from ParameterSets and puts
36  // it in a map that is stored in the EventSetupProvider
37  std::shared_ptr<EventSetupProvider> returnValue(makeEventSetupProvider(iPSet, providers_.size(), activityRegistry) );
38 
39  // Construct the ESProducers and ESSources
40  // shared_ptrs to them are temporarily stored in this
41  // EventSetupsController and in the EventSetupProvider
42  fillEventSetupProvider(*this, *returnValue, iPSet);
43 
44  providers_.push_back(returnValue);
45  return returnValue;
46  }
47 
48  void
50 
52  std::for_each(providers_.begin(), providers_.end(), [](std::shared_ptr<EventSetupProvider> const& esp) {
53  esp->finishConfiguration();
54  });
55  // When the ESSources and ESProducers were constructed a first pass was
56  // done which attempts to get component sharing between SubProcesses
57  // correct, but in this pass only the configuration of the components
58  // being shared are compared. This is not good enough for ESProducers.
59  // In the following function, all the other components that contribute
60  // to the same record and also the records that record depends on are
61  // also checked. The component sharing is appropriately fixed as necessary.
65  }
66 
67  std::for_each(providers_.begin(), providers_.end(), [&syncValue](std::shared_ptr<EventSetupProvider> const& esp) {
68  esp->eventSetupForInstance(syncValue);
69  });
70  }
71 
72  void
74  std::for_each(providers_.begin(), providers_.end(), [](std::shared_ptr<EventSetupProvider> const& esp) {
75  esp->forceCacheClear();
76  });
77  }
78 
79  bool
81  for(auto const& provider: providers_) {
82  if( not provider->isWithinValidityInterval(syncValue)) {
83  return false;
84  }
85  }
86  return true;
87  }
88 
89  std::shared_ptr<DataProxyProvider>
91  // Try to find a DataProxyProvider with a matching ParameterSet
92  auto elements = esproducers_.equal_range(pset.id());
93  for (auto it = elements.first; it != elements.second; ++it) {
94  // Untracked parameters must also match, do complete comparison if IDs match
95  if (isTransientEqual(pset, *it->second.pset())) {
96  // Register processes with an exact match
97  it->second.subProcessIndexes().push_back(subProcessIndex);
98  // Return the DataProxyProvider
99  return it->second.provider();
100  }
101  }
102  // Could not find it
103  return std::shared_ptr<DataProxyProvider>();
104  }
105 
106  void
107  EventSetupsController::putESProducer(ParameterSet const& pset, std::shared_ptr<DataProxyProvider> const& component, unsigned subProcessIndex) {
108  auto newElement = esproducers_.insert(std::pair<ParameterSetID, ESProducerInfo>(pset.id(),
109  ESProducerInfo(&pset, component)));
110  // Register processes with an exact match
111  newElement->second.subProcessIndexes().push_back(subProcessIndex);
112  }
113 
114  std::shared_ptr<EventSetupRecordIntervalFinder>
116  // Try to find a EventSetupRecordIntervalFinder with a matching ParameterSet
117  auto elements = essources_.equal_range(pset.id());
118  for (auto it = elements.first; it != elements.second; ++it) {
119  // Untracked parameters must also match, do complete comparison if IDs match
120  if (isTransientEqual(pset, *it->second.pset())) {
121  // Register processes with an exact match
122  it->second.subProcessIndexes().push_back(subProcessIndex);
123  // Return the EventSetupRecordIntervalFinder
124  return it->second.finder();
125  }
126  }
127  // Could not find it
128  return std::shared_ptr<EventSetupRecordIntervalFinder>();
129  }
130 
131  void
132  EventSetupsController::putESSource(ParameterSet const& pset, std::shared_ptr<EventSetupRecordIntervalFinder> const& component, unsigned subProcessIndex) {
133  auto newElement = essources_.insert(std::pair<ParameterSetID, ESSourceInfo>(pset.id(),
134  ESSourceInfo(&pset, component)));
135  // Register processes with an exact match
136  newElement->second.subProcessIndexes().push_back(subProcessIndex);
137  }
138 
139  void
141  esproducers_.clear();
142  essources_.clear();
143  }
144 
145  void
147  unsigned subProcessIndex,
148  unsigned precedingProcessIndex,
149  bool& firstProcessWithThisPSet,
150  bool& precedingHasMatchingPSet) const {
151 
152  auto elements = esproducers_.equal_range(psetID);
153  for (auto it = elements.first; it != elements.second; ++it) {
154 
155  std::vector<unsigned> const& subProcessIndexes = it->second.subProcessIndexes();
156 
157  auto iFound = std::find(subProcessIndexes.begin(), subProcessIndexes.end(), subProcessIndex);
158  if (iFound == subProcessIndexes.end()) {
159  continue;
160  }
161 
162  if (iFound == subProcessIndexes.begin()) {
163  firstProcessWithThisPSet = true;
164  precedingHasMatchingPSet = false;
165  } else {
166  auto iFoundPreceding = std::find(subProcessIndexes.begin(), iFound, precedingProcessIndex);
167  if (iFoundPreceding == iFound) {
168  firstProcessWithThisPSet = false;
169  precedingHasMatchingPSet = false;
170  } else {
171  firstProcessWithThisPSet = false;
172  precedingHasMatchingPSet = true;
173  }
174  }
175  return;
176  }
178  << "EventSetupsController::lookForMatches\n"
179  << "Subprocess index not found. This should never happen\n"
180  << "Please report this to a Framework Developer\n";
181  }
182 
183  bool
185  unsigned subProcessIndex,
186  unsigned precedingProcessIndex) const {
187 
188  auto elements = esproducers_.equal_range(psetID);
189  for (auto it = elements.first; it != elements.second; ++it) {
190 
191  std::vector<unsigned> const& subProcessIndexes = it->second.subProcessIndexes();
192 
193  auto iFound = std::find(subProcessIndexes.begin(), subProcessIndexes.end(), subProcessIndex);
194  if (iFound == subProcessIndexes.end()) {
195  continue;
196  }
197 
198  auto iFoundPreceding = std::find(subProcessIndexes.begin(), iFound, precedingProcessIndex);
199  if (iFoundPreceding == iFound) {
200  break;
201  } else {
202  return iFoundPreceding == subProcessIndexes.begin();
203  }
204  }
206  << "EventSetupsController::isFirstMatch\n"
207  << "Subprocess index not found. This should never happen\n"
208  << "Please report this to a Framework Developer\n";
209  return false;
210  }
211 
212  bool
214  unsigned subProcessIndex,
215  unsigned precedingProcessIndex) const {
216 
217  auto elements = esproducers_.equal_range(psetID);
218  for (auto it = elements.first; it != elements.second; ++it) {
219 
220  std::vector<unsigned> const& subProcessIndexes = it->second.subProcessIndexes();
221 
222  auto iFound = std::find(subProcessIndexes.begin(), subProcessIndexes.end(), subProcessIndex);
223  if (iFound == subProcessIndexes.end()) {
224  continue;
225  }
226 
227  auto iFoundPreceding = std::find(subProcessIndexes.begin(), iFound, precedingProcessIndex);
228  if (iFoundPreceding == iFound) {
229  break;
230  } else {
231  return (++iFoundPreceding) == iFound;
232  }
233  }
235  << "EventSetupsController::isLastMatch\n"
236  << "Subprocess index not found. This should never happen\n"
237  << "Please report this to a Framework Developer\n";
238  return false;
239  }
240 
241  bool
243  unsigned subProcessIndex,
244  unsigned precedingProcessIndex) const {
245  auto elements = essources_.equal_range(psetID);
246  for (auto it = elements.first; it != elements.second; ++it) {
247 
248  std::vector<unsigned> const& subProcessIndexes = it->second.subProcessIndexes();
249 
250  auto iFound = std::find(subProcessIndexes.begin(), subProcessIndexes.end(), subProcessIndex);
251  if (iFound == subProcessIndexes.end()) {
252  continue;
253  }
254 
255  auto iFoundPreceding = std::find(subProcessIndexes.begin(), iFound, precedingProcessIndex);
256  if (iFoundPreceding == iFound) {
257  return false;
258  } else {
259  return true;
260  }
261  }
263  << "EventSetupsController::lookForMatchingESSource\n"
264  << "Subprocess index not found. This should never happen\n"
265  << "Please report this to a Framework Developer\n";
266  return false;
267  }
268 
269  bool
271  unsigned subProcessIndex,
272  unsigned precedingProcessIndex) const {
273  auto elements = esproducers_.equal_range(psetID);
274  for (auto it = elements.first; it != elements.second; ++it) {
275 
276  std::vector<unsigned> const& subProcessIndexes = it->second.subProcessIndexes();
277 
278  auto iFound = std::find(subProcessIndexes.begin(), subProcessIndexes.end(), subProcessIndex);
279  if (iFound == subProcessIndexes.end()) {
280  continue;
281  }
282 
283  auto iFoundPreceding = std::find(subProcessIndexes.begin(), iFound, precedingProcessIndex);
284  if (iFoundPreceding == iFound) {
285  return false;
286  } else {
287  return true;
288  }
289  }
291  << "EventSetupsController::lookForMatchingESSource\n"
292  << "Subprocess index not found. This should never happen\n"
293  << "Please report this to a Framework Developer\n";
294  return false;
295  }
296 
297  ParameterSet const*
299  unsigned subProcessIndex) const {
300 
301  auto elements = esproducers_.equal_range(psetID);
302  for (auto it = elements.first; it != elements.second; ++it) {
303 
304  std::vector<unsigned> const& subProcessIndexes = it->second.subProcessIndexes();
305 
306  auto iFound = std::find(subProcessIndexes.begin(), subProcessIndexes.end(), subProcessIndex);
307  if (iFound == subProcessIndexes.end()) {
308  continue;
309  }
310  return it->second.pset();
311  }
313  << "EventSetupsController::getESProducerPSet\n"
314  << "Subprocess index not found. This should never happen\n"
315  << "Please report this to a Framework Developer\n";
316  return nullptr;
317  }
318 
319  void
321 
322  // Loop over SubProcesses, skip the top level process.
323  auto esProvider = providers_.begin();
324  auto esProviderEnd = providers_.end();
325  if (esProvider != esProviderEnd) ++esProvider;
326  for ( ; esProvider != esProviderEnd; ++esProvider) {
327 
328  // An element is added to this set for each ESProducer
329  // when we have determined which preceding process
330  // this process can share that ESProducer with or
331  // we have determined that it cannot be shared with
332  // any preceding process.
333  // Note the earliest possible preceding process
334  // will be the one selected if there is more than one.
335  std::set<ParameterSetIDHolder> sharingCheckDone;
336 
337  // This will hold an entry for DataProxy's that are
338  // referenced by an EventSetupRecord in this SubProcess.
339  // But only for DataProxy's that are associated with
340  // an ESProducer (not the ones associated with ESSource's
341  // or EDLooper's)
342  std::map<EventSetupRecordKey, std::vector<ComponentDescription const*> > referencedESProducers;
343 
344  // For each EventSetupProvider from a SubProcess, loop over the
345  // EventSetupProviders from the preceding processes (the first
346  // preceding process will be the top level process and the others
347  // SubProcess's)
348  for (auto precedingESProvider = providers_.begin();
349  precedingESProvider != esProvider;
350  ++precedingESProvider) {
351 
352  (*esProvider)->checkESProducerSharing(**precedingESProvider, sharingCheckDone, referencedESProducers, *this);
353  }
354 
355  (*esProvider)->resetRecordToProxyPointers();
356  }
357  esProvider = providers_.begin();
358  for ( ; esProvider != esProviderEnd; ++esProvider) {
359  (*esProvider)->clearInitializationData();
360  }
361  }
362  }
363 }
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)