Skip to content

Commit fe7d0b2

Browse files
committed
LHCInfo* inspection and validation tools
1 parent 6b29f9a commit fe7d0b2

12 files changed

+553
-38
lines changed

CondTools/RunInfo/plugins/BuildFile.xml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@
5555
<flags EDM_PLUGIN="1"/>
5656
</library>
5757

58+
<library file="LHCInfoPerLSCsvAnalyzer.cc" name="LHCInfoPerLSCsvAnalyzer">
59+
<flags EDM_PLUGIN="1"/>
60+
</library>
61+
5862
<library file="LHCInfoPerFillWriter.cc" name="LHCInfoPerFillWriter">
5963
<flags EDM_PLUGIN="1"/>
6064
</library>
@@ -63,27 +67,26 @@
6367
<flags EDM_PLUGIN="1"/>
6468
</library>
6569

66-
<library file="LHCInfoPerLSPopConAnalyzer.cc" name="CondToolsLHCInfoPerLSPopConAnalyzer">
70+
<library file="LHCInfoAnalyzer.cc" name="LHCInfoAnalyzer">
6771
<flags EDM_PLUGIN="1"/>
6872
</library>
6973

70-
<library file="LHCInfoPerFillPopConAnalyzer.cc" name="CondToolsLHCInfoPerFillPopConAnalyzer">
74+
<library file="LHCInfoPerLSPopConAnalyzer.cc" name="CondToolsLHCInfoPerLSPopConAnalyzer">
7175
<flags EDM_PLUGIN="1"/>
7276
</library>
7377

74-
<library file="LHCInfoPerLSWriter.cc" name="LHCInfoPerLSWriter">
78+
<library file="LHCInfoPerFillPopConAnalyzer.cc" name="CondToolsLHCInfoPerFillPopConAnalyzer">
7579
<flags EDM_PLUGIN="1"/>
7680
</library>
7781

78-
<library file="LHCInfoPerLSAnalyzer.cc" name="LHCInfoPerLSAnalyzer">
82+
<library file="LHCInfoPerLSWriter.cc" name="LHCInfoPerLSWriter">
7983
<flags EDM_PLUGIN="1"/>
8084
</library>
8185

8286
<library file="LHCInfoPerFillWriter.cc" name="LHCInfoPerFillWriter">
8387
<flags EDM_PLUGIN="1"/>
8488
</library>
8589

86-
8790
<library file="LHCInfoPerFillAnalyzer.cc" name="LHCInfoPerFillAnalyzer">
8891
<flags EDM_PLUGIN="1"/>
8992
</library>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include "FWCore/Framework/interface/Frameworkfwd.h"
2+
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
3+
#include "FWCore/Framework/interface/Event.h"
4+
#include "FWCore/Framework/interface/EventSetup.h"
5+
#include "FWCore/Framework/interface/ESHandle.h"
6+
#include "FWCore/Framework/interface/ESWatcher.h"
7+
#include "FWCore/Framework/interface/MakerMacros.h"
8+
9+
#include "FWCore/ParameterSet/interface/ParameterSet.h"
10+
#include "FWCore/ServiceRegistry/interface/Service.h"
11+
12+
#include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
13+
14+
#include "CondFormats/RunInfo/interface/LHCInfo.h"
15+
#include "CondFormats/DataRecord/interface/LHCInfoRcd.h"
16+
17+
#include <memory>
18+
#include <iostream>
19+
20+
class LHCInfoAnalyzer : public edm::one::EDAnalyzer<> {
21+
public:
22+
explicit LHCInfoAnalyzer(const edm::ParameterSet&) : tokenInfo_(esConsumes<LHCInfo, LHCInfoRcd>()) {}
23+
24+
private:
25+
void beginJob() override {}
26+
void analyze(const edm::Event&, const edm::EventSetup&) override;
27+
void endJob() override {}
28+
29+
edm::ESWatcher<LHCInfoRcd> InfoWatcher_;
30+
31+
edm::ESGetToken<LHCInfo, LHCInfoRcd> tokenInfo_;
32+
};
33+
34+
void LHCInfoAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
35+
// get Info
36+
if (InfoWatcher_.check(iSetup)) {
37+
const auto& lhcInfo = iSetup.getData(tokenInfo_);
38+
std::cout << "LHCInfo;" << iEvent.time().unixTime() << ";" << lhcInfo.lumiSection() << ";"
39+
<< lhcInfo.crossingAngle() << ";" << lhcInfo.betaStar() << ";" << lhcInfo.delivLumi() << ";" << std::endl;
40+
}
41+
}
42+
43+
DEFINE_FWK_MODULE(LHCInfoAnalyzer);

