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
 
virtual void retrieveData (unsigned int runnumber)
 
virtual const std::string sourceType () const
 
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 386 of file CMSRunSummary2DB.cc.

386 {}

Member Function Documentation

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

Implements lumi::DataPipe.

Definition at line 371 of file CMSRunSummary2DB.cc.

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

Definition at line 94 of file CMSRunSummary2DB.cc.

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

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(), 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;
79  std::string line;
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:11
tuple result
Definition: query.py:137
tuple cout
Definition: gather_cfg.py:121
void lumi::CMSRunSummary2DB::retrieveData ( unsigned int  runnumber)
virtual

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 108 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(), and python.CommonUtils::svc.

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

Implements lumi::DataPipe.

Definition at line 374 of file CMSRunSummary2DB.cc.

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

Definition at line 377 of file CMSRunSummary2DB.cc.

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

Referenced by parseFillCSV(), and retrieveData().

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