1 #include <RunHistory/RunHistory.h> 2 #include <DatabaseUtils/DAQConfig/PixelEnableMasks.h> 3 #include <DatabaseUtils/DAQConfig/PixelThresholds.h> 4 #include <DatabaseUtils/DCS/APDSettings.h> 5 #include <DAQChannelMap/DAQChannelMap.h> 7 #include <Database/cxx/include/Table.h> 8 #include <Database/cxx/include/Util.h> 15 #include <cetlib_except/exception.h> 22 #include <TTimeStamp.h> 23 #include <TStopwatch.h> 32 std::map<HardwareLocation, std::pair<FEBInfo, APDInfo>>
gLocToFA;
37 std::unique_ptr<Table>
const& hwTable)
39 bool gotConnection = hwTable->GetConnection();
42 LOG_WARNING(
"RunHistory") <<
"Failed to connect to hardware database! " 43 <<
"Failed to load hardware info.";
46 LOG_DEBUG(
"RunHistory") <<
"about to execute query\n" 51 if (hwTable->ExecuteSQL(query,res)) {
52 if (PQresultStatus(res) != PGRES_TUPLES_OK) {
55 hwTable->CloseConnection();
62 hwTable->CloseConnection();
66 LOG_DEBUG(
"RunHistory") <<
"query returned " << PQntuples(res) <<
" rows";
74 return (db1.
num < db2.
num);
111 ,
_tStart(
"2010-01-01 00:00:00")
155 ,
_tStart(
"2010-01-01 00:00:00")
198 ,
_tStart(
"2010-01-01 00:00:00")
248 for (
unsigned int j=0;
j<
_dbList[
i].dcm.size(); ++
j)
362 std::cerr << __PRETTY_FUNCTION__ <<
" FD RHC run start list is not the same length as the run stop list. Something is wrong..." <<
std::endl;
379 std::cerr << __PRETTY_FUNCTION__ <<
" ND RHC run start list is not the same length as the run stop list. Something is wrong..." <<
std::endl;
391 std::cerr << __PRETTY_FUNCTION__ <<
" Unknown detector. Why are asking for beam mode?" <<
std::endl;
418 LOG_INFO(
"RunHistory") <<
"RunHistory: Loading FEB and APD installation information" <<
std::endl;
422 std::unique_ptr<db::Table> hwTable;
435 bool gotConnection = hwTable->GetConnection(
_nRetryLoads);
437 if (!gotConnection) {
438 LOG_ERROR(
"RunHistory") <<
"RunHistory::LoadHardwareInfo(): Failed to connect to hardware database! Failed to load hardware info." <<
std::endl;
446 query=
"SELECT dcm_name,dcm_port,block,plane,module_position from hardware_position where detector='NearDet' and install_date at time zone 'UTC' < '" +
_tStart +
"' and (remove_date is NULL or remove_date at time zone 'UTC' > '" +
_tStart +
"') and hw_type='APD' order by dcm_name,dcm_port";
448 if (hwTable->ExecuteSQL(query,res)) {
449 if (PQresultStatus(res) != PGRES_TUPLES_OK) {
452 hwTable->CloseConnection();
458 int nRow = PQntuples(res);
459 for (
int i=0;
i < nRow;
i++) {
460 dcmName = PQgetvalue(res,
i,0);
461 int ifeb = atoi(PQgetvalue(res,
i,1));
462 short diblock = atoi(dcmName.substr(6,2).c_str());
464 unsigned int idcm = atoi(dcmName.substr(9,2).c_str());
468 _dbList[idb].hasNoAPDs =
false;
470 _dbList[idb].dcm[idcm-1].feb[ifeb].hasAPD =
true;
471 _dbList[idb].dcm[idcm-1].feb[ifeb].block = atoi(PQgetvalue(res,
i,2));
472 _dbList[idb].dcm[idcm-1].feb[ifeb].layer = atoi(PQgetvalue(res,
i,3));
473 _dbList[idb].dcm[idcm-1].feb[ifeb].pos_in_layer = atoi(PQgetvalue(res,
i,4));
474 _dbList[idb].dcm[idcm-1].nInstrumentedFEBs++;
475 _dbList[idb].nInstrumentedFEBs++;
487 query=
"SELECT btrim(fcom.location1,'DIBLK:') diblk, btrim(fcom.position1,'DCM:') pos, CAST(btrim(fcom.port1,'PRT:') AS INT) feb, mod.block AS block, mod.layer AS plane, mod.position_in_layer AS position FROM public.feb_comm_cables fcom, ashriverprod_factory.module mod LEFT OUTER JOIN ashriverprod_factory.barcoded_item bm ON (mod.barcoded_item_id = bm.barcoded_item_id) LEFT OUTER JOIN ashriverprod_factory.module_apd_connection ON (mod.barcoded_item_id = module_apd_connection.module) LEFT OUTER JOIN ashriverprod_factory.apd ON (module_apd_connection.apd = apd.barcoded_item_id) LEFT OUTER JOIN ashriverprod_factory.barcoded_item ba ON (apd.barcoded_item_id = ba.barcoded_item_id) LEFT OUTER JOIN ashriverprod_factory.nova_connection mac ON (mac.connection_id = module_apd_connection.connection_id) WHERE mac.date_created AT TIME ZONE 'CDT' < '" +
_tStart +
"' and (mac.date_removed is NULL or mac.date_removed AT TIME ZONE 'CDT' > '" +
_tStart +
"') and (mod.block=CAST(btrim(fcom.location2,'BLK:') AS INT) and mod.layer=CAST(btrim(fcom.position2,'PLN:') AS INT) and mod.position_in_layer=CAST(btrim(fcom.port2,'POS:') AS INT)) ORDER BY diblk,pos,feb";
489 if (hwTable->ExecuteSQL(query,res)) {
490 if (PQresultStatus(res) != PGRES_TUPLES_OK) {
493 hwTable->CloseConnection();
499 int nRow = PQntuples(res);
500 for (
int i=0;
i < nRow;
i++) {
501 int diblock = atoi(PQgetvalue(res,
i,0));
503 unsigned int idcm = atoi(PQgetvalue(res,
i,1));
506 int ifeb = atoi(PQgetvalue(res,
i,2));
507 if( (diblock==4 &&idcm==7 &&ifeb==15) ||
508 (diblock==5 &&idcm==7 &&ifeb==59) ||
509 (diblock==14&&idcm==6 &&ifeb==42) )
continue;
512 _dbList[idb].hasNoAPDs =
false;
514 _dbList[idb].dcm[idcm-1].feb[ifeb].hasAPD =
true;
515 _dbList[idb].dcm[idcm-1].feb[ifeb].block = atoi(PQgetvalue(res,
i,3));
516 _dbList[idb].dcm[idcm-1].feb[ifeb].layer = atoi(PQgetvalue(res,
i,4));
517 _dbList[idb].dcm[idcm-1].feb[ifeb].pos_in_layer = atoi(PQgetvalue(res,
i,5));
518 _dbList[idb].dcm[idcm-1].nInstrumentedFEBs++;
519 _dbList[idb].nInstrumentedFEBs++;
526 std::cerr << __PRETTY_FUNCTION__ <<
" SQL error, failed query: " << query <<
std::endl;
528 hwTable->CloseConnection();
533 hwTable->CloseConnection();
544 LOG_ERROR(
"RunHistory") <<
"Ideal run number not acceptable for this method. Aborting.";
555 std::unique_ptr<db::Table>
t;
556 t.reset(
new db::Table(
"RunHistory/tables/PedestalsByRun.xml"));
563 int pedIdx = t->GetColIndex(
"ped");
575 std::cerr << __PRETTY_FUNCTION__ <<
"No pedestals found in DB!";
580 if (t->NRow() == 0) {
581 LOG_ERROR(
"RunHistory") << __PRETTY_FUNCTION__ <<
": failed to get any rows from database, which should not happen." <<
std::endl;
593 for (
unsigned int idb=0; idb<
_dbList.size(); ++idb) {
595 for (
unsigned int idcm=0; idcm<
_dbList[idb].dcm.size(); ++idcm) {
596 if (!
_dbList[idb].
dcm[idcm].isActive)
continue;
597 int dcmNum =
_dbList[idb].dcm[idcm].position;
598 int nfebs =
_dbList[idb].dcm[idcm].feb.size();
599 int64_t febmask =
_dbList[idb].dcm[idcm].febMask;
600 for (
int ifeb=0; ifeb<nfebs; ++ifeb) {
601 if (!(febmask >> ifeb)&0
x1)
continue;
602 for (
int ip=0;
ip<32; ++
ip) {
617 row->
Col(pedIdx).
Get(ped);
618 _dbList[idb].dcm[idcm].feb[ifeb].pixelThresh[
ip] = ped;
662 return _dbList[idb].
dcm[dcmId-1].
feb[ifeb].pixelThresh[ipix];
701 return _dbList[idb].
dcm[dcmId-1].
feb[ifeb].pixelThresh[ipix];
712 LOG_ERROR(
"RunHistory") <<
"Ideal run number not acceptable for this method. Aborting.";
723 std::unique_ptr<db::Table>
t;
724 t.reset(
new db::Table(
"RunHistory/tables/PixelMasksByRun.xml"));
731 int maskIdx = t->GetColIndex(
"mask");
743 std::cerr << __PRETTY_FUNCTION__ <<
"No pixel masks found in DB!";
748 if (t->NRow() == 0) {
749 LOG_ERROR(
"RunHistory") << __PRETTY_FUNCTION__ <<
": failed to get any rows from database, which should not happen." <<
std::endl;
760 for (
unsigned int idb=0; idb<
_dbList.size(); ++idb) {
762 for (
unsigned int idcm=0; idcm<
_dbList[idb].dcm.size(); ++idcm) {
763 if (!
_dbList[idb].
dcm[idcm].isActive)
continue;
764 int dcmNum =
_dbList[idb].dcm[idcm].position;
765 int nfebs =
_dbList[idb].dcm[idcm].feb.size();
766 for (
int ifeb=0; ifeb<nfebs; ++ifeb) {
767 int tchan = detId*1000000 + 10000*dbNum + 100*dcmNum + ifeb;
773 row->
Col(maskIdx).
Get(pMask);
774 _dbList[idb].dcm[idcm].feb[ifeb].pixelMask = pMask;
792 std::unique_ptr<db::Table>
t;
793 t.reset(
new db::Table(
"RunHistory/tables/FEBMasksByRun.xml"));
800 int maskIdx = t->GetColIndex(
"mask");
812 std::cerr << __PRETTY_FUNCTION__ <<
"No pixel masks found in DB!";
817 if (t->NRow() == 0) {
818 LOG_ERROR(
"RunHistory") << __PRETTY_FUNCTION__ <<
": failed to get any rows from database, which should not happen." <<
std::endl;
830 for (
unsigned int idb=0; idb<
_dbList.size(); ++idb) {
832 for (
unsigned int idcm=0; idcm<
_dbList[idb].dcm.size(); ++idcm) {
833 if (!
_dbList[idb].
dcm[idcm].isActive)
continue;
834 int dcmNum =
_dbList[idb].dcm[idcm].position;
835 int tchan = detId*1000000 + 10000*dbNum + 100*dcmNum;
841 row->
Col(maskIdx).
Get(pMask);
842 _dbList[idb].dcm[idcm].febMask = pMask;
865 sprintf(daqEnv,
"NOVADAQ_ENVIRONMENT=%s",
_detector.c_str());
868 std::vector<std::string> tmpDCMList;
870 for (
unsigned int j=0;
j <
_dbList[
i].dcm.size(); ++
j) {
882 for (
unsigned int idb=0; idb<
_dbList.size(); ++idb) {
883 for (
unsigned int idcm=0; idcm<
_dbList[idb].dcm.size(); ++idcm) {
884 if (!
_dbList[idb].
dcm[idcm].isActive)
continue;
889 _dbList[idb].dcm[idcm].febMask = febMask;
906 std::cerr << __PRETTY_FUNCTION__ <<
" giving up!" 920 sprintf(daqEnv,
"NOVADAQ_ENVIRONMENT=%s",
_detector.c_str());
923 std::vector<std::string> tmpDCMList;
925 for (
unsigned int j=0;
j <
_dbList[
i].dcm.size(); ++
j) {
944 for (
unsigned int idb=0; idb<
_dbList.size(); ++idb) {
945 for (
unsigned int idcm=0; idcm<
_dbList[idb].dcm.size(); ++idcm) {
946 if (!
_dbList[idb].
dcm[idcm].isActive)
continue;
951 _dbList[idb].dcm[idcm].febMask = febMask;
952 int nfeb =
_dbList[idb].dcm[idcm].feb.size();
953 for (
int ifeb = 0; ifeb < nfeb; ++ifeb) {
964 getEnabledPixelCountForFEB(dcmName, ifeb);
974 std::cerr << __PRETTY_FUNCTION__ <<
" failed to get valid data" 977 int sleepTime = 1 + ((double)random()/(double)RAND_MAX)*(1 << nAttempt++);
1010 std::unique_ptr<db::Table>
t;
1011 t.reset(
new db::Table(
"RunHistory/tables/GainSetting.xml"));
1018 int gainIdx = t->GetColIndex(
"gain");
1028 std::cerr << __PRETTY_FUNCTION__ <<
"No gain setting found in DB!";
1030 LOG_WARNING(
"RunHistory") <<
"WARNING: RunHistory::DetGainSetting(): No detector gain setting\n" 1031 " info found for run " <<
_runNumber <<
", so setting gain to 1";
1036 if (t->NRow() != 1) {
1037 LOG_ERROR(
"RunHistory") << __PRETTY_FUNCTION__ <<
": failed to get 1 row from database. Aborting." <<
std::endl;
1078 std::vector<std::string> tmpDCMList;
1079 for (
unsigned int idb=0; idb<
_dbList.size(); ++idb)
1080 for (
unsigned int idcm=0; idcm<
_dbList[idb].dcm.size(); ++idcm)
1082 tmpDCMList.push_back(
_dbList[idb].
dcm[idcm].appname);
1085 sprintf(daqEnv,
"NOVADAQ_ENVIRONMENT=%s",
_detector.c_str());
1090 for (
unsigned int idb=0; idb <
_dbList.size(); ++idb) {
1091 for (
unsigned int idcm = 0; idcm <
_dbList[idb].dcm.size(); ++idcm) {
1092 if (!
_dbList[idb].
dcm[idcm].isActive)
continue;
1094 for (
int ifeb = 0; ifeb < 64; ++ifeb) {
1118 for(
auto const& locitr : gLocToFA){
1120 auto const& hl = locitr.first;
1121 auto const&
apd = locitr.second.second;
1123 if(hl._diblock >
_dbList.size() )
continue;
1124 for (
unsigned int idb=0; idb<
_dbList.size(); ++idb) {
1128 if(!
_dbList[idb].
dcm[hl._dcm-1].feb[hl._feb].hasAPD)
1131 auto pixGain =
apd._pixelGain;
1134 for(
size_t p = 0;
p < pixGain.size(); ++
p){
1135 pGain = pixGain.at(
p);
1136 _dbList[idb].dcm[hl._dcm-1].feb[hl._feb].pixelGain.at(
p) = pGain;
1140 _dbList[idb].dcm[hl._dcm-1].feb[hl._feb].gain = avGain;
1143 LOG_WARNING(
"RunHistory") <<
"average gain for APD " 1146 <<
"dcm-2-" << hl._diblock
1150 <<
" : 100 expected so default to that";
1151 _dbList[idb].dcm[hl._dcm-1].feb[hl._feb].gain = 100.;
1152 for(
size_t p = 0;
p < pixGain.size(); ++
p)
1153 _dbList[idb].
dcm[hl._dcm-1].feb[hl._feb].pixelGain.at(
p) = 100.;
1176 if (subrun < 0 || subrun > 63) {
1178 LOG_WARNING(
"RunHistory") << __PRETTY_FUNCTION__ <<
" invalid subrun " << subrun <<
". Converted to subrun " << subrun <<
std::endl;
1195 if (idb < 1)
return false;
1200 if (subrun < 0 || subrun > 63) {
1202 LOG_WARNING(
"RunHistory") << __PRETTY_FUNCTION__ <<
" invalid subrun " << subrun <<
". Converted to subrun " << subrun <<
std::endl;
1208 return ((
_subrunList[subrun].goodDiBlockMask >> (idb-1))&0
x1);
1218 std::unique_ptr<db::Table>
t;
1219 t.reset(
new db::Table(
"RunHistory/tables/DataEpochs.xml"));
1226 int nameIdx = t->GetColIndex(
"name");
1227 int rstartIdx = t->GetColIndex(
"run_start");
1228 int rendIdx = t->GetColIndex(
"run_end");
1234 bool loadFailed =
false;
1237 if (! t->Load()) loadFailed =
true;
1240 LOG_ERROR(
"RunHistory") <<
"Loading of data epoch info from database failed." <<
std::endl;
1244 int nRow = t->NRow();
1248 for (
int i=0;
i<nRow; ++
i) {
1249 t->GetRow(
i)->Col(rstartIdx).Get(runStart);
1250 if (! t->GetRow(
i)->Col(rendIdx).Get(runEnd))
1262 LOG_ERROR(
"RunHistory") <<
"Failed to find data epoch in the database!" <<
std::endl;
1294 for (
int isr=0; isr<64; ++isr)
1304 for (
int isr=1; isr<64; ++isr)
1310 bool fallback =
false;
1312 std::unique_ptr<db::Table>
t;
1315 t.reset(
new db::Table(
"RunHistory/tables/DQValidity.xml"));
1317 t.reset(
new db::Table(
"RunHistory/tables/GoodDiBlocksVsRun.xml"));
1324 int maskIdx = t->GetColIndex(
"dbmask");
1331 t->AddOrderColumn(
"inserttime");
1346 bool loadFailed =
false;
1349 if (! t->Load()) loadFailed =
true;
1351 if (loadFailed || t->NRow() == 0) {
1352 std::cerr << __PRETTY_FUNCTION__ <<
"No mask found in DB!";
1354 LOG_WARNING(
"RunHistory") << __PRETTY_FUNCTION__ <<
": RunHistory::LoadGoodDiBlockMask(): No good diblock mask";
1362 t->GetRow(0)->Col(maskIdx).Get(
_subrunList[0].goodDiBlockMask);
1363 for (
size_t isr=1; isr<64; ++isr)
1367 t->FillChanRowMap();
1369 for (
int isr=0; isr<64; ++isr) {
1372 row->
Col(maskIdx).
Get(tmask);
1381 LOG_DEBUG(
"RunHistory") << __PRETTY_FUNCTION__ <<
": Applying analysis diblock masking: ";
1382 for (
int isr=0; isr<64; ++isr) {
1385 LOG_DEBUG(
"RunHistory") <<
"mask [" << isr <<
"] unchanged from " <<
1389 LOG_INFO(
"RunHistory") <<
"mask [" << isr <<
"] modified from " 1397 LOG_ERROR(
"RunHistory") << __PRETTY_FUNCTION__ <<
"WARNING: entire detector masked off by analysis requirements!" <<
std::endl;
1398 LOG_ERROR(
"RunHistory") << __PRETTY_FUNCTION__ <<
"No analyzable detector region found for run " <<
_runNumber <<
", subrun " << isr <<
std::endl;
1418 bool diblocks[4] = {0};
1420 for(
unsigned int i = 0;
i <
_dbList.size();
i++) {
1421 if(
_dbList[
i].nInstrumentedFEBs>=175 &&
i < 3) diblocks[
_dbList[
i].num-1] =
true;
1422 if(_dbList[
i].nInstrumentedFEBs>=45 &&
i == 3) diblocks[_dbList[
i].num-1] =
true;
1424 for(
int i = 0;
i < 4;
i++) {
1425 if(diblocks[
i]) config+=1<<
i;
1430 bool diblocks[14] = {0};
1432 for(
unsigned int i = 0;
i <
_dbList.size();
i++) {
1435 for(
int i = 0;
i < 14;
i++) {
1436 if(diblocks[
i]) config+=1<<
i;
1449 for (
int iD=0;iD<14;iD++) {
1450 if (mask&(1<<(iD))) {
1471 const int NUMDIB = 14;
1473 for (
int iD=0;iD<NUMDIB;iD++) {
1474 dib[iD] = (mask&(1<<iD));
1478 int partial_answer = 0;
1480 for (
int iD=0;iD<NUMDIB;iD++) {
1482 if (iStart<0&&dib[iD]) {
1487 if (iStart>=0&&dib[iD]) {
1489 partial_answer += (1<<iD);
1492 if (iStart>=0&&(!dib[iD]||iD==NUMDIB-1)) {
1494 int curr_size = iD-iStart;
1495 if (dib[iD]&&iD==NUMDIB-1) curr_size++;
1498 answer += partial_answer;
1517 std::unique_ptr<db::Table> potTable;
1519 potTable.reset(
new db::Table(
"RunHistory/tables/POTByRun.xml"));
1526 int potIdx = potTable->GetColIndex(
"npot");
1527 int avgIdx = potTable->GetColIndex(
"avg_i");
1532 potTable->SetValidityRange(
"run",
_runNumber);
1534 if (potTable->NRow() == 0) {
1535 std::cerr << __PRETTY_FUNCTION__ <<
" No POT info found for run " 1540 potTable->GetRow(0)->Col(potIdx).Get(
_npot);
1541 potTable->GetRow(0)->Col(avgIdx).Get(
_avgpot);
1557 LOG_ERROR(
"RunHistory")<<
"LoadDAQRunHistory: failed to find the run in the runs table." <<
std::endl;
1560 else std::cerr << __PRETTY_FUNCTION__ <<
" failed to find the run in the runs table." <<
std::endl;
1566 LOG_INFO(
"RunHistory") <<
"Looks like a MC run number - assume perfect + any mask" <<
std::endl;
1574 std::unique_ptr<db::Table> runsTable;
1575 std::unique_ptr<db::Table> resTable;
1576 std::unique_ptr<db::Table> srTable;
1578 runsTable.reset(
new db::Table(
"RunHistory/tables/Runs.xml"));
1579 srTable.reset(
new db::Table(
"RunHistory/tables/Subruns.xml"));
1580 resTable.reset(
new db::Table(
"RunHistory/tables/DAQResourcesByRun.xml"));
1587 resTable->SetVerbosity(100);
1595 LOG_ERROR(
"RunHistory")<<
"RunHistory::LoadDAQRun: invalid detector name!"<<
std::endl;
1600 runsTable->SetSubSchema(
"daq");
1601 runsTable->SetValidityRange(
"run",
_runNumber);
1603 runsTable->AddExcludeCol(
std::string(
"begin_comment"));
1604 runsTable->AddExcludeCol(
std::string(
"end_comment"));
1607 if (!runsTable->Load()){
1608 LOG_ERROR(
"RunHistory")<<
"LoadDAQRunHistory: failed to load the runs table." <<
std::endl;
1610 else if (
_detector!=
"TestBeam") std::abort();
1613 if (runsTable->NRow() == 0) {
1621 if (row->
Col(runsTable->GetColIndex(
"tstart")).
Get(timeStr))
_tStart = timeStr;
1622 if (row->
Col(runsTable->GetColIndex(
"tstop")).
Get(timeStr))
_tEnd = timeStr;
1661 resTable->SetSubSchema(
"daq");
1662 resTable->SetValidityRange(
"run",
_runNumber);
1663 resTable->AddOrderColumn(
"appname");
1665 if (!resTable->Load())
1667 LOG_ERROR(
"RunHistory")<<
"LoadDAQRunHistory: failed to load the resources table." <<
std::endl;
1672 int nResources = resTable->NRow();
1673 if (nResources == 0){
1678 int rtIdx = resTable->GetColIndex(
"resource_type");
1679 int anIdx = resTable->GetColIndex(
"appname");
1680 int detIdx = resTable->GetColIndex(
"detector");
1684 for (
int i=0;
i<nResources; ++
i) {
1685 row = resTable->GetRow(
i);
1689 if (row->
Col(rtIdx).
Get(rtype)) {
1690 row->
Col(detIdx).
Get(detector);
1693 if (rtype ==
"bnevb") {
1695 row->
Col(anIdx).
Get(appname);
1699 else if (rtype ==
"dcm") {
1700 row->
Col(anIdx).
Get(appname);
1701 bool foundDiBlock =
false;
1702 short dbnum = atoi(appname.substr(6,2).c_str());
1703 short pos = atoi(appname.substr(9,2).c_str());
1713 for (
unsigned int idb=0; idb <
_dbList.size(); ++idb) {
1715 _dbList[idb].dcm[pos-1].appname = appname;
1717 _dbList[idb].dcm[pos-1].diblock = dbnum;
1718 _dbList[idb].dcm[pos-1].isActive =
true;
1719 _dbList[idb].dcm[pos-1].feb.resize(64);
1720 _dbList[idb].dcm[pos-1].nInstrumentedFEBs = 0;
1721 foundDiBlock =
true;
1725 if (!foundDiBlock) {
1727 unsigned int ndcms=12;
1763 if (i >=
int(
_dbList.size())) {
1788 for (
unsigned int i=0;
i<
_dbList.size(); ++
i)
1790 if (
_dbList[
i].hasNoAPDs)
return false;
1795 return _dbList[
i].dcm[dcmId-1].feb[ifeb].hasAPD;
1820 for (
unsigned int i=0;
i<
_dbList.size(); ++
i) {
1836 std::cerr << __PRETTY_FUNCTION__ <<
" is not yet implemented!" 1839 bool iscooled =
false;
1848 for (
unsigned int iDB=0; iDB<
_dbList.size(); ++iDB) {
1850 if (
_dbList[iDB].hasNoAPDs)
return iscooled;
1852 if (iDCM >= (
int)
_dbList[iDB].dcm.size())
return iscooled;
1854 if (!
_dbList[iDB].
dcm[iDCM].isActive)
return iscooled;
1857 if (ifeb >=
_dbList[iDB].
dcm[iDCM].
feb.size())
return iscooled;
1859 FEB& currFEB =
_dbList[iDB].dcm[iDCM].feb[ifeb];
1860 if (!currFEB.
isEnabled)
return iscooled;
1862 if ( !currFEB.
hasAPD )
return iscooled;
1897 for (
size_t iDB = 0; iDB <
_dbList.size(); ++iDB) {
1902 if (iDCM >= (
int)currDiBlock.
dcm.size())
return feb;
1904 DCM currDCM = currDiBlock.
dcm[iDCM];
1907 std::bitset<64> febSet(currDCM.
febMask);
1908 if (ifeb >= currDCM.
feb.size())
return feb;
1910 FEB currFEB = currDCM.
feb[ifeb];
1934 return this->
GetFEB(daqChan, ok);
1945 if(ok)
return feb.
gain;
1993 return std::vector<float>(32, 0.);
2024 for (
unsigned int iDB=0; iDB<
_dbList.size(); ++iDB) {
2029 if (iDCM >= (
int)
_dbList[iDB].dcm.size())
break;
2034 std::bitset<64> febSet(currDCM.
febMask);
2035 if (ifeb >= currDCM.
feb.size())
break;
2037 FEB& currFEB = currDCM.
feb[ifeb];
2038 if (!febSet[ifeb] || !currFEB.
isEnabled)
break;
2040 std::bitset<32> pixSet(currFEB.
pixelMask);
2041 if (!pixSet[ipix])
break;
2043 if ( !currFEB.
hasAPD )
break;
2077 std::unique_ptr<db::Table> dqTable(
new nova::dbi::Table(
"RunHistory/tables/DQSubrunInfo.xml"));
2080 dqTable->AddOrderColumn(
"version");
2081 dqTable->SetOrderDesc();
2083 dqTable->AddExcludeCol(
std::string(
"inserttime"));
2084 dqTable->AddExcludeCol(
std::string(
"insertuser"));
2088 std::map<std::string,int> colName = dqTable->GetColNameToIndexMap();
2092 for (
int i=0;
i<dqTable->NRow(); ++
i) {
2095 dqTable->GetRow(
i)->Col(colName[
"version"]).Get(version);
2099 dqTable->GetRow(
i)->Col(colName[
"version"]).Get(nextVersion);
2101 if (nextVersion != version)
break;
2106 dqTable->GetRow(
i)->Col(colName[
"subrun"]).Get(sri.
_subrun);
2107 dqTable->GetRow(
i)->Col(colName[
"flag"]).Get(sri.
_flag);
2108 dqTable->GetRow(
i)->Col(colName[
"miprate"]).Get(sri.
_miprate);
2109 dqTable->GetRow(
i)->Col(colName[
"ngooddb"]).Get(sri.
_ngooddb);
2110 dqTable->GetRow(
i)->Col(colName[
"numslc"]).Get(sri.
_numslc);
2111 dqTable->GetRow(
i)->Col(colName[
"trkfrac"]).Get(sri.
_trkfrac);
2123 std::map<geo::OfflineChan,std::vector<ChanInfo_t> >::iterator
it =
_chanInfo.begin();
2125 std::vector<ChanInfo_t>& ci = it->second;
2127 for (
unsigned int j=0;
j<ci.size(); ++
j)
2152 for (; i<cis.size() && cis[
i].tstart<
t; ++
i);
2154 return cis[i-1].occ;
2166 for (; i<cis.size() && cis[
i].tstart<
t; ++
i);
2168 return cis[i-1].coinc;
2195 if (isr < 0 || isr >
_nsubrun)
return 0;
2196 if (isr == 0)
return this->
TStart();
2203 if (isr < 0 || isr >
_nsubrun)
return 0;
2204 if (isr == _nsubrun-1)
return this->
TStop();
2225 tEnd =
"2000-01-01 00:00:00";
2245 for (
unsigned int i=0;
i<
_dbList.size(); ++
i)
2246 for (
unsigned int j=0;
j<
_dbList[
i].dcm.size(); ++
j)
2278 for (
int isr=0; isr<
_nsubrun; ++isr) {
2309 std::map<uint32_t, APDInfo> apdinfomap;
2310 std::map<std::string, std::vector<float> > apdgains;
2312 std::list<std::string> notInstalledAPD;
2314 std::unique_ptr<db::Table> hwTable;
2336 SQL =
"select right(gain.apd_id, 7), gain.batch_no, gain.target_degc, gain.pixel_col, gain.pixel_row, gain.pixel_m from public.apd_pixel_m gain where gain.target_degc<0 ORDER BY right(gain.apd_id, 7) ASC, gain.batch_no DESC, gain.target_degc ASC, gain.pixel_col ASC, gain.pixel_row ASC";
2344 int numRows = PQntuples(res);
2347 for(
int r = 0;
r < numRows; ++
r){
2349 apdSN = PQgetvalue(res,
r, 0);
2350 batch = std::atoi(PQgetvalue(res,
r, 1));
2354 if(apdgains.count(apdSN) < 1){
2355 apdgains[apdSN] = std::vector<float>(32,100.);
2357 while(apdSN.compare(PQgetvalue(res,
r, 0)) == 0 &&
2358 batch == std::atoi(PQgetvalue(res,
r, 1)) ){
2359 colStr = PQgetvalue(res,
r, 3);
2360 row = std::atoi(PQgetvalue(res,
r, 4)) - 1;
2362 if (colStr.compare(
"B") == 0) col = 8;
2363 else if(colStr.compare(
"C") == 0) col = 16;
2364 else if(colStr.compare(
"D") == 0) col = 24;
2371 apdgains[apdSN][pixel] = std::atof(PQgetvalue(res,
r, 5));
2381 SQL =
"select right(astat.apd_id, 7), astat.batch_no, astat.target_degc, astat.vr, bi.barcoded_item_id, bi.date_added, mac.module, mac.connection_id, nc.date_removed from public.apd_stats astat, ashriverprod_factory.barcoded_item bi, ashriverprod_factory.module_apd_connection mac, ashriverprod_factory.nova_connection nc ";
2382 SQL +=
"where right(bi.barcode,7)=right(astat.apd_id,7) and bi.glassfish_discriminator='apd' and mac.apd=bi.barcoded_item_id and nc.connection_id=mac.connection_id and bi.date_added < '";
2384 SQL +=
"' and (nc.date_removed is NULL or nc.date_removed > '";
2386 SQL +=
"') and (bi.date_removed is NULL or bi.date_removed > '";
2392 SQL +=
"ORDER BY right(astat.apd_id, 7) ASC, astat.target_degc ASC";
2415 numRows = PQntuples(res);
2417 LOG_DEBUG(
"RunHistory") <<
"Found " << numRows <<
" apds in the db";
2419 for(
int r = 0;
r < numRows; ++
r){
2422 date = PQgetvalue(res,
r, 5);
2423 TTimeStamp ts(std::atoi(date.substr(0,4).c_str()),
2424 std::atoi(date.substr(5,2).c_str()),
2425 std::atoi(date.substr(8,2).c_str()),
2426 std::atoi(date.substr(12,2).c_str()),
2427 std::atoi(date.substr(15,2).c_str()),
2428 std::atoi(date.substr(18,2).c_str()));
2430 apdi.
_sn = PQgetvalue(res,
r, 0);
2431 apdi.
_batch = std::atoi(PQgetvalue(res,
r, 1));
2432 apdi.
_temp = std::atoi(PQgetvalue(res,
r, 2));
2433 apdi.
_voltage = std::atof(PQgetvalue(res,
r, 3));
2434 apdi.
_barcode = std::atoi(PQgetvalue(res,
r, 4));
2436 apdi.
_module = std::atoi(PQgetvalue(res,
r, 6));
2437 apdi.
_modcon = std::atoi(PQgetvalue(res,
r, 7));
2439 if(apdgains.count(apdi.
_sn) > 0)
2447 if(apdinfomap.count(apdi.
_module) > 0){
2449 prevAPD = apdinfomap.at(apdi.
_module);
2453 apdinfomap[apdi.
_module] = apdi;
2456 apdinfomap[apdi.
_module] = apdi;
2472 << apdinfomap.size()
2473 <<
" apds were installed" 2474 <<
"print out info for all APDs";
2476 hwTable->CloseConnection();
2489 std::list<std::pair<FEBInfo, APDInfo>> febtoapd;
2490 std::map<uint32_t, FEBInfo> febinfomap;
2492 std::unique_ptr<db::Table> hwTable;
2498 LOG_ERROR(
"RunHistory")<<
"could not extablish table connection for detector"<<
std::endl;
2510 std::map<HardwareLocation, std::pair<FEBInfo, APDInfo>> htol;
2515 SQL =
"select bi.barcode, febtest.hvfitintercept, febtest.hvfitslope, bi.barcoded_item_id, bi.date_added, mfc.module, mfc.connection_id, nc.date_removed from ashriverprod_factory.barcoded_item bi, ashriverprod_factory.module_feb_connection mfc, ashriverprod_factory.nova_connection nc, public.feb_test_summary febtest where bi.barcode=overlay(overlay(febtest.febsn placing '.' from 5 for 1) placing '.' from 7 for 1) and bi.glassfish_discriminator='feb' and mfc.feb=bi.barcoded_item_id and nc.connection_id=mfc.connection_id and bi.date_added < '";
2517 SQL +=
"' and (nc.date_removed is NULL or nc.date_removed > '";
2519 SQL +=
"') and (bi.date_removed is NULL or bi.date_removed > '";
2521 SQL +=
"') ORDER BY bi.date_added DESC";
2528 int nRow = PQntuples(res);
2529 for(
int r = 0;
r < nRow; ++
r){
2532 TTimeStamp ts(std::atoi(date.substr(0,4).c_str()),
2533 std::atoi(date.substr(5,2).c_str()),
2534 std::atoi(date.substr(8,2).c_str()),
2535 std::atoi(date.substr(12,2).c_str()),
2536 std::atoi(date.substr(15,2).c_str()),
2537 std::atoi(date.substr(18,2).c_str()));
2540 febi.
_sn = PQgetvalue(res,
r, 0);
2541 febi.
_intercept = std::atof(PQgetvalue(res,
r, 1));
2542 febi.
_slope = std::atof(PQgetvalue(res,
r, 2));
2543 febi.
_barcode = std::atoi(PQgetvalue(res,
r, 3));
2544 febi.
_module = std::atoi(PQgetvalue(res,
r, 5));
2545 febi.
_modcon = std::atoi(PQgetvalue(res,
r, 6));
2553 if(febinfomap.count(febi.
_module) > 0){
2556 febinfomap[febi.
_module] = febi;
2559 febinfomap[febi.
_module] = febi;
2565 <<
"there are " << febinfomap.size()
2566 <<
" febs installed and put in the map and " 2567 << apdinfomap.size() <<
" apds";
2570 SQL =
"select btrim(fcom.location1, 'DIBLK:') diblk, btrim(fcom.position1, 'DCM:') dcm, btrim(fcom.port1,'PRT:') feb, mod.block, mod.layer, mod.position_in_layer, mod.barcoded_item_id from public.feb_comm_cables fcom, ashriverprod_factory.module mod where (mod.block=CAST(btrim(fcom.location2,'BLK:') AS INT) and mod.layer=CAST(btrim(fcom.position2,'PLN:') AS INT) and mod.position_in_layer=CAST(btrim(fcom.port2,'POS:') AS INT)) ORDER BY diblk ASC, dcm ASC, feb ASC";
2577 for(
int r = 0;
r < PQntuples(res); ++
r){
2580 hl.
_diblock = std::atoi(PQgetvalue(res,
r, 0));
2581 hl.
_dcm = std::atoi(PQgetvalue(res,
r, 1));
2582 hl.
_feb = std::atoi(PQgetvalue(res,
r, 2));
2583 hl.
_block = std::atoi(PQgetvalue(res,
r, 3));
2584 hl.
_layer = std::atoi(PQgetvalue(res,
r, 4));
2585 hl.
_layerPos = std::atoi(PQgetvalue(res,
r, 5));
2586 mod = std::atoi(PQgetvalue(res,
r, 6));
2589 if(febinfomap.count(mod) > 0){
2590 std::pair<FEBInfo, APDInfo> hwpair;
2591 hwpair.first = febinfomap[
mod];
2594 if(apdinfomap.count(mod) > 0)
2595 hwpair.second = apdinfomap[mod];
2599 <<
" no APD found for " 2600 << hwpair.first <<
" installed at " << hl;
2611 <<
"There are " << febinfomap.size()
2612 <<
" febs in the db, and " << htol.size()
2613 <<
" are connected to a harward location" <<
std::endl 2614 <<
"There are " << apdinfomap.size() <<
" apds installed";
2622 hwTable->CloseConnection();
2641 int missingHardware = 0;
2642 for (
int idb=0; idb<14; ++idb) {
2643 for (
unsigned int idcm=0; idcm<12; ++idcm) {
2644 for (
int j=0;
j<64; ++
j) {
2654 LOG_DEBUG(
"RunHistory") << hl <<
" is not in the location map";
2660 LOG_DEBUG(
"RunHistory") <<
"there are " << missingHardware <<
" locations without hardware";
2672 unsigned int fNDiblocks = 14;
2673 unsigned int fNDCMs = 12;
2680 for (
unsigned int ndib = 1; ndib<=fNDiblocks; ndib++) {
2694 for(
unsigned int ndcm = 1; ndcm <= fNDCMs; ndcm++) {
static std::string GetName(int id)
#define LOG_DEBUG(stream)
std::vector< DQSubrunInfo > _dqSRInfo
float _intercept
intercept for voltage setting
::xsd::cxx::tree::date< char, simple_type > date
diblock
print "ROW IS " print row
Column & Col(int i)
Find index of column with name. Suitable for passing to Col.
uint32_t _layerPos
position in the layer
bool IsDiBlockFullyInstrumented(int idb)
returns true if nInstrumentedFEBs in diblock (which counts FEBs that are instrumented, active, and unmasked only) is >= 700
time_t SubrunTStop(int isr)
int NAnalysisChannels(int sr=0)
bool getFEBEnableMask(const std::string &dcmName, int64_t &febMask)
bool isActive
if it was active in run according to DAQ
void SetDetector(novadaq::cnv::DetId det)
uint32_t _modcon
module connection id
uint32_t pixel_t
Type for physical pixel on APD.
bool LoadPixelInfo(int nAttempt=0)
Float_t x1[n_points_granero]
static bool TimeAsStringToTime_t(std::string ts, time_t &t)
PGresult * PerformPGQuery(std::string const &query, std::unique_ptr< Table > const &hwTable)
float GetPixelGain(geo::OfflineChan const &, bool &)
std::vector< float > _pixelGain
pixel gain map for APD
bool DetFineTimingSetting() const
std::map< HardwareLocation, std::pair< FEBInfo, APDInfo > > gLocToFA
DiBlock GetDiBlock(int i, bool loadAll=true)
get ith diblock is RH list (which only includes diblocks with activity), starting with i=0...
int ApplyAnalysisDiBlockMask(const int mask) const
converts normal mask to analysis rules mask (any continuous chunk of four or more diblocks kept) ...
bool getTemperatureEnable(const std::string &dcmName, const int &febId, bool &enableFlag)
cout<< "Opened file "<< fin<< " ixs= "<< ixs<< endl;if(ixs==0) hhh=(TH1F *) fff-> Get("h1")
time_t SubrunTStart(int isr)
std::vector< DQSubrunInfo > GetDQSubrunInfo()
void MapHardwareToLocation()
cell_t getCell(lchan logicalchan) const
Decode the cell number from an lchan.
std::vector< BNEVB > _bnevbList
lchan encodeLChan(int detId, plane_t plane, cell_t cell) const
uint32_t _diblock
Diblock.
uint32_t _batch
APD batch number.
std::vector< int16_t > pixelThresh
std::vector< float > pixelGain
each entry is the gain for the pixel with the number of the index
bool getThresholdsForFEB(const std::string &dcmName, const int &febId, std::vector< int16_t > &thresholdList)
void SetRunNumber(int run)
std::string TStopAsString()
bool _analysisDiBlockMasking
bool getPixelEnableMask(const std::string &dcmName, const int &febId, int32_t &pixelMask)
int ToDBValidityChan() const
Far Detector at Ash River, MN.
bool _abortIfMissingRunInDB
uint32_t _modcon
module connection id
int GetPedestal(const geo::OfflineChan &, bool &)
std::string _badChanVersion
bool SortDiBlocks(RunHistory::DiBlock db1, RunHistory::DiBlock db2)
static DAQChannelMap * getInstance(int detID)
void SetChanInfo(geo::OfflineChan, float, float, time_t)
std::string DiBlockMaskToString(const int mask) const
uint32_t _layer
layer in the block
std::map< int, int > _diblockIndex
bool LoadFEBMasksFromDAQDB()
float _slope
slope for voltage setting
uint32_t _module
module APD is connected to
bool IsCooled(const geo::OfflineChan &)
std::vector< DiBlock > _dbList
static bool DetIdOk(int id)
Near Detector in the NuMI cavern.
std::map< uint32_t, APDInfo > PullAPDInfoFromDB()
uint32_t feb_t
Type for DCM link port. Counts from 0.
nova::dbi::DataType _dataType
float GetGain(const geo::OfflineChan &, bool &)
Hold drift constants from current run.
void InvalidateCaches()
Call at new run/detector etc.
void SetIsBad(geo::OfflineChan, bool, time_t)
uint32_t _module
module FEB is connected to
bool febIsEnabled(const std::string &dcmName, const int &febId)
bool getTemperature(const std::string &dcmName, const int &febId, int &temperature)
std::vector< int > _fdRHCRunStart
#define LOG_WARNING(category)
bool hasAPD
true if instrumented and active in run, and not masked
unsigned short Plane() const
uint32_t dcm_id_t
Type for DCM number, counts from 1.
static int GetId(std::string name)
bool IsGoodDiBlock(int idb, int subrun=-1)
pixel_t getPixel(dchan daqchan) const
Decode the pixel id from a dchan.
std::map< geo::OfflineChan, std::vector< BadChan_t > > _badChan
float Coincidence(geo::OfflineChan, time_t)
std::vector< int > _fdRHCRunStop
unsigned short Cell() const
std::vector< Subrun > _subrunList
uint32_t _block
installed block
bool IsBad(geo::OfflineChan, time_t)
int NAnalysisDiBlocks(int sr=0)
std::vector< int > _ndRHCRunStart
std::vector< int > _ndRHCRunStop
FEB GetFEB(geo::OfflineChan const &, bool &)
bool HasAPD(const geo::OfflineChan &)
basic check for if a channel should be live. Used by BadChannels. Checks if channel has instrumented ...
int32_t _temp
operating temperature
std::vector< float > GetPixelGains(geo::OfflineChan const &, bool &)
plane_t getPlane(lchan logicalchan) const
Decode the plane number from an lchan.
std::map< geo::OfflineChan, std::vector< ChanInfo_t > > _chanInfo
uint32_t diblock_t
Type for diblocks and blocks.
bool LoadGoodDiBlockMask()
dcm_id_t getDCM(dchan daqchan) const
Decode the dcm ID from a dchan.
bool getVoltage(const std::string &dcmName, const int &febId, int ®ulatorSetting)
dchan encodeDChan(int detID, diblock_t diblock, dcm_id_t dcm, feb_t feb, pixel_t pixel) const
virtual fiber_t computeFiberInModule(dchan daqchan) const =0
Which fiber does this dchan readout?
bool LoadDCSAlarms(int subrun=-1)
uint32_t _barcode
barcoded_item_id from barcoded_item table
int GoodDiBlockMask(int subrun=-1, bool reload=false)
bool _getDiBlockMaskFromCondb
float Occupancy(geo::OfflineChan, time_t)
uint32_t dchan
< DAQ Channel Map Package
int nInstrumentedFEBs
number of FEBs that were instrumented and active in run and not masked
void SetDBInfo(std::string dbname="", std::string dbhost="", std::string user="", std::string port="")
int nInstrumentedFEBs
number of FEBs that were intrumented and active in run and not masked
static bool DetNameOk(std::string name)
float _voltage
operating voltage
uint32_t _barcode
barcode id from barcoded_item table
diblock_t getDiBlock(dchan daqchan) const
Decode the diblock ID from a dchan.
bool hasValidData() const
std::map< HardwareLocation, std::pair< FEBInfo, APDInfo > > PullFEBInfoFromDB(std::map< uint32_t, APDInfo > apdinfomap)
#define LOG_ERROR(stream)
std::string TStartAsString()
bool hasValidData() const
int GetThreshold(const geo::OfflineChan &, bool &)
int32_t _detid
Detector ID.
feb_t getFEB(dchan daqchan) const
Decode the feb id from a dchan.