CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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_(0),
46  db_(0),
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::InRun>("Run");
81  if (lumi_) produces<HLTPrescaleTable,edm::InLumi>("Lumi");
82  if (event_) produces<HLTPrescaleTable,edm::InEvent>("Event");
83 
84 }
85 
87 {
88 }
89 
90 //
91 // member functions
92 //
93 
96  // # (single) source:
97  // # -1:PrescaleServicePSet, 0:PrescaleService,
98  // # 1:Run, 2:Lumi, 3:Event, 4:CondDB
99  desc.add<int>("src",0);
100  // # (multiple) destinations
101  desc.add<bool>("run",true);
102  desc.add<bool>("lumi",true);
103  desc.add<bool>("event",true);
104  desc.add<bool>("condDB",true);
105  // # src=-1
106  desc.add<std::string>("psetName","");
107  // # src= 1,2,3
108  desc.add<edm::InputTag>("hltInputTag",edm::InputTag("","",""));
109  // # src= 4
110  desc.add<std::string>("hltDBTag","");
111  //
112  descriptions.add("hltPrescaleRecorder", desc);
113 }
114 
115 void HLTPrescaleRecorder::beginRun(edm::Run const& iRun, const edm::EventSetup& iSetup) {
116 
118 
119  if (src_==-1) {
123 
124  string defaultLabel(iPS.getParameter<std::string>("lvl1DefaultLabel"));
125  vector<string> labels(iPS.getParameter<std::vector<std::string> >("lvl1Labels"));
126  vector<ParameterSet> vpTable(iPS.getParameter<std::vector<ParameterSet> >("prescaleTable"));
127 
128  unsigned int set(0);
129  const unsigned int n(labels.size());
130  for (unsigned int i=0; i!=n; ++i) {
131  if (labels[i]==defaultLabel) set=i;
132  }
133 
134  map<string,vector<unsigned int> > table;
135  const unsigned int m (vpTable.size());
136  for (unsigned int i=0; i!=m; ++i) {
137  table[vpTable[i].getParameter<std::string>("pathName")] =
138  vpTable[i].getParameter<std::vector<unsigned int> >("prescales");
139  }
140  hlt_=HLTPrescaleTable(set,labels,table);
141 
142  } else if (src_==0) {
145  if (ps_!=0) {
147  } else {
149  LogError("HLTPrescaleRecorder")<<"PrescaleService not found!";
150  }
151  } else if (src_==1) {
154  hlt_=*hltHandle_;
155  } else {
156  LogError("HLTPrescaleRecorder")<<"HLTPrescaleTable not found in Run!";
157  }
158  } else if (src_==4) {
160  const HLTPrescaleTableRcd& hltRecord(iSetup.get<HLTPrescaleTableRcd>());
161  hltRecord.get(hltDBTag_,hltESHandle_);
162  hlt_=hltESHandle_->hltPrescaleTable();
163  }
164 
165  return;
166 }
167 
169 
170  if (src_==0) {
173  if (ps_!=0) {
175  } else {
177  LogError("HLTPrescaleRecorder")<<"PrescaleService not found!";
178  }
179  } else if (src_==2) {
181  if (iLumi.getByToken(hltInputToken_,hltHandle_)) {
182  hlt_=*hltHandle_;
183  } else {
185  LogError("HLTPrescaleRecorder")<<"HLTPrescaleTable not found in LumiBlock!";
186  }
187  }
188 
189  return;
190 }
191 
193 
194  if (src_==3) {
196  if (iEvent.getByToken(hltInputToken_,hltHandle_)) {
197  hlt_=*hltHandle_;
198  } else {
200  LogError("HLTPrescaleRecorder")<<"HLTPrescaleTable not found in Event!";
201  }
202  }
203 
204  if (event_) {
206  auto_ptr<HLTPrescaleTable> product (new HLTPrescaleTable(hlt_));
207  iEvent.put(product,"Event");
208  }
209 
210  return;
211 }
213 }
214 
216 
217  if (lumi_) {
219  auto_ptr<HLTPrescaleTable> product (new HLTPrescaleTable(hlt_));
220  iLumi.put(product,"Lumi");
221  }
222  return;
223 }
224 
225 void HLTPrescaleRecorder::endRun(edm::Run const& iRun, const edm::EventSetup& iSetup) {
226 
228  ostringstream oss;
229  const unsigned int n(hlt_.size());
230  oss << "PrescaleTable: # of labels = " << n << endl;
231  const vector<string>& labels(hlt_.labels());
232  for (unsigned int i=0; i!=n; ++i) {
233  oss << " " << i << "/'" << labels.at(i) << "'";
234  }
235  oss << endl;
236  const map<string,vector<unsigned int> >& table(hlt_.table());
237  oss << "PrescaleTable: # of paths = " << table.size() << endl;
238  const map<string,vector<unsigned int> >::const_iterator tb(table.begin());
239  const map<string,vector<unsigned int> >::const_iterator te(table.end());
240  for (map<string,vector<unsigned int> >::const_iterator ti=tb; ti!=te; ++ti) {
241  for (unsigned int i=0; i!=n; ++i) {
242  oss << " " << ti->second.at(i);
243  }
244  oss << " " << ti->first << endl;
245  }
246  LogVerbatim("HLTPrescaleRecorder") << oss.str();
247 
248  if (condDB_) {
250  if (db_!=0) {
252  const string rcdName("HLTPrescaleTableRcd");
253  if ( db_->isNewTagRequest(rcdName) ) {
255  db_->beginOfTime(),db_->endOfTime(),rcdName);
256  } else {
257  ::timeval tv;
258  gettimeofday(&tv,0);
259  edm::Timestamp tstamp((unsigned long long)tv.tv_sec);
261 // db_->currentTime()
262  tstamp.value()
263  ,rcdName);
264  }
265  } else {
266  LogError("HLTPrescaleRecorder") << "PoolDBOutputService not available!";
267  }
268  }
269 
270  return;
271 }
272 
274  if (run_) {
276  auto_ptr<HLTPrescaleTable> product (new HLTPrescaleTable(hlt_));
277  iRun.put(product,"Run");
278  }
279 }
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
virtual void endRunProduce(edm::Run &iRun, const edm::EventSetup &iSetup) overridefinal
edm::service::PrescaleService * ps_
Prescale service.
unsigned int getLvl1IndexDefault() const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
bool getByToken(EDGetToken token, Handle< PROD > &result) const
edm::EDGetTokenT< trigger::HLTPrescaleTable > hltInputToken_
InputToken of HLTPrescaleTable product (src=1,2,3)
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
virtual void beginRun(edm::Run const &iRun, const edm::EventSetup &iSetup) overridefinal
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:164
virtual void beginLuminosityBlock(edm::LuminosityBlock const &iLumi, const edm::EventSetup &iSetup) overridefinal
ParameterSet const & getProcessParameterSetContainingModule(ModuleDescription const &moduleDescription)
void appendSinceTime(T *payloadObj, cond::Time_t sinceTime, const std::string &recordName, bool withlogging=false)
int iEvent
Definition: GenABIO.cc:230
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) overridefinal
virtual void endRun(edm::Run const &iRun, const edm::EventSetup &iSetup) overridefinal
bool isNewTagRequest(const std::string &recordName)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
virtual void endLuminosityBlockProduce(edm::LuminosityBlock &iLumi, const edm::EventSetup &iSetup) overridefinal
const std::vector< std::string > & labels() const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Run.h:261
void get(HolderT &iHolder) const
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)
#define table(NAME)
Definition: DbCore.h:49
const VString_t & getLvl1Labels() const
const T & get() const
Definition: EventSetup.h:56
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
void event_()
HLTPrescaleRecorder(const edm::ParameterSet &)
void put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Run.h:112
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
edm::InputTag hltInputTag_
InputTag of HLTPrescaleTable product (src=1,2,3)
Definition: Run.h:43
void put(std::auto_ptr< PROD > product)
Put a new product.
virtual void endLuminosityBlock(edm::LuminosityBlock const &iLumi, const edm::EventSetup &iSetup) overridefinal