CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/HLTrigger/HLTcore/src/HLTConfigProvider.cc

Go to the documentation of this file.
00001 
00012 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
00013 #include "FWCore/Utilities/interface/ThreadSafeRegistry.h"
00014 #include "FWCore/ParameterSet/interface/Registry.h"
00015 #include "FWCore/Framework/interface/Run.h"
00016 #include "FWCore/Framework/interface/Event.h"
00017 #include "FWCore/Framework/interface/LuminosityBlock.h"
00018 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00019 #include "DataFormats/Provenance/interface/ProcessHistory.h"
00020 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00021 
00022 
00023 typedef edm::detail::ThreadSafeRegistry<edm::ParameterSetID, HLTConfigData> HLTConfigDataRegistry;
00024 
00025 // an empty dummy config data used when we fail to initialize 
00026 static const HLTConfigData* s_dummyHLTConfigData()
00027 { static HLTConfigData dummyHLTConfigData;
00028   return &dummyHLTConfigData;
00029 }
00030 
00031 HLTConfigProvider::HLTConfigProvider():
00032   processName_(""),
00033   inited_(false),
00034   changed_(true),
00035   hltConfigData_(s_dummyHLTConfigData()),
00036   l1GtUtils_(new L1GtUtils())
00037 {
00038 }
00039 
00040 bool HLTConfigProvider::init(const edm::Run& iRun, 
00041                              const edm::EventSetup& iSetup, 
00042                              const std::string& processName, 
00043                              bool& changed) {
00044 
00045    using namespace std;
00046    using namespace edm;
00047 
00048    LogInfo("HLTConfigData") << "Called (R) with processName '"
00049                             << processName
00050                             << "' for " << iRun.id() << endl;
00051 
00052    init(iRun.processHistory(),processName);
00053 
00056 
00057    processName_=processName;
00058    changed=changed_;
00059    return inited_;
00060 
00061 }
00062 
00063 void HLTConfigProvider::init(const edm::ProcessHistory& iHistory, const std::string& processName) {
00064 
00065    using namespace std;
00066    using namespace edm;
00067 
00069    const ProcessHistory::const_iterator hb(iHistory.begin());
00070    const ProcessHistory::const_iterator he(iHistory.end());
00071    unsigned int n(0);
00072    for (ProcessHistory::const_iterator hi=hb; hi!=he; ++hi) {
00073      if (hi->processName()==processName) {n++;}
00074    }
00075    if (n>1) {
00076      clear();
00077      LogError("HLTConfigProvider") << " ProcessName '"<< processName
00078                                    << " found " << n
00079                                    << " times in history!" << endl;
00080      return;
00081    }
00082 
00084    ProcessConfiguration processConfiguration;
00085    if (iHistory.getConfigurationForProcess(processName,processConfiguration)) {
00086      if ((hltConfigData_ !=s_dummyHLTConfigData()) && (processConfiguration.parameterSetID() == hltConfigData_->id())) {
00087        changed_ = false;
00088        inited_  = true;
00089        return;
00090      } else {
00091        getDataFrom(processConfiguration.parameterSetID(),processName);
00092      }
00093    } else {
00094      LogError("HLTConfigProvider") << "Falling back to processName-only init!";
00095      clear();
00096      init(processName);
00097      if (!inited_) {
00098        LogError("HLTConfigProvider") << "ProcessName not found in history!";
00099      }
00100      return;
00101    }
00102 }
00103 
00104 void HLTConfigProvider::getDataFrom(const edm::ParameterSetID& iID, const std::string& processName )
00105 {
00106   //is it in our registry?
00107   HLTConfigDataRegistry* reg = HLTConfigDataRegistry::instance();
00108   const HLTConfigData* d = reg->getMapped(iID);
00109   if(0 != d) {
00110     changed_ = true;
00111     inited_  = true;
00112     hltConfigData_ = d;
00113   } else {
00114     const edm::ParameterSet* processPSet = 0;
00115     if ( 0 != (processPSet = edm::pset::Registry::instance()->getMapped(iID))) {
00116        if (not processPSet->id().isValid()) {
00117          clear();
00118          edm::LogError("HLTConfigProvider") << "ProcessPSet found is empty!";
00119          changed_ = true; 
00120          inited_  = false; 
00121          hltConfigData_ = s_dummyHLTConfigData();
00122          return; 
00123        } else { 
00124          clear(); 
00125          reg->insertMapped( HLTConfigData(processPSet));
00126          changed_ = true; 
00127          inited_  = true; 
00128          hltConfigData_ = reg->getMapped(processPSet->id());
00129          return;
00130        }
00131      } else {
00132        clear();
00133        edm::LogError("HLTConfigProvider") << "ProcessPSet not found in regsistry!";
00134        changed_ = true;
00135        inited_  = false;
00136        hltConfigData_ = s_dummyHLTConfigData();       
00137        return;
00138      }
00139   }
00140   return;
00141 }
00142 
00143 void HLTConfigProvider::init(const std::string& processName)
00144 {
00145    using namespace std;
00146    using namespace edm;
00147 
00148    // Obtain ParameterSetID for requested process (with name
00149    // processName) from pset registry
00150    string pNames("");
00151    string hNames("");
00152    const ParameterSet*   pset = 0;
00153    ParameterSetID psetID;
00154    unsigned int   nPSets(0);
00155    const edm::pset::Registry * registry_(pset::Registry::instance());
00156    const edm::pset::Registry::const_iterator rb(registry_->begin());
00157    const edm::pset::Registry::const_iterator re(registry_->end());
00158    for (edm::pset::Registry::const_iterator i = rb; i != re; ++i) {
00159      if (i->second.exists("@process_name")) {
00160        const std::string pName(i->second.getParameter<string>("@process_name"));
00161        pNames += pName+" ";
00162        if ( pName == processName ) {
00163          psetID = i->first;
00164          nPSets++;
00165          if ((hltConfigData_ != s_dummyHLTConfigData()) && (hltConfigData_->id()==psetID)) {
00166            hNames += tableName();
00167          } else if ( 0 != (pset = registry_->getMapped(psetID))) {
00168            if (pset->exists("HLTConfigVersion")) {
00169              const ParameterSet& HLTPSet(pset->getParameterSet("HLTConfigVersion"));
00170              if (HLTPSet.exists("tableName")) {
00171                hNames += HLTPSet.getParameter<string>("tableName")+" ";
00172              }
00173            }
00174          }
00175        }
00176      }
00177    }
00178 
00179    LogVerbatim("HLTConfigProvider") << "Unordered list of all process names found: "
00180                                     << pNames << "." << endl;
00181 
00182    LogVerbatim("HLTConfigProvider") << "HLT TableName of each selected process: "
00183                                     << hNames << "." << endl;
00184 
00185    if (nPSets==0) {
00186      clear();
00187      LogError("HLTConfigProvider") << " Process name '"
00188                                    << processName
00189                                    << "' not found in registry!" << endl;
00190      return;
00191    }
00192    if (psetID==ParameterSetID()) {
00193      clear();
00194      LogError("HLTConfigProvider") << " Process name '"
00195                                    << processName
00196                                    << "' found but ParameterSetID invalid!"
00197                                    << endl;
00198      return;
00199    }
00200    if (nPSets>1) {
00201      clear();
00202      LogError("HLTConfigProvider") << " Process name '"
00203                                    << processName
00204                                    << " found " << nPSets
00205                                    << " times in registry!" << endl;
00206      return;
00207    }
00208 
00209    getDataFrom(psetID,processName);
00210 
00211    return;
00212 
00213 }
00214 
00215 void HLTConfigProvider::clear()
00216 {
00217    // clear all data members
00218 
00219    processName_   = "";
00220    inited_        = false;
00221    changed_       = true;
00222    hltConfigData_ = s_dummyHLTConfigData();
00223    *l1GtUtils_    = L1GtUtils();
00224 
00225    return;
00226 }
00227 
00228 
00229 int HLTConfigProvider::prescaleSet(const edm::Event& iEvent, const edm::EventSetup& iSetup) const {
00230   // return hltPrescaleTable_.set();
00231   l1GtUtils_->retrieveL1EventSetup(iSetup);
00232   int errorTech(0);
00233   const int psfsiTech(l1GtUtils_->prescaleFactorSetIndex(iEvent,L1GtUtils::TechnicalTrigger,errorTech));
00234   int errorPhys(0);
00235   const int psfsiPhys(l1GtUtils_->prescaleFactorSetIndex(iEvent,L1GtUtils::AlgorithmTrigger,errorPhys));
00236   assert(psfsiTech==psfsiPhys);
00237   if ( (errorTech==0) && (errorPhys==0) &&
00238        (psfsiTech>=0) && (psfsiPhys>=0) && (psfsiTech==psfsiPhys) ) {
00239     return psfsiPhys;
00240   } else {
00242     edm::LogError("HLTConfigData")
00243       << " Error in determining HLT prescale set index from L1 data using L1GtUtils: "
00244       << " Tech/Phys error = " << errorTech << "/" << errorPhys
00245       << " Tech/Phys psfsi = " << psfsiTech << "/" << psfsiPhys;
00246     return -1;
00247   }
00248 }
00249 
00250 unsigned int HLTConfigProvider::prescaleValue(const edm::Event& iEvent, const edm::EventSetup& iSetup, const std::string& trigger) const {
00251   const int set(prescaleSet(iEvent,iSetup));
00252   if (set<0) {
00253     return 1;
00254   } else {
00255     return prescaleValue(static_cast<unsigned int>(set),trigger);
00256   }
00257 }
00258 
00259 std::pair<int,int>  HLTConfigProvider::prescaleValues(const edm::Event& iEvent, const edm::EventSetup& iSetup, const std::string& trigger) const {
00260 
00261   // start with setting both L1T and HLT prescale values to 0
00262   std::pair<int,int> result(std::pair<int,int>(0,0));
00263 
00264   // get HLT prescale (possible if HLT prescale set index is correctly found)
00265   const int set(prescaleSet(iEvent,iSetup));
00266   if (set<0) {
00267     result.second = -1;
00268   } else {
00269     result.second = static_cast<int>(prescaleValue(static_cast<unsigned int>(set),trigger));
00270   }
00271 
00272   // get L1T prescale - works only for those hlt trigger paths with
00273   // exactly one L1GT seed module which has exactly one L1T name as seed
00274   const unsigned int nL1GTSeedModules(hltL1GTSeeds(trigger).size());
00275   if (nL1GTSeedModules==0) {
00276     // no L1 seed module on path hence no L1 seed hence formally no L1 prescale
00277     result.first=1;
00278   } else if (nL1GTSeedModules==1) {
00279     l1GtUtils_->retrieveL1EventSetup(iSetup);
00280     const std::string l1tname(hltL1GTSeeds(trigger).at(0).second);
00281     int               l1error(0);
00282     result.first = l1GtUtils_->prescaleFactor(iEvent,l1tname,l1error);
00283     if (l1error!=0) {
00284       edm::LogError("HLTConfigData")
00285         << " Error in determining L1T prescale for HLT path: '" << trigger
00286         << "' with L1T seed: '" << l1tname
00287         << "' using L1GtUtils: error code: " << l1error
00288         << ". (Note: only a single L1T name, not a bit number, is allowed as seed for a proper determination of the L1T prescale!)";
00289       result.first = -1;
00290     }
00291   } else {
00293     std::string dump("'"+hltL1GTSeeds(trigger).at(0).second+"'");
00294     for (unsigned int i=1; i!=nL1GTSeedModules; ++i) {
00295       dump += " * '"+hltL1GTSeeds(trigger).at(i).second+"'";
00296     }
00297     edm::LogError("HLTConfigData")
00298       << " Error in determining L1T prescale for HLT path: '" << trigger
00299       << "' has multiple L1GTSeed modules, " << nL1GTSeedModules
00300       << ", with L1 seeds: " << dump
00301       << ". (Note: at most one L1GTSeed module is allowed for a proper determination of the L1T prescale!)";
00302     result.first = -1;
00303   }
00304 
00305   return result;
00306 }