CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/HLTrigger/HLTcore/src/HLTConfigData.cc

Go to the documentation of this file.
00001 
00012 #include "HLTrigger/HLTcore/interface/HLTConfigData.h"
00013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00014 
00015 #include <iostream>
00016 
00017 static const edm::ParameterSet* s_dummyPSet()
00018 {
00019   static edm::ParameterSet dummyPSet;
00020   dummyPSet.registerIt();
00021   return &dummyPSet;
00022 }
00023 
00024 HLTConfigData::HLTConfigData():
00025   processPSet_(s_dummyPSet()),
00026   processName_(""), globalTag_(""),
00027   tableName_(), triggerNames_(), moduleLabels_(), saveTagsModules_(),
00028   triggerIndex_(), moduleIndex_(),
00029   hltL1GTSeeds_(),
00030   streamNames_(), streamIndex_(), streamContents_(),
00031   datasetNames_(), datasetIndex_(), datasetContents_(),
00032   hltPrescaleTable_()
00033 {
00034   if (processPSet_->id().isValid()) {
00035     extract();
00036   }
00037 }
00038 
00039 HLTConfigData::HLTConfigData(const edm::ParameterSet* iPSet):
00040   processPSet_(iPSet),
00041   processName_(""), globalTag_(""),
00042   tableName_(), triggerNames_(), moduleLabels_(), saveTagsModules_(),
00043   triggerIndex_(), moduleIndex_(),
00044   hltL1GTSeeds_(),
00045   streamNames_(), streamIndex_(), streamContents_(),
00046   datasetNames_(), datasetIndex_(), datasetContents_(),
00047   hltPrescaleTable_()
00048 {
00049   if (processPSet_->id().isValid()) {
00050     extract();
00051   }
00052 }
00053 
00054 void HLTConfigData::extract()
00055 {
00056    using namespace std;
00057    using namespace edm;
00058    using namespace trigger;
00059 
00060    // Extract process name
00061    if (processPSet_->existsAs<string>("@process_name",true)) {
00062      processName_= processPSet_->getParameter<string>("@process_name");
00063    }
00064 
00065    // Extract globaltag
00066    globalTag_="";
00067    const ParameterSet* GlobalTagPSet(0);
00068    if (processPSet_->exists("GlobalTag")) {
00069      GlobalTagPSet = &(processPSet_->getParameterSet("GlobalTag"));
00070    } else if (processPSet_->exists("PoolDBESSource@GlobalTag")) {
00071      GlobalTagPSet = &(processPSet_->getParameterSet("PoolDBESSource@GlobalTag"));
00072    }
00073    if (GlobalTagPSet && GlobalTagPSet->existsAs<std::string>("globaltag",true)) {
00074        globalTag_=GlobalTagPSet->getParameter<std::string>("globaltag");
00075    }
00076 
00077    // Obtain PSet containing table name (available only in 2_1_10++ files)
00078    if (processPSet_->existsAs<ParameterSet>("HLTConfigVersion",true)) {
00079      const ParameterSet& HLTPSet(processPSet_->getParameterSet("HLTConfigVersion"));
00080      if (HLTPSet.existsAs<string>("tableName",true)) {
00081        tableName_=HLTPSet.getParameter<string>("tableName");
00082      }
00083    }
00084 
00085    LogVerbatim("HLTConfigData") << "ProcessPSet with: "
00086                                 << processName_ << " "
00087                                 << globalTag_ << " "
00088                                 << tableName_;
00089 
00090    // Extract trigger paths (= paths - end_paths)
00091    if (processPSet_->existsAs<ParameterSet>("@trigger_paths",true)) {
00092      const ParameterSet& HLTPSet(processPSet_->getParameterSet("@trigger_paths"));
00093      if (HLTPSet.existsAs<vector<string> >("@trigger_paths",true)) {
00094        triggerNames_= HLTPSet.getParameter<vector<string> >("@trigger_paths");
00095      }
00096    }
00097 
00098    // Obtain module labels of all modules on all trigger paths
00099    const unsigned int n(size());
00100    moduleLabels_.reserve(n);
00101    for (unsigned int i=0;i!=n; ++i) {
00102      if (processPSet_->existsAs<vector<string> >(triggerNames_[i],true)) {
00103        moduleLabels_.push_back(processPSet_->getParameter<vector<string> >(triggerNames_[i]));
00104      }
00105    }
00106    saveTagsModules_.reserve(n);
00107    vector<string> labels;
00108    for (unsigned int i=0;i!=n; ++i) {
00109      labels.clear();
00110      const vector<string>& modules(moduleLabels(i));
00111      const unsigned int m(modules.size());
00112      labels.reserve(m);
00113      for (unsigned int j=0;j!=m; ++j) {
00114        const string& label(modules[j]);
00115        if (saveTags(label)) labels.push_back(label);
00116      }
00117      saveTagsModules_.push_back(labels);
00118    }
00119 
00120    // Fill index maps for fast lookup
00121    moduleIndex_.resize(n);
00122    for (unsigned int i=0; i!=n; ++i) {
00123      triggerIndex_[triggerNames_[i]]=i;
00124      moduleIndex_[i].clear();
00125      const unsigned int m(size(i));
00126      for (unsigned int j=0; j!=m; ++j) {
00127        moduleIndex_[i][moduleLabels_[i][j]]=j;
00128      }
00129    }
00130 
00131    // Extract and fill HLTLevel1GTSeed information for each trigger path
00132    hltL1GTSeeds_.resize(n);
00133    for (unsigned int i=0; i!=n; ++i) {
00134      hltL1GTSeeds_[i].clear();
00135      const unsigned int m(size(i));
00136      for (unsigned int j=0; j!=m; ++j) {
00137        const string& label(moduleLabels_[i][j]);
00138        if (moduleType(label) == "HLTLevel1GTSeed") {
00139          const ParameterSet& pset(modulePSet(label));
00140          if (pset!=ParameterSet()) {
00141            const bool   l1Tech(pset.getParameter<bool>("L1TechTriggerSeeding"));
00142            const string l1Seed(pset.getParameter<string>("L1SeedsLogicalExpression"));
00143            hltL1GTSeeds_[i].push_back(pair<bool,string>(l1Tech,l1Seed));
00144          }
00145        }
00146      }
00147    }
00148 
00149    // Extract and fill streams information
00150    if (processPSet_->existsAs<ParameterSet>("streams",true)) {
00151      const ParameterSet& streams(processPSet_->getParameterSet("streams"));
00152      streamNames_=streams.getParameterNamesForType<vector<string> >();
00153      sort(streamNames_.begin(),streamNames_.end());
00154      const unsigned int n(streamNames_.size());
00155      streamContents_.resize(n);
00156      for (unsigned int i=0; i!=n; ++i) {
00157        streamIndex_[streamNames_[i]]=i;
00158        streamContents_[i]=streams.getParameter<vector<string> >(streamNames_[i]);
00159        sort(streamContents_[i].begin(),streamContents_[i].end());
00160      }
00161      
00162    }
00163 
00164    // Extract and fill datasets information
00165    if (processPSet_->existsAs<ParameterSet>("datasets",true)) {
00166      const ParameterSet& datasets(processPSet_->getParameterSet("datasets"));
00167      datasetNames_=datasets.getParameterNamesForType<vector<string> >();
00168      sort(datasetNames_.begin(),datasetNames_.end());
00169      const unsigned int n(datasetNames_.size());
00170      datasetContents_.resize(n);
00171      for (unsigned int i=0; i!=n; ++i) {
00172        datasetIndex_[datasetNames_[i]]=i;
00173        datasetContents_[i]=datasets.getParameter< vector<string> >(datasetNames_[i]);
00174        sort(datasetContents_[i].begin(),datasetContents_[i].end());
00175      }
00176    }
00177 
00178    // Extract and fill Prescale information
00179 
00180    // Check various possibilities to get the HLT prescale sets:
00181    string prescaleName("");
00182    const string preS("PrescaleService");
00183    const string preT("PrescaleTable");
00184    if (processPSet_->existsAs<ParameterSet>(preS,true)) {
00185      prescaleName=preS;
00186    } else if ( processPSet_->existsAs<ParameterSet>(preT,true)) {
00187      prescaleName=preT;
00188    }
00189    if (prescaleName=="") {
00190      hltPrescaleTable_=HLTPrescaleTable();
00191    } else {
00192      const ParameterSet& iPS(processPSet_->getParameterSet(prescaleName));
00193      string defaultLabel("default");
00194      if (iPS.existsAs<string>("lvl1DefaultLabel",true)) {
00195        defaultLabel = iPS.getParameter<string>("lvl1DefaultLabel");
00196      }
00197      vector<string> labels;
00198      if (iPS.existsAs<vector<string> >("lvl1Labels",true)) {
00199        labels = iPS.getParameter<vector<string> >("lvl1Labels");
00200      }
00201      unsigned int set(0);
00202      const unsigned int n(labels.size());
00203      for (unsigned int i=0; i!=n; ++i) {
00204        if (labels[i]==defaultLabel) set=i;
00205      }
00206      map<string,vector<unsigned int> > table;
00207      if (iPS.existsAs< vector<ParameterSet> >("prescaleTable",true)) {
00208        const vector<ParameterSet>& vpTable(iPS.getParameterSetVector("prescaleTable"));
00209        const unsigned int m (vpTable.size());
00210        for (unsigned int i=0; i!=m; ++i) {
00211          table[vpTable[i].getParameter<std::string>("pathName")] = 
00212            vpTable[i].getParameter<std::vector<unsigned int> >("prescales");
00213        }
00214      }
00215      if (n>0) {
00216        hltPrescaleTable_=HLTPrescaleTable(set,labels,table);
00217      } else {
00218        hltPrescaleTable_=HLTPrescaleTable();
00219      }
00220 
00221    }
00222 
00223    return;
00224 }
00225 
00226 void HLTConfigData::dump(const std::string& what) const {
00227    using namespace std;
00228    using namespace edm;
00229 
00230    if (what=="ProcessPSet") {
00231      cout << "HLTConfigData::dump: ProcessPSet = " << endl << *processPSet_ << endl;
00232    } else if (what=="ProcessName") {
00233      cout << "HLTConfigData::dump: ProcessName = " << processName_ << endl;
00234    } else if (what=="GlobalTag") {
00235      cout << "HLTConfigData::dump: GlobalTag = " << globalTag_ << endl;
00236    } else if (what=="TableName") {
00237      cout << "HLTConfigData::dump: TableName = " << tableName_ << endl;
00238    } else if (what=="Triggers") {
00239      const unsigned int n(size());
00240      cout << "HLTConfigData::dump: Triggers: " << n << endl;
00241      for (unsigned int i=0; i!=n; ++i) {
00242        cout << "  " << i << " " << triggerNames_[i] << endl;
00243      }
00244    } else if (what=="TriggerSeeds") {
00245      const unsigned int n(size());
00246      cout << "HLTConfigData::dump: TriggerSeeds: " << n << endl;
00247      for (unsigned int i=0; i!=n; ++i) {
00248        const unsigned int m(hltL1GTSeeds_[i].size());
00249        cout << "  " << i << " " << triggerNames_[i] << " " << m << endl;
00250        for (unsigned int j=0; j!=m; ++j) {
00251          cout << "    " << j
00252               << " " << hltL1GTSeeds_[i][j].first
00253               << "/" << hltL1GTSeeds_[i][j].second << endl;
00254        }
00255      }
00256    } else if (what=="Modules") {
00257      const unsigned int n(size());
00258      cout << "HLTConfigData::dump Triggers and Modules: " << n << endl;
00259      for (unsigned int i=0; i!=n; ++i) {
00260        const unsigned int m(size(i));
00261        cout << i << " " << triggerNames_[i] << " " << m << endl;
00262        cout << " - Modules: ";
00263        unsigned int nHLTPrescalers(0);
00264        unsigned int nHLTLevel1GTSeed(0);
00265        for (unsigned int j=0; j!=m; ++j) {
00266          const string& label(moduleLabels_[i][j]);
00267          const string  type(moduleType(label));
00268          const string  edmtype(moduleEDMType(label));
00269          const bool    tags(saveTags(label));
00270          cout << " " << j << ":" << label << "/" << type << "/" << edmtype << "/" << tags;
00271          if (type=="HLTPrescaler") nHLTPrescalers++;
00272          if (type=="HLTLevel1GTSeed") nHLTLevel1GTSeed++;
00273        }
00274        cout << endl;
00275        cout << " - Number of HLTPrescaler/HLTLevel1GTSeed modules: " 
00276             << nHLTPrescalers << "/" << nHLTLevel1GTSeed << endl;
00277      }
00278    } else if (what=="StreamNames") {
00279      const unsigned int n(streamNames_.size());
00280      cout << "HLTConfigData::dump: StreamNames: " << n << endl;
00281      for (unsigned int i=0; i!=n; ++i) {
00282        cout << "  " << i << " " << streamNames_[i] << endl;
00283      }
00284    } else if (what=="Streams") {
00285      const unsigned int n(streamNames_.size());
00286      cout << "HLTConfigData::dump: Streams: " << n << endl;
00287      for (unsigned int i=0; i!=n; ++i) {
00288        const unsigned int m(streamContents_[i].size());
00289        cout << "  " << i << " " << streamNames_[i] << " " << m << endl;
00290        for (unsigned int j=0; j!=m; ++j) {
00291          cout << "    " << j << " " << streamContents_[i][j] << endl;
00292        }
00293      }
00294    } else if (what=="DatasetNames") {
00295      const unsigned int n(datasetNames_.size());
00296      cout << "HLTConfigData::dump: DatasetNames: " << n << endl;
00297      for (unsigned int i=0; i!=n; ++i) {
00298        cout << "  " << i << " " << datasetNames_[i] << endl;
00299      }
00300    } else if (what=="Datasets") {
00301      const unsigned int n(datasetNames_.size());
00302      cout << "HLTConfigData::dump: Datasets: " << n << endl;
00303      for (unsigned int i=0; i!=n; ++i) {
00304        const unsigned int m(datasetContents_[i].size());
00305        cout << "  " << i << " " << datasetNames_[i] << " " << m << endl;
00306        for (unsigned int j=0; j!=m; ++j) {
00307          cout << "    " << j << " " << datasetContents_[i][j] << endl;
00308        }
00309      }
00310    } else if (what=="PrescaleTable") {
00311      const unsigned int n (hltPrescaleTable_.size());
00312      cout << "HLTConfigData::dump: PrescaleTable: # of sets : " << n << endl;
00313      const vector<string>& labels(hltPrescaleTable_.labels());
00314      for (unsigned int i=0; i!=n; ++i) {
00315        cout << " " << i << "/'" << labels.at(i) << "'";
00316      }
00317      if (n>0) cout << endl;
00318      const map<string,vector<unsigned int> >& table(hltPrescaleTable_.table());
00319      cout << "HLTConfigData::dump: PrescaleTable: # of paths: " << table.size() << endl;
00320      const map<string,vector<unsigned int> >::const_iterator tb(table.begin());
00321      const map<string,vector<unsigned int> >::const_iterator te(table.end());
00322      for (map<string,vector<unsigned int> >::const_iterator ti=tb; ti!=te; ++ti) {
00323        for (unsigned int i=0; i!=n; ++i) {
00324          cout << " " << ti->second.at(i);
00325        }
00326        cout << " " << ti->first << endl;
00327      }
00328    } else {
00329      cout << "HLTConfigData::dump: Unkown dump request: " << what << endl;
00330    }
00331    return;
00332 }
00333 
00334 const std::string& HLTConfigData::processName() const {
00335   return processName_;
00336 }
00337 
00338 unsigned int HLTConfigData::size() const {
00339   return triggerNames_.size();
00340 }
00341 unsigned int HLTConfigData::size(unsigned int trigger) const {
00342   return moduleLabels_.at(trigger).size();
00343 }
00344 unsigned int HLTConfigData::size(const std::string& trigger) const {
00345   return size(triggerIndex(trigger));
00346 }
00347 
00348 const std::string& HLTConfigData::tableName() const {
00349   return tableName_;
00350 }
00351 const std::vector<std::string>& HLTConfigData::triggerNames() const {
00352   return triggerNames_;
00353 }
00354 const std::string& HLTConfigData::triggerName(unsigned int trigger) const {
00355   return triggerNames_.at(trigger);
00356 }
00357 unsigned int HLTConfigData::triggerIndex(const std::string& trigger) const {
00358   const std::map<std::string,unsigned int>::const_iterator index(triggerIndex_.find(trigger));
00359   if (index==triggerIndex_.end()) {
00360     return size();
00361   } else {
00362     return index->second;
00363   }
00364 }
00365 
00366 const std::vector<std::string>& HLTConfigData::moduleLabels(unsigned int trigger) const {
00367   return moduleLabels_.at(trigger);
00368 }
00369 const std::vector<std::string>& HLTConfigData::moduleLabels(const std::string& trigger) const {
00370   return moduleLabels_.at(triggerIndex(trigger));
00371 }
00372 
00373 const std::vector<std::string>& HLTConfigData::saveTagsModules(unsigned int trigger) const {
00374   return saveTagsModules_.at(trigger);
00375 }
00376 const std::vector<std::string>& HLTConfigData::saveTagsModules(const std::string& trigger) const {
00377   return saveTagsModules_.at(triggerIndex(trigger));
00378 }
00379 
00380 const std::string& HLTConfigData::moduleLabel(unsigned int trigger, unsigned int module) const {
00381   return moduleLabels_.at(trigger).at(module);
00382 }
00383 const std::string& HLTConfigData::moduleLabel(const std::string& trigger, unsigned int module) const {
00384   return moduleLabels_.at(triggerIndex(trigger)).at(module);
00385 }
00386 
00387 unsigned int HLTConfigData::moduleIndex(unsigned int trigger, const std::string& module) const {
00388   const std::map<std::string,unsigned int>::const_iterator index(moduleIndex_.at(trigger).find(module));
00389   if (index==moduleIndex_.at(trigger).end()) {
00390     return size(trigger);
00391   } else {
00392     return index->second;
00393   }
00394 }
00395 unsigned int HLTConfigData::moduleIndex(const std::string& trigger, const std::string& module) const {
00396   return moduleIndex(triggerIndex(trigger),module);
00397 }
00398 
00399 const std::string HLTConfigData::moduleType(const std::string& module) const {
00400   const edm::ParameterSet& pset(modulePSet(module));
00401   if (pset.existsAs<std::string>("@module_type",true)) {
00402     return pset.getParameter<std::string>("@module_type");
00403   } else {
00404     return "";
00405   }
00406 }
00407 
00408 const std::string HLTConfigData::moduleEDMType(const std::string& module) const {
00409   const edm::ParameterSet& pset(modulePSet(module));
00410   if (pset.existsAs<std::string>("@module_edm_type",true)) {
00411     return pset.getParameter<std::string>("@module_edm_type");
00412   } else {
00413     return "";
00414   }
00415 }
00416 
00417 const edm::ParameterSet& HLTConfigData::processPSet() const {
00418   return *processPSet_;
00419 }
00420 
00421 const edm::ParameterSet& HLTConfigData::modulePSet(const std::string& module) const {
00422   if (processPSet_->exists(module)) {
00423     return processPSet_->getParameterSet(module);
00424   } else {
00425     return *s_dummyPSet();
00426   }
00427 }
00428 
00429 bool HLTConfigData::saveTags(const std::string& module) const {
00430   const edm::ParameterSet& pset(modulePSet(module));
00431   if (pset.existsAs<bool>("saveTags",true)) {
00432     return pset.getParameter<bool>("saveTags");
00433   } else {
00434     return false;
00435   }
00436 }
00437 
00438 const std::vector<std::vector<std::pair<bool,std::string> > >& HLTConfigData::hltL1GTSeeds() const {
00439   return hltL1GTSeeds_;
00440 }
00441 
00442 const std::vector<std::pair<bool,std::string> >& HLTConfigData::hltL1GTSeeds(const std::string& trigger) const {
00443   return hltL1GTSeeds(triggerIndex(trigger));
00444 }
00445 
00446 const std::vector<std::pair<bool,std::string> >& HLTConfigData::hltL1GTSeeds(unsigned int trigger) const {
00447   return hltL1GTSeeds_.at(trigger);
00448 }
00449 
00451 const std::vector<std::string>& HLTConfigData::streamNames() const {
00452   return streamNames_;
00453 }
00454 
00455 const std::string& HLTConfigData::streamName(unsigned int stream) const {
00456   return streamNames_.at(stream);
00457 }
00458 
00459 unsigned int HLTConfigData::streamIndex(const std::string& stream) const {
00460   const std::map<std::string,unsigned int>::const_iterator index(streamIndex_.find(stream));
00461   if (index==streamIndex_.end()) {
00462     return streamNames_.size();
00463   } else {
00464     return index->second;
00465   }
00466 }
00467 
00468 const std::vector<std::vector<std::string> >& HLTConfigData::streamContents() const {
00469   return streamContents_;
00470 }
00471 
00472 const std::vector<std::string>& HLTConfigData::streamContent(unsigned int stream) const {
00473   return streamContents_.at(stream);
00474 }
00475 
00476 const std::vector<std::string>& HLTConfigData::streamContent(const std::string& stream) const {
00477   return streamContent(streamIndex(stream));
00478 }
00479 
00481 const std::vector<std::string>& HLTConfigData::datasetNames() const {
00482   return datasetNames_;
00483 }
00484 
00485 const std::string& HLTConfigData::datasetName(unsigned int dataset) const {
00486   return datasetNames_.at(dataset);
00487 }
00488 
00489 unsigned int HLTConfigData::datasetIndex(const std::string& dataset) const {
00490   const std::map<std::string,unsigned int>::const_iterator index(datasetIndex_.find(dataset));
00491   if (index==datasetIndex_.end()) {
00492     return datasetNames_.size();
00493   } else {
00494     return index->second;
00495   }
00496 }
00497 
00498 const std::vector<std::vector<std::string> >& HLTConfigData::datasetContents() const {
00499   return datasetContents_;
00500 }
00501 
00502 const std::vector<std::string>& HLTConfigData::datasetContent(unsigned int dataset) const {
00503   return datasetContents_.at(dataset);
00504 }
00505 
00506 const std::vector<std::string>& HLTConfigData::datasetContent(const std::string& dataset) const {
00507   return datasetContent(datasetIndex(dataset));
00508 }
00509 
00510 
00511 unsigned int HLTConfigData::prescaleSize() const {
00512   return hltPrescaleTable_.size();
00513 }
00514 unsigned int HLTConfigData::prescaleValue(unsigned int set, const std::string& trigger) const {
00515   return hltPrescaleTable_.prescale(set,trigger);
00516 }
00517 
00518 const std::vector<std::string>& HLTConfigData::prescaleLabels() const {
00519   return hltPrescaleTable_.labels();
00520 }
00521 const std::map<std::string,std::vector<unsigned int> >& HLTConfigData::prescaleTable() const {
00522   return hltPrescaleTable_.table();
00523 }
00524 
00525 edm::ParameterSetID HLTConfigData::id() const {
00526   return processPSet_->id();
00527 }