12 #include <Event/Event.h>
18 #include <pdbcalbase/PdbApplication.h>
19 #include <pdbcalbase/PdbBankID.h>
20 #include <pdbcalbase/PdbBankList.h>
21 #include <pdbcalbase/PdbBankListIterator.h>
22 #include <pdbcalbase/PdbBankManager.h>
23 #include <pdbcalbase/PdbCalBank.h>
24 #include <pgcal/PgPostCalBank.h>
26 #include <pdbcalbase/RunToTime.h>
34 #pragma GCC diagnostic push
35 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
36 #pragma GCC diagnostic ignored "-Woverloaded-virtual"
42 #pragma GCC diagnostic pop
44 #include <boost/foreach.hpp>
46 #include <sys/utsname.h>
60 const static string cvstag =
"OnCalv86";
82 , SetEndTimeStampByHand(
false)
83 , SetBeginTimeStampByHand(
false)
84 , successTable(
"OnCal_status")
87 , eventcheckfrequency(1000)
88 , database(
"calBookKeep")
116 cout <<
PHWHERE <<
"Screwup - the end validity time is not set" << endl;
131 cout <<
PHWHERE <<
"Screwup - the begin validity time is not set" << endl;
140 string fileprefix =
"./";
142 if (getenv(
"ONCAL_SAVEDIR"))
144 fileprefix = getenv(
"ONCAL_SAVEDIR");
149 map<string, set<string> >::const_iterator iter;
152 set<string>::const_iterator siter;
156 filename << fileprefix <<
"Run_"
158 <<
"_" << iter->first <<
".root";
159 TFile *hfile =
new TFile(filename.str().c_str(),
"RECREATE",
160 "Created by Online Calibrator", compress);
161 cout <<
"OnCalServer::dumpHistos() Output root file: " << filename.str() << endl;
162 for (siter = (iter->second).begin(); siter != (iter->second).
end(); ++siter)
164 histo =
dynamic_cast<TH1 *
>(
getHisto(*siter));
171 cout <<
PHWHERE <<
"Histogram "
172 << *siter <<
" not found, will not be saved in "
173 << filename.str() << endl;
187 string calibratorname = Calibrator->
Name();
188 map<string, set<string> >::iterator iter;
192 (iter->second).insert(h1d->GetName());
197 newset.insert(h1d->GetName());
198 newset.insert(
"OnCalServerVars");
219 cout <<
nEvents <<
" events, testing" << endl;
221 unsigned int ical = 0;
222 vector<pair<SubsysReco *, PHCompositeNode *> >::const_iterator iter;
225 OnCal *oncal =
dynamic_cast<OnCal *
>(iter->first);
229 cout <<
"Name: " << oncal->
Name()
230 <<
" is " << oncal->
AllDone() << endl;
236 cout <<
"Everyone is done after "
237 <<
nEvents <<
" Events" << endl;
248 cout <<
PHWHERE <<
"Invalid Run Number: " << runno << endl;
263 vector<pair<SubsysReco *, PHCompositeNode *> >::iterator iter;
267 set<SubsysReco *> NeedOtherTimeStamp;
268 map<string, set<SubsysReco *> >::const_iterator miter;
269 set<SubsysReco *>::const_iterator siter;
273 for (siter = miter->second.begin(); siter != miter->second.end(); ++siter)
275 NeedOtherTimeStamp.insert(*siter);
281 int oncalrun = runno;
282 int fun4allrun = runno;
287 PHTimeStamp Fun4AllBORTimeStamp(OnCalBORTimeStamp);
293 Fun4AllBORTimeStamp = *ts;
302 string currdir = gDirectory->GetPath();
303 set<string> droplist;
306 ostringstream newdirname;
307 newdirname << (*iter).second->getName() <<
"/" << (*iter).first->Name();
308 if (!gROOT->cd(newdirname.str().c_str()))
310 cout <<
PHWHERE <<
"Unexpected TDirectory Problem cd'ing to "
311 << (*iter).second->getName()
312 <<
" - send e-mail to off-l with your macro" << endl;
315 OnCal *oncal =
dynamic_cast<OnCal *
>((*iter).first);
318 string table =
"OnCal";
319 table += (*iter).first->
Name();
322 string calibname = (*iter).first->Name();
324 set<int>::const_iterator runiter;
326 if (calibstatus > 0 &&
testmode == 0)
328 cout << calibname <<
" already ran for run " <<
runNum << endl;
329 droplist.insert(calibname);
335 ostringstream stringarg;
337 for (runiter =
runlist.begin(); runiter !=
runlist.end(); ++runiter)
343 if (NeedOtherTimeStamp.find((*iter).first) != NeedOtherTimeStamp.end())
345 cout <<
"changing timestamp for " << (*iter).first->Name() << endl;
354 if (droplist.find((*iter).first->Name()) == droplist.end())
356 iret = (*iter).first->InitRun(
TopNode);
359 cout <<
PHWHERE <<
"Module " << (*iter).first->Name() <<
" issued Abort Run, exiting" << endl;
365 gROOT->cd(currdir.c_str());
395 cout <<
"No Events read, you probably gave me an empty filelist" << endl;
401 vector<pair<SubsysReco *, PHCompositeNode *> >::iterator iter;
403 string currdir = gDirectory->GetPath();
407 ostringstream newdirname;
408 newdirname << (*iter).second->getName() <<
"/" << (*iter).first->Name();
409 if (!gROOT->cd(newdirname.str().c_str()))
411 cout <<
PHWHERE <<
"Unexpected TDirectory Problem cd'ing to "
412 << (*iter).second->getName()
413 <<
" - send e-mail to off-l with your macro" << endl;
420 cout <<
"End: cded to " << newdirname.str().c_str() << endl;
423 i += (*iter).first->End((*iter).second);
427 currdir = gDirectory->GetPath();
430 OnCal *oncal =
dynamic_cast<OnCal *
>((*iter).first);
435 ostringstream newdirname;
436 newdirname << (*iter).second->getName() <<
"/" << (*iter).first->
Name();
437 if (!gROOT->cd(newdirname.str().c_str()))
439 cout <<
PHWHERE <<
"Unexpected TDirectory Problem cd'ing to "
440 << (*iter).second->getName()
441 <<
" - send e-mail to off-l with your macro" << endl;
445 string CalibratorName = oncal->
Name();
453 string table =
"OnCal";
454 table += CalibratorName;
456 ostringstream stringarg;
465 set<int>::const_iterator runiter;
466 for (runiter =
runlist.begin(); runiter !=
runlist.end(); ++runiter)
473 databasecommitstatus);
476 stringarg << databasecommitstatus;
480 stringarg << verificationstatus;
488 stringarg << beginticks;
490 stp.setTime(beginticks);
494 stringarg << endticks;
496 stp.setTime(endticks);
499 string filelist =
"";
506 filelist += (
infile).substr(((infile).find_last_of(
'/') + 1), (infile).size());
512 cout <<
"FileList: " << filelist << endl;
517 cout <<
"SERVER SUMMARY: " << oncal->
Name() <<
" "
518 << (verificationstatus == 1 ?
"Verification: SUCCESS " :
"Verification: FAILURE ")
519 << (databasecommitstatus == 1 ?
"DB commit: SUCCESS " :
"DB commit: FAILURE ")
524 gROOT->cd(currdir.c_str());
533 if (what ==
"ALL" || what ==
"CALIBRATOR")
538 cout <<
"--------------------------------------" << endl
540 cout <<
"List of Calibrators in OnCalServer:" << endl;
542 vector<pair<SubsysReco *, PHCompositeNode *> >::const_iterator miter;
546 OnCal *oncal =
dynamic_cast<OnCal *
>((*miter).first);
549 cout << oncal->
Name() << endl;
554 if (what ==
"ALL" || what ==
"REQUIRED")
559 cout <<
"--------------------------------------" << endl
561 cout <<
"List of required Calibrations in OnCalServer:" << endl;
563 map<string, set<SubsysReco *> >::const_iterator iter;
564 set<SubsysReco *>::const_iterator siter;
568 cout << iter->first <<
" calibrations are needed by " << endl;
569 for (siter = iter->second.begin(); siter != iter->second.end(); ++siter)
571 cout << (*siter)->Name() << endl;
576 if (what ==
"ALL" || what ==
"FILES")
578 cout <<
"--------------------------------------" << endl
580 cout <<
"List of PRDF Files in OnCalServer:" << endl;
587 cout <<
"File: " << infile << endl;
592 if (what ==
"ALL" || what ==
"RUNS")
594 cout <<
"--------------------------------------" << endl
596 cout <<
"List of Run Numbers in OnCalServer:" << endl;
597 set<int>::const_iterator liter;
600 cout <<
"Run : " << *liter << endl;
611 cout <<
"*******************************************" << endl;
612 cout <<
"* VALIDITY RANGE FOR THIS CALIBRATION *" << endl;
613 cout <<
"* *" << endl;
614 cout <<
"* Used Run : ";
617 cout <<
"* Begin Valid : ";
620 cout <<
"* End Valid : ";
623 cout <<
"* *" << endl;
624 cout <<
"*******************************************" << endl;
638 set<int>::const_iterator runiter;
639 time_t beginrunticks;
641 ostringstream stringarg;
643 for (runiter =
runlist.begin(); runiter !=
runlist.end(); ++runiter)
648 stringarg << beginrunticks;
653 stringarg << endrunticks;
677 while (failure && countdown > 0)
683 DriverManager::getConnection(
database.c_str(),
"phnxrc",
"");
687 cout <<
"Cannot connect to " <<
database.c_str() << endl;
689 cout <<
"countdown: " << countdown << endl;
697 cout <<
"could not connect to DB after 10 tries in 1000 secs, giving up" << endl;
700 cout <<
"connected to " <<
database.c_str() <<
" database." << endl;
720 cout <<
"new row will be created in DB for run " << runno << endl;
725 cmd <<
"INSERT INTO "
727 <<
" (runnumber) VALUES ("
732 cout <<
"in function OnCalServer::insertRunNumInDB() ... ";
733 cout <<
"executing SQL statements ..." << endl;
734 cout << cmd.str() << endl;
761 cmd <<
"SELECT runnumber FROM "
763 <<
" WHERE runnumber = "
770 cout <<
"in function OnCalServer::findRunNumInDB() ";
771 cout <<
"executing SQL statement ..." << endl
772 << cmd.str() << endl;
790 entry = rs->
getInt(
"runnumber");
802 cout <<
"run number " << entry <<
" already exists in DB" << endl;
815 TString command =
"UPDATE ";
821 command +=
" WHERE runnumber >= ";
823 command +=
" and runnumber <= ";
828 cout <<
"in function OnCalServer::updateDB() ... ";
829 cout <<
"executin SQL statement ... " << endl;
830 cout << command.Data() << endl;
858 TString command =
"UPDATE ";
864 command +=
" WHERE runnumber = ";
869 cout <<
"in function OnCalServer::updateDB() ... ";
870 cout <<
"executin SQL statement ... " << endl;
871 cout << command.Data() << endl;
897 TString command =
"UPDATE ";
902 command +=
static_cast<int>(
entry);
903 command +=
"' WHERE runnumber = ";
908 cout <<
"in function OnCalServer::updateDB() ... ";
909 cout <<
"executin SQL statement ... " << endl;
910 cout << command.Data() << endl;
946 <<
" WHERE runnumber = "
951 cout <<
"in function OnCalServer::updateDB() ... ";
952 cout <<
"executin SQL statement ... " << endl;
953 cout << cmd.str() << endl;
970 const string &
entry,
const int runno,
const bool append)
987 query <<
"SELECT * FROM "
989 <<
" WHERE runnumber = "
998 cout <<
"in function OnCalServer::updateDB() ... ";
999 cout <<
"run number " << runno <<
"not found in DB" << endl;
1011 cout <<
"in function OnCalServer::updateDB() ... " << endl;
1012 cout <<
"nothing to append." << endl;
1025 <<
"' WHERE runnumber = "
1030 cout <<
"in function OnCalServer::updateDB() ... ";
1031 cout <<
"executin SQL statement ... " << endl;
1032 cout << cmd.str() << endl;
1054 cout <<
"could not connect to " <<
database << endl;
1057 vector<pair<string, string> > calibrator_columns;
1058 vector<pair<string, string> >::const_iterator coliter;
1059 calibrator_columns.emplace_back(
"runnumber",
"int NOT NULL");
1060 calibrator_columns.emplace_back(
"verified",
"int default -2");
1061 calibrator_columns.emplace_back(
"committed",
"int default -2");
1062 calibrator_columns.emplace_back(
"date",
"timestamp(0) with time zone");
1063 calibrator_columns.emplace_back(
"comment",
"text");
1064 calibrator_columns.emplace_back(
"files",
"text");
1065 calibrator_columns.emplace_back(
"cvstag",
"text");
1066 calibrator_columns.emplace_back(
"startvaltime",
"bigint");
1067 calibrator_columns.emplace_back(
"endvaltime",
"bigint");
1068 calibrator_columns.emplace_back(
"begintime",
"timestamp(0) with time zone");
1069 calibrator_columns.emplace_back(
"endtime",
"timestamp(0) with time zone");
1073 cmd <<
"SELECT * FROM " << tablename <<
" LIMIT 1" <<
ends;
1081 cout <<
"Table " << tablename <<
" does not exist, will create it" << endl;
1087 cmd <<
"CREATE TABLE "
1090 for (coliter = calibrator_columns.begin(); coliter != calibrator_columns.end(); ++coliter)
1092 cmd << (*coliter).
first <<
" " << (*coliter).second <<
", ";
1095 cmd <<
"primary key(runnumber))";
1100 for (coliter = calibrator_columns.begin(); coliter != calibrator_columns.end(); ++coliter)
1108 const string &exceptionmessage = e.
getMessage();
1109 if (exceptionmessage.find(
"not found in result set") != string::npos)
1111 cout <<
"Column " << (*coliter).first <<
" does not exist in "
1112 << tablename <<
", creating it" << endl;
1114 cmd <<
"ALTER TABLE "
1119 << (*coliter).second;
1141 cout <<
"could not connect to " <<
database << endl;
1148 const string &calibname = calibratorname;
1152 cmd <<
"ALTER TABLE " <<
successTable <<
" ADD COLUMN "
1153 << calibname <<
" int";
1160 cout <<
"Message: " << e.
getMessage() << endl;
1161 cout <<
"cmd: " << cmd.str() << endl;
1165 cmd <<
"ALTER TABLE " <<
successTable <<
" ALTER COLUMN "
1173 cout <<
"Message: " << e.
getMessage() << endl;
1174 cout <<
"cmd: " << cmd.str() << endl;
1186 cout <<
"Message: " << e.
getMessage() << endl;
1187 cout <<
"cmd: " << cmd.str() << endl;
1200 cout <<
"could not connect to " <<
database << endl;
1203 string calibname = calibratorname;
1214 cout <<
"Message: " << e.
getMessage() << endl;
1215 cout <<
"Table " <<
successTable <<
" does not exist, your logic is off" << endl;
1222 transform(calibname.begin(), calibname.end(), calibname.begin(), (int (*)(int)) tolower);
1224 for (
unsigned int i = 1;
i <= nocolumn;
i++)
1230 cout << calibname <<
" is in " <<
successTable << endl;
1244 cout <<
"could not connect to " <<
database << endl;
1249 cmd <<
"SELECT runnumber FROM " << tablename <<
" LIMIT 1" <<
ends;
1257 cout <<
"Table " << tablename <<
" does not exist, will create it" << endl;
1263 cmd <<
"CREATE TABLE " << tablename <<
"(runnumber int NOT NULL, "
1264 <<
"startvaltime bigint, "
1265 <<
"endvaltime bigint, "
1266 <<
"beginrun timestamp(0) with time zone, "
1267 <<
"endrun timestamp(0) with time zone, "
1269 <<
"primary key(runnumber))";
1270 cout << cmd.str() << endl;
1277 cout <<
"Error, Message: " << e.
getMessage() << endl;
1297 cout <<
"OnCalServer::BeginTimeStamp: Setting BOR TimeStamp to " <<
beginTimeStamp << endl;
1303 cout <<
"OnCalServer::EndTimeStamp: Setting EOR TimeStamp to " <<
endTimeStamp << endl;
1312 cout <<
"could not connect to " <<
database << endl;
1317 ostringstream subsystable;
1318 subsystable <<
"oncal" << calibrator->
Name();
1319 cmd <<
"SELECT runnumber FROM " <<
successTable <<
" where runnumber < "
1321 << calibrator->
Name() <<
" > 0 order by runnumber desc limit 1";
1329 cout <<
"Table " << subsystable.str() <<
" does not exist" << endl;
1335 int oldrun = rs->
getInt(
"runnumber");
1337 cout <<
"Getting previous good run, current run: " << irun
1338 <<
", previous good run: " << oldrun
1345 cout <<
PHWHERE <<
" No previous good run found for run " << irun << endl;
1353 vector<string> caltab;
1355 vector<string>::const_iterator iter;
1356 for (iter = caltab.begin(); iter != caltab.end(); ++iter)
1358 cout <<
"dealing with table: " << *iter << endl;
1372 con = DriverManager::getConnection(
database.c_str(),
"phnxrc",
"");
1376 cout <<
"Cannot connect to " <<
database.c_str() << endl;
1382 concalib = DriverManager::getConnection(
"oncal",
"phnxrc",
"");
1386 cout <<
"Cannot connect to "
1398 cout <<
"Cannot create statement" << endl;
1408 cmd <<
"SELECT * from " << table <<
" where startvaltime = ?";
1413 cout <<
"Cannot create statement" << endl;
1422 cmd <<
"update " << table <<
" set endvaltime = ? where startvaltime = ?";
1427 cout <<
"Cannot create statement" << endl;
1433 cmd <<
"select * from "
1446 cout <<
"Message: " << e.
getMessage() << endl;
1452 int startticks = rs->
getLong(
"startvaltime");
1453 int endticks = rs->
getLong(
"endvaltime");
1459 stmt1->
setInt(1, startticks);
1466 cout <<
"Message: " << e.
getMessage() << endl;
1471 int calibendval = 0;
1474 calibendval = rs1->
getInt(
"endvaltime");
1475 if (endticks != rs1->
getInt(
"endvaltime"))
1479 cout <<
"endvaltime problem with run " << run << endl;
1480 cout <<
"endvaltime from oncal_status: " << endticks << endl;
1481 cout <<
"startvaltime from oncal_status: " << startticks << endl;
1482 cout <<
"endvaltime from calibrations DB: " << rs1->
getInt(
"endvaltime") << endl;
1483 if (endticks < rs1->getInt(
"endvaltime"))
1485 cout <<
"ENDTICKS smaller CALIB" << endl;
1495 cout <<
"endvaltime changes, check run " << run << endl;
1505 cout <<
"Adjusting run " << run << endl;
1506 cout <<
"changing endvaltime from " << calibendval
1507 <<
" to " << endticks << endl;
1510 stmtupd->
setInt(1, endticks);
1511 stmtupd->
setInt(2, startticks);
1517 cout <<
"Run " << run <<
" not found" << endl;
1534 con = DriverManager::getConnection(
database.c_str(),
"phnxrc",
"");
1538 cout <<
"Cannot connect to " <<
database.c_str() << endl;
1549 cout <<
"Cannot create statement" << endl;
1558 cmd <<
"UPDATE oncal_status set endvaltime = ? where runnumber = ?";
1563 cout <<
"Cannot create statement" << endl;
1569 cmd <<
"select * from "
1578 cout <<
"Message: " << e.
getMessage() << endl;
1584 int startticks = rs->
getLong(
"startvaltime");
1585 int endticks = rs->
getLong(
"endvaltime");
1586 int rtstartticks = 0;
1592 rtstartticks = rtstart->
getTics();
1597 rtendticks = rtend->
getTics();
1600 if (rtstartticks != startticks)
1602 cout <<
"Run " << run
1603 <<
": Start mismatch, oncal: " << startticks
1604 <<
", rt: " << rtstartticks << endl;
1606 if (rtendticks != endticks)
1610 if (rtstartticks != rtendticks)
1612 cout <<
"Run " << run
1613 <<
": End mismatch, oncal: " << endticks
1614 <<
", rt: " << rtendticks << endl;
1615 if (endticks > rtendticks)
1617 cout <<
"BAD: endticks: " << endticks
1618 <<
", rtendticks: " << rtendticks
1624 stmtupd->
setLong(1, rtendticks);
1631 if (startticks != endticks - 1)
1633 cout <<
"Run " << run
1634 <<
": Start/End mismatch, Start: " << startticks
1635 <<
", End: " << endticks << endl;
1636 endticks = startticks + 1;
1639 stmtupd->
setLong(1, endticks);
1648 cout <<
"run " << run <<
" was twiddled by OnCal" << endl;
1665 int iret = calibrator->
CopyTables(FromRun, ToRun, commit);
1677 cout <<
"could not connect to " <<
database << endl;
1681 string table =
"OnCal";
1682 table += calibrator->
Name();
1687 cmd <<
"SELECT runnumber FROM "
1697 cout <<
"Table " <<
successTable <<
" does not exist" << endl;
1706 cmd <<
"SELECT runnumber FROM "
1708 << myrunnumber <<
" and "
1709 << calibrator->
Name() <<
" <= 0";
1716 cout <<
PHWHERE <<
" Exception caught, Message: "
1725 string tablecomment =
"Subsytem provided";
1729 cout <<
"Comment: " << tablecomment << endl;
1730 cout <<
"updating oncal status tables for " <<
runnumber << endl;
1738 cout <<
"Calibratior " << calibrator->
Name() <<
" for run " <<
runnumber <<
" failed" << endl;
1747 cout <<
PHWHERE <<
" Run " <<
runnumber <<
" is already successfully calibrated for "
1748 << calibrator->
Name() << endl;
1758 ostringstream stringarg;
1769 stringarg << beginticks;
1771 stp.setTime(beginticks);
1775 stringarg << endticks;
1777 stp.setTime(endticks);
1783 string filelist =
"";
1784 BOOST_FOREACH (
string infile, flist)
1789 filelist.pop_back();
1790 cout <<
"FileList: " << filelist << endl;
1796 int OnCalServer::CopySnglTable(
const string &pdbclass,
const string &tablename,
const int bankid,
const int FromRun,
const int ToRun,
const int commit)
1811 PdbCalBank *pdbBank = bankManager->
fetchBank(pdbclass.c_str(), BankID, tablename.c_str(), *ts);
1817 ostringstream newdesc;
1818 newdesc <<
"copied from run " << FromRun;
1824 for (
unsigned int i = 0;
i < pdbBank->
getLength();
i++)
1826 cout <<
"orig: " << endl;
1828 cout <<
"new: " << endl;
1837 if (bankid != Tobankid)
1850 application->
commit(pdbBanknew);
1854 application->
abort();
1871 cout <<
PHWHERE <<
"Unknown Run " << irun << endl;
1877 int curend = curstart;
1883 int closestrun = -1;
1886 cout <<
"could not connect to " <<
database << endl;
1893 cmd <<
"SELECT runnumber,startvaltime,endvaltime FROM "
1896 << calibrator->
Name() <<
" = 1 order by runnumber desc limit 1";
1904 cout <<
"Table " <<
successTable <<
" does not exist" << endl;
1908 unsigned int prevend = 0;
1911 prevrun = rs->
getInt(
"runnumber");
1912 unsigned int prevstart = rs->
getLong(
"startvaltime");
1913 prevend = rs->
getLong(
"endvaltime");
1914 cout <<
"previous run: " << prevrun
1915 <<
", start: " << prevstart
1916 <<
", end: " << prevend
1923 cout <<
PHWHERE <<
" No previous good run found for run " << irun << endl;
1927 closestrun = prevrun;
1932 cout <<
"Closest previous run is " << closestrun << endl;
1937 cmd <<
"SELECT runnumber,startvaltime,endvaltime FROM "
1940 << calibrator->
Name() <<
" = 1 order by runnumber asc limit 1";
1947 cout <<
"Table " <<
successTable <<
" does not exist" << endl;
1951 unsigned int nextstart = 0;
1954 nextrun = rs->
getInt(
"runnumber");
1955 nextstart = rs->
getLong(
"startvaltime");
1956 unsigned int nextend = rs->
getLong(
"endvaltime");
1959 cout <<
"next run: " << nextrun
1960 <<
", start: " << nextstart
1961 <<
", end: " << nextend
1969 cout <<
PHWHERE <<
" No next good run found for run " << irun << endl;
1973 int tdiffprev = curstart - prevend;
1977 tdiffnext = nextstart - curend;
1982 tdiffnext = tdiffprev + 1;
1986 cout <<
"diff prev: " << tdiffprev
1987 <<
", next: " << tdiffnext
1990 if (tdiffprev < tdiffnext)
1992 closestrun = prevrun;
1996 closestrun = nextrun;
2000 cout <<
"closest run: " << closestrun << endl;
2011 int iret =
CopyTables(calibrator, FromRun, runno, commit);
2021 cout <<
"could not connect to " <<
database << endl;
2028 cmd <<
"SELECT runnumber FROM "
2038 cout <<
"Table " <<
successTable <<
" does not exist" << endl;
2047 cmd <<
"SELECT runnumber FROM "
2050 << calibrator->
Name() <<
" <= 0";
2057 cout <<
PHWHERE <<
" Exception caught, Message: "
2073 cout <<
"ClosestGoodRun returned bad runnumber: " << FromRun << endl;
2077 cout <<
"Going to copy calibration for run " << runno
2078 <<
" from run " << FromRun << endl;
2084 if (FromRun < runno)
2092 string table =
"OnCal";
2093 table += calibrator->
Name();
2095 comment <<
" CopiedRun(" << FromRun <<
")";
2096 cout <<
"updating oncal status tables for " << runno << endl;
2102 updateDB(table.c_str(),
"committed",
true);
2108 cout <<
"Run " << runno
2109 <<
" has a good calibrations, doing nothing" << endl;
2123 cout <<
PHWHERE <<
"Cannot get begin time for run " << runno << endl;
2124 cout <<
"Exiting" << endl;
2132 cout <<
"OnCalServer::SetBorTime from RunToTime was found for run : " << runno <<
" to ";
2133 BeginRunTimeStamp.
print();
2145 time_t eorticks = 0;
2147 time_t borticks = 0;
2151 eorticks = EorTimeStp->
getTics();
2158 if (eorticks <= borticks)
2160 eorticks = borticks + 1;
2161 EorTimeStp->setTics(eorticks);
2164 cout <<
"OnCalServer::SetEorTime: setting eor time to ";
2165 EorTimeStp->print();
2177 cout <<
PHWHERE <<
"Cannot get begin time for run " << runno << endl;
2178 cout <<
"Exiting" << endl;
2181 borticks = TimeStp->getTics();
2186 eorticks = TimeStp->
getTics();
2194 if (eorticks <= borticks)
2196 eorticks = borticks + 1;
2203 map<string, set<SubsysReco *> >::iterator iter;
2206 cout <<
PHWHERE <<
" the calibrator " << calibratorname <<
" is unknown to me" << endl;
2212 iter->second.insert(reco);
2216 set<SubsysReco *> subsys;
2217 subsys.insert(reco);
2229 cout <<
PHWHERE <<
"Unknown Run " << irun << endl;
2234 cout <<
PHWHERE <<
"No required calibrations given" << endl;
2240 int curend = curstart;
2246 int closestrun = -1;
2249 cout <<
"could not connect to " <<
database << endl;
2254 map<string, set<SubsysReco *> >::const_iterator iter;
2256 cmd <<
"SELECT runnumber,startvaltime,endvaltime FROM "
2261 cmd <<
" and " << iter->first <<
" > 0 ";
2264 cmd <<
" order by runnumber desc limit 1";
2272 cout <<
"Table " <<
successTable <<
" does not exist" << endl;
2276 unsigned int prevend = 0;
2279 prevrun = rs->
getInt(
"runnumber");
2280 unsigned int prevstart = rs->
getLong(
"startvaltime");
2281 prevend = rs->
getLong(
"endvaltime");
2282 if (prevrun != irun)
2284 cout <<
"previous run: " << prevrun
2285 <<
", start: " << prevstart
2286 <<
", end: " << prevend
2292 cout <<
PHWHERE <<
" No previous good run found for run " << irun << endl;
2296 if (prevrun == irun)
2298 cout <<
"closest run with required calibs is current run: " << irun << endl;
2302 cmd <<
"SELECT runnumber,startvaltime,endvaltime FROM "
2307 cmd <<
" and " << iter->first <<
" > 0 ";
2310 cmd <<
" order by runnumber asc limit 1";
2317 cout <<
"Table " <<
successTable <<
" does not exist" << endl;
2321 unsigned int nextstart = 0;
2324 nextrun = rs->
getInt(
"runnumber");
2325 nextstart = rs->
getLong(
"startvaltime");
2326 unsigned int nextend = rs->
getLong(
"endvaltime");
2327 cout <<
"next run: " << nextrun
2328 <<
", start: " << nextstart
2329 <<
", end: " << nextend
2334 cout <<
PHWHERE <<
" No next good run found for run " << irun << endl;
2337 int tdiffprev = curstart - prevend;
2341 tdiffnext = nextstart - curend;
2346 tdiffnext = tdiffprev + 1;
2348 if (tdiffprev < tdiffnext)
2350 closestrun = prevrun;
2354 closestrun = nextrun;
2356 cout <<
"closest run with required calibs: " << closestrun << endl;
2381 int firstrun = *
runlist.begin();
2382 int lastrun = *
runlist.rbegin();
2386 string table =
"OnCalRichCal";
2390 ostringstream stringarg;
2405 stringarg << beginticks;
2406 updateDB(table,
"startvaltime", stringarg.str(), firstrun);
2410 stringarg << endticks;
2411 updateDB(table,
"endvaltime", stringarg.str(), firstrun);
2485 cout <<
"could not connect to " <<
database << endl;
2492 cmd <<
"SELECT " << calibname <<
" FROM "
2495 cout <<
"exec " << cmd.str() << endl;
2503 cout <<
"Table " <<
successTable <<
" does not exist" << endl;
2508 iret = rs->
getInt(calibname.c_str());
2512 cout <<
PHWHERE <<
" No calib status for " << calibname
2513 <<
" for " << runno << endl;
2521 const char *logname = getenv(
"LOGNAME");
2524 if (strcmp(logname,
"phnxcal") == 0 || strcmp(logname,
"anatrain") == 0)
2526 cout <<
"phnxcal,anatrain account is not allowed to run in testmode" << endl;
2535 cout <<
"could not get account via env var LOGNAME, not setting testmode" << endl;