125 std::string runsessionParamTable(
"RUNSESSION_PARAMETER");
126 coral::ConnectionService* svc =
new coral::ConnectionService;
136 if (cutpos != std::string::npos) {
137 dbsource =
m_source.substr(0, cutpos);
138 csvsource =
m_source.substr(cutpos + 1);
141 coral::ISessionProxy* runinfosession = svc->connect(dbsource, coral::ReadOnly);
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)) {
149 std::string(
"non-existing table " + runsessionParamTable),
"CMSRunSummary2DB",
"retrieveData");
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));
159 amodetagCondition[
"runnumber"].data<
unsigned int>() =
runnumber;
160 amodetagQuery->addToOutputList(
"distinct(STRING_VALUE)");
161 amodetagQuery->setCondition(
"NAME=:name AND RUNNUMBER=:runnumber", amodetagCondition);
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>());
175 for (std::vector<std::string>::iterator it = amodes.begin(); it != amodes.end(); ++it) {
176 if (it->find(
"PHYS") == std::string::npos)
180 if (amd.empty() && !amodes.empty()) {
181 amd = *(amodes.begin());
188 delete amodetagQuery;
190 coral::IQuery* egevQuery = runinfoschemaHandle.tableHandle(runsessionParamTable).newQuery();
191 coral::AttributeList egevOutput;
193 coral::AttributeList egevCondition;
194 egevCondition = coral::AttributeList();
196 egevCondition.extend(
"runnumber",
typeid(
unsigned int));
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();
204 while (egevCursor.next()) {
205 const coral::AttributeList& row = egevCursor.currentRow();
208 if (tmpgev >
result.egev) {
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));
222 seqBindVariableList[
"runnumber"].data<
unsigned int>() =
runnumber;
224 seqQuery->setCondition(
"RUNNUMBER =:runnumber AND NAME =:name", seqBindVariableList);
225 seqQuery->addToOutputList(
"STRING_VALUE");
226 coral::ICursor& seqCursor = seqQuery->execute();
228 while (seqCursor.next()) {
229 const coral::AttributeList& row = seqCursor.currentRow();
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));
239 hltkeyBindVariableList[
"runnumber"].data<
unsigned int>() =
runnumber;
241 hltkeyQuery->setCondition(
"RUNNUMBER =:runnumber AND NAME =:name", hltkeyBindVariableList);
242 hltkeyQuery->addToOutputList(
"STRING_VALUE");
243 coral::ICursor& hltkeyCursor = hltkeyQuery->execute();
245 while (hltkeyCursor.next()) {
246 const coral::AttributeList& row = hltkeyCursor.currentRow();
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));
256 fillBindVariableList[
"runnumber"].data<
unsigned int>() =
runnumber;
258 fillQuery->setCondition(
"RUNNUMBER =:runnumber AND NAME =:name", fillBindVariableList);
259 fillQuery->addToOutputList(
"STRING_VALUE");
260 fillQuery->addToOrderList(
"TIME");
262 coral::ICursor& fillCursor = fillQuery->execute();
264 while (fillCursor.next()) {
265 const coral::AttributeList& row = fillCursor.currentRow();
272 if (
result.fillnumber.empty()) {
273 throw nonCollisionException(
"retrieveData",
"CMSRunSummary2DB");
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));
280 startTVariableList[
"runnumber"].data<
unsigned int>() =
runnumber;
282 startTQuery->setCondition(
"RUNNUMBER =:runnumber AND NAME =:name", startTVariableList);
283 startTQuery->addToOutputList(
"TIME");
284 coral::ICursor& startTCursor = startTQuery->execute();
286 while (startTCursor.next()) {
287 const coral::AttributeList& row = startTCursor.currentRow();
288 result.startT = row[
"TIME"].data<coral::TimeStamp>();
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));
296 stopTVariableList[
"runnumber"].data<
unsigned int>() =
runnumber;
298 stopTQuery->setCondition(
"RUNNUMBER =:runnumber AND NAME =:name", stopTVariableList);
299 stopTQuery->addToOutputList(
"TIME");
300 coral::ICursor& stopTCursor = stopTQuery->execute();
302 while (stopTCursor.next()) {
303 const coral::AttributeList& row = stopTCursor.currentRow();
304 result.stopT = row[
"TIME"].data<coral::TimeStamp>();
307 coral::IQuery* l1keyQuery = runinfoschemaHandle.tableHandle(runsessionParamTable).newQuery();
308 coral::AttributeList l1keyOutput;
310 coral::AttributeList l1keyCondition;
311 l1keyCondition = coral::AttributeList();
312 l1keyCondition.extend(
"name",
typeid(
std::string));
313 l1keyCondition.extend(
"runnumber",
typeid(
unsigned int));
315 l1keyCondition[
"runnumber"].data<
unsigned int>() =
runnumber;
316 l1keyQuery->addToOutputList(
"STRING_VALUE");
317 l1keyQuery->setCondition(
"NAME=:name AND RUNNUMBER=:runnumber", l1keyCondition);
319 l1keyQuery->defineOutput(l1keyOutput);
320 coral::ICursor& l1keyCursor = l1keyQuery->execute();
321 while (l1keyCursor.next()) {
322 const coral::AttributeList& row = l1keyCursor.currentRow();
327 runinfosession->transaction().rollback();
328 delete runinfosession;
332 runinfosession->transaction().commit();
333 delete runinfosession;
335 if (!csvsource.empty()) {
339 result.ncollidingbunches = 0;
342 <<
" : hltkey : " <<
result.hltkey <<
" : fillnumber : " <<
result.fillnumber
343 <<
" : l1key : " <<
result.l1key <<
" : amodetag :" <<
result.amodetag <<
" : egev : " <<
result.egev
344 <<
" : fillscheme " <<
result.fillscheme <<
" : ncollidingbunches : " <<
result.ncollidingbunches
348 coral::ISessionProxy* destsession = svc->connect(
m_dest, coral::Update);
350 coral::ITypeConverter& desttpc = destsession->typeConverter();
351 desttpc.setCppTypeForSqlType(
"unsigned int",
"NUMBER(10)");
353 destsession->transaction().start(
false);
354 coral::ISchema& destschema = destsession->nominalSchema();
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);
362 runData[
"STARTTIME"].data<coral::TimeStamp>() =
result.startT;
363 runData[
"STOPTIME"].data<coral::TimeStamp>() =
result.stopT;
365 runData[
"EGEV"].data<
unsigned int>() = (
unsigned int)
result.egev;
368 runData[
"NCOLLIDINGBUNCHES"].data<
unsigned int>() =
result.ncollidingbunches;
369 destruntable.dataEditor().insertRow(runData);
371 std::cout <<
"database problem " << er.what() << std::endl;
372 destsession->transaction().rollback();
377 destsession->transaction().commit();
void parseFillCSV(const std::string &csvsource, cmsrunsum &result)
unsigned int str2int(const std::string &s) const
static const std::string cmsrunsummaryTableName()