Skip to content

Commit

Permalink
added startup script
Browse files Browse the repository at this point in the history
  • Loading branch information
sikler committed May 10, 2022
1 parent 306732b commit f61ebc1
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 44 deletions.
84 changes: 40 additions & 44 deletions DQM/BeamMonitor/bin/beamSpotDipStandalone.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <sstream>
#include <vector>
#include <cmath>
#include <cstring>
#include <ctime>
#include <sys/stat.h>
#include <bitset>
Expand Down Expand Up @@ -83,19 +84,17 @@ float Centroid[3];
float Tilt[2];

//
const bool verbose = true;
const bool testing = false;
bool verbose = false;
bool testing = false;

const string subjectCMS = "dip/CMS/Tracker/BeamSpot";
const string subjectLHC = "dip/CMS/LHC/LuminousRegion";
const string subjectPV = "dip/CMS/Tracker/PrimaryVertices";
const string subjectPV = "dip/CMS/Tracker/PrimaryVertices";

const string sourceFile =
"/nfshome0/dqmpro/BeamMonitorDQM/BeamFitResultsForDIP.txt";
const string sourceFile1 =
"/nfshome0/dqmpro/BeamMonitorDQM/BeamFitResultsOld_TkStatus.txt";
string sourceFile = "/nfshome0/dqmpro/BeamMonitorDQM/BeamFitResultsForDIP.txt";
string sourceFile1 = "/nfshome0/dqmpro/BeamMonitorDQM/BeamFitResultsOld_TkStatus.txt";

const int timeoutLS[2] = { 1, 2 };
const int timeoutLS[2] = {1, 2};

//

Expand Down Expand Up @@ -332,8 +331,7 @@ void publishRcd(string qlty, string err, bool pubCMS, bool fitTime) {
}

/*****************************************************************************/
bool readRcd(ifstream& file)
{
bool readRcd(ifstream& file) {
int nthLnInRcd = 0;
bool rcdQlty = false;

Expand Down Expand Up @@ -518,8 +516,7 @@ void problem() {

lsCount++;

if ((lsCount % (timeoutLS[0]*secPerLS) == 0)
&& (lsCount % (timeoutLS[1]*secPerLS) != 0)) // first timeout
if ((lsCount % (timeoutLS[0] * secPerLS) == 0) && (lsCount % (timeoutLS[1] * secPerLS) != 0)) // first timeout
{
if (!alive.test(1))
alive.flip(1);
Expand All @@ -539,7 +536,7 @@ void problem() {
warnMsg << "No new data for " << lsCount << " LS: " << tkStatus();
publishRcd("Bad", warnMsg.str(), false, false);
}
} else if (lsCount % (timeoutLS[1]*secPerLS) == 0) { // second timeout
} else if (lsCount % (timeoutLS[1] * secPerLS) == 0) { // second timeout
if (!alive.test(2))
alive.flip(2);
fakeRcd();
Expand All @@ -551,34 +548,32 @@ void problem() {
}

/*****************************************************************************/
void polling()
{
void polling() {
try {
ifstream logFile(sourceFile);

if (!logFile.good()) {
cerr << "Source File: " + sourceFile + " doesn't exist!" << endl;
problem();
problem();
} else {
lastModTime = getLastTime(sourceFile);

if (lastFitTime == 0)
lastFitTime = lastModTime;

if (getFileSize(sourceFile) == 0) {
// source file has zero length
// source file has zero length
if (lastModTime > lastFitTime) {
string tmp = tkStatus();
cerr << "New run starts. Run number: " << runnum << endl;
if (verbose)
cerr << "Initial lastModTime = " + getDateTime(lastModTime) << endl;
}
lastFitTime = lastModTime;

string tmp = tkStatus();
cerr << "New run starts. Run number: " << runnum << endl;
if (verbose)
cerr << "Initial lastModTime = " + getDateTime(lastModTime) << endl;
}
lastFitTime = lastModTime;
}

if (lastModTime > lastFitTime) {
// source file modified
// source file modified
if (verbose) {
cerr << "time of last fit = " + getDateTime(lastFitTime) << endl;
cerr << "time of current fit = " + getDateTime(lastModTime) << endl;
Expand All @@ -597,7 +592,7 @@ void polling()
trueRcd();
alive.reset();
alive.flip(7);
} else {
} else {
if (verbose)
cerr << "problem with new record" << endl;
fakeRcd();
Expand All @@ -606,9 +601,9 @@ void polling()
lsCount = 0;
}
} else {
// source file not touched
problem();
}
// source file not touched
problem();
}
}

logFile.close();
Expand All @@ -619,8 +614,7 @@ void polling()
}

/*****************************************************************************/
void beginServer()
{
void beginServer() {
try {
ErrHandler errHandler;

Expand Down Expand Up @@ -648,8 +642,7 @@ void beginServer()
}

/*****************************************************************************/
void endServer()
{
void endServer() {
// destroy publications and data
cerr << "destroying publication " + subjectCMS << endl;
dip->destroyDipPublication(publicationCMS);
Expand All @@ -658,20 +651,27 @@ void endServer()
cerr << "destroying publication " + subjectLHC << endl;
dip->destroyDipPublication(publicationLHC);
delete messageLHC;

cerr << "destroying publication " + subjectPV << endl;
dip->destroyDipPublication(publicationPV);
delete messagePV;
}

/*****************************************************************************/
int main()
{
int main(int narg, char* args[]) {
// options
verbose = strcmp(args[1], "true");
testing = strcmp(args[2], "true");

sourceFile = args[3];
sourceFile1 = args[4];

//
startTime = getDateTime();
endTime = getDateTime();
endTime = getDateTime();

dip = Dip::create("CmsBeamSpotServer");
// dip->setDNSNode("cmsdimns1.cern.ch");
// dip->setDNSNode("cmsdimns1.cern.ch");
dip->setDNSNode("cmsdimns2.cern.ch");

cerr << "reading from file (NFS)" << endl;
Expand All @@ -681,19 +681,15 @@ int main()

cerr << "entering polling loop" << endl;

while(true)
{
while (true) {
polling();
sleep(1);
}



cerr << "[done]" << endl;

//
endServer();

return 0;
}

12 changes: 12 additions & 0 deletions DQM/BeamMonitor/bin/runtest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

verbose=false
testing=false

prefix=/nfshome0/dqmpro/BeamMonitorDQM

sourceFile=$prefix/BeamFitResultsForDIP.txt
sourceFile1=$prefix/BeamFitResultsOld_TkStatus.txt

beamSpotDipStandalone $verbose $testing $sourceFile $sourceFile1

0 comments on commit f61ebc1

Please sign in to comment.