CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  boost::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  boost::shared_ptr<EventSetupProvider> returnValue(makeEventSetupProvider(iPSet, providers_.size()) );
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(), [](boost::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](boost::shared_ptr<EventSetupProvider> const& esp) {
68  esp->eventSetupForInstance(syncValue);
69  });
70  }
71 
72  void
74  std::for_each(providers_.begin(), providers_.end(), [](boost::shared_ptr<EventSetupProvider> const& esp) {
75  esp->forceCacheClear();
76  });
77  }
78 
79  boost::shared_ptr<DataProxyProvider>
81  // Try to find a DataProxyProvider with a matching ParameterSet
82  auto elements = esproducers_.equal_range(pset.id());
83  for (auto it = elements.first; it != elements.second; ++it) {
84  // Untracked parameters must also match, do complete comparison if IDs match
85  if (isTransientEqual(pset, *it->second.pset())) {
86  // Register processes with an exact match
87  it->second.subProcessIndexes().push_back(subProcessIndex);
88  // Return the DataProxyProvider
89  return it->second.provider();
90  }
91  }
92  // Could not find it
93  return boost::shared_ptr<DataProxyProvider>();
94  }
95 
96  void
97  EventSetupsController::putESProducer(ParameterSet const& pset, boost::shared_ptr<DataProxyProvider> const& component, unsigned subProcessIndex) {
98  auto newElement = esproducers_.insert(std::pair<ParameterSetID, ESProducerInfo>(pset.id(),
99  ESProducerInfo(&pset, component)));
100  // Register processes with an exact match
101  newElement->second.subProcessIndexes().push_back(subProcessIndex);
102  }
103 
104  boost::shared_ptr<EventSetupRecordIntervalFinder>
106  // Try to find a EventSetupRecordIntervalFinder with a matching ParameterSet
107  auto elements = essources_.equal_range(pset.id());
108  for (auto it = elements.first; it != elements.second; ++it) {
109  // Untracked parameters must also match, do complete comparison if IDs match
110  if (isTransientEqual(pset, *it->second.pset())) {
111  // Register processes with an exact match
112  it->second.subProcessIndexes().push_back(subProcessIndex);
113  // Return the EventSetupRecordIntervalFinder
114  return it->second.finder();
115  }
116  }
117  // Could not find it
118  return boost::shared_ptr<EventSetupRecordIntervalFinder>();
119  }
120 
121  void
122  EventSetupsController::putESSource(ParameterSet const& pset, boost::shared_ptr<EventSetupRecordIntervalFinder> const& component, unsigned subProcessIndex) {
123  auto newElement = essources_.insert(std::pair<ParameterSetID, ESSourceInfo>(pset.id(),
124  ESSourceInfo(&pset, component)));
125  // Register processes with an exact match
126  newElement->second.subProcessIndexes().push_back(subProcessIndex);
127  }
128 
129  void
131  esproducers_.clear();
132  essources_.clear();
133  }
134 
135  void
137  unsigned subProcessIndex,
138  unsigned precedingProcessIndex,
139  bool& firstProcessWithThisPSet,
140  bool& precedingHasMatchingPSet) const {
141 
142  auto elements = esproducers_.equal_range(psetID);
143  for (auto it = elements.first; it != elements.second; ++it) {
144 
145  std::vector<unsigned> const& subProcessIndexes = it->second.subProcessIndexes();
146 
147  auto iFound = std::find(subProcessIndexes.begin(), subProcessIndexes.end(), subProcessIndex);
148  if (iFound == subProcessIndexes.end()) {
149  continue;
150  }
151 
152  if (iFound == subProcessIndexes.begin()) {
153  firstProcessWithThisPSet = true;
154  precedingHasMatchingPSet = false;
155  } else {
156  auto iFoundPreceding = std::find(subProcessIndexes.begin(), iFound, precedingProcessIndex);
157  if (iFoundPreceding == iFound) {
158  firstProcessWithThisPSet = false;
159  precedingHasMatchingPSet = false;
160  } else {
161  firstProcessWithThisPSet = false;
162  precedingHasMatchingPSet = true;
163  }
164  }
165  return;
166  }
168  << "EventSetupsController::lookForMatches\n"
169  << "Subprocess index not found. This should never happen\n"
170  << "Please report this to a Framework Developer\n";
171  }
172 
173  bool
175  unsigned subProcessIndex,
176  unsigned precedingProcessIndex) const {
177 
178  auto elements = esproducers_.equal_range(psetID);
179  for (auto it = elements.first; it != elements.second; ++it) {
180 
181  std::vector<unsigned> const& subProcessIndexes = it->second.subProcessIndexes();
182 
183  auto iFound = std::find(subProcessIndexes.begin(), subProcessIndexes.end(), subProcessIndex);
184  if (iFound == subProcessIndexes.end()) {
185  continue;
186  }
187 
188  auto iFoundPreceding = std::find(subProcessIndexes.begin(), iFound, precedingProcessIndex);
189  if (iFoundPreceding == iFound) {
190  break;
191  } else {
192  return iFoundPreceding == subProcessIndexes.begin();
193  }
194  }
196  << "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 
202  bool
204  unsigned subProcessIndex,
205  unsigned precedingProcessIndex) const {
206 
207  auto elements = esproducers_.equal_range(psetID);
208  for (auto it = elements.first; it != elements.second; ++it) {
209 
210  std::vector<unsigned> const& subProcessIndexes = it->second.subProcessIndexes();
211 
212  auto iFound = std::find(subProcessIndexes.begin(), subProcessIndexes.end(), subProcessIndex);
213  if (iFound == subProcessIndexes.end()) {
214  continue;
215  }
216 
217  auto iFoundPreceding = std::find(subProcessIndexes.begin(), iFound, precedingProcessIndex);
218  if (iFoundPreceding == iFound) {
219  break;
220  } else {
221  return (++iFoundPreceding) == iFound;
222  }
223  }
225  << "EventSetupsController::isLastMatch\n"
226  << "Subprocess index not found. This should never happen\n"
227  << "Please report this to a Framework Developer\n";
228  return false;
229  }
230 
231  bool
233  unsigned subProcessIndex,
234  unsigned precedingProcessIndex) const {
235  auto elements = essources_.equal_range(psetID);
236  for (auto it = elements.first; it != elements.second; ++it) {
237 
238  std::vector<unsigned> const& subProcessIndexes = it->second.subProcessIndexes();
239 
240  auto iFound = std::find(subProcessIndexes.begin(), subProcessIndexes.end(), subProcessIndex);
241  if (iFound == subProcessIndexes.end()) {
242  continue;
243  }
244 
245  auto iFoundPreceding = std::find(subProcessIndexes.begin(), iFound, precedingProcessIndex);
246  if (iFoundPreceding == iFound) {
247  return false;
248  } else {
249  return true;
250  }
251  }
253  << "EventSetupsController::lookForMatchingESSource\n"
254  << "Subprocess index not found. This should never happen\n"
255  << "Please report this to a Framework Developer\n";
256  return false;
257  }
258 
259  bool
261  unsigned subProcessIndex,
262  unsigned precedingProcessIndex) const {
263  auto elements = esproducers_.equal_range(psetID);
264  for (auto it = elements.first; it != elements.second; ++it) {
265 
266  std::vector<unsigned> const& subProcessIndexes = it->second.subProcessIndexes();
267 
268  auto iFound = std::find(subProcessIndexes.begin(), subProcessIndexes.end(), subProcessIndex);
269  if (iFound == subProcessIndexes.end()) {
270  continue;
271  }
272 
273  auto iFoundPreceding = std::find(subProcessIndexes.begin(), iFound, precedingProcessIndex);
274  if (iFoundPreceding == iFound) {
275  return false;
276  } else {
277  return true;
278  }
279  }
281  << "EventSetupsController::lookForMatchingESSource\n"
282  << "Subprocess index not found. This should never happen\n"
283  << "Please report this to a Framework Developer\n";
284  return false;
285  }
286 
287  ParameterSet const*
289  unsigned subProcessIndex) const {
290 
291  auto elements = esproducers_.equal_range(psetID);
292  for (auto it = elements.first; it != elements.second; ++it) {
293 
294  std::vector<unsigned> const& subProcessIndexes = it->second.subProcessIndexes();
295 
296  auto iFound = std::find(subProcessIndexes.begin(), subProcessIndexes.end(), subProcessIndex);
297  if (iFound == subProcessIndexes.end()) {
298  continue;
299  }
300  return it->second.pset();
301  }
303  << "EventSetupsController::getESProducerPSet\n"
304  << "Subprocess index not found. This should never happen\n"
305  << "Please report this to a Framework Developer\n";
306  return 0;
307  }
308 
309  void
311 
312  // Loop over SubProcesses, skip the top level process.
313  auto esProvider = providers_.begin();
314  auto esProviderEnd = providers_.end();
315  if (esProvider != esProviderEnd) ++esProvider;
316  for ( ; esProvider != esProviderEnd; ++esProvider) {
317 
318  // An element is added to this set for each ESProducer
319  // when we have determined which preceding process
320  // this process can share that ESProducer with or
321  // we have determined that it cannot be shared with
322  // any preceding process.
323  // Note the earliest possible preceding process
324  // will be the one selected if there is more than one.
325  std::set<ParameterSetIDHolder> sharingCheckDone;
326 
327  // This will hold an entry for DataProxy's that are
328  // referenced by an EventSetupRecord in this SubProcess.
329  // But only for DataProxy's that are associated with
330  // an ESProducer (not the ones associated with ESSource's
331  // or EDLooper's)
332  std::map<EventSetupRecordKey, std::vector<ComponentDescription const*> > referencedESProducers;
333 
334  // For each EventSetupProvider from a SubProcess, loop over the
335  // EventSetupProviders from the preceding processes (the first
336  // preceding process will be the top level process and the others
337  // SubProcess's)
338  for (auto precedingESProvider = providers_.begin();
339  precedingESProvider != esProvider;
340  ++precedingESProvider) {
341 
342  (*esProvider)->checkESProducerSharing(**precedingESProvider, sharingCheckDone, referencedESProducers, *this);
343  }
344 
345  (*esProvider)->resetRecordToProxyPointers();
346  }
347  esProvider = providers_.begin();
348  for ( ; esProvider != esProviderEnd; ++esProvider) {
349  (*esProvider)->clearInitializationData();
350  }
351  }
352  }
353 }
void lookForMatches(ParameterSetID const &psetID, unsigned subProcessIndex, unsigned precedingProcessIndex, bool &firstProcessWithThisPSet, bool &precedingHasMatchingPSet) const
bool isFirstMatch(ParameterSetID const &psetID, unsigned subProcessIndex, unsigned precedingProcessIndex) const
bool isMatchingESProducer(ParameterSetID const &psetID, unsigned subProcessIndex, unsigned precedingProcessIndex) const
Definition: Hash.h:42
ParameterSetID id() const
std::multimap< ParameterSetID, ESProducerInfo > esproducers_
list elements
Definition: asciidump.py:414
bool isLastMatch(ParameterSetID const &psetID, unsigned subProcessIndex, unsigned precedingProcessIndex) const
void putESSource(ParameterSet const &pset, boost::shared_ptr< EventSetupRecordIntervalFinder > const &component, unsigned subProcessIndex)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
ParameterSet const * getESProducerPSet(ParameterSetID const &psetID, unsigned subProcessIndex) const
void putESProducer(ParameterSet const &pset, boost::shared_ptr< DataProxyProvider > const &component, unsigned subProcessIndex)
void eventSetupForInstance(IOVSyncValue const &syncValue)
boost::shared_ptr< DataProxyProvider > getESProducerAndRegisterProcess(ParameterSet const &pset, unsigned subProcessIndex)
void fillEventSetupProvider(EventSetupsController &esController, EventSetupProvider &cp, ParameterSet &params)
std::multimap< ParameterSetID, ESSourceInfo > essources_
boost::shared_ptr< EventSetupRecordIntervalFinder > getESSourceAndRegisterProcess(ParameterSet const &pset, unsigned subProcessIndex)
std::vector< boost::shared_ptr< EventSetupProvider > > providers_
boost::shared_ptr< EventSetupProvider > makeProvider(ParameterSet &)
bool isMatchingESSource(ParameterSetID const &psetID, unsigned subProcessIndex, unsigned precedingProcessIndex) const
std::auto_ptr< EventSetupProvider > makeEventSetupProvider(ParameterSet const &params, unsigned subProcessIndex)
bool isTransientEqual(ParameterSet const &a, ParameterSet const &b)