Skip to content

Commit c01d0d2

Browse files
committed
Add a unit test for G2GainsValidator
1 parent a026ca6 commit c01d0d2

File tree

4 files changed

+64
-28
lines changed

4 files changed

+64
-28
lines changed

CondCore/SiStripPlugins/scripts/G2GainsValidator.py

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
from __future__ import print_function
22

3+
from datetime import datetime
4+
import ROOT
35
import configparser as ConfigParser
6+
import datetime
47
import glob
5-
import os
8+
import json
69
import numpy
10+
import optparse
11+
import os
712
import re
8-
import ROOT
13+
import sqlalchemy
914
import string
1015
import subprocess
1116
import sys
12-
import optparse
1317
import time
14-
import json
15-
import datetime
16-
from datetime import datetime
1718
import CondCore.Utilities.conddblib as conddb
1819

1920
##############################################
@@ -59,6 +60,14 @@ def build_curl_command(url, proxy="", certs="", timeout=30, retries=3, user_agen
5960
cmd += f'--connect-timeout {timeout} --retry {retries} {url}'
6061
return cmd
6162

63+
##############################################
64+
def get_hlt_fcsr(session):
65+
##############################################
66+
RunInfo = session.get_dbtype(conddb.RunInfo)
67+
lastRun = session.query(sqlalchemy.func.max(RunInfo.run_number)).scalar()
68+
fcsr = lastRun+1
69+
return int(fcsr)
70+
6271
##############################################
6372
def getFCSR(proxy="", certs=""):
6473
##############################################
@@ -86,6 +95,24 @@ def getExpressGT(proxy="", certs=""):
8695
response = json.loads(out)["result"][0]['global_tag']
8796
return response
8897

98+
##############################################
99+
def resetSynchonization(db_name):
100+
##############################################
101+
import sqlite3
102+
103+
# Connect to the SQLite database
104+
conn = sqlite3.connect(db_name)
105+
106+
# Create a cursor object to execute SQL commands
107+
cursor = conn.cursor()
108+
109+
# Execute the SQL command to update the database
110+
cursor.execute("UPDATE TAG SET SYNCHRONIZATION='any' WHERE SYNCHRONIZATION='express';")
111+
112+
# Commit the changes and close the connection
113+
conn.commit()
114+
conn.close()
115+
89116
##############################################
90117
if __name__ == "__main__":
91118
##############################################
@@ -130,10 +157,12 @@ def getExpressGT(proxy="", certs=""):
130157
FCSR = getFCSR(proxy=options.proxy, certs=certs)
131158
promptGT = getPromptGT(proxy=options.proxy, certs=certs)
132159
expressGT = getExpressGT(proxy=options.proxy, certs=certs)
133-
print ("Current FCSR:",FCSR,"| Express Global Tag",expressGT,"| Prompt Global Tag",promptGT)
134160

135161
con = conddb.connect(url = conddb.make_url("pro"))
136162
session = con.session()
163+
164+
HLTFCSR = get_hlt_fcsr(session)
165+
print ("Current next HLT run", HLTFCSR, "| curret FCSR:", FCSR ,"| Express Global Tag",expressGT,"| Prompt Global Tag",promptGT)
137166
IOV = session.get_dbtype(conddb.IOV)
138167
TAG = session.get_dbtype(conddb.Tag)
139168
GT = session.get_dbtype(conddb.GlobalTag)
@@ -154,12 +183,12 @@ def getExpressGT(proxy="", certs=""):
154183
IOVsToValidate=[]
155184
if(options.since==-1):
156185
IOVsToValidate.append(validationTagIOVs[-1][0])
157-
print("changing the default validation tag since to:",IOVsToValidate[0])
186+
print("Changing the default validation tag since to:",IOVsToValidate[0])
158187

159188
else:
160189
for entry in validationTagIOVs:
161190
if(options.since!=1 and int(entry[0])>=int(options.since)):
162-
print("appending to the validation list:",entry[0],entry[1],entry[2])
191+
print("Appending to the validation list:",entry[0],entry[1],entry[2])
163192
IOVsToValidate.append(entry[0])
164193

165194
for element in myGTMap:
@@ -169,24 +198,33 @@ def getExpressGT(proxy="", certs=""):
169198
Tag = element[2]
170199
if(Record=="SiStripApvGain2Rcd"):
171200
TagIOVs = session.query(IOV.since,IOV.payload_hash,IOV.insertion_time).filter(IOV.tag_name == Tag).all()
172-
lastG2Payload = TagIOVs[-1]
173-
print("last payload has IOV since:",lastG2Payload[0],"payload hash:",lastG2Payload[1],"insertion time:",lastG2Payload[2])
201+
sorted_TagIOVs = sorted(TagIOVs, key=lambda x: x[0])
202+
lastG2Payload = sorted_TagIOVs[-1]
203+
print("Last G2 Prompt payload has IOV since:",lastG2Payload[0],"payload hash:",lastG2Payload[1],"insertion time:",lastG2Payload[2])
204+
205+
# Get and print the current working directory
206+
current_directory = os.getcwd()
207+
print("Current Working Directory:", current_directory)
208+
174209
command = 'conddb_import -c sqlite_file:toCompare.db -f frontier://FrontierProd/CMS_CONDITIONS -i '+str(Tag) +' -t '+str(Tag)+' -b '+str(lastG2Payload[0])
175210
print(command)
176211
getCommandOutput(command)
177212

213+
# set syncrhonization to any
214+
resetSynchonization("toCompare.db")
215+
178216
for i,theValidationTagSince in enumerate(IOVsToValidate):
179217

180218
command = 'conddb_import -c sqlite_file:toCompare.db -f frontier://FrontierPrep/CMS_CONDITIONS -i '+str(options.validationTag) +' -t '+str(Tag)+' -b '+str(theValidationTagSince)
181219
if(theValidationTagSince < lastG2Payload[0]):
182-
print("the last available IOV in the validation tag is older than the current last express IOV, taking FCSR as a since!")
220+
print("The last available IOV in the validation tag is older than the current last express IOV, taking FCSR as a since!")
183221
command = 'conddb_import -c sqlite_file:toCompare.db -f frontier://FrontierPrep/CMS_CONDITIONS -i '+str(options.validationTag) +' -t '+str(Tag)+' -b '+str(FCSR+i)
184222

185223
print(command)
186224
getCommandOutput(command)
187225

188-
command = './testCompare.sh SiStripApvGain_FromParticles_GR10_v1_express '+str(lastG2Payload[0])+' '+str(theValidationTagSince)+ ' toCompare.db'
226+
command = '${CMSSW_BASE}/src/CondCore/SiStripPlugins/scripts/testCompare.sh SiStripApvGain_FromParticles_GR10_v1_express '+str(lastG2Payload[0])+' '+str(theValidationTagSince)+' '+current_directory+'/toCompare.db'
189227
if(theValidationTagSince < lastG2Payload[0]):
190-
command = './testCompare.sh SiStripApvGain_FromParticles_GR10_v1_express '+str(lastG2Payload[0])+' '+str(FCSR+i)+ ' toCompare.db'
228+
command = '${CMSSW_BASE}/src/CondCore/SiStripPlugins/scripts/testCompare.sh SiStripApvGain_FromParticles_GR10_v1_express '+str(lastG2Payload[0])+' '+str(FCSR+i)+' '+current_directory+'/toCompare.db'
191229
print(command)
192230
getCommandOutput(command)

CondCore/SiStripPlugins/scripts/testCompare.sh

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,25 @@ display_usage() {
66
}
77

88
# if less than two arguments supplied, display usage
9-
if [ $# -le 3 ]
10-
then
11-
display_usage
12-
exit 1
13-
fi
9+
if [ $# -le 3 ]
10+
then
11+
display_usage
12+
exit 1
13+
fi
1414

1515
# check whether user had supplied -h or --help . If yes display usage
16-
if [[ ( $# == "--help") || $# == "-h" ]]
17-
then
18-
display_usage
19-
exit 0
20-
fi
16+
if [[ ( $# == "--help") || $# == "-h" ]]
17+
then
18+
display_usage
19+
exit 0
20+
fi
2121

2222
# Save current working dir so img can be outputted there later
2323
W_DIR=$(pwd);
24-
# Set SCRAM architecture var
25-
SCRAM_ARCH=slc6_amd64_gcc630;
24+
2625
STARTIOV=$2
2726
ENDIOV=$3
2827

29-
export SCRAM_ARCH;
3028
source /afs/cern.ch/cms/cmsset_default.sh;
3129
eval `scram run -sh`;
3230
# Go back to original working directory

CondCore/SiStripPlugins/test/BuildFile.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
<use name="CalibTracker/SiStripCommon"/>
99
<bin file="testSiStripPayloadInspector.cpp" name="testSiStripPayloadInspector">
1010
</bin>
11+
<test name="test_G2GainsValidator" command="test_G2GainsValidator.sh"/>

CondCore/SiStripPlugins/test/test_G2GainsValidator.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22

33
function die { echo $1: status $2 ; exit $2; }
44
python3 $CMSSW_BASE/src/CondCore/SiStripPlugins/scripts/G2GainsValidator.py || die "Failure running G2GainsValidator.py" $?
5-

0 commit comments

Comments
 (0)