11from __future__ import print_function
22
3+ from datetime import datetime
4+ import ROOT
35import configparser as ConfigParser
6+ import datetime
47import glob
5- import os
8+ import json
69import numpy
10+ import optparse
11+ import os
712import re
8- import ROOT
13+ import sqlalchemy
914import string
1015import subprocess
1116import sys
12- import optparse
1317import time
14- import json
15- import datetime
16- from datetime import datetime
1718import CondCore .Utilities .conddblib as conddb
1819
1920##############################################
@@ -31,26 +32,87 @@ def getCommandOutput(command):
3132 return data
3233
3334##############################################
34- def getFCSR ():
35+ def getCerts () -> str :
36+ ##############################################
37+ cert_path = os .getenv ('X509_USER_CERT' , '' )
38+ key_path = os .getenv ('X509_USER_KEY' , '' )
39+
40+ certs = ""
41+ if cert_path :
42+ certs += f' --cert { cert_path } '
43+ else :
44+ print ("No certificate, nor proxy provided for Tier0 access" )
45+ if key_path :
46+ certs += f' --key { key_path } '
47+ return certs
48+
49+ ##############################################
50+ def build_curl_command (url , proxy = "" , certs = "" , timeout = 30 , retries = 3 , user_agent = "MyUserAgent" ):
51+ ##############################################
52+ """Builds the curl command with the appropriate proxy, certs, and options."""
53+ cmd = f'/usr/bin/curl -k -L --user-agent "{ user_agent } " '
54+
55+ if proxy :
56+ cmd += f'--proxy { proxy } '
57+ else :
58+ cmd += f'{ certs } '
59+
60+ cmd += f'--connect-timeout { timeout } --retry { retries } { url } '
61+ return cmd
62+
3563##############################################
36- out = subprocess .check_output (["curl" , "-k" , "-s" , "https://cmsweb.cern.ch/t0wmadatasvc/prod/firstconditionsaferun" ])
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+
71+ ##############################################
72+ def getFCSR (proxy = "" , certs = "" ):
73+ ##############################################
74+ url = "https://cmsweb.cern.ch/t0wmadatasvc/prod/firstconditionsaferun"
75+ cmd = build_curl_command (url , proxy = proxy , certs = certs )
76+ out = subprocess .check_output (cmd , shell = True )
3777 response = json .loads (out )["result" ][0 ]
3878 return int (response )
3979
4080##############################################
41- def getPromptGT ():
81+ def getPromptGT (proxy = "" , certs = "" ):
4282##############################################
43- out = subprocess .check_output (["curl" , "-k" , "-s" , "https://cmsweb.cern.ch/t0wmadatasvc/prod/reco_config" ])
83+ url = "https://cmsweb.cern.ch/t0wmadatasvc/prod/reco_config"
84+ cmd = build_curl_command (url , proxy = proxy , certs = certs )
85+ out = subprocess .check_output (cmd , shell = True )
4486 response = json .loads (out )["result" ][0 ]['global_tag' ]
4587 return response
4688
4789##############################################
48- def getExpressGT ():
90+ def getExpressGT (proxy = "" , certs = "" ):
4991##############################################
50- out = subprocess .check_output (["curl" , "-k" , "-s" , "https://cmsweb.cern.ch/t0wmadatasvc/prod/express_config" ])
92+ url = "https://cmsweb.cern.ch/t0wmadatasvc/prod/express_config"
93+ cmd = build_curl_command (url , proxy = proxy , certs = certs )
94+ out = subprocess .check_output (cmd , shell = True )
5195 response = json .loads (out )["result" ][0 ]['global_tag' ]
5296 return response
5397
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+
54116##############################################
55117if __name__ == "__main__" :
56118##############################################
@@ -68,17 +130,39 @@ def getExpressGT():
68130 default = - 1 ,
69131 help = 'sinces to copy from validation tag' ,
70132 )
71-
133+
134+ parser .add_option ('-p' , '--proxy' ,
135+ dest = 'proxy' ,
136+ default = "" ,
137+ help = 'proxy to use for curl requests' ,
138+ )
139+
140+ parser .add_option ('-u' , '--user-mode' ,
141+ dest = 'user_mode' ,
142+ action = 'store_true' ,
143+ default = False ,
144+ help = 'Enable user mode with specific X509 user certificate and key' )
145+
72146 (options , arguments ) = parser .parse_args ()
73147
148+ if options .user_mode :
149+ os .environ ['X509_USER_KEY' ] = os .path .expanduser ('~/.globus/userkey.pem' )
150+ os .environ ['X509_USER_CERT' ] = os .path .expanduser ('~/.globus/usercert.pem' )
151+ print ("User mode enabled. Using X509_USER_KEY and X509_USER_CERT from ~/.globus/" )
74152
75- FCSR = getFCSR ()
76- promptGT = getPromptGT ()
77- expressGT = getExpressGT ()
78- print ("Current FCSR:" ,FCSR ,"| Express Global Tag" ,expressGT ,"| Prompt Global Tag" ,promptGT )
153+ certs = ""
154+ if not options .proxy :
155+ certs = getCerts ()
156+
157+ FCSR = getFCSR (proxy = options .proxy , certs = certs )
158+ promptGT = getPromptGT (proxy = options .proxy , certs = certs )
159+ expressGT = getExpressGT (proxy = options .proxy , certs = certs )
79160
80161 con = conddb .connect (url = conddb .make_url ("pro" ))
81162 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 )
82166 IOV = session .get_dbtype (conddb .IOV )
83167 TAG = session .get_dbtype (conddb .Tag )
84168 GT = session .get_dbtype (conddb .GlobalTag )
@@ -99,12 +183,12 @@ def getExpressGT():
99183 IOVsToValidate = []
100184 if (options .since == - 1 ):
101185 IOVsToValidate .append (validationTagIOVs [- 1 ][0 ])
102- print ("changing the default validation tag since to:" ,IOVsToValidate [0 ])
186+ print ("Changing the default validation tag since to:" ,IOVsToValidate [0 ])
103187
104188 else :
105189 for entry in validationTagIOVs :
106190 if (options .since != 1 and int (entry [0 ])>= int (options .since )):
107- 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 ])
108192 IOVsToValidate .append (entry [0 ])
109193
110194 for element in myGTMap :
@@ -114,24 +198,33 @@ def getExpressGT():
114198 Tag = element [2 ]
115199 if (Record == "SiStripApvGain2Rcd" ):
116200 TagIOVs = session .query (IOV .since ,IOV .payload_hash ,IOV .insertion_time ).filter (IOV .tag_name == Tag ).all ()
117- lastG2Payload = TagIOVs [- 1 ]
118- 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+
119209 command = 'conddb_import -c sqlite_file:toCompare.db -f frontier://FrontierProd/CMS_CONDITIONS -i ' + str (Tag ) + ' -t ' + str (Tag )+ ' -b ' + str (lastG2Payload [0 ])
120210 print (command )
121211 getCommandOutput (command )
122212
213+ # set syncrhonization to any
214+ resetSynchonization ("toCompare.db" )
215+
123216 for i ,theValidationTagSince in enumerate (IOVsToValidate ):
124217
125218 command = 'conddb_import -c sqlite_file:toCompare.db -f frontier://FrontierPrep/CMS_CONDITIONS -i ' + str (options .validationTag ) + ' -t ' + str (Tag )+ ' -b ' + str (theValidationTagSince )
126219 if (theValidationTagSince < lastG2Payload [0 ]):
127- 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!" )
128221 command = 'conddb_import -c sqlite_file:toCompare.db -f frontier://FrontierPrep/CMS_CONDITIONS -i ' + str (options .validationTag ) + ' -t ' + str (Tag )+ ' -b ' + str (FCSR + i )
129222
130223 print (command )
131224 getCommandOutput (command )
132225
133- 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'
134227 if (theValidationTagSince < lastG2Payload [0 ]):
135- 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'
136229 print (command )
137230 getCommandOutput (command )
0 commit comments