CondTools/RunInfo/plugins/LHCInfoPerFillAnalyzer.cc

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -31,33 +31,33 @@ class LHCInfoPerFillAnalyzer : public edm::one::EDAnalyzer<> {
3131
void LHCInfoPerFillAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
3232
assert(infoPerFillWatcher_.check(iSetup));
3333

34-
LHCInfoPerFill lhcInfoPerFill = iSetup.getData(tokenInfoPerFill_);
35-
const float EPS = 1E-4;
36-
assert(lhcInfoPerFill.fillNumber() == 3);
37-
assert(lhcInfoPerFill.bunchesInBeam1() == 10);
38-
assert(lhcInfoPerFill.bunchesInBeam2() == 8);
39-
assert(lhcInfoPerFill.collidingBunches() == 5);
40-
assert(lhcInfoPerFill.targetBunches() == 4);
41-
assert(lhcInfoPerFill.fillType() == lhcInfoPerFill.PROTONS);
42-
assert(lhcInfoPerFill.particleTypeForBeam1() == lhcInfoPerFill.PROTON);
43-
assert(lhcInfoPerFill.particleTypeForBeam2() == lhcInfoPerFill.PROTON);
44-
assert(abs(lhcInfoPerFill.intensityForBeam1() - 1016.5) < EPS);
45-
assert(abs(lhcInfoPerFill.intensityForBeam2() - 1096.66) < EPS);
46-
assert(abs(lhcInfoPerFill.energy() - 7000) < EPS);
47-
assert(abs(lhcInfoPerFill.delivLumi() - 2E-07) < EPS);
48-
assert(abs(lhcInfoPerFill.recLumi() - 2E-07) < EPS);
49-
assert(abs(lhcInfoPerFill.instLumi() - 0) < EPS);
50-
assert(abs(lhcInfoPerFill.instLumiError() - 0) < EPS);
51-
assert(lhcInfoPerFill.createTime() == 6561530930997627120);
52-
assert(lhcInfoPerFill.beginTime() == 6561530930997627120);
53-
assert(lhcInfoPerFill.endTime() == 6561530930997627120);
54-
assert(lhcInfoPerFill.injectionScheme() == "None");
55-
assert(lhcInfoPerFill.lumiPerBX().size() == 2);
56-
assert(abs(lhcInfoPerFill.lumiPerBX()[0] - 0.000114139) < EPS);
57-
assert(abs(lhcInfoPerFill.lumiPerBX()[1] - 0.000114139) < EPS);
58-
assert(lhcInfoPerFill.lhcState() == "some lhcState");
59-
assert(lhcInfoPerFill.lhcComment() == "some lhcComment");
60-
assert(lhcInfoPerFill.ctppsStatus() == "some ctppsStatus");
34+
const LHCInfoPerFill& lhcInfoPerFill = iSetup.getData(tokenInfoPerFill_);
35+
// const float EPS = 1E-4;
36+
// assert(lhcInfoPerFill.fillNumber() == 3);
37+
// assert(lhcInfoPerFill.bunchesInBeam1() == 10);
38+
// assert(lhcInfoPerFill.bunchesInBeam2() == 8);
39+
// assert(lhcInfoPerFill.collidingBunches() == 5);
40+
// assert(lhcInfoPerFill.targetBunches() == 4);
41+
// assert(lhcInfoPerFill.fillType() == lhcInfoPerFill.PROTONS);
42+
// assert(lhcInfoPerFill.particleTypeForBeam1() == lhcInfoPerFill.PROTON);
43+
// assert(lhcInfoPerFill.particleTypeForBeam2() == lhcInfoPerFill.PROTON);
44+
// assert(abs(lhcInfoPerFill.intensityForBeam1() - 1016.5) < EPS);
45+
// assert(abs(lhcInfoPerFill.intensityForBeam2() - 1096.66) < EPS);
46+
// assert(abs(lhcInfoPerFill.energy() - 7000) < EPS);
47+
// assert(abs(lhcInfoPerFill.delivLumi() - 2E-07) < EPS);
48+
// assert(abs(lhcInfoPerFill.recLumi() - 2E-07) < EPS);
49+
// assert(abs(lhcInfoPerFill.instLumi() - 0) < EPS);
50+
// assert(abs(lhcInfoPerFill.instLumiError() - 0) < EPS);
51+
// assert(lhcInfoPerFill.createTime() == 6561530930997627120);
52+
// assert(lhcInfoPerFill.beginTime() == 6561530930997627120);
53+
// assert(lhcInfoPerFill.endTime() == 6561530930997627120);
54+
// assert(lhcInfoPerFill.injectionScheme() == "None");
55+
// assert(lhcInfoPerFill.lumiPerBX().size() == 2);
56+
// assert(abs(lhcInfoPerFill.lumiPerBX()[0] - 0.000114139) < EPS);
57+
// assert(abs(lhcInfoPerFill.lumiPerBX()[1] - 0.000114139) < EPS);
58+
// assert(lhcInfoPerFill.lhcState() == "some lhcState");
59+
// assert(lhcInfoPerFill.lhcComment() == "some lhcComment");
60+
// assert(lhcInfoPerFill.ctppsStatus() == "some ctppsStatus");
6161
edm::LogInfo("LHCInfoPerFillAnalyzer") << "LHCInfoPerFill retrieved:\n" << lhcInfoPerFill;
6262
}
6363

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include "FWCore/Framework/interface/Frameworkfwd.h"
2+
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
3+
#include "FWCore/Framework/interface/Event.h"
4+
#include "FWCore/Framework/interface/EventSetup.h"
5+
#include "FWCore/Framework/interface/ESWatcher.h"
6+
#include "FWCore/Framework/interface/MakerMacros.h"
7+
8+
#include "CondFormats/RunInfo/interface/LHCInfoPerLS.h"
9+
#include "CondFormats/DataRecord/interface/LHCInfoPerLSRcd.h"
10+
11+
#include <memory>
12+
#include <iostream>
13+
#include <cassert>
14+
15+
class LHCInfoPerLSCsvAnalyzer : public edm::one::EDAnalyzer<> {
16+
public:
17+
explicit LHCInfoPerLSCsvAnalyzer(const edm::ParameterSet&)
18+
: tokenInfoPerLS_(esConsumes<LHCInfoPerLS, LHCInfoPerLSRcd>()) {}
19+
20+
private:
21+
void beginJob() override {}
22+
void analyze(const edm::Event&, const edm::EventSetup&) override;
23+
void endJob() override {}
24+
25+
edm::ESWatcher<LHCInfoPerLSRcd> infoPerLSWatcher_;
26+
27+
edm::ESGetToken<LHCInfoPerLS, LHCInfoPerLSRcd> tokenInfoPerLS_;
28+
};
29+
30+
void LHCInfoPerLSCsvAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
31+
if (infoPerLSWatcher_.check(iSetup)) {
32+
const LHCInfoPerLS& infoPerLS = iSetup.getData(tokenInfoPerLS_);
33+
std::cout << "LHCInfo;" << iEvent.time().unixTime() << ";" << infoPerLS.runNumber() << ";"
34+
<< infoPerLS.lumiSection() << ";" << infoPerLS.crossingAngleX() << ";" << infoPerLS.crossingAngleY()
35+
<< ";" << infoPerLS.betaStarX() << ";" << infoPerLS.betaStarY() << ";" << std::endl;
36+
}
37+
}
38+
39+
DEFINE_FWK_MODULE(LHCInfoPerLSCsvAnalyzer);
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import sys
2+
3+
import FWCore.ParameterSet.Config as cms
4+
import FWCore.ParameterSet.VarParsing as VarParsing
5+
process = cms.Process('test')
6+
7+
options = VarParsing.VarParsing()
8+
options.register( 'source'
9+
, 'sqlite_file:lhcinfo_pop_test.db' #default value
10+
, VarParsing.VarParsing.multiplicity.singleton
11+
, VarParsing.VarParsing.varType.string
12+
, "Connection string to the DB where payloads are going to be read from"
13+
)
14+
options.register( 'tag'
15+
, 'LHCInfo_PopCon_test'
16+
, VarParsing.VarParsing.multiplicity.singleton
17+
, VarParsing.VarParsing.varType.string
18+
, "Tag to read from in source"
19+
)
20+
options.register( 'timestamp'
21+
, 7133428598295232512
22+
, VarParsing.VarParsing.multiplicity.singleton
23+
, VarParsing.VarParsing.varType.int
24+
, "Timestamp to which payload with relavant IOV will be read"
25+
)
26+
options.parseArguments()
27+
28+
# minimum logging
29+
process.MessageLogger = cms.Service("MessageLogger",
30+
cerr = cms.untracked.PSet(
31+
enable = cms.untracked.bool(False)
32+
),
33+
cout = cms.untracked.PSet(
34+
enable = cms.untracked.bool(True),
35+
threshold = cms.untracked.string('ERROR')
36+
)
37+
)
38+
39+
process.source = cms.Source('EmptyIOVSource',
40+
timetype = cms.string('timestamp'),
41+
firstValue = cms.uint64(options.timestamp),
42+
lastValue = cms.uint64(options.timestamp),
43+
interval = cms.uint64(1)
44+
)
45+
46+
# load info from database
47+
process.load('CondCore.CondDB.CondDB_cfi')
48+
process.CondDB.connect= options.source # SQLite input
49+
50+
process.PoolDBESSource = cms.ESSource('PoolDBESSource',
51+
process.CondDB,
52+
DumpStats = cms.untracked.bool(True),
53+
toGet = cms.VPSet(
54+
cms.PSet(
55+
record = cms.string('LHCInfoRcd'),
56+
tag = cms.string(options.tag)
57+
)
58+
)
59+
)
60+
61+
process.LHCInfoAnalyzer = cms.EDAnalyzer('LHCInfoAnalyzer')
62+
63+
process.path = cms.Path(
64+
process.LHCInfoAnalyzer
65+
)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
filename=9019_fixed_content
2+
extention=csv
3+
4+
# echo > ${filename}.${extention}
5+
while read iov; do
6+
echo -n "$iov;" >> ${filename}.${extention}
7+
# cmsRun LHCInfoAnalyzer_sqlite.py $iov >> ${filename}.out
8+
cmsRun LHCInfoAnalyzer.py tag=LHCInfoEndFill_Run3_validation_v2 \
9+
source=sqlite_file:lhcinfo_9019_fixed.db timestamp=$iov >> ${filename}.${extention}
10+
done < rest_9019_only_iovs_fixed.txt
11+
12+
# grep -E '^(LHC fill|processed iov timestamp|Run number|Crossing angle|Beta star|Delivered Luminosity|Lumi section)' ${filename}.out > ${filename}_grep.out
13+
# grep -E 'processed iov timestamp|LHC fill|Bunches in|Bunches in|Colliding bunches|Target bunches|Fill type|Particle type|Particle type|Crossing angle|Beta star|Average Intensity|Average Intensity|Energy \(GeV|Delivered Luminosity|Recorded Luminosity|Instantaneous Luminosity|Instantaneous Luminosity|Creation time|Begin time|End time|Injection scheme|LHC State|LHC Comments|CTPPS Status|Lumi section|Luminosity per|Beam 1|Beam 2|Beam 1|Beam 2|Bunches filled|Bunches filled' ${filename}.out > ${filename}_grep.out
14+
# grep -E 'LHCInfo' ${filename}.out > ${filename}_grep.csv
15+
16+
#archive
17+
# cmsRun LHCInfoAnalyzer.py tag=LHCInfoEndFill_Run3_validation_v1 \
18+
# source=sqlite_file:lhcinfo_pop_test_8614.db timestamp=$iov >> ${filename}.out
19+
20+
# cmsRun LHCInfoAnalyzer.py tag=LHCInfoEndFill_Run3_validation_v2 \
21+
# source=sqlite_file:lhcinfo_8614_fixed.db timestamp=$iov >> ${filename}.${extention}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#usage: ./getIovList.sh <db> <tag> <limit (default=2000)>
2+
conddb --db $1 list $2 --limit ${3:-2000} | awk '{print $3}'| rev | cut -c2- | rev | cut -c2- | tail -n +4
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
from datetime import datetime
2+
import time
3+
4+
def to_unix_timestamp(date_string):
5+
# try:
6+
date_format = "%d/%m/%Y %H:%M:%S"
7+
datetime_obj = datetime.strptime(date_string, date_format)
8+
unix_timestamp = int(time.mktime(datetime_obj.timetuple()))
9+
return unix_timestamp
10+
# except ValueError:
11+
# throw ValueError("Invalid date format. Please provide date string in the format 'DD/MM/YYYY HH:MI:SS'.")
12+
13+
def to_date_string(unix_timestamp):
14+
# try:
15+
datetime_obj = datetime.fromtimestamp(unix_timestamp)
16+
date_string = datetime_obj.strftime("%d/%m/%Y %H:%M:%S")
17+
return date_string
18+
# except ValueError:
19+
# print("Invalid timestamp. Please provide a valid Unix timestamp.")
20+
21+
22+
with open('8614_pps.txt') as f_pps:
23+
with open('8614_content_csv_ext.out') as f_lhc:
24+
print("fill", "run", "LS", "beta*", "xangle", "dip date", "record", "LS", "beta", "xangle", "delivLumi", "IOV", "IOV date", "beta* error", "xangle error", "", sep = ";")
25+
26+
lhc_beta = None
27+
lhc_xangle = None
28+
29+
line_lhc = f_lhc.readline()
30+
#skip the headers
31+
if "IOV" in line_lhc or line_lhc == "\n":
32+
# print("skipping the header") #TODO remove
33+
line_lhc = f_lhc.readline()
34+
35+
split_lhc = line_lhc.split(';')
36+
37+
for line_pps in f_pps:
38+
line_pps = line_pps[1:-2]
39+
split_pps = line_pps.split(', ')
40+
41+
for i, val in enumerate(split_pps):
42+
print(val, end = ";" if i <= 5 or i == len(split_pps)-1 else ", ")
43+
44+
45+
46+
# print(" pps:", (split_pps[2]), "lhc:", (split_lhc[2]))
47+
if(len(split_pps) > 5 and len(split_lhc) > 5):
48+
# if len(split_pps[5][1:-1]) != len('17/04/2023 07:30:42'):
49+
# print(split_pps[5][1:-1], len(split_pps[5][1:-1]), len('17/04/2023 07:30:42'))
50+
# print(split_pps[5][1:-1])
51+
# print('17/04/2023 07:30:42')
52+
# exit(0)
53+
pps_timestamp = to_unix_timestamp(split_pps[5][1:-1]) + 2*60*60 # - coversion of time zones
54+
# print(pps_timestamp, "-", int(split_lhc[2]), "=", pps_timestamp -int(split_lhc[2]), end = " |; ")
55+
if(abs(pps_timestamp-int(split_lhc[2])) < 10*60 and split_pps[2] == split_lhc[3]):
56+
# print(line_lhc, end="")
57+
print(split_lhc[1], split_lhc[3], split_lhc[5], split_lhc[4], split_lhc[6],
58+
split_lhc[0], to_date_string(int(split_lhc[2])), sep=";", end=";")
59+
lhc_beta = float(split_lhc[5])
60+
lhc_xangle = float(split_lhc[4])
61+
62+
line_lhc = f_lhc.readline()
63+
split_lhc = line_lhc.split(';')
64+
else:
65+
print(";;;;;;;", end = "")
66+
67+
# lhc_beta = lhc_beta
68+
# lhc_xangle = lhc_xangle
69+
pps_beta = float(split_pps[3])
70+
pps_xangle = float(split_pps[4])
71+
# print(pps_beta, lhc_beta, pps_xangle, lhc_xangle, sep=" - ", end = " | ")
72+
print(abs(pps_beta-lhc_beta) if lhc_beta is not None else 0,
73+
abs(pps_xangle-lhc_xangle) if lhc_xangle is not None else 0, "", sep = ";")
74+
75+

0 commit comments

Comments
 (0)