00001 00012 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h" 00013 #include <cassert> 00014 #include <iostream> 00015 00016 bool HLTConfigProvider::init(const std::string& processName) 00017 { 00018 using namespace std; 00019 using namespace edm; 00020 00021 // clear and initialise 00022 00023 processName_ = processName; 00024 registry_ = pset::Registry::instance(); 00025 00026 ProcessPSet_ = ParameterSet(); 00027 tableName_ = "/dev/null"; 00028 00029 triggerNames_.clear(); 00030 moduleLabels_.clear(); 00031 00032 triggerIndex_.clear(); 00033 moduleIndex_.clear(); 00034 00035 pathNames_.clear(); 00036 endpathNames_.clear(); 00037 00038 // Obtain ParameterSetID for requested process (with name 00039 // processName) from pset registry 00040 ParameterSetID ProcessPSetID; 00041 for (edm::pset::Registry::const_iterator i = registry_->begin(); i != registry_->end(); ++i) { 00042 if (i->second.exists("@process_name") and i->second.getParameter<string>("@process_name") == processName_) 00043 ProcessPSetID = i->first; 00044 } 00045 if (ProcessPSetID==ParameterSetID()) return false; 00046 00047 // Obtain ParameterSet from ParameterSetID 00048 if (!(registry_->getMapped(ProcessPSetID,ProcessPSet_))) return false; 00049 00050 // Obtain HLT PSet containing table name (available only in 2_1_10++ files) 00051 if (ProcessPSet_.exists("HLTConfigVersion")) { 00052 const ParameterSet HLTPSet(ProcessPSet_.getParameter<ParameterSet>("HLTConfigVersion")); 00053 if (HLTPSet.exists("tableName")) { 00054 tableName_=HLTPSet.getParameter<string>("tableName"); 00055 } 00056 } 00057 //cout << "HLTConfigProvider::init() HLT-ConfDB TableName = " << tableName_ << endl; 00058 00059 // Extract trigger paths, which are paths but with endpaths to be 00060 // removed, from ParameterSet 00061 pathNames_ = ProcessPSet_.getParameter<vector<string> >("@paths"); 00062 endpathNames_= ProcessPSet_.getParameter<vector<string> >("@end_paths"); 00063 const unsigned int nP(pathNames_.size()); 00064 const unsigned int nE(endpathNames_.size()); 00065 for (unsigned int iE=0; iE!=nE; ++iE) { 00066 const std::string& endpath(endpathNames_[iE]); 00067 for (unsigned int iP=0; iP!=nP; ++iP) { 00068 if (pathNames_[iP]==endpath) { 00069 pathNames_[iP]=""; // erase endpaths 00070 } 00071 } 00072 } 00073 triggerNames_.reserve(nP); 00074 for (unsigned int iP=0; iP!=nP; ++iP) { 00075 if (pathNames_[iP]!="") {triggerNames_.push_back(pathNames_[iP]);} 00076 } 00077 pathNames_ = ProcessPSet_.getParameter<vector<string> >("@paths"); 00078 00079 // Obtain module labels of all modules on all trigger paths 00080 const unsigned int n(size()); 00081 moduleLabels_.reserve(n); 00082 for (unsigned int i=0;i!=n; ++i) { 00083 moduleLabels_.push_back(ProcessPSet_.getParameter<vector<string> >(triggerNames_[i])); 00084 } 00085 00086 // Fill index maps for fast lookup 00087 moduleIndex_.resize(n); 00088 for (unsigned int i=0; i!=n; ++i) { 00089 triggerIndex_[triggerNames_[i]]=i; 00090 moduleIndex_[i].clear(); 00091 const unsigned int m(size(i)); 00092 for (unsigned int j=0; j!=m; ++j) { 00093 moduleIndex_[i][moduleLabels_[i][j]]=j; 00094 } 00095 } 00096 00097 return true; 00098 } 00099 00100 void HLTConfigProvider::dump (const std::string& what) const { 00101 using namespace std; 00102 using namespace edm; 00103 00104 if (what=="processName") { 00105 cout << "HLTConfigProvider::dump: ProcessName = " << processName_ << endl; 00106 } else if (what=="ProcessPSet") { 00107 cout << "HLTConfigProvider::dump: ProcessPSet = " << endl << ProcessPSet_ << endl; 00108 } else if (what=="TableName") { 00109 cout << "HLTConfigProvider::dump: TableName = " << tableName_ << endl; 00110 } else if (what=="Triggers") { 00111 cout << "HLTConfigProvider::dump: Triggers: " << endl; 00112 const unsigned int n(size()); 00113 for (unsigned int i=0; i!=n; ++i) { 00114 cout << " " << i << " " << triggerNames_[i] << endl; 00115 } 00116 } else if (what=="Modules") { 00117 cout << "HLTConfigProvider::dump Triggers and Modules: " << endl; 00118 const unsigned int n(size()); 00119 for (unsigned int i=0; i!=n; ++i) { 00120 cout << i << " " << triggerNames_[i] << endl; 00121 const unsigned int m(size(i)); 00122 cout << " - Modules: "; 00123 unsigned int nHLTPrescalers(0); 00124 unsigned int nHLTLevel1GTSeed(0); 00125 for (unsigned int j=0; j!=m; ++j) { 00126 const string& label(moduleLabels_[i][j]); 00127 const string type(moduleType(label)); 00128 cout << " " << j << ":" << label << "/" << type ; 00129 if (type=="HLTPrescaler") nHLTPrescalers++; 00130 if (type=="HLTLevel1GTSeed") nHLTLevel1GTSeed++; 00131 } 00132 cout << endl; 00133 cout << " - Number of HLTPrescaler/HLTLevel1GTSeed modules: " 00134 << nHLTPrescalers << "/" << nHLTLevel1GTSeed << endl; 00135 } 00136 } else { 00137 cout << "HLTConfigProvider::dump: Unkown dump request: " << what << endl; 00138 } 00139 return; 00140 } 00141 00142 unsigned int HLTConfigProvider::size() const { 00143 return triggerNames_.size(); 00144 } 00145 unsigned int HLTConfigProvider::size(unsigned int trigger) const { 00146 return moduleLabels_.at(trigger).size(); 00147 } 00148 unsigned int HLTConfigProvider::size(const std::string& trigger) const { 00149 return size(triggerIndex(trigger)); 00150 } 00151 00152 const std::string& HLTConfigProvider::tableName() const { 00153 return tableName_; 00154 } 00155 const std::vector<std::string>& HLTConfigProvider::triggerNames() const { 00156 return triggerNames_; 00157 } 00158 const std::string& HLTConfigProvider::triggerName(unsigned int trigger) const { 00159 return triggerNames_.at(trigger); 00160 } 00161 unsigned int HLTConfigProvider::triggerIndex(const std::string& trigger) const { 00162 const std::map<std::string,unsigned int>::const_iterator index(triggerIndex_.find(trigger)); 00163 if (index==triggerIndex_.end()) { 00164 return size(); 00165 } else { 00166 return index->second; 00167 } 00168 } 00169 00170 const std::vector<std::string>& HLTConfigProvider::moduleLabels(unsigned int trigger) const { 00171 return moduleLabels_.at(trigger); 00172 } 00173 const std::vector<std::string>& HLTConfigProvider::moduleLabels(const std::string& trigger) const { 00174 return moduleLabels_.at(triggerIndex(trigger)); 00175 } 00176 00177 const std::string& HLTConfigProvider::moduleLabel(unsigned int trigger, unsigned int module) const { 00178 return moduleLabels_.at(trigger).at(module); 00179 } 00180 const std::string& HLTConfigProvider::moduleLabel(const std::string& trigger, unsigned int module) const { 00181 return moduleLabels_.at(triggerIndex(trigger)).at(module); 00182 } 00183 00184 unsigned int HLTConfigProvider::moduleIndex(unsigned int trigger, const std::string& module) const { 00185 const std::map<std::string,unsigned int>::const_iterator index(moduleIndex_.at(trigger).find(module)); 00186 if (index==moduleIndex_.at(trigger).end()) { 00187 return size(trigger); 00188 } else { 00189 return index->second; 00190 } 00191 } 00192 unsigned int HLTConfigProvider::moduleIndex(const std::string& trigger, const std::string& module) const { 00193 return moduleIndex(triggerIndex(trigger),module); 00194 } 00195 00196 const std::string HLTConfigProvider::moduleType(const std::string& module) const { 00197 if (ProcessPSet_.exists(module)) { 00198 return modulePSet(module).getParameter<std::string>("@module_type"); 00199 } else { 00200 return ""; 00201 } 00202 } 00203 00204 const edm::ParameterSet HLTConfigProvider::modulePSet(const std::string& module) const { 00205 if (ProcessPSet_.exists(module)) { 00206 return ProcessPSet_.getParameter<edm::ParameterSet>(module); 00207 } else { 00208 return edm::ParameterSet(); 00209 } 00210 }