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(
"cmsdimns1.cern.ch");
62 edm::LogInfo(
"BeamSpotDipServer") <<
"reading from " << (readFromNFS ?
"file (NFS)" :
"database");
77 edm::LogInfo(
"BeamSpotDipServer") <<
"server started at " + getDateTime();
79 edm::LogInfo(
"BeamSpotDipServer") <<
"creating publication " + subjectCMS;
80 publicationCMS = dip->createDipPublication(subjectCMS.c_str(), &errHandler);
81 messageCMS = dip->createDipData();
83 edm::LogInfo(
"BeamSpotDipServer") <<
"creating publication " + subjectLHC;
84 publicationLHC = dip->createDipPublication(subjectLHC.c_str(), &errHandler);
85 messageLHC = dip->createDipData();
87 edm::LogInfo(
"BeamSpotDipServer") <<
"creating publication " + subjectPV;
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();
109 runnum = iEvent.
run();
114 if (nthlumi > lastlumi) {
118 iEvent.
getByToken(dcsRecordToken_, dcsRecord);
126 edm::LogInfo(
"BeamSpotDipServer") <<
"whole tracker on? " << (wholeTrackerOn ?
"yes" :
"no");
139 if (!logFile.good()) {
140 edm::LogWarning(
"BeamSpotDipServer") <<
"Source File: " + sourceFile +
" doesn't exist!";
143 lastModTime = getLastTime(sourceFile);
145 if (lastFitTime == 0)
146 lastFitTime = lastModTime;
148 if (getFileSize(sourceFile) == 0) {
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;
168 if (getFileSize(sourceFile) > 0) {
170 edm::LogInfo(
"BeamSpotDipServer") <<
"reading record from " + sourceFile;
172 if (readRcd(logFile)) {
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();
229 edm::LogInfo(
"BeamSpotDipServer") <<
"destroying publication " + subjectCMS;
230 dip->destroyDipPublication(publicationCMS);
233 edm::LogInfo(
"BeamSpotDipServer") <<
"destroying publication " + subjectLHC;
234 dip->destroyDipPublication(publicationLHC);
237 edm::LogInfo(
"BeamSpotDipServer") <<
"destroying publication " + subjectPV;
238 dip->destroyDipPublication(publicationPV);
244 struct stat stat_buf;
245 int rc =
stat(filename.c_str(), &stat_buf);
246 return (rc == 0 ? stat_buf.st_size : -1);
251 struct stat stat_buf;
252 int rc =
stat(filename.c_str(), &stat_buf);
253 return (rc == 0 ? stat_buf.st_mtime : -1);
261 while ((pos = line.find(delimiter)) != string::npos) {
262 string token = line.substr(0, pos);
264 list.push_back(token);
266 line.erase(0, pos + delimiter.length());
269 list.push_back(line);
281 if (!logfile.good() || getFileSize(sourceFile1) == 0) {
283 outstr =
"No CMS Tracker status available. No DAQ/DQM.";
291 while (getline(logfile, record)) {
293 vector<string>
tmp =
parse(record,
" ");
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;
333 if ((lsCount % timeoutLS[0] == 0) && (lsCount % timeoutLS[1] != 0))
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);
353 }
else if (lsCount % timeoutLS[1] == 0)
359 stringstream warnMsg;
360 warnMsg <<
"No new data for " << lsCount <<
" LS: " << tkStatus();
361 publishRcd(
"Bad", warnMsg.str(),
false,
false);
379 edm::LogWarning(
"BeamSpotDipServer") <<
"time variables are not available (readRcd): " << e.what();
390 edm::LogWarning(
"BeamSpotDipServer") <<
"lumirange variable not avaialble (readRcd): " << e.what();
400 edm::LogInfo(
"BeamSpotDipServer") <<
"run: " << runnum <<
", LS: " << currentLS <<
", time: " <<
startTime <<
" "
437 edm::LogWarning(
"BeamSpotDipServer") <<
"PV variables are not available (readRcd): " << e.what();
450 edm::LogInfo(
"BeamSpotDipServer") <<
"pos: (" <<
x <<
"," <<
y <<
"," <<
z <<
")"
460 bool rcdQlty =
false;
464 while (getline(file, record)) {
467 vector<string>
tmp =
parse(record,
" ");
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];
482 endTime = tmp[1] +
" " + tmp[2] +
" " + tmp[3];
489 currentLS = stoi(tmp[3]);
512 sigma_z = stof(tmp[1]);
521 width_x = stof(tmp[1]);
524 width_y = stof(tmp[1]);
528 err_x =
sqrt(stof(tmp[1]));
531 err_y =
sqrt(stof(tmp[2]));
534 err_z =
sqrt(stof(tmp[3]));
537 err_sigma_z =
sqrt(stof(tmp[4]));
540 err_dxdz =
sqrt(stof(tmp[5]));
543 err_dydz =
sqrt(stof(tmp[6]));
546 err_width_x =
sqrt(stof(tmp[7]));
547 err_width_y = err_width_x;
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");
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");
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))
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);
double Getdydz() const
get dydz slope, crossing angle in YZ
T getUntrackedParameter(std::string const &, T const &) const
void CMS2LHCRF_POS(float x, float y, float z)
std::string GetStartTime() const
double GetY() const
get Y beam position
std::string getDateTime()
void dqmEndRun(const edm::Run &, const edm::EventSetup &iSetup) override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
#define DEFINE_FWK_MODULE(type)
uint32_t const *__restrict__ Quality * quality
cond::Time_t GetCreationTime() const
std::string GetLumiRange() const
double GetSigmaZ() const
get sigma Z, RMS bunch length
bool readRcd(const BeamSpotOnlineObjects &bs)
edm::LuminosityBlockNumber_t luminosityBlock() const
cond::Time_t GetStartTimeStamp() const
double GetBeamWidthX() const
get average transverse beam width
int GetLastAnalyzedLumi() const
Getters Methods.
double GetYError() const
get Y beam position Error
void handleException(DipPublication *publication, DipException &e) override
double GetBeamWidthYError() const
get average transverse beam width error X = Y
Log< level::Error, false > LogError
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
std::string GetEndTime() const
void dqmEndLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &) override
LuminosityBlockNumber_t luminosityBlock() const
float GetMeanErrorPV() const
void publishRcd(std::string qlty, std::string err, bool pubCMS, bool fitTime)
long getFileSize(std::string filename)
static constexpr int verbose
int GetUsedEvents() const
int GetBeamType() const
get beam type
BeamSpotDipServer(const edm::ParameterSet &)
void analyze(const edm::Event &e, const edm::EventSetup &) override
double GetdydzError() const
get dydz slope, crossing angle in YZ Error
double GetZ() const
get Z beam position
int GetLastAnalyzedRun() const
double Getdxdz() const
get dxdz slope, crossing angle in XZ
double GetdxdzError() const
get dxdz slope, crossing angle in XZ Error
double GetBeamWidthXError() const
get average transverse beam width error ASSUME the same for X and Y
std::vector< std::string > parse(std::string line, const std::string &delimiter)
double GetSigmaZError() const
get sigma Z, RMS bunch length Error
Log< level::Info, false > LogInfo
double GetX() const
get X beam position
time_t getLastTime(std::string filename)
double GetXError() const
get X beam position Error
void dqmBeginLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &) override
float GetRmsErrorPV() const
T getParameter(std::string const &) const
void dqmBeginRun(const edm::Run &r, const edm::EventSetup &) override
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Log< level::Warning, false > LogWarning
double GetZError() const
get Z beam position Error
void bookHistograms(DQMStore::IBooker &, const edm::Run &, const edm::EventSetup &) override
cond::Time_t GetEndTimeStamp() const