22 for (
const auto& it : pids) {
35 if (dps.size() == 0) {
41 LOG(
debug) <<
"\n\n\nProcessing new DCS DP map\n-----------------";
45 mFirstTime = mStartValidity;
50 for (
const auto& dp : dps) {
51 const auto& el = mPids.find(dp.id);
54 if (el == mPids.end()) {
55 LOG(info) <<
"DP " << dp.id <<
"Not found, will not be processed";
62 const std::string_view alias(dp.id.get_alias());
63 const auto detectorId = alias.substr(0, 4);
64 const auto transparencyId = alias.substr(0, 22);
67 if (transparencyId == TRANS_ID) {
69 }
else if (detectorId == HMPID_ID) {
72 LOG(warn) <<
"Missing data point: " << alias;
79void HMPIDDCSProcessor::processHMPID(
const DPCOM& dp)
82 const auto hmpidString = alias.substr(alias.length() - 8);
84 if (hmpidString == TEMP_IN_ID) {
86 LOG(info) <<
"Temperature_in DP: " << dp;
89 }
else if (hmpidString == TEMP_OUT_ID) {
91 LOG(info) <<
"Temperature_out DP: " << dp;
94 }
else if (hmpidString == HV_ID) {
96 LOG(info) <<
"HV DP: " << dp;
99 }
else if (hmpidString == ENV_PRESS_ID) {
101 LOG(info) <<
"Environment Pressure DP: " << dp;
104 }
else if (hmpidString == CH_PRESS_ID) {
106 LOG(info) <<
"Chamber Pressure DP: " << dp;
110 LOG(warn) <<
"Missing data point: " << dp;
116void HMPIDDCSProcessor::processTRANS(
const DPCOM& dp)
118 const auto& dpid = dp.
id;
119 const std::string alias(dpid.get_alias());
120 const auto transparencyString = alias.substr(alias.length() - 9);
125 const int num = dig1 * 10 + dig2;
127 if (dig1 == -1 || dig2 == -1) {
128 LOG(warn) <<
"digits in string invalid" << dig1 <<
" " << dig2;
132 if (num < 0 || num > 29) {
133 LOG(warn) <<
"num out of range " <<
num;
137 if (alias.substr(alias.length() - 10) == WAVE_LEN_ID) {
138 waveLenVec[
num].emplace_back(dp);
140 LOG(info) <<
"WAVE_LEN_ID DP: " << dp;
142 }
else if (transparencyString == FREON_CELL_ID) {
143 freonCellVec[
num].emplace_back(dp);
145 LOG(info) <<
"FREON_CELL_ID DP: " << dp;
147 }
else if (transparencyString == ARGON_CELL_ID) {
149 LOG(info) <<
"ARGON_CELL_ID DP: " << dp;
151 argonCellVec[
num].emplace_back(dp);
152 }
else if (transparencyString == REF_ID) {
153 if (alias.substr(alias.length() - 14) == ARGON_REF_ID) {
155 LOG(info) <<
"ARGON_REF_ID DP: " << dp;
157 argonRefVec[
num].emplace_back(dp);
158 }
else if (alias.substr(alias.length() - 14) == FREON_REF_ID) {
159 freonRefVec[
num].emplace_back(dp);
161 LOG(info) <<
"FREON_REF_ID DP: " << dp;
164 LOG(warn) <<
"Missing Data point: " << dp;
167 LOG(warn) <<
"Missing Data point: " << dp;
175void HMPIDDCSProcessor::fillEnvPressure(
const DPCOM& dpcom)
177 auto& dpid = dpcom.
id;
181 if (
type == DeliveryType::DPVAL_DOUBLE) {
182 dpVecEnv.emplace_back(dpcom);
184 LOG(warn) <<
"Invalid Datatype for Env Pressure";
189void HMPIDDCSProcessor::fillChPressure(
const DPCOM& dpcom)
191 auto& dpid = dpcom.
id;
194 if (
type == DeliveryType::DPVAL_DOUBLE) {
198 if (chNum < 7 && chNum >= 0) {
199 dpVecCh[chNum].emplace_back(dpcom);
201 LOGP(warn,
"Chamber Number out of range for Pressure P{}: ", chNum);
202 const std::string inputString(dpid.get_alias());
203 char stringPos = inputString[indexChPr];
206 LOGP(warn,
"Not correct datatype for Pressure");
211void HMPIDDCSProcessor::fillHV(
const DPCOM& dpcom)
213 auto& dpid = dpcom.
id;
216 if (
type == DeliveryType::DPVAL_DOUBLE) {
220 if (chNum < 7 && chNum >= 0) {
221 if (secNum < 6 && secNum >= 0) {
222 dpVecHV[6 * chNum + secNum].emplace_back(dpcom);
224 LOGP(warn,
"Sector Number out of range for High Voltage HV{}{}", chNum, secNum);
227 LOGP(warn,
"Chamber Number out of range for High Voltage HV{}{}", chNum, secNum);
230 LOGP(warn,
"Not correct datatype for High Voltage");
235void HMPIDDCSProcessor::fillTempIn(
const DPCOM& dpcom)
237 auto& dpid = dpcom.
id;
240 if (
type == DeliveryType::DPVAL_DOUBLE) {
245 if (chNum < 7 && chNum >= 0) {
246 if (radNum < 3 && radNum >= 0) {
247 dpVecTempIn[3 * chNum + radNum].emplace_back(dpcom);
249 LOGP(warn,
"Radiator Number out of range for TempIn Tin{}{}", chNum, radNum);
252 LOGP(warn,
"Chamber Number out of range for TempIn Tin{}{}", chNum, radNum);
255 LOGP(warn,
"Not correct datatype for TempIn");
260void HMPIDDCSProcessor::fillTempOut(
const DPCOM& dpcom)
262 auto& dpid = dpcom.
id;
265 if (
type == DeliveryType::DPVAL_DOUBLE) {
270 if (chNum < 7 && chNum >= 0) {
271 if (radNum < 3 && radNum >= 0) {
272 dpVecTempOut[3 * chNum + radNum].emplace_back(dpcom);
275 LOGP(warn,
"Radiator Number out of range for TempOut Tout{}{}", chNum, radNum);
278 LOGP(warn,
"Chamber Number out of range for TempOut Tout{}{}", chNum, radNum);
281 LOGP(warn,
"Not correct datatype for TempOut");
288double HMPIDDCSProcessor::procTrans()
290 for (
int i = 0;
i < 30;
i++) {
298 photEn = calculatePhotonEnergy(
i);
302 LOG(warn) <<
"photon energy out of range" << photEn;
303 lambda = arrWaveLenDefault[
i];
304 photEn = nm2eV / lambda;
312 TransparencyDpInfo refArgonDP = dpVector2Double(argonRefVec[
i],
"ARGONREF",
i);
313 if (refArgonDP.isDpValid ==
false) {
316 refArgon = refArgonDP.dpVal;
320 TransparencyDpInfo cellArgonDP = dpVector2Double(argonCellVec[
i],
"ARGONCELL",
i);
321 if (cellArgonDP.isDpValid ==
false) {
324 cellArgon = cellArgonDP.dpVal;
328 TransparencyDpInfo refFreonDP = dpVector2Double(freonRefVec[
i],
"C6F14REFERENCE",
i);
329 if (refFreonDP.isDpValid ==
false) {
332 refFreon = refFreonDP.dpVal;
336 TransparencyDpInfo cellFreonDP = dpVector2Double(freonCellVec[
i],
"C6F14CELL",
i);
337 if (cellFreonDP.isDpValid ==
false) {
340 cellFreon = cellFreonDP.dpVal;
344 bool isEvalCorrOk = evalCorrFactor(refArgon, cellArgon, refFreon, cellFreon, photEn,
i);
355 eMean = sEnergProb / sProb;
357 LOGP(warn,
" sProb < 0 --> Default E mean used! ");
363 LOGP(warn,
"eMean out of range ({}) --> Default E mean used! ", eMean);
382double HMPIDDCSProcessor::calculatePhotonEnergy(
int i)
385 if (waveLenVec[
i].
size() == 0) {
386 LOGP(warn,
"No Data Point values for HMP_TRANPLANT_MEASURE_{}_WAVELENGTH --> Default wavelength used for iteration procTrans{}",
i,
i);
388 lambda = arrWaveLenDefault[
i];
389 return nm2eV / lambda;
392 const DPCOM& dp = (waveLenVec[
i])[0];
395 if (dp.
id.
get_type() == DeliveryType::DPVAL_DOUBLE) {
396 lambda = o2::dcs::getValue<double>(dp);
398 LOGP(warn,
"DP type is {}", (
int)dp.
id.
get_type());
399 LOGP(warn,
"Not correct datatype for HMP_TRANPLANT_MEASURE_{}_WAVELENGTH --> Default wavelength used for iteration procTrans{}",
i,
i);
400 lambda = arrWaveLenDefault[
i];
404 if (lambda < 150. || lambda > 230.) {
405 LOGP(warn,
"Wrong value for (lambda out of range) HMP_TRANPLANT_MEASURE_{}_WAVELENGTH --> Default wavelength used for iteration procTrans{}",
i,
i);
406 lambda = arrWaveLenDefault[
i];
411 photEn = nm2eV / lambda;
418TransparencyDpInfo HMPIDDCSProcessor::dpVector2Double(
const std::vector<DPCOM>& dpVec,
419 const char* dpString,
int i)
422 TransparencyDpInfo transDpInfo;
423 if (dpVec.size() == 0) {
424 LOGP(warn,
"No Data Point values for HMP_TRANPLANT_MEASURE_{}_{}---> Default E mean used!",
429 const DPCOM& dp = dpVec[0];
431 if (dp.
id.
get_type() == DeliveryType::DPVAL_DOUBLE) {
432 transDpInfo.dpVal = o2::dcs::getValue<double>(dp);
433 transDpInfo.isDpValid =
true;
435 LOGP(warn,
"Not correct datatype for HMP_TRANPLANT_MEASURE_{}_{} -----> Default E mean used!",
442bool HMPIDDCSProcessor::evalCorrFactor(
const double& dRefArgon,
const double& dCellArgon,
const double& dRefFreon,
443 const double& dCellFreon,
const double& dPhotEn,
const int&
i)
459 if (dRefArgon == -999 || dCellArgon == -999 || dRefFreon == -999 || dCellFreon == -999) {
460 LOGP(warn,
"One of the Phototube-currents was not assigned --> Default E mean used!");
464 if (dRefFreon * dRefArgon > 0) {
465 aTransRad = TMath::Power((dCellFreon / dRefFreon) /
466 (dCellArgon / dRefArgon) * aCorrFactor[
i],
469 LOGP(warn,
"dRefFreon*dRefArgon<0 --> Default E mean used! dRefFreon = {} | dRefArgon = {}", dRefFreon, dRefArgon);
486 aTotConvolution = aTransRad * aTransSiO2 * aTransGap * aCsIQE;
488 sEnergProb += aTotConvolution * dPhotEn;
489 double sProbPrev = sProb;
490 sProb += aTotConvolution;
500std::unique_ptr<TF1> HMPIDDCSProcessor::finalizeEnvPressure()
502 std::unique_ptr<TF1> pEnv;
503 if (dpVecEnv.size() != 0) {
505 envPrFirstTime = getMinTime(dpVecEnv);
506 envPrLastTime = getMaxTime(dpVecEnv);
508 int cntEnvPressure = 0;
509 std::unique_ptr<TGraph> pGrPenv;
510 pGrPenv.reset(
new TGraph);
512 for (
const DPCOM& dp : dpVecEnv) {
513 auto dpVal = o2::dcs::getValue<double>(dp);
515 pGrPenv->SetPoint(cntEnvPressure++,
time, dpVal);
520 if (cntEnvPressure <= 0) {
521 LOGP(warn,
"No entries in Environment Pressure");
522 }
else if (pGrPenv ==
nullptr) {
523 LOGP(warn,
"NullPtr in Environment Pressure");
524 }
else if (cntEnvPressure == 1) {
525 pGrPenv->GetPoint(0, xP, yP);
527 new TF1(
"Penv", Form(
"%f", yP), envPrFirstTime, envPrLastTime));
529 pEnv.reset(
new TF1(
"Penv",
"1000+x*[0]", envPrFirstTime, envPrLastTime));
530 pGrPenv->Fit(
"Penv",
"Q");
533 LOG(warn) << Form(
"No entries in environment pressure Penv");
539std::unique_ptr<TF1> HMPIDDCSProcessor::finalizeChPressure(
int iCh)
541 std::unique_ptr<TF1> pCh;
542 if (dpVecCh[iCh].
size() != 0) {
545 std::unique_ptr<TGraph> pGrP;
546 pGrP.reset(
new TGraph);
548 chPrFirstTime = getMinTime(dpVecCh[iCh]);
549 chPrLastTime = getMaxTime(dpVecCh[iCh]);
551 for (
const DPCOM& dp : dpVecCh[iCh]) {
552 auto dpVal = o2::dcs::getValue<double>(dp);
554 pGrP->SetPoint(cntChPressure++,
time, dpVal);
559 if (pGrP ==
nullptr || cntChPressure <= 0) {
560 LOGP(warn,
"nullptr in chamber-pressure for P{}", iCh);
561 }
else if (cntChPressure == 1) {
562 pGrP->GetPoint(0, xP, yP);
563 (pCh).reset(
new TF1(Form(
"P%i", iCh), Form(
"%f", yP), chPrFirstTime,
566 (pCh).reset(
new TF1(Form(
"P%i", iCh),
"[0] + x*[1]", chPrFirstTime,
568 pGrP->Fit(Form(
"P%i", iCh),
"Q");
571 LOGP(warn,
"No entries in chamber-pressure for P{}", iCh);
577bool HMPIDDCSProcessor::finalizeTempOut(
int iCh,
int iRad)
579 if (dpVecTempOut[3 * iCh + iRad].
size() != 0) {
582 auto minTime = getMinTime(dpVecTempOut[3 * iCh + iRad]);
583 auto maxTime = getMaxTime(dpVecTempOut[3 * iCh + iRad]);
585 if (iCh == 0 && iRad == 0) {
586 mTimeEMean.first = minTime;
587 mTimeEMean.last = maxTime;
590 std::unique_ptr<TGraph> pGrTOut;
591 pGrTOut.reset(
new TGraph);
593 for (
const DPCOM& dp : dpVecTempOut[3 * iCh + iRad]) {
594 auto dpVal = o2::dcs::getValue<double>(dp);
596 pGrTOut->SetPoint(cntTOut++,
time, dpVal);
599 std::unique_ptr<TF1> pTout;
601 new TF1(Form(
"Tout%i%i", iCh, iRad),
"[0]+[1]*x", minTime, maxTime));
603 if (pTout ==
nullptr || pGrTOut ==
nullptr || cntTOut <= 0) {
604 LOGP(warn,
"NullPtr in Temperature out Tout{}{}", iCh, iRad);
606 }
else if (cntTOut == 1) {
607 pGrTOut->GetPoint(0, xP, yP);
608 pTout->SetParameter(0, yP);
609 pTout->SetParameter(1, 0);
611 pGrTOut->Fit(Form(
"Tout%i%i", iCh, iRad),
"R");
617 if (pTout !=
nullptr && pGrTOut !=
nullptr && cntTOut > 0) {
618 pTout->SetTitle(Form(
"Temp-Out Fit Chamber%i Radiator%i; Time [ms];Temp [C]", iCh, iRad));
619 arNmean[6 * iCh + 2 * iRad + 1] = *(pTout.get());
622 LOGP(warn,
"NullPtr in Temperature out Tout{}{}", iCh, iRad);
626 LOGP(warn,
"No entries in Temperature out Tout{}{}", iCh, iRad);
632bool HMPIDDCSProcessor::finalizeTempIn(
int iCh,
int iRad)
634 if (dpVecTempIn[3 * iCh + iRad].
size() != 0) {
637 auto minTime = getMinTime(dpVecTempIn[3 * iCh + iRad]);
638 auto maxTime = getMaxTime(dpVecTempIn[3 * iCh + iRad]);
640 std::unique_ptr<TGraph> pGrTIn;
641 pGrTIn.reset(
new TGraph);
643 for (
const DPCOM& dp : dpVecTempIn[3 * iCh + iRad]) {
644 auto dpVal = o2::dcs::getValue<double>(dp);
646 pGrTIn->SetPoint(cntTin++,
time, dpVal);
649 std::unique_ptr<TF1> pTin;
651 new TF1(Form(
"Tin%i%i", iCh, iRad),
"[0]+[1]*x", minTime, maxTime));
653 if (pTin ==
nullptr || pGrTIn ==
nullptr || cntTin <= 0) {
654 LOGP(warn,
"NullPtr in Temperature in Tin{}{}", iCh, iRad);
656 }
else if (cntTOut == 1) {
657 pGrTIn->GetPoint(0, xP, yP);
658 pTin->SetParameter(0, yP);
659 pTin->SetParameter(1, 0);
661 pGrTIn->Fit(Form(
"Tin%i%i", iCh, iRad),
"R");
667 if (pTin !=
nullptr && pGrTIn !=
nullptr && cntTin > 0) {
668 pTin->SetTitle(Form(
"Temp-In Fit Chamber%i Radiator%i; Time [ms];Temp [C]", iCh, iRad));
669 arNmean[6 * iCh + 2 * iRad] = *(pTin.get());
672 LOGP(warn,
"NullPtr in Temperature in Tin{}{}", iCh, iRad);
676 LOGP(warn,
"No entries in Temperature in Tin{}{}", iCh, iRad);
682std::unique_ptr<TF1> HMPIDDCSProcessor::finalizeHv(
int iCh,
int iSec)
684 std::unique_ptr<TF1> pHvTF;
685 if (dpVecHV[3 * iCh + iSec].
size() != 0) {
687 std::unique_ptr<TGraph> pGrHV;
688 pGrHV.reset(
new TGraph);
691 hvFirstTime = getMinTime(dpVecHV[3 * iCh + iSec]);
692 hvLastTime = getMaxTime(dpVecHV[3 * iCh + iSec]);
694 for (
const DPCOM& dp : dpVecHV[3 * iCh + iSec]) {
695 auto dpVal = o2::dcs::getValue<double>(dp);
697 pGrHV->SetPoint(cntHV++,
time, dpVal);
702 if (pGrHV ==
nullptr || cntHV <= 0) {
703 LOGP(warn,
"nullptr in High Voltage for HV{}{}", iCh, iSec);
704 }
else if (cntHV == 1) {
705 pGrHV->GetPoint(0, xP, yP);
706 (pHvTF).reset(
new TF1(Form(
"HV%i%i", iCh, iSec), Form(
"%f", yP),
707 hvFirstTime, hvLastTime));
709 (pHvTF).reset(
new TF1(Form(
"HV%i%i", iCh, iSec),
"[0]+x*[1]",
710 hvFirstTime, hvLastTime));
711 pGrHV->Fit(Form(
"HV%i%i", iCh, iSec),
"Q");
714 LOGP(warn,
"No entries in High Voltage for HV{}{}", iCh, iSec);
725 LOG(info) <<
"finalize=================================== ";
726 std::unique_ptr<TF1> pEnv = finalizeEnvPressure();
727 for (
int iCh = 0; iCh < 7; iCh++) {
729 std::unique_ptr<TF1> pChPres = finalizeChPressure(iCh);
732 for (
int iRad = 0; iRad < 3; iRad++) {
735 bool isTempInValid = finalizeTempIn(iCh, iRad);
737 if (isTempInValid ==
false) {
738 LOGP(warn,
"Tin{}{} not valid! Setting default TF1!", iCh, iRad);
740 std::unique_ptr<TF1> pTinDefault;
741 pTinDefault.reset(
new TF1());
742 setDefault(pTinDefault.get(),
true);
746 arNmean[6 * iCh + 2 * iRad] = *(pTinDefault.get());
750 bool isTempOutValid = finalizeTempOut(iCh, iRad);
752 if (isTempOutValid ==
false) {
753 LOGP(warn,
"Tout{}{} not valid! Setting default TF1!", iCh, iRad);
755 std::unique_ptr<TF1> pToutDefault;
756 pToutDefault.reset(
new TF1());
757 setDefault(pToutDefault.get(),
true);
761 arNmean[6 * iCh + 2 * iRad + 1] = *(pToutDefault.get());
766 for (
int iSec = 0; iSec < 6; iSec++) {
768 std::unique_ptr<TF1> pHV = finalizeHv(iCh, iSec);
771 if (pEnv !=
nullptr && pChPres !=
nullptr && pHV !=
nullptr) {
772 const char* hvChar = (pHV.get())->GetName();
773 const char* chChar = (pChPres.get())->GetName();
774 const char* envChar = (pEnv.get())->GetName();
775 const char* fFormula =
776 "3*10^(3.01e-3*%s - 4.72)+170745848*exp(-(%s+%s)*0.0162012)";
777 const char* fName = Form(fFormula, hvChar, chChar, envChar);
779 auto minTime = std::max({envPrFirstTime, hvFirstTime, chPrFirstTime});
780 auto maxTime = std::min({envPrLastTime, hvLastTime, chPrLastTime});
782 std::unique_ptr<TF1> pQthre;
783 pQthre.reset(
new TF1(Form(
"HMP_QthreC%iS%i", iCh, iSec), fName, minTime,
785 pQthre->SetTitle(Form(
786 "Charge-Threshold Ch%iSec%i; Time [mS]; Threshold ", iCh, iSec));
788 if (pQthre !=
nullptr) {
789 arQthre[6 * iCh + iSec] = *(pQthre.get());
791 std::unique_ptr<TF1> pQthreDefault;
792 pQthreDefault.reset(
new TF1());
793 setDefault(pQthreDefault.get(),
true);
796 arQthre[6 * iCh + iSec] = *(pQthreDefault.get());
797 LOGP(warn,
"Nullptr in Charge-Threshold arQthre{} in chamber{} sector{} ", 6 * iCh + iSec, iCh, iSec);
800 std::unique_ptr<TF1> pQthreDefault;
801 pQthreDefault.reset(
new TF1());
802 setDefault(pQthreDefault.get(),
true);
805 arQthre[6 * iCh + iSec] = *(pQthreDefault.get());
806 LOGP(warn,
"Missing entry in Charge-Threshold arQthre{} in chamber{} sector{} ", 6 * iCh + iSec, iCh, iSec);
812 LOG(info) <<
"======================================== ";
814 double eMean = procTrans();
816 std::unique_ptr<TF1> pPhotMean;
817 pPhotMean.reset(
new TF1(
"HMP_PhotEmean", Form(
"%f", eMean), mTimeEMean.first,
820 pPhotMean->SetTitle(Form(
"HMP_PhotEmean; Time [mS]; Photon Energy [eV]"));
822 if (pPhotMean !=
nullptr) {
823 arNmean[42] = *(pPhotMean.get());
827 std::unique_ptr<TF1> pPhotMeanDefault;
828 pPhotMeanDefault.reset(
new TF1());
829 setDefault(pPhotMeanDefault.get(),
true);
830 arNmean[42] = *(pPhotMeanDefault.get());
845 std::map<std::string, std::string> md;
846 md[
"responsible"] =
"Erlend Flatland";
867 LOG(
debug) <<
"KEEP_ALIVE_FLAG active for DP " <<
pid;
880 const std::string inputString(dpid.
get_alias());
881 char stringPos = inputString[startIndex];
882 int charInt = ((
int)stringPos) - ((
int)
'0');
883 if (charInt < 10 && charInt >= 0) {
static constexpr long DAY
DeliveryType get_type() const noexcept
const char *const get_alias() const noexcept
void init(const std::vector< DPID > &pids)
int aliasStringToInt(const DPID &dpid, std::size_t startIndex)
uint64_t processFlags(const uint64_t flags, const char *pid)
void process(const gsl::span< const DPCOM > dps)
static double lAbsGap(double eV)
static double lAbsWin(double eV)
static double qEffCSI(double eV)
GLint GLint GLsizei GLint GLenum GLenum type
static void prepareCCDBobjectInfo(T &obj, o2::ccdb::CcdbObjectInfo &info, const std::string &path, const std::map< std::string, std::string > &md, long start, long end=-1)
const DataPointIdentifier id
uint64_t get_epoch_time() const noexcept
static constexpr uint16_t END_FLAG
static constexpr uint16_t KEEP_ALIVE_FLAG
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"