16 #include "boost/bind.hpp"
30 namespace eventsetup {
45 mustFinishConfiguration_(
true),
79 boost::shared_ptr<EventSetupRecordProvider>
temp(iProvider.release());
88 assert(&(*iProvider) != 0);
97 assert(&(*iFinder) != 0);
101 typedef std::map<EventSetupRecordKey, boost::shared_ptr<EventSetupRecordProvider> >
Providers;
102 typedef std::map<EventSetupRecordKey, EventSetupRecordProvider::DataToPreferredProviderMap>
RecordToPreferred;
111 bool foundProxyProvider =
false;
112 for(Providers::const_iterator itProvider = iProviders.begin(), itProviderEnd = iProviders.end();
113 itProvider!= itProviderEnd;
115 std::set<ComponentDescription>
components = itProvider->second->proxyProviderDescriptions();
116 if(components.find(iComponent)!= components.end()) {
117 boost::shared_ptr<DataProxyProvider> proxyProv =
118 itProvider->second->proxyProvider(*(components.find(iComponent)));
119 assert(proxyProv.get());
121 std::set<EventSetupRecordKey> records = proxyProv->usingRecords();
122 for(std::set<EventSetupRecordKey>::iterator itRecord = records.begin(),
123 itRecordEnd = records.end();
124 itRecord != itRecordEnd;
127 if(!keyedProxies.empty()){
130 iReturnValue[*itRecord];
132 for(DataProxyProvider::KeyedProxies::const_iterator itProxy = keyedProxies.begin(),
133 itProxyEnd = keyedProxies.end();
134 itProxy != itProxyEnd;
136 EventSetupRecordProvider::DataToPreferredProviderMap::iterator itFind =
137 dataToProviderMap.find(itProxy->first);
138 if(itFind != dataToProviderMap.end()){
139 throw cms::Exception(
"ESPreferConflict") <<
"Two providers have been set to be preferred for\n"
140 <<itProxy->first.type().name()<<
" \""<<itProxy->first.name().value()<<
"\""
141 <<
"\n the providers are "
142 <<
"\n 1) type="<<itFind->second.type_<<
" label=\""<<itFind->second.label_<<
"\""
143 <<
"\n 2) type="<<iComponent.
type_<<
" label=\""<<iComponent.
label_<<
"\""
144 <<
"\nPlease modify configuration so only one is preferred";
146 dataToProviderMap.insert(std::make_pair(itProxy->first,iComponent));
150 foundProxyProvider=
true;
154 if(!foundProxyProvider) {
156 <<
"\" label=\""<<iComponent.
label_<<
"\" a preferred Provider."<<
157 "\n Please check spelling of name, or that it was loaded into the job.";
164 using namespace edm::eventsetup;
167 for(EventSetupProvider::PreferredProviderInfo::const_iterator itInfo = iInfo->begin(),
168 itInfoEnd = iInfo->end();
171 if(itInfo->second.empty()) {
175 for(EventSetupProvider::RecordToDataMap::const_iterator itRecData = itInfo->second.begin(),
176 itRecDataEnd = itInfo->second.end();
177 itRecData != itRecDataEnd;
182 throw cms::Exception(
"ESPreferUnknownRecord") <<
"Unknown record \""<<recordName
183 <<
"\" used in es_prefer statement for type="
184 <<itInfo->first.type_<<
" label=\""<<itInfo->first.label_
185 <<
"\"\n Please check spelling.";
189 Providers::const_iterator itRecordProvider = iProviders.find(recordKey);
190 assert(itRecordProvider != iProviders.end());
192 std::set<ComponentDescription>
components = itRecordProvider->second->proxyProviderDescriptions();
193 std::set<ComponentDescription>::iterator itProxyProv = components.find(itInfo->first);
194 if(itProxyProv == components.end()){
195 throw cms::Exception(
"ESPreferWrongRecord")<<
"The type="<<itInfo->first.type_<<
" label=\""<<
196 itInfo->first.label_<<
"\" does not provide data for the Record "<<
recordName;
202 throw cms::Exception(
"ESPreferWrongDataType")<<
"The es_prefer statement for type="<<itInfo->first.type_<<
" label=\""<<
203 itInfo->first.label_<<
"\" has the unknown data type \""<<itRecData->second.first<<
"\""
204 <<
"\n Please check spelling";
209 boost::shared_ptr<DataProxyProvider> proxyProv =
210 itRecordProvider->second->proxyProvider(*itProxyProv);
212 if(std::find_if(keyedProxies.begin(), keyedProxies.end(),
215 throw cms::Exception(
"ESPreferWrongData")<<
"The es_prefer statement for type="<<itInfo->first.type_<<
" label=\""<<
216 itInfo->first.label_<<
"\" specifies the data item \n"
217 <<
" type=\""<<itRecData->second.first<<
"\" label=\""<<itRecData->second.second<<
"\""
218 <<
" which is not provided. Please check spelling.";
222 =returnValue[recordKey];
224 if(dataToProviderMap.end() != dataToProviderMap.find(datumKey)) {
225 EventSetupRecordProvider::DataToPreferredProviderMap::iterator itFind =
226 dataToProviderMap.find(datumKey);
227 throw cms::Exception(
"ESPreferConflict") <<
"Two providers have been set to be preferred for\n"
228 <<datumKey.type().name()<<
" \""<<datumKey.name().value()<<
"\""
229 <<
"\n the providers are "
230 <<
"\n 1) type="<<itFind->second.type_<<
" label=\""<<itFind->second.label_<<
"\""
231 <<
"\n 2) type="<<itProxyProv->type_<<
" label=\""<<itProxyProv->label_<<
"\""
232 <<
"\nPlease modify configuration so only one is preferred";
234 dataToProviderMap.insert(std::make_pair(datumKey,*itProxyProv));
246 for(std::vector<boost::shared_ptr<EventSetupRecordIntervalFinder> >::iterator itFinder=
finders_->begin(),
250 typedef std::set<EventSetupRecordKey>
Keys;
251 const Keys recordsUsing = (*itFinder)->findingForRecords();
253 for(Keys::const_iterator itKey = recordsUsing.begin(), itKeyEnd = recordsUsing.end();
256 Providers::iterator itFound =
providers_.find(*itKey);
262 itFound->second->addFinder(*itFinder);
270 typedef std::set<EventSetupRecordKey>
Keys;
271 for(std::vector<boost::shared_ptr<DataProxyProvider> >::iterator itProvider=
dataProviders_->begin(),
276 const Keys recordsUsing = (*itProvider)->usingRecords();
278 for(Keys::const_iterator itKey = recordsUsing.begin(), itKeyEnd = recordsUsing.end();
281 Providers::iterator itFound =
providers_.find(*itKey);
287 itFound->second->add(*itProvider);
300 itProvider != itProviderEnd;
303 RecordToPreferred::const_iterator itRecordFound = recordToPreferred.find(itProvider->first);
304 if(itRecordFound != recordToPreferred.end()) {
305 preferredInfo = &(itRecordFound->second);
308 itProvider->second->usePreferred(*preferredInfo);
310 std::set<EventSetupRecordKey> records = itProvider->second->dependentRecords();
311 if(records.size() != 0) {
312 std::string missingRecords;
313 std::vector<boost::shared_ptr<EventSetupRecordProvider> > depProviders;
314 depProviders.reserve(records.size());
315 bool foundAllProviders =
true;
316 for(std::set<EventSetupRecordKey>::iterator itRecord = records.begin(),
317 itRecordEnd = records.end();
318 itRecord != itRecordEnd;
320 Providers::iterator itFound =
providers_.find(*itRecord);
322 foundAllProviders =
false;
323 if(missingRecords.size() == 0) {
324 missingRecords = itRecord->name();
326 missingRecords +=
", ";
327 missingRecords += itRecord->name();
331 depProviders.push_back(itFound->second);
335 if(!foundAllProviders) {
336 edm::LogInfo(
"EventSetupDependency")<<
"The EventSetup record "<<itProvider->second->key().name()
337 <<
" depends on at least one Record \n ("<<missingRecords<<
") which is not present in the job."
338 "\n This may lead to an exception begin thrown during event processing.\n If no exception occurs during the job than it is usually safe to ignore this message.";
344 itProvider->second->setDependentProviders(depProviders);
350 typedef std::map<EventSetupRecordKey, boost::shared_ptr<EventSetupRecordProvider> >
Providers;
351 typedef Providers::iterator
Itr;
357 std::vector<boost::shared_ptr<EventSetupRecordProvider> >& oDependents)
360 for(Itr it = itBegin; it != itEnd; ++it) {
362 const std::set<EventSetupRecordKey>& deps = it->second->dependentRecords();
363 if(deps.end() != deps.find(iKey)) {
364 oDependents.push_back(it->second);
374 Providers::iterator itFind =
providers_.find(iKey);
380 std::vector<boost::shared_ptr<EventSetupRecordProvider> > dependents;
383 dependents.erase(std::unique(dependents.begin(),dependents.end()), dependents.end());
385 itFind->second->resetProxies();
397 it->second->resetProxies();
422 itProvider != itProviderEnd;
424 itProvider->second->addRecordToIfValid(*
this, iValue);
432 struct InsertAll :
public std::unary_function< const std::set<ComponentDescription>&, void>{
434 typedef std::set<ComponentDescription> Set;
437 void operator()(
const Set& iSet) {
442 std::set<ComponentDescription>
446 typedef std::set<ComponentDescription> Set;
450 bind(InsertAll(descriptions),
454 for(std::vector<boost::shared_ptr<DataProxyProvider> >::const_iterator it =
dataProviders_->begin(),
458 descriptions.insert((*it)->description());
EventSetup const & eventSetupForInstance(IOVSyncValue const &)
void finishConfiguration()
std::map< DataKey, ComponentDescription > DataToPreferredProviderMap
std::auto_ptr< PreferredProviderInfo > preferredProviderInfo_
EventSetupProvider(PreferredProviderInfo const *iInfo=0)
static EventSetupRecordProviderFactoryManager & instance()
std::auto_ptr< std::vector< boost::shared_ptr< EventSetupRecordIntervalFinder > > > finders_
void forceCacheClear()
Used when testing that all code properly updates on IOV changes of all Records.
bool mustFinishConfiguration_
std::map< EventSetupRecordKey, boost::shared_ptr< EventSetupRecordProvider > > Providers
void resetRecordPlusDependentRecords(EventSetupRecordKey const &)
Used when we need to force a Record to reset all its proxies.
void insert(std::auto_ptr< T > iRecordProvider)
std::map< EventSetupRecordKey, EventSetupRecordProvider::DataToPreferredProviderMap > RecordToPreferred
void addRecordToEventSetup(EventSetupRecord &iRecord)
std::auto_ptr< std::vector< boost::shared_ptr< DataProxyProvider > > > dataProviders_
std::map< ComponentDescription, RecordToDataMap > PreferredProviderInfo
void add(boost::shared_ptr< DataProxyProvider >)
Func for_all(ForwardSequence &s, Func f)
wrapper for std::for_each
U second(std::pair< T, U > const &p)
virtual ~EventSetupProvider()
std::vector< std::pair< DataKey, boost::shared_ptr< DataProxy > > > KeyedProxies
static void findDependents(const EventSetupRecordKey &iKey, Itr itBegin, Itr itEnd, std::vector< boost::shared_ptr< EventSetupRecordProvider > > &oDependents)
static RecordToPreferred determinePreferred(const EventSetupProvider::PreferredProviderInfo *iInfo, const Providers &iProviders)
static void preferEverything(const ComponentDescription &iComponent, const Providers &iProviders, RecordToPreferred &iReturnValue)
find everything made by a DataProxyProvider and add it to the 'preferred' list
std::vector< size_type > Keys
void add(const eventsetup::EventSetupRecord &iRecord)
heterocontainer::HCTypeTag TypeTag
std::set< ComponentDescription > proxyProviderDescriptions() const
return information on which DataProxyProviders are supplying information
const TypeTag & type() const
void setIOVSyncValue(const IOVSyncValue &)
void setEventSetup(EventSetup const *iEventSetup)
std::set< ComponentDescription > proxyProviderDescriptions() const
void resetProxies()
This will clear the cache's of all the Proxies so that next time they are called they will run...
static HCTypeTag findType(char const *iTypeName)
find a type based on the types name, if not found will return default HCTypeTag