CMS 3D CMS Logo

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)
 
const std::string dataType () const override
 
unsigned long long retrieveData (unsigned int runnumber) override
 
const std::string sourceType () const override
 
unsigned int str2int (const std::string &s) const
 
 ~CMSRunSummary2DB () override
 
- Public Member Functions inherited from lumi::DataPipe
 DataPipe (const std::string &)
 
 DataPipe (const DataPipe &)=delete
 
std::string getAuthPath () const
 
std::string getMode () const
 
float getNorm () const
 
std::string getSource () const
 
const DataPipeoperator= (const DataPipe &)=delete
 
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

◆ CMSRunSummary2DB()

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

Definition at line 94 of file CMSRunSummary2DB.cc.

94 : DataPipe(dest) {}
DataPipe(const std::string &)
Definition: DataPipe.cc:2

◆ ~CMSRunSummary2DB()

lumi::CMSRunSummary2DB::~CMSRunSummary2DB ( )
override

Definition at line 392 of file CMSRunSummary2DB.cc.

392 {}

Member Function Documentation

◆ dataType()

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

Implements lumi::DataPipe.

Definition at line 381 of file CMSRunSummary2DB.cc.

381 { return "CMSRUNSUMMARY"; }

◆ isCollisionRun()

bool lumi::CMSRunSummary2DB::isCollisionRun ( const lumi::CMSRunSummary2DB::cmsrunsum rundata)
private

Definition at line 95 of file CMSRunSummary2DB.cc.

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

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

◆ parseFillCSV()

void lumi::CMSRunSummary2DB::parseFillCSV ( const std::string &  csvsource,
cmsrunsum result 
)
private

Definition at line 68 of file CMSRunSummary2DB.cc.

References gather_cfg::cout, mps_splice::line, AlCaHarvesting_cff::record, mps_fire::result, str2int(), and AlCaHLTBitMon_QueryRunRegistry::string.

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)
84  continue;
85  std::string fillnum = record[0];
86  if (fillnum == result.fillnumber) {
87  result.fillscheme = record[1];
88  std::string ncollidingbunchesStr = record[2];
89  result.ncollidingbunches = str2int(ncollidingbunchesStr);
90  break;
91  }
92  }
93  }
unsigned int str2int(const std::string &s) const

◆ retrieveData()

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 111 of file CMSRunSummary2DB.cc.

References lumi::LumiNames::cmsrunsummaryTableName(), gather_cfg::cout, Exception, createfilelist::int, lumi::DataPipe::m_authpath, lumi::DataPipe::m_dest, lumi::DataPipe::m_source, parseFillCSV(), mps_fire::result, cond::runnumber, lumi::DBConfig::setAuthentication(), str2int(), and AlCaHLTBitMon_QueryRunRegistry::string.

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

◆ sourceType()

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

Implements lumi::DataPipe.

Definition at line 382 of file CMSRunSummary2DB.cc.

382 { return "DB"; }

◆ str2int()

unsigned int lumi::CMSRunSummary2DB::str2int ( const std::string &  s) const

Definition at line 383 of file CMSRunSummary2DB.cc.

References Exception, mps_fire::i, alignCSCRings::s, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by parseFillCSV(), and retrieveData().

383  {
384  std::istringstream myStream(s);
385  unsigned int i;
386  if (myStream >> i) {
387  return i;
388  } else {
389  throw lumi::Exception(std::string("str2int error"), "str2int", "CMSRunSummary2DB");
390  }
391  }