CMS 3D CMS Logo

HLTPrescaleRecorder.cc
Go to the documentation of this file.
1 
11 
14 
16 
18 
21 
22 #include <sys/time.h>
24 
25 #include<string>
26 #include<ostream>
27 
28 using namespace std;
29 using namespace edm;
30 using namespace trigger;
31 
32 //
33 // constructors and destructor
34 //
36  src_(ps.getParameter<int>("src")),
37  run_(ps.getParameter<bool>("run")),
38  lumi_(ps.getParameter<bool>("lumi")),
39  event_(ps.getParameter<bool>("event")),
40  condDB_(ps.getParameter<bool>("condDB")),
41  psetName_(ps.getParameter<string>("psetName")),
42  hltInputTag_(ps.getParameter<InputTag>("hltInputTag")),
43  hltInputToken_(),
44  hltDBTag_(ps.getParameter<string>("hltDBTag")),
45  ps_(nullptr),
46  db_(nullptr),
47  hltHandle_(),
48  hltESHandle_(),
49  hlt_()
50 {
51  if (src_==1) {
52  // Run
53  hltInputToken_=consumes<trigger::HLTPrescaleTable,edm::InRun>(hltInputTag_);
54  } else if (src_==2) {
55  // Lumi
56  hltInputToken_=consumes<trigger::HLTPrescaleTable,edm::InLumi>(hltInputTag_);
57  } else if (src_==3) {
58  // Event
59  hltInputToken_=consumes<trigger::HLTPrescaleTable>(hltInputTag_);
60  }
61 
62  LogInfo("HLTPrescaleRecorder")
63  << "src:run-lumi-event-condDB+psetName+tags: "
64  << src_ << ":" << run_ << "-" << lumi_ << "-" << event_ << "-"
65  << condDB_ << "+" << psetName_ << "+"
66  << hltInputTag_.encode() << "+" << hltDBTag_;
67 
70  } else if (src_==0) {
71  LogError("HLTPrescaleRecorder")<<"PrescaleService requested as source but unavailable!";
72  }
73 
76  } else if (condDB_) {
77  LogError("HLTPrescaleRecorder")<<"PoolDBOutputService requested as destination but unavailable!";
78  }
79 
80  if (run_) produces<HLTPrescaleTable,edm::Transition::EndRun>("Run");
81  if (lumi_) produces<HLTPrescaleTable,edm::Transition::EndLuminosityBlock>("Lumi");
82  if (event_) produces<HLTPrescaleTable,edm::Transition::Event>("Event");
83 
84 }
85 
87 
88 //
89 // member functions
90 //
91 
94  // # (single) source:
95  // # -1:PrescaleServicePSet, 0:PrescaleService,
96  // # 1:Run, 2:Lumi, 3:Event, 4:CondDB
97  desc.add<int>("src",0);
98  // # (multiple) destinations
99  desc.add<bool>("run",true);
100  desc.add<bool>("lumi",true);
101  desc.add<bool>("event",true);
102  desc.add<bool>("condDB",true);
103  // # src=-1
104  desc.add<std::string>("psetName","");
105  // # src= 1,2,3
106  desc.add<edm::InputTag>("hltInputTag",edm::InputTag("","",""));
107  // # src= 4
108  desc.add<std::string>("hltDBTag","");
109  //
110  descriptions.add("hltPrescaleRecorder", desc);
111 }
112 
113 void HLTPrescaleRecorder::beginRun(edm::Run const& iRun, const edm::EventSetup& iSetup) {
114 
116 
117  if (src_==-1) {
121 
122  string defaultLabel(iPS.getParameter<std::string>("lvl1DefaultLabel"));
123  vector<string> labels(iPS.getParameter<std::vector<std::string> >("lvl1Labels"));
124  vector<ParameterSet> vpTable(iPS.getParameter<std::vector<ParameterSet> >("prescaleTable"));
125 
126  unsigned int set(0);
127  const unsigned int n(labels.size());
128  for (unsigned int i=0; i!=n; ++i) {
129  if (labels[i]==defaultLabel) set=i;
130  }
131 
132  map<string,vector<unsigned int> > table;
133  const unsigned int m (vpTable.size());
134  for (unsigned int i=0; i!=m; ++i) {
135  table[vpTable[i].getParameter<std::string>("pathName")] =
136  vpTable[i].getParameter<std::vector<unsigned int> >("prescales");
137  }
138  hlt_=HLTPrescaleTable(set,labels,table);
139 
140  } else if (src_==0) {
143  if (ps_!=nullptr) {
145  } else {
147  LogError("HLTPrescaleRecorder")<<"PrescaleService not found!";
148  }
149  } else if (src_==1) {
152  hlt_=*hltHandle_;
153  } else {
154  LogError("HLTPrescaleRecorder")<<"HLTPrescaleTable not found in Run!";
155  }
156  } else if (src_==4) {
158  const HLTPrescaleTableRcd& hltRecord(iSetup.get<HLTPrescaleTableRcd>());
159  hltRecord.get(hltDBTag_,hltESHandle_);
161  }
162 
163  return;
164 }
165 
167 
168  if (src_==0) {
171  if (ps_!=nullptr) {
173  } else {
175  LogError("HLTPrescaleRecorder")<<"PrescaleService not found!";
176  }
177  } else if (src_==2) {
179  if (iLumi.getByToken(hltInputToken_,hltHandle_)) {
180  hlt_=*hltHandle_;
181  } else {
183  LogError("HLTPrescaleRecorder")<<"HLTPrescaleTable not found in LumiBlock!";
184  }
185  }
186 
187  return;
188 }
189 
191 
192  if (src_==3) {
194  if (iEvent.getByToken(hltInputToken_,hltHandle_)) {
195  hlt_=*hltHandle_;
196  } else {
198  LogError("HLTPrescaleRecorder")<<"HLTPrescaleTable not found in Event!";
199  }
200  }
201 
202  if (event_) {
204  unique_ptr<HLTPrescaleTable> product (new HLTPrescaleTable(hlt_));
205  iEvent.put(std::move(product),"Event");
206  }
207 
208  return;
209 }
211 }
212 
214 
215  if (lumi_) {
217  unique_ptr<HLTPrescaleTable> product (new HLTPrescaleTable(hlt_));
218  iLumi.put(std::move(product),"Lumi");
219  }
220  return;
221 }
222 
223 void HLTPrescaleRecorder::endRun(edm::Run const& iRun, const edm::EventSetup& iSetup) {
224 
226  ostringstream oss;
227  const unsigned int n(hlt_.size());
228  oss << "PrescaleTable: # of labels = " << n << endl;
229  const vector<string>& labels(hlt_.labels());
230  for (unsigned int i=0; i!=n; ++i) {
231  oss << " " << i << "/'" << labels.at(i) << "'";
232  }
233  oss << endl;
234  const map<string,vector<unsigned int> >& table(hlt_.table());
235  oss << "PrescaleTable: # of paths = " << table.size() << endl;
236  const map<string,vector<unsigned int> >::const_iterator tb(table.begin());
237  const map<string,vector<unsigned int> >::const_iterator te(table.end());
238  for (map<string,vector<unsigned int> >::const_iterator ti=tb; ti!=te; ++ti) {
239  for (unsigned int i=0; i!=n; ++i) {
240  oss << " " << ti->second.at(i);
241  }
242  oss << " " << ti->first << endl;
243  }
244  LogVerbatim("HLTPrescaleRecorder") << oss.str();
245 
246  if (condDB_) {
248  if (db_!=nullptr) {
249  auto product (new HLTPrescaleTableCond(hlt_));
250  const string rcdName("HLTPrescaleTableRcd");
251  if ( db_->isNewTagRequest(rcdName) ) {
253  db_->beginOfTime(),db_->endOfTime(),rcdName);
254  } else {
255  ::timeval tv;
256  gettimeofday(&tv,nullptr);
257  edm::Timestamp tstamp((unsigned long long)tv.tv_sec);
259 // db_->currentTime()
260  tstamp.value()
261  ,rcdName);
262  }
263  } else {
264  LogError("HLTPrescaleRecorder") << "PoolDBOutputService not available!";
265  }
266  }
267 
268  return;
269 }
270 
272  if (run_) {
274  unique_ptr<HLTPrescaleTable> product (new HLTPrescaleTable(hlt_));
275  iRun.put(std::move(product),"Run");
276  }
277 }
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
void endRunProduce(edm::Run &iRun, const edm::EventSetup &iSetup) final
void endRun(edm::Run const &iRun, const edm::EventSetup &iSetup) final
edm::service::PrescaleService * ps_
Prescale service.
unsigned int getLvl1IndexDefault() const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
bool getByToken(EDGetToken token, Handle< PROD > &result) const
edm::EDGetTokenT< trigger::HLTPrescaleTable > hltInputToken_
InputToken of HLTPrescaleTable product (src=1,2,3)
#define nullptr
The single EDProduct containing the HLT Prescale Table.
std::string hltDBTag_
Tag of DB entry (HLT Key Name) (src=4)
const PrescaleTable_t & getPrescaleTable() const
ModuleDescription const & moduleDescription() const
const std::map< std::string, std::vector< unsigned int > > & table() const
edm::ESHandle< trigger::HLTPrescaleTableCond > hltESHandle_
std::string encode() const
Definition: InputTag.cc:159
void beginLuminosityBlock(edm::LuminosityBlock const &iLumi, const edm::EventSetup &iSetup) final
PRODUCT const & get(ESGetToken< PRODUCT, T > const &iToken) const
ParameterSet const & getProcessParameterSetContainingModule(ModuleDescription const &moduleDescription)
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) final
void appendSinceTime(T *payloadObj, cond::Time_t sinceTime, const std::string &recordName, bool withlogging=false)
int iEvent
Definition: GenABIO.cc:224
bool isNewTagRequest(const std::string &recordName)
void endLuminosityBlockProduce(edm::LuminosityBlock &iLumi, const edm::EventSetup &iSetup) final
const std::vector< std::string > & labels() const
~HLTPrescaleRecorder() override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Run.h:315
void beginRun(edm::Run const &iRun, const edm::EventSetup &iSetup) final
void put(std::unique_ptr< PROD > product)
Put a new product.
ParameterDescriptionBase * add(U const &iLabel, T const &value)
cond::service::PoolDBOutputService * db_
Pool DB service.
trigger::HLTPrescaleTable hlt_
payload HLT object
void createNewIOV(T *firstPayloadObj, cond::Time_t firstSinceTime, cond::Time_t firstTillTime, const std::string &recordName, bool withlogging=false)
void endLuminosityBlock(edm::LuminosityBlock const &iLumi, const edm::EventSetup &iSetup) final
const VString_t & getLvl1Labels() const
void put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Run.h:108
void add(std::string const &label, ParameterSetDescription const &psetDescription)
edm::Handle< trigger::HLTPrescaleTable > hltHandle_
Handle and ESHandle for existing HLT object.
bool run_
(Multiple) Destinations
HLT enums.
T get() const
Definition: EventSetup.h:71
void event_()
HLTPrescaleRecorder(const edm::ParameterSet &)
const trigger::HLTPrescaleTable & hltPrescaleTable() const
trivial const accessor
unsigned int size() const
consistency condition: all vectors must have the same length
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
TimeValue_t value() const
Definition: Timestamp.h:56
def move(src, dest)
Definition: eostools.py:511
edm::InputTag hltInputTag_
InputTag of HLTPrescaleTable product (src=1,2,3)
Definition: Run.h:45