test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Member Functions | Private Member Functions
lumi::CMSRunSummary2DB Class Reference
Inheritance diagram for lumi::CMSRunSummary2DB:
lumi::DataPipe

Classes

struct  cmsrunsum
 

Public Member Functions

 CMSRunSummary2DB (const std::string &dest)
 
virtual const std::string dataType () const override
 
virtual unsigned long long retrieveData (unsigned int runnumber) override
 
virtual const std::string sourceType () const override
 
unsigned int str2int (const std::string &s) const
 
virtual ~CMSRunSummary2DB ()
 
- Public Member Functions inherited from lumi::DataPipe
 DataPipe (const std::string &)
 
std::string getAuthPath () const
 
std::string getMode () const
 
float getNorm () const
 
std::string getSource () const
 
void setAuthPath (const std::string &authpath)
 
void setMode (const std::string &mode)
 
void setNoCheckingStableBeam ()
 
void setNorm (float norm)
 
void setNoValidate ()
 
void setSource (const std::string &source)
 
virtual ~DataPipe ()
 

Private Member Functions

bool isCollisionRun (const lumi::CMSRunSummary2DB::cmsrunsum &rundata)
 
void parseFillCSV (const std::string &csvsource, cmsrunsum &result)
 

Additional Inherited Members

- Protected Attributes inherited from lumi::DataPipe
std::string m_authpath
 
std::string m_dest
 
std::string m_mode
 
bool m_nocheckingstablebeam
 
float m_norm
 
bool m_novalidate
 
std::string m_source
 

Detailed Description

Definition at line 40 of file CMSRunSummary2DB.cc.

Constructor & Destructor Documentation

lumi::CMSRunSummary2DB::CMSRunSummary2DB ( const std::string &  dest)

Definition at line 93 of file CMSRunSummary2DB.cc.

93 :DataPipe(dest){}
DataPipe(const std::string &)
Definition: DataPipe.cc:2
lumi::CMSRunSummary2DB::~CMSRunSummary2DB ( )
virtual

Definition at line 388 of file CMSRunSummary2DB.cc.

388 {}

Member Function Documentation

const std::string lumi::CMSRunSummary2DB::dataType ( ) const
overridevirtual

Implements lumi::DataPipe.

Definition at line 373 of file CMSRunSummary2DB.cc.

373  {
374  return "CMSRUNSUMMARY";
375  }
bool lumi::CMSRunSummary2DB::isCollisionRun ( const lumi::CMSRunSummary2DB::cmsrunsum rundata)
private

Definition at line 94 of file CMSRunSummary2DB.cc.

References lumi::CMSRunSummary2DB::cmsrunsum::hltkey, lumi::CMSRunSummary2DB::cmsrunsum::l1key, and AlCaHLTBitMon_QueryRunRegistry::string.

94  {
95  bool isCollision=false;
96  bool isPhysics=false;
97  std::string hk=rundata.hltkey;
98  std::string lk=rundata.l1key;
99  boost::match_results<std::string::const_iterator> what;
100  const boost::regex lexpr("^TSC_.+_collisions_.+");
101  boost::regex_match(lk,what,lexpr,boost::match_default);
102  if(what[0].matched) isCollision=true;
103  const boost::regex hexpr("^/cdaq/physics/.+");
104  boost::regex_match(hk,what,hexpr,boost::match_default);
105  if(what[0].matched) isPhysics=true;
106  return (isCollision&&isPhysics);
107  }
void lumi::CMSRunSummary2DB::parseFillCSV ( const std::string &  csvsource,
cmsrunsum result 
)
private

Definition at line 68 of file CMSRunSummary2DB.cc.

References gather_cfg::cout, lumi::CMSRunSummary2DB::cmsrunsum::fillnumber, lumi::CMSRunSummary2DB::cmsrunsum::fillscheme, geometryCSVtoXML::line, lumi::CMSRunSummary2DB::cmsrunsum::ncollidingbunches, record, str2int(), AlCaHLTBitMon_QueryRunRegistry::string, and results_mgr::tok.

