16 #include "DipFactory.h"
17 #include "DipPublication.h"
18 #include "DipTimestamp.h"
29 edm::LogError(
"BeamSpotDipServer") <<
"exception (create): " <<
e.what();
51 bsLegacyToken_ = esConsumes<edm::Transition::EndLuminosityBlock>();
54 dcsRecordToken_ = consumes<DCSRecord>(dcsRecordInputTag_);
73 edm::LogInfo(
"BeamSpotDipServer") <<
"server started at " + getDateTime();
76 publicationCMS = dip->createDipPublication(
subjectCMS.c_str(), &errHandler);
77 messageCMS = dip->createDipData();
80 publicationLHC = dip->createDipPublication(
subjectLHC.c_str(), &errHandler);
81 messageLHC = dip->createDipData();
84 publicationPV = dip->createDipPublication(
subjectPV.c_str(), &errHandler);
85 messagePV = dip->createDipData();
88 publishRcd(
"UNINITIALIZED",
"",
true,
false);
90 edm::LogError(
"BeamSpotDipServer") <<
"exception (start up): " <<
e.what();
108 int nthlumi =
iEvent.luminosityBlock();
110 if (nthlumi > lastlumi) {
122 edm::LogInfo(
"BeamSpotDipServer") <<
"whole tracker on? " << (wholeTrackerOn ?
"yes" :
"no");
141 if (lastFitTime == 0)
142 lastFitTime = lastModTime;
146 if (lastModTime > lastFitTime) {
147 string tmp = tkStatus();
148 edm::LogInfo(
"BeamSpotDipServer") <<
"New run starts. Run number: " << runnum;
150 edm::LogInfo(
"BeamSpotDipServer") <<
"Initial lastModTime = " + getDateTime(lastModTime);
152 lastFitTime = lastModTime;
155 if (lastModTime > lastFitTime) {
158 edm::LogInfo(
"BeamSpotDipServer") <<
"time of last fit = " + getDateTime(lastFitTime);
159 edm::LogInfo(
"BeamSpotDipServer") <<
"time of current fit = " + getDateTime(lastModTime);
161 lastFitTime = lastModTime;
170 edm::LogInfo(
"BeamSpotDipServer") <<
"got new record from file";
177 edm::LogInfo(
"BeamSpotDipServer") <<
"problem with new record";
192 auto const&
bs = *bsLegacyHandle;
197 edm::LogInfo(
"BeamSpotDipServer") <<
"got new record from database";
203 edm::LogInfo(
"BeamSpotDipServer") <<
"problem with new record";
212 publishRcd(qualities[0],
"Testing",
true,
true);
213 else if (
quality == qualities[1])
214 publishRcd(
quality,
"No fit or fit fails",
true,
true);
216 publishRcd(
quality,
"",
true,
true);
218 edm::LogWarning(
"BeamSpotDipServer") <<
"io exception (end of lumi): " <<
e.what();
226 dip->destroyDipPublication(publicationCMS);
230 dip->destroyDipPublication(publicationLHC);
234 dip->destroyDipPublication(publicationPV);
240 struct stat stat_buf;
242 return (rc == 0 ? stat_buf.st_size : -1);
247 struct stat stat_buf;
249 return (rc == 0 ? stat_buf.st_mtime : -1);
260 list.push_back(
token);
265 list.push_back(
line);
279 outstr =
"No CMS Tracker status available. No DAQ/DQM.";
291 switch (nthLnInRcd) {
293 if (
tmp[1].
find(
"Yes") == string::npos)
294 outstr =
"CMS Tracker OFF.";
296 outstr =
"CMS not taking data or no beam.";
299 runnum = stoi(
tmp[1]);
306 edm::LogWarning(
"BeamSpotDipServer") <<
"exception (tkStatus): " <<
e.what();
314 outstr =
"CMS not taking data or no beam.";
316 outstr =
"CMS Tracker OFF.";
325 edm::LogInfo(
"BeamSpotDipServer") <<
"no update | alive = " << alive;
333 if (!alive.test(2)) {
339 stringstream warnMsg;
340 warnMsg <<
"No new data for " << lsCount <<
" LS";
341 publishRcd(
"Uncertain", warnMsg.str(),
false,
false);
345 stringstream warnMsg;
346 warnMsg <<
"No new data for " << lsCount <<
" LS: " << tkStatus();
347 publishRcd(
"Bad", warnMsg.str(),
false,
false);
355 stringstream warnMsg;
356 warnMsg <<
"No new data for " << lsCount <<
" LS: " << tkStatus();
357 publishRcd(
"Bad", warnMsg.str(),
false,
false);
365 runnum =
bs.GetLastAnalyzedRun();
370 startTime =
bs.GetStartTime();
371 startTimeStamp =
bs.GetStartTimeStamp();
372 endTime =
bs.GetEndTime();
373 endTimeStamp =
bs.GetEndTimeStamp();
375 edm::LogWarning(
"BeamSpotDipServer") <<
"time variables are not available (readRcd): " <<
e.what();
377 startTime =
bs.GetCreationTime();
378 startTimeStamp =
bs.GetCreationTime();
379 endTime =
bs.GetCreationTime();
380 endTimeStamp =
bs.GetCreationTime();
384 lumiRange =
bs.GetLumiRange();
386 edm::LogWarning(
"BeamSpotDipServer") <<
"lumirange variable not avaialble (readRcd): " <<
e.what();
388 lumiRange = to_string(
bs.GetLastAnalyzedLumi());
391 currentLS =
bs.GetLastAnalyzedLumi();
396 edm::LogInfo(
"BeamSpotDipServer") <<
"run: " << runnum <<
", LS: " << currentLS <<
", time: " << startTime <<
" "
397 << startTimeStamp <<
", type: " <<
type;
410 sigma_z =
bs.GetSigmaZ();
413 width_x =
bs.GetBeamWidthX();
414 width_y =
bs.GetBeamWidthX();
416 err_x =
bs.GetXError();
417 err_y =
bs.GetYError();
418 err_z =
bs.GetZError();
419 err_sigma_z =
bs.GetSigmaZError();
420 err_dxdz =
bs.GetdxdzError();
421 err_dydz =
bs.GetdydzError();
422 err_width_x =
bs.GetBeamWidthXError();
423 err_width_y =
bs.GetBeamWidthYError();
427 meanPV =
bs.GetMeanPV();
428 err_meanPV =
bs.GetMeanErrorPV();
429 rmsPV =
bs.GetRmsPV();
430 err_rmsPV =
bs.GetRmsErrorPV();
431 maxPV =
bs.GetMaxPVs();
433 edm::LogWarning(
"BeamSpotDipServer") <<
"PV variables are not available (readRcd): " <<
e.what();
443 nPV =
bs.GetNumPVs();
446 edm::LogInfo(
"BeamSpotDipServer") <<
"pos: (" <<
x <<
"," <<
y <<
"," <<
z <<
")"
456 bool rcdQlty =
false;
465 switch (nthLnInRcd) {
467 if (
record.rfind(
"Run", 0) != 0) {
468 edm::LogError(
"BeamSpotDipServer") <<
"Reading of results text file interrupted. " + getDateTime();
471 runnum = stoi(
tmp[1]);
474 startTime =
tmp[1] +
" " +
tmp[2] +
" " +
tmp[3];
475 startTimeStamp = stol(
tmp[4]);
478 endTime =
tmp[1] +
" " +
tmp[2] +
" " +
tmp[3];
479 endTimeStamp = stol(
tmp[4]);
482 lumiRange =
record.substr(10);
484 edm::LogInfo(
"BeamSpotDipServer") <<
"lumisection range: " + lumiRange;
485 currentLS = stoi(
tmp[3]);
508 sigma_z = stof(
tmp[1]);
517 width_x = stof(
tmp[1]);
520 width_y = stof(
tmp[1]);
533 err_sigma_z =
sqrt(stof(
tmp[4]));
542 err_width_x =
sqrt(stof(
tmp[7]));
543 err_width_y = err_width_x;
556 meanPV = stof(
tmp[1]);
559 err_meanPV = stof(
tmp[1]);
562 rmsPV = stof(
tmp[1]);
565 err_rmsPV = stof(
tmp[1]);
568 maxPV = stoi(
tmp[1]);
582 edm::LogWarning(
"BeamSpotDipServer") <<
"io exception (readRcd): " <<
e.what();
594 Centroid[0] *= -1.0 * cm2um;
604 Centroid[1] *= cm2um;
614 Centroid[2] *= -1.0 * cm2mm;
623 CMS2LHCRF_POS(
x,
y,
z);
625 Tilt[0] =
dxdz * rad2urad;
626 Tilt[1] = (
dydz != 0 ? (
dydz * -1 * rad2urad) : 0);
628 Size[0] = width_x * cm2um;
629 Size[1] = width_y * cm2um;
630 Size[2] = sigma_z * cm2mm;
633 messageCMS->insert(runnum,
"runnum");
634 messageCMS->insert(startTime,
"startTime");
635 messageCMS->insert(endTime,
"endTime");
636 messageCMS->insert(startTimeStamp,
"startTimeStamp");
637 messageCMS->insert(endTimeStamp,
"endTimeStamp");
638 messageCMS->insert(lumiRange,
"lumiRange");
639 messageCMS->insert(
quality,
"quality");
640 messageCMS->insert(
type,
"type");
641 messageCMS->insert(
x,
"x");
642 messageCMS->insert(
y,
"y");
643 messageCMS->insert(
z,
"z");
644 messageCMS->insert(
dxdz,
"dxdz");
645 messageCMS->insert(
dydz,
"dydz");
646 messageCMS->insert(width_x,
"width_x");
647 messageCMS->insert(width_y,
"width_y");
648 messageCMS->insert(sigma_z,
"sigma_z");
650 if (publishStatErrors) {
651 messageCMS->insert(err_x,
"err_x");
652 messageCMS->insert(err_y,
"err_y");
653 messageCMS->insert(err_z,
"err_z");
654 messageCMS->insert(err_dxdz,
"err_dxdz");
655 messageCMS->insert(err_dydz,
"err_dydz");
656 messageCMS->insert(err_width_x,
"err_width_x");
657 messageCMS->insert(err_width_y,
"err_width_y");
658 messageCMS->insert(err_sigma_z,
"err_sigma_z");
662 messageLHC->insert(Size, 3,
"Size");
663 messageLHC->insert(Centroid, 3,
"Centroid");
664 messageLHC->insert(Tilt, 2,
"Tilt");
667 messagePV->insert(runnum,
"runnum");
668 messagePV->insert(startTime,
"startTime");
669 messagePV->insert(endTime,
"endTime");
670 messagePV->insert(startTimeStamp,
"startTimeStamp");
671 messagePV->insert(endTimeStamp,
"endTimeStamp");
672 messagePV->insert(lumiRange,
"lumiRange");
673 messagePV->insert(
events,
"events");
674 messagePV->insert(meanPV,
"meanPV");
675 messagePV->insert(err_meanPV,
"err_meanPV");
676 messagePV->insert(rmsPV,
"rmsPV");
677 messagePV->insert(err_rmsPV,
"err_rmsPV");
678 messagePV->insert(maxPV,
"maxPV");
679 messagePV->insert(nPV,
"nPV");
681 edm::LogWarning(
"BeamSpotDipServer") <<
"exception (trueRcd): " <<
e.what();
699 messageLHC->insert(Size, 3,
"Size");
700 messageLHC->insert(Centroid, 3,
"Centroid");
701 messageLHC->insert(Tilt, 2,
"Tilt");
703 edm::LogWarning(
"BeamSpotDipServer") <<
"exception (fakeRcd): " <<
e.what();
710 bool updateCMS = pubCMS && (currentLS % intLS == 0);
713 edm::LogInfo(
"BeamSpotDipServer") <<
"sending (" << qlty <<
" | " <<
err <<
")";
718 else if (!alive.test(1) && !alive.test(2))
726 epoch = endTimeStamp * 1000;
727 zeit = DipTimestamp(epoch);
729 zeit = DipTimestamp();
733 publicationCMS->send(messageCMS, zeit);
735 publicationLHC->send(messageLHC, zeit);
736 publicationPV->send(messagePV, zeit);
739 if (qlty == qualities[0]) {
741 publicationCMS->setQualityUncertain(
err.c_str());
743 publicationLHC->setQualityUncertain(
err.c_str());
744 }
else if (qlty == qualities[1]) {
746 publicationCMS->setQualityBad(
err.c_str());
748 publicationLHC->setQualityBad(
err.c_str());
749 }
else if (qlty ==
"UNINITIALIZED") {
751 publicationCMS->setQualityBad(
"UNINITIALIZED");
753 publicationLHC->setQualityBad(
"UNINITIALIZED");
756 edm::LogWarning(
"BeamSpotDipServer") <<
"exception (publishRcd): " <<
e.what();
763 strftime(mbstr,
sizeof(mbstr),
"%Y.%m.%d %H:%M:%S %z", std::localtime(&
t));
770 time_t
t =
time(
nullptr);
772 return getDateTime(
t);