00001 // -*- C++ -*- 00002 // 00003 // Package: Framework 00004 // Class : DataProxyProvider 00005 // 00006 // Implementation: 00007 // <Notes on implementation> 00008 // 00009 // Author: Chris Jones 00010 // Created: Mon Mar 28 15:07:54 EST 2005 00011 // 00012 00013 // system include files 00014 #include <algorithm> 00015 00016 // user include files 00017 #include "FWCore/Framework/interface/DataProxyProvider.h" 00018 #include "FWCore/Framework/interface/DataProxy.h" 00019 #include "FWCore/ParameterSet/interface/ParameterSet.h" 00020 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" 00021 #include <cassert> 00022 00023 namespace edm { 00024 namespace eventsetup { 00025 // 00026 // constants, enums and typedefs 00027 // 00028 00029 // 00030 // static data member definitions 00031 // 00032 00033 // 00034 // constructors and destructor 00035 // 00036 DataProxyProvider::DataProxyProvider() : recordProxies_(), description_() 00037 { 00038 } 00039 00040 // DataProxyProvider::DataProxyProvider(const DataProxyProvider& rhs) 00041 // { 00042 // // do actual copying here; 00043 // } 00044 00045 DataProxyProvider::~DataProxyProvider() 00046 { 00047 } 00048 00049 // 00050 // assignment operators 00051 // 00052 // const DataProxyProvider& DataProxyProvider::operator=(const DataProxyProvider& rhs) 00053 // { 00054 // //An exception safe implementation is 00055 // DataProxyProvider temp(rhs); 00056 // swap(rhs); 00057 // 00058 // return *this; 00059 // } 00060 00061 // 00062 // member functions 00063 // 00064 void 00065 DataProxyProvider::usingRecordWithKey(const EventSetupRecordKey& iKey) 00066 { 00067 recordProxies_[iKey]; 00068 //keys_.push_back(iKey); 00069 } 00070 00071 void 00072 DataProxyProvider::invalidateProxies(const EventSetupRecordKey& iRecordKey) 00073 { 00074 KeyedProxies& proxyList((*(recordProxies_.find(iRecordKey))).second) ; 00075 KeyedProxies::iterator finished(proxyList.end()) ; 00076 for (KeyedProxies::iterator keyedProxy(proxyList.begin()) ; 00077 keyedProxy != finished ; 00078 ++keyedProxy) { 00079 (*((*keyedProxy).second)).invalidate() ; 00080 } 00081 00082 } 00083 00084 void 00085 DataProxyProvider::resetProxies(const EventSetupRecordKey& iRecordKey) 00086 { 00087 invalidateProxies(iRecordKey); 00088 } 00089 00090 void 00091 DataProxyProvider::resetProxiesIfTransient(const EventSetupRecordKey& iRecordKey) 00092 { 00093 KeyedProxies& proxyList((*(recordProxies_.find(iRecordKey))).second) ; 00094 KeyedProxies::iterator finished(proxyList.end()) ; 00095 for (KeyedProxies::iterator keyedProxy(proxyList.begin()) ; 00096 keyedProxy != finished ; 00097 ++keyedProxy) { 00098 (*((*keyedProxy).second)).resetIfTransient() ; 00099 } 00100 00101 } 00102 00103 void 00104 DataProxyProvider::setAppendToDataLabel(const edm::ParameterSet& iToAppend) 00105 { 00106 std::string oldValue( appendToDataLabel_); 00107 //this can only be changed once and the default value is the empty string 00108 assert(0 == oldValue.size()); 00109 00110 const std::string kParamName("appendToDataLabel"); 00111 if(iToAppend.exists(kParamName) ) { 00112 appendToDataLabel_ = iToAppend.getParameter<std::string>(kParamName); 00113 } 00114 } 00115 // 00116 // const member functions 00117 // 00118 bool 00119 DataProxyProvider::isUsingRecord(const EventSetupRecordKey& iKey) const 00120 { 00121 return recordProxies_.end() != recordProxies_.find(iKey); 00122 } 00123 00124 std::set<EventSetupRecordKey> 00125 DataProxyProvider::usingRecords() const 00126 { 00127 std::set<EventSetupRecordKey> returnValue; 00128 for(RecordProxies::const_iterator itRecProxies = recordProxies_.begin(), 00129 itRecProxiesEnd = recordProxies_.end(); 00130 itRecProxies != itRecProxiesEnd; 00131 ++itRecProxies) { 00132 returnValue.insert(returnValue.end(), itRecProxies->first); 00133 } 00134 //copy_all(keys_, std::inserter(returnValue, returnValue.end())); 00135 return returnValue; 00136 } 00137 00138 const DataProxyProvider::KeyedProxies& 00139 DataProxyProvider::keyedProxies(const EventSetupRecordKey& iRecordKey) const 00140 { 00141 RecordProxies::const_iterator itFind = recordProxies_.find(iRecordKey); 00142 assert(itFind != recordProxies_.end()); 00143 00144 if(itFind->second.empty()) { 00145 //delayed registration 00146 KeyedProxies& proxies = const_cast<KeyedProxies&>(itFind->second); 00147 const_cast<DataProxyProvider*>(this)->registerProxies(iRecordKey, 00148 proxies); 00149 00150 bool mustChangeLabels = (0 != appendToDataLabel_.size()); 00151 for(KeyedProxies::iterator itProxy = proxies.begin(), itProxyEnd = proxies.end(); 00152 itProxy != itProxyEnd; 00153 ++itProxy) { 00154 itProxy->second->setProviderDescription(&description()); 00155 if( mustChangeLabels ) { 00156 //Using swap is fine since 00157 // 1) the data structure is not a map and so we have not sorted on the keys 00158 // 2) this is the first time filling this so no outside agency has yet seen 00159 // the label and therefore can not be dependent upon its value 00160 std::string temp(std::string(itProxy->first.name().value())+appendToDataLabel_); 00161 DataKey newKey(itProxy->first.type(),temp.c_str()); 00162 swap(itProxy->first,newKey); 00163 } 00164 } 00165 } 00166 00167 return itFind->second; 00168 } 00169 00170 // 00171 // static member functions 00172 // 00173 static const std::string kAppendToDataLabel("appendToDataLabel"); 00174 00175 void 00176 DataProxyProvider::prevalidate(ConfigurationDescriptions& iDesc) 00177 { 00178 if(iDesc.defaultDescription()) { 00179 if (iDesc.defaultDescription()->isLabelUnused(kAppendToDataLabel)) { 00180 iDesc.defaultDescription()->add<std::string>(kAppendToDataLabel, std::string("")); 00181 } 00182 } 00183 for(auto& v: iDesc) { 00184 if (v.second.isLabelUnused(kAppendToDataLabel)) { 00185 v.second.add<std::string>(kAppendToDataLabel, std::string("")); 00186 } 00187 } 00188 } 00189 00190 } 00191 } 00192