Referenced by retrieveData().

68  {
69  result.fillscheme=std::string("");
70  result.ncollidingbunches=0;
71  std::ifstream csvfile;
72  csvfile.open(csvsource.c_str());
73  if(!csvfile){
74  std::cout<<"[warning] unable to open file: "<<csvsource<<std::endl;
75  return;
76  }
77  typedef boost::tokenizer< boost::escaped_list_separator<char> > Tokenizer;
78  std::vector<std::string> record;
80  while(std::getline(csvfile,line)){
81  Tokenizer tok(line);
82  record.assign(tok.begin(),tok.end());
83  if(record.size()<3) continue;
84  std::string fillnum=record[0];
85  if(fillnum==result.fillnumber){
86  result.fillscheme=record[1];
87  std::string ncollidingbunchesStr=record[2];
88  result.ncollidingbunches=str2int(ncollidingbunchesStr);
89  break;
90  }
91  }
92  }
unsigned int str2int(const std::string &s) const
JetCorrectorParameters::Record record
Definition: classes.h:7
tuple result
Definition: query.py:137
tuple cout
Definition: gather_cfg.py:121
unsigned long long lumi::CMSRunSummary2DB::retrieveData ( unsigned int  runnumber)
overridevirtual

select distinct name from runsession_parameter l1key: select string_value from cms_runinfo.runsession_parameter where runnumber=:runnumber and name='CMS.TRG:TSC_KEY'; amodetag: select distinct(string_value),session_id from cms_runinfo.runsession_parameter where runnumber=:runnumber and name='CMS.SCAL:AMODEtag' egev: select distinct(string_value) from cms_runinfo.runsession_parameter where runnumber=:runnumber and name='CMS.SCAL:EGEV' hltkey: select string_value from cms_runinfo.runsession_parameter where runnumber=129265 and name='CMS.LVL0:HLT_KEY_DESCRIPTION'; fillnumber: select string_value from cms_runinfo.runsession_parameter where runnumber=129265 and name='CMS.SCAL:FILLN' order by time;//take the first one sequence: select string_value from cms_runinfo.runsession_parameter where runnumber=129265 and name='CMS.LVL0:SEQ_NAME' start/stop time: select time from cms_runinfo.runsession_parameter where runnumber=129265 and name='CMS.LVL0:START_TIME_T'; select time from cms_runinfo.runsession_parameter where runnumber=129265 and name='CMS.LVL0:STOP_TIME_T';

Implements lumi::DataPipe.

Definition at line 109 of file CMSRunSummary2DB.cc.

References lumi::CMSRunSummary2DB::cmsrunsum::amodetag, lumi::LumiNames::cmsrunsummaryTableName(), gather_cfg::cout, python.DBCopy::destsession, lumi::CMSRunSummary2DB::cmsrunsum::egev, edm::hlt::Exception, lumi::CMSRunSummary2DB::cmsrunsum::fillnumber, lumi::CMSRunSummary2DB::cmsrunsum::fillscheme, lumi::CMSRunSummary2DB::cmsrunsum::hltkey, lumi::CMSRunSummary2DB::cmsrunsum::l1key, lumi::DataPipe::m_authpath, lumi::DataPipe::m_dest, lumi::DataPipe::m_source, lumi::CMSRunSummary2DB::cmsrunsum::ncollidingbunches, parseFillCSV(), query::result, lumi::CMSRunSummary2DB::cmsrunsum::sequence, lumi::DBConfig::setAuthentication(), lumi::CMSRunSummary2DB::cmsrunsum::startT, lumi::CMSRunSummary2DB::cmsrunsum::stopT, str2int(), AlCaHLTBitMon_QueryRunRegistry::string, and python.CommonUtils::svc.

