CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/FWCore/Framework/src/DataProxyProvider.cc

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