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_);
60 dip->setDNSNode(
"dipns1,dipns2");
77 edm::LogInfo(
"BeamSpotDipServer") <<
"server started at " + getDateTime();
80 publicationCMS = dip->createDipPublication(
subjectCMS.c_str(), &errHandler);
81 messageCMS = dip->createDipData();
84 publicationLHC = dip->createDipPublication(
subjectLHC.c_str(), &errHandler);
85 messageLHC = dip->createDipData();
88 publicationPV = dip->createDipPublication(
subjectPV.c_str(), &errHandler);
89 messagePV = dip->createDipData();
92 publishRcd(
"UNINITIALIZED",
"",
true,
false);
94 edm::LogError(
"BeamSpotDipServer") <<
"exception (start up): " <<
e.what();
112 int nthlumi =
iEvent.luminosityBlock();
114 if (nthlumi > lastlumi) {
126 edm::LogInfo(
"BeamSpotDipServer") <<
"whole tracker on? " << (wholeTrackerOn ?
"yes" :
"no");
145 if (lastFitTime == 0)
146 lastFitTime = lastModTime;
150 if (lastModTime > lastFitTime) {
151 string tmp = tkStatus();
152 edm::LogInfo(
"BeamSpotDipServer") <<
"New run starts. Run number: " << runnum;
154 edm::LogInfo(
"BeamSpotDipServer") <<
"Initial lastModTime = " + getDateTime(lastModTime);
156 lastFitTime = lastModTime;
159 if (lastModTime > lastFitTime) {
162 edm::LogInfo(
"BeamSpotDipServer") <<
"time of last fit = " + getDateTime(lastFitTime);
163 edm::LogInfo(
"BeamSpotDipServer") <<
"time of current fit = " + getDateTime(lastModTime);
165 lastFitTime = lastModTime;
174 edm::LogInfo(
"BeamSpotDipServer") <<
"got new record from file";
181 edm::LogInfo(
"BeamSpotDipServer") <<
"problem with new record";
196 auto const&
bs = *bsLegacyHandle;
201 edm::LogInfo(
"BeamSpotDipServer") <<
"got new record from database";
207 edm::LogInfo(
"BeamSpotDipServer") <<
"problem with new record";
216 publishRcd(qualities[0],
"Testing",
true,
true);
217 else if (
quality == qualities[1])
218 publishRcd(
quality,
"No fit or fit fails",
true,
true);
220 publishRcd(
quality,
"",
true,
true);
222 edm::LogWarning(
"BeamSpotDipServer") <<
"io exception (end of lumi): " <<
e.what();
230 dip->destroyDipPublication(publicationCMS);
234 dip->destroyDipPublication(publicationLHC);
238 dip->destroyDipPublication(publicationPV);
244 struct stat stat_buf;
246 return (rc == 0 ? stat_buf.st_size : -1);
251 struct stat stat_buf;
253 return (rc == 0 ? stat_buf.st_mtime : -1);
264 list.push_back(
token);
269 list.push_back(
line);
283 outstr =
"No CMS Tracker status available. No DAQ/DQM.";
295 switch (nthLnInRcd) {
297 if (
tmp[1].
find(
"Yes") == string::npos)
298 outstr =
"CMS Tracker OFF.";
300 outstr =
"CMS not taking data or no beam.";
303 runnum = stoi(
tmp[1]);
310 edm::LogWarning(
"BeamSpotDipServer") <<
"exception (tkStatus): " <<
e.what();
318 outstr =
"CMS not taking data or no beam.";
320 outstr =
"CMS Tracker OFF.";
329 edm::LogInfo(
"BeamSpotDipServer") <<
"no update | alive = " << alive;
337 if (!alive.test(2)) {
343 stringstream warnMsg;
344 warnMsg <<
"No new data for " << lsCount <<
" LS";
345 publishRcd(
"Uncertain", warnMsg.str(),
false,
false);
349 stringstream warnMsg;
350 warnMsg <<
"No new data for " << lsCount <<
" LS: " << tkStatus();
351 publishRcd(
"Bad", warnMsg.str(),
false,
false);
359 stringstream warnMsg;
360 warnMsg <<
"No new data for " << lsCount <<
" LS: " << tkStatus();
361 publishRcd(
"Bad", warnMsg.str(),
false,
false);
369 runnum =
bs.GetLastAnalyzedRun();
374 startTime =
bs.GetStartTime();
375 startTimeStamp =
bs.GetStartTimeStamp();
376 endTime =
bs.GetEndTime();
377 endTimeStamp =
bs.GetEndTimeStamp();
379 edm::LogWarning(
"BeamSpotDipServer") <<
"time variables are not available (readRcd): " <<
e.what();
381 startTime =
bs.GetCreationTime();
382 startTimeStamp =
bs.GetCreationTime();
383 endTime =
bs.GetCreationTime();
384 endTimeStamp =
bs.GetCreationTime();
388 lumiRange =
bs.GetLumiRange();
390 edm::LogWarning(
"BeamSpotDipServer") <<
"lumirange variable not avaialble (readRcd): " <<
e.what();
392 lumiRange = to_string(
bs.GetLastAnalyzedLumi());
395 currentLS =
bs.GetLastAnalyzedLumi();
400 edm::LogInfo(
"BeamSpotDipServer") <<
"run: " << runnum <<
", LS: " << currentLS <<
", time: " << startTime <<
" "
401 << startTimeStamp <<
", type: " <<
type;
414 sigma_z =
bs.GetSigmaZ();
417 width_x =
bs.GetBeamWidthX();
418 width_y =
bs.GetBeamWidthX();
420 err_x =
bs.GetXError();
421 err_y =
bs.GetYError();
422 err_z =
bs.GetZError();
423 err_sigma_z =
bs.GetSigmaZError();
424 err_dxdz =
bs.GetdxdzError();
425 err_dydz =
bs.GetdydzError();
426 err_width_x =
bs.GetBeamWidthXError();
427 err_width_y =
bs.GetBeamWidthYError();
431 meanPV =
bs.GetMeanPV();
432 err_meanPV =
bs.GetMeanErrorPV();
433 rmsPV =
bs.GetRmsPV();
434 err_rmsPV =
bs.GetRmsErrorPV();
435 maxPV =
bs.GetMaxPVs();
437 edm::LogWarning(
"BeamSpotDipServer") <<
"PV variables are not available (readRcd): " <<
e.what();
447 nPV =
bs.GetNumPVs();
450 edm::LogInfo(
"BeamSpotDipServer") <<
"pos: (" <<
x <<
"," <<
y <<
"," <<
z <<
")"
460 bool rcdQlty =
false;
469 switch (nthLnInRcd) {
471 if (
record.rfind(
"Run", 0) != 0) {
472 edm::LogError(
"BeamSpotDipServer") <<
"Reading of results text file interrupted. " + getDateTime();
475 runnum = stoi(
tmp[1]);
478 startTime =
tmp[1] +
" " +
tmp[2] +
" " +
tmp[3];
479 startTimeStamp = stol(
tmp[4]);
482 endTime =
tmp[1] +
" " +
tmp[2] +
" " +
tmp[3];
483 endTimeStamp = stol(
tmp[4]);
486 lumiRange =
record.substr(10);
488 edm::LogInfo(
"BeamSpotDipServer") <<
"lumisection range: " + lumiRange;
489 currentLS = stoi(
tmp[3]);
512 sigma_z = stof(
tmp[1]);
521 width_x = stof(
tmp[1]);
524 width_y = stof(
tmp[1]);
537 err_sigma_z =
sqrt(stof(
tmp[4]));
546 err_width_x =
sqrt(stof(
tmp[7]));
547 err_width_y = err_width_x;
560 meanPV = stof(
tmp[1]);
563 err_meanPV = stof(
tmp[1]);
566 rmsPV = stof(
tmp[1]);
569 err_rmsPV = stof(
tmp[1]);
572 maxPV = stoi(
tmp[1]);
586 edm::LogWarning(
"BeamSpotDipServer") <<
"io exception (readRcd): " <<
e.what();
598 Centroid[0] *= -1.0 * cm2um;
608 Centroid[1] *= cm2um;
618 Centroid[2] *= -1.0 * cm2mm;
627 CMS2LHCRF_POS(
x,
y,
z);
629 Tilt[0] =
dxdz * rad2urad;
630 Tilt[1] = (
dydz != 0 ? (
dydz * -1 * rad2urad) : 0);
632 Size[0] = width_x * cm2um;
633 Size[1] = width_y * cm2um;
634 Size[2] = sigma_z * cm2mm;
637 messageCMS->insert(runnum,
"runnum");
638 messageCMS->insert(startTime,
"startTime");
639 messageCMS->insert(endTime,
"endTime");
640 messageCMS->insert(startTimeStamp,
"startTimeStamp");
641 messageCMS->insert(endTimeStamp,
"endTimeStamp");
642 messageCMS->insert(lumiRange,
"lumiRange");
643 messageCMS->insert(
quality,
"quality");
644 messageCMS->insert(
type,
"type");
645 messageCMS->insert(
x,
"x");
646 messageCMS->insert(
y,
"y");
647 messageCMS->insert(
z,
"z");
648 messageCMS->insert(
dxdz,
"dxdz");
649 messageCMS->insert(
dydz,
"dydz");
650 messageCMS->insert(width_x,
"width_x");
651 messageCMS->insert(width_y,
"width_y");
652 messageCMS->insert(sigma_z,
"sigma_z");
654 if (publishStatErrors) {
655 messageCMS->insert(err_x,
"err_x");
656 messageCMS->insert(err_y,
"err_y");
657 messageCMS->insert(err_z,
"err_z");
658 messageCMS->insert(err_dxdz,
"err_dxdz");
659 messageCMS->insert(err_dydz,
"err_dydz");
660 messageCMS->insert(err_width_x,
"err_width_x");
661 messageCMS->insert(err_width_y,
"err_width_y");
662 messageCMS->insert(err_sigma_z,
"err_sigma_z");
666 messageLHC->insert(Size, 3,
"Size");
667 messageLHC->insert(Centroid, 3,
"Centroid");
668 messageLHC->insert(Tilt, 2,
"Tilt");
671 messagePV->insert(runnum,
"runnum");
672 messagePV->insert(startTime,
"startTime");
673 messagePV->insert(endTime,
"endTime");
674 messagePV->insert(startTimeStamp,
"startTimeStamp");
675 messagePV->insert(endTimeStamp,
"endTimeStamp");
676 messagePV->insert(lumiRange,
"lumiRange");
677 messagePV->insert(
events,
"events");
678 messagePV->insert(meanPV,
"meanPV");
679 messagePV->insert(err_meanPV,
"err_meanPV");
680 messagePV->insert(rmsPV,
"rmsPV");
681 messagePV->insert(err_rmsPV,
"err_rmsPV");
682 messagePV->insert(maxPV,
"maxPV");
683 messagePV->insert(nPV,
"nPV");
685 edm::LogWarning(
"BeamSpotDipServer") <<
"exception (trueRcd): " <<
e.what();
703 messageLHC->insert(Size, 3,
"Size");
704 messageLHC->insert(Centroid, 3,
"Centroid");
705 messageLHC->insert(Tilt, 2,
"Tilt");
707 edm::LogWarning(
"BeamSpotDipServer") <<
"exception (fakeRcd): " <<
e.what();
714 bool updateCMS = pubCMS && (currentLS % intLS == 0);
717 edm::LogInfo(
"BeamSpotDipServer") <<
"sending (" << qlty <<
" | " <<
err <<
")";
722 else if (!alive.test(1) && !alive.test(2))
730 epoch = endTimeStamp * 1000;
731 zeit = DipTimestamp(epoch);
733 zeit = DipTimestamp();
737 publicationCMS->send(messageCMS, zeit);
739 publicationLHC->send(messageLHC, zeit);
740 publicationPV->send(messagePV, zeit);
743 if (qlty == qualities[0]) {
745 publicationCMS->setQualityUncertain(
err.c_str());
747 publicationLHC->setQualityUncertain(
err.c_str());
748 }
else if (qlty == qualities[1]) {
750 publicationCMS->setQualityBad(
err.c_str());
752 publicationLHC->setQualityBad(
err.c_str());
753 }
else if (qlty ==
"UNINITIALIZED") {
755 publicationCMS->setQualityBad(
"UNINITIALIZED");
757 publicationLHC->setQualityBad(
"UNINITIALIZED");
760 edm::LogWarning(
"BeamSpotDipServer") <<
"exception (publishRcd): " <<
e.what();
767 strftime(mbstr,
sizeof(mbstr),
"%Y.%m.%d %H:%M:%S %z", std::localtime(&
t));
774 time_t
t =
time(
nullptr);
776 return getDateTime(
t);