109  {
121  cmsrunsum result;
122  std::string runinfoschema("CMS_RUNINFO");
123  std::string runsessionParamTable("RUNSESSION_PARAMETER");
124  coral::ConnectionService* svc=new coral::ConnectionService;
125  lumi::DBConfig dbconf(*svc);
126  if(!m_authpath.empty()){
127  dbconf.setAuthentication(m_authpath);
128  }
129 
130  //std::cout<<"m_source "<<m_source<<std::endl;
131  std::string::size_type cutpos=m_source.find(';');
132  std::string dbsource=m_source;
133  std::string csvsource("");
134  if(cutpos!=std::string::npos){
135  dbsource=m_source.substr(0,cutpos);
136  csvsource=m_source.substr(cutpos+1);
137  }
138  //std::cout<<"dbsource: "<<dbsource<<" , csvsource: "<<csvsource<<std::endl;
139  coral::ISessionProxy* runinfosession=svc->connect(dbsource,coral::ReadOnly);
140  try{
141  coral::ITypeConverter& tpc=runinfosession->typeConverter();
142  tpc.setCppTypeForSqlType("unsigned int","NUMBER(38)");
143  runinfosession->transaction().start(true);
144  coral::ISchema& runinfoschemaHandle=runinfosession->schema(runinfoschema);
145  if(!runinfoschemaHandle.existsTable(runsessionParamTable)){
146  throw lumi::Exception(std::string("non-existing table "+runsessionParamTable),"CMSRunSummary2DB","retrieveData");
147  }
148  coral::IQuery* amodetagQuery=runinfoschemaHandle.tableHandle(runsessionParamTable).newQuery();
149  coral::AttributeList amodetagOutput;
150  amodetagOutput.extend("amodetag",typeid(std::string));
151  coral::AttributeList amodetagCondition;
152  amodetagCondition=coral::AttributeList();
153  amodetagCondition.extend("name",typeid(std::string));
154  amodetagCondition.extend("runnumber",typeid(unsigned int));
155  amodetagCondition["name"].data<std::string>()=std::string("CMS.SCAL:AMODEtag");
156  amodetagCondition["runnumber"].data<unsigned int>()=runnumber;
157  amodetagQuery->addToOutputList("distinct(STRING_VALUE)");
158  amodetagQuery->setCondition("NAME=:name AND RUNNUMBER=:runnumber",amodetagCondition);
159  //amodetagQuery->limitReturnedRows(1);
160  amodetagQuery->defineOutput(amodetagOutput);
161  coral::ICursor& amodetagCursor=amodetagQuery->execute();
162  std::vector<std::string> amodes;
163  while (amodetagCursor.next()){
164  const coral::AttributeList& row=amodetagCursor.currentRow();
165  amodes.push_back(row["amodetag"].data<std::string>());
166  //result.amodetag=row["amodetag"].data<std::string>();
167  }
168  //
169  //priority pick the one contains PHYS if not found pick the first
170  //
171  std::string amd;
172  for(std::vector<std::string>::iterator it=amodes.begin();it!=amodes.end();++it){
173  if(it->find("PHYS")==std::string::npos) continue;
174  amd=*it;
175  }
176  if(amd.size()==0&&amodes.size()!=0){
177  amd=*(amodes.begin());
178  }
179  if(amd.size()==0){
180  amd=std::string("PROTPHYS");//last resort
181  }
182  //std::cout<<"amd "<<amd<<std::endl;
183  result.amodetag=amd;
184  delete amodetagQuery;
185 
186  coral::IQuery* egevQuery=runinfoschemaHandle.tableHandle(runsessionParamTable).newQuery();
187  coral::AttributeList egevOutput;
188  egevOutput.extend("egev",typeid(std::string));
189  coral::AttributeList egevCondition;
190  egevCondition=coral::AttributeList();
191  egevCondition.extend("name",typeid(std::string));
192  egevCondition.extend("runnumber",typeid(unsigned int));
193  egevCondition["name"].data<std::string>()=std::string("CMS.SCAL:EGEV");
194  egevCondition["runnumber"].data<unsigned int>()=runnumber;
195  egevQuery->addToOutputList("distinct(STRING_VALUE)");
196  egevQuery->setCondition("NAME=:name AND RUNNUMBER=:runnumber",egevCondition);
197  egevQuery->defineOutput(egevOutput);
198  coral::ICursor& egevCursor=egevQuery->execute();
199  result.egev=0;
200  while (egevCursor.next()){
201  const coral::AttributeList& row=egevCursor.currentRow();
202  std::string egevstr=row["egev"].data<std::string>();
203  int tmpgev=str2int(egevstr);
204  if(tmpgev>result.egev){
205  result.egev=tmpgev;
206  }
207  }
208  if(result.egev==0){
209  result.egev=3500;//last resort
210  }
211  delete egevQuery;
212 
213  coral::IQuery* seqQuery=runinfoschemaHandle.tableHandle(runsessionParamTable).newQuery();
214  coral::AttributeList seqBindVariableList;
215  seqBindVariableList.extend("runnumber",typeid(unsigned int));
216  seqBindVariableList.extend("name",typeid(std::string));
217 
218  seqBindVariableList["runnumber"].data<unsigned int>()=runnumber;
219  seqBindVariableList["name"].data<std::string>()=std::string("CMS.LVL0:SEQ_NAME");
220  seqQuery->setCondition("RUNNUMBER =:runnumber AND NAME =:name",seqBindVariableList);
221  seqQuery->addToOutputList("STRING_VALUE");
222  coral::ICursor& seqCursor=seqQuery->execute();
223 
224  while( seqCursor.next() ){
225  const coral::AttributeList& row=seqCursor.currentRow();
226  result.sequence=row["STRING_VALUE"].data<std::string>();
227  }
228  delete seqQuery;
229 
230  coral::IQuery* hltkeyQuery=runinfoschemaHandle.tableHandle(runsessionParamTable).newQuery();
231  coral::AttributeList hltkeyBindVariableList;
232  hltkeyBindVariableList.extend("runnumber",typeid(unsigned int));
233  hltkeyBindVariableList.extend("name",typeid(std::string));
234 
235  hltkeyBindVariableList["runnumber"].data<unsigned int>()=runnumber;
236  hltkeyBindVariableList["name"].data<std::string>()=std::string("CMS.LVL0:HLT_KEY_DESCRIPTION");
237  hltkeyQuery->setCondition("RUNNUMBER =:runnumber AND NAME =:name",hltkeyBindVariableList);
238  hltkeyQuery->addToOutputList("STRING_VALUE");
239  coral::ICursor& hltkeyCursor=hltkeyQuery->execute();
240 
241  while( hltkeyCursor.next() ){
242  const coral::AttributeList& row=hltkeyCursor.currentRow();
243  result.hltkey=row["STRING_VALUE"].data<std::string>();
244  }
245  delete hltkeyQuery;
246 
247  coral::IQuery* fillQuery=runinfoschemaHandle.tableHandle(runsessionParamTable).newQuery();
248  coral::AttributeList fillBindVariableList;
249  fillBindVariableList.extend("runnumber",typeid(unsigned int));
250  fillBindVariableList.extend("name",typeid(std::string));
251 
252  fillBindVariableList["runnumber"].data<unsigned int>()=runnumber;
253  fillBindVariableList["name"].data<std::string>()=std::string("CMS.SCAL:FILLN");
254  fillQuery->setCondition("RUNNUMBER =:runnumber AND NAME =:name",fillBindVariableList);
255  fillQuery->addToOutputList("STRING_VALUE");
256  fillQuery->addToOrderList("TIME");
257  //fillQuery->limitReturnedRows(1);
258  coral::ICursor& fillCursor=fillQuery->execute();
259  unsigned int cc=0;
260  while( fillCursor.next() ){
261  const coral::AttributeList& row=fillCursor.currentRow();
262  if (cc==0){
263  result.fillnumber=row["STRING_VALUE"].data<std::string>();
264  }
265  ++cc;
266  }
267  delete fillQuery;
268  if (result.fillnumber.empty()){
269  throw nonCollisionException("retrieveData","CMSRunSummary2DB");
270  }
271  coral::IQuery* startTQuery=runinfoschemaHandle.tableHandle(runsessionParamTable).newQuery();
272  coral::AttributeList startTVariableList;
273  startTVariableList.extend("runnumber",typeid(unsigned int));
274  startTVariableList.extend("name",typeid(std::string));
275 
276  startTVariableList["runnumber"].data<unsigned int>()=runnumber;
277  startTVariableList["name"].data<std::string>()=std::string("CMS.LVL0:START_TIME_T");
278  startTQuery->setCondition("RUNNUMBER =:runnumber AND NAME =:name",startTVariableList);
279  startTQuery->addToOutputList("TIME");
280  coral::ICursor& startTCursor=startTQuery->execute();
281 
282  while( startTCursor.next() ){
283  const coral::AttributeList& row=startTCursor.currentRow();
284  result.startT=row["TIME"].data<coral::TimeStamp>();
285  }
286  delete startTQuery;
287  coral::IQuery* stopTQuery=runinfoschemaHandle.tableHandle(runsessionParamTable).newQuery();
288  coral::AttributeList stopTVariableList;
289  stopTVariableList.extend("runnumber",typeid(unsigned int));
290  stopTVariableList.extend("name",typeid(std::string));
291 
292  stopTVariableList["runnumber"].data<unsigned int>()=runnumber;
293  stopTVariableList["name"].data<std::string>()=std::string("CMS.LVL0:STOP_TIME_T");
294  stopTQuery->setCondition("RUNNUMBER =:runnumber AND NAME =:name",stopTVariableList);
295  stopTQuery->addToOutputList("TIME");
296  coral::ICursor& stopTCursor=stopTQuery->execute();
297 
298  while( stopTCursor.next() ){
299  const coral::AttributeList& row=stopTCursor.currentRow();
300  result.stopT=row["TIME"].data<coral::TimeStamp>();
301  }
302  delete stopTQuery;
303  coral::IQuery* l1keyQuery=runinfoschemaHandle.tableHandle(runsessionParamTable).newQuery();
304  coral::AttributeList l1keyOutput;
305  l1keyOutput.extend("l1key",typeid(std::string));
306  coral::AttributeList l1keyCondition;
307  l1keyCondition=coral::AttributeList();
308  l1keyCondition.extend("name",typeid(std::string));
309  l1keyCondition.extend("runnumber",typeid(unsigned int));
310  l1keyCondition["name"].data<std::string>()=std::string("CMS.TRG:TSC_KEY");
311  l1keyCondition["runnumber"].data<unsigned int>()=runnumber;
312  l1keyQuery->addToOutputList("STRING_VALUE");
313  l1keyQuery->setCondition("NAME=:name AND RUNNUMBER=:runnumber",l1keyCondition);
314  //l1keyQuery->limitReturnedRows(1);
315  l1keyQuery->defineOutput(l1keyOutput);
316  coral::ICursor& l1keyCursor=l1keyQuery->execute();
317  while (l1keyCursor.next()){
318  const coral::AttributeList& row=l1keyCursor.currentRow();
319  result.l1key=row["l1key"].data<std::string>();
320  }
321  delete l1keyQuery;
322  }catch( const coral::Exception& er){
323  runinfosession->transaction().rollback();
324  delete runinfosession;
325  delete svc;
326  throw er;
327  }
328  runinfosession->transaction().commit();
329  delete runinfosession;
330 
331  if(csvsource.size()!=0){
332  parseFillCSV(csvsource,result);
333  }else{
334  result.fillscheme=std::string("");
335  result.ncollidingbunches=0;
336  }
337  std::cout<<"result for run "<<runnumber<<" : sequence : "<<result.sequence<<" : hltkey : "<<result.hltkey<<" : fillnumber : "<<result.fillnumber<<" : l1key : "<<result.l1key<<" : amodetag :"<<result.amodetag<<" : egev : "<<result.egev<<" : fillscheme "<<result.fillscheme<<" : ncollidingbunches : "<<result.ncollidingbunches<<std::endl;
338 
339  //std::cout<<"connecting to dest "<<m_dest<<std::endl;
340  coral::ISessionProxy* destsession=svc->connect(m_dest,coral::Update);
341 
342  coral::ITypeConverter& desttpc=destsession->typeConverter();
343  desttpc.setCppTypeForSqlType("unsigned int","NUMBER(10)");
344  try{
345  destsession->transaction().start(false);
346  coral::ISchema& destschema=destsession->nominalSchema();
347  coral::ITable& destruntable=destschema.tableHandle(LumiNames::cmsrunsummaryTableName());
348  coral::AttributeList runData;
349  destruntable.dataEditor().rowBuffer(runData);
350  runData["RUNNUM"].data<unsigned int>()=runnumber;
351  runData["FILLNUM"].data<unsigned int>()=str2int(result.fillnumber);
352  runData["SEQUENCE"].data<std::string>()=result.sequence;
353  runData["HLTKEY"].data<std::string>()=result.hltkey;
354  runData["STARTTIME"].data<coral::TimeStamp>()=result.startT;
355  runData["STOPTIME"].data<coral::TimeStamp>()=result.stopT;
356  runData["AMODETAG"].data<std::string>()=result.amodetag;
357  runData["EGEV"].data<unsigned int>()=(unsigned int)result.egev;
358  runData["L1KEY"].data<std::string>()=result.l1key;
359  runData["FILLSCHEME"].data<std::string>()=result.fillscheme;
360  runData["NCOLLIDINGBUNCHES"].data<unsigned int>()=result.ncollidingbunches;
361  destruntable.dataEditor().insertRow(runData);
362  }catch( const coral::Exception& er){
363  std::cout<<"database problem "<<er.what()<<std::endl;
364  destsession->transaction().rollback();
365  delete destsession;
366  delete svc;
367  throw er;
368  }
369  destsession->transaction().commit();
370  delete svc;
371  return 0;
372  }
unsigned int str2int(const std::string &s) const
uint16_t size_type
void parseFillCSV(const std::string &csvsource, cmsrunsum &result)
std::string m_dest
Definition: DataPipe.h:27
tuple result
Definition: query.py:137
std::string m_source
Definition: DataPipe.h:28
std::string m_authpath
Definition: DataPipe.h:29
tuple cout
Definition: gather_cfg.py:121
static const std::string cmsrunsummaryTableName()
Definition: LumiNames.cc:2
tuple destsession
Definition: DBCopy.py:270
const std::string lumi::CMSRunSummary2DB::sourceType ( ) const
overridevirtual

Implements lumi::DataPipe.

Definition at line 376 of file CMSRunSummary2DB.cc.

376  {
377  return "DB";
378  }
unsigned int lumi::CMSRunSummary2DB::str2int ( const std::string &  s) const

Definition at line 379 of file CMSRunSummary2DB.cc.

References edm::hlt::Exception, i, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by parseFillCSV(), and retrieveData().

379  {
380  std::istringstream myStream(s);
381  unsigned int i;
382  if(myStream>>i){
383  return i;
384  }else{
385  throw lumi::Exception(std::string("str2int error"),"str2int","CMSRunSummary2DB");
386  }
387  }
int i
Definition: DBlmapReader.cc:9