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