Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-03-27 22:29:40

0001 from __future__ import print_function 
0002 
0003 import configparser as ConfigParser
0004 import glob
0005 import os
0006 import numpy
0007 import re
0008 import ROOT
0009 import string
0010 import subprocess
0011 import sys
0012 import optparse
0013 import time
0014 import json
0015 import datetime
0016 from datetime import datetime
0017 import CondCore.Utilities.conddblib as conddb
0018 
0019 ##############################################
0020 def getCommandOutput(command):
0021 ##############################################
0022     """This function executes `command` and returns it output.
0023     Arguments:
0024     - `command`: Shell command to be invoked by this function.
0025     """
0026     child = os.popen(command)
0027     data = child.read()
0028     err = child.close()
0029     if err:
0030         print ('%s failed w/ exit code %d' % (command, err))
0031     return data
0032 
0033 ##############################################
0034 def getFCSR():
0035 ##############################################
0036     out = subprocess.check_output(["curl", "-k", "-s", "https://cmsweb.cern.ch/t0wmadatasvc/prod/firstconditionsaferun"])
0037     response = json.loads(out)["result"][0]
0038     return int(response)
0039 
0040 ##############################################
0041 def getPromptGT():
0042 ##############################################
0043     out = subprocess.check_output(["curl", "-k", "-s", "https://cmsweb.cern.ch/t0wmadatasvc/prod/reco_config"])
0044     response = json.loads(out)["result"][0]['global_tag']
0045     return response
0046 
0047 ##############################################
0048 def getExpressGT():
0049 ##############################################
0050     out = subprocess.check_output(["curl", "-k", "-s", "https://cmsweb.cern.ch/t0wmadatasvc/prod/express_config"])
0051     response = json.loads(out)["result"][0]['global_tag']
0052     return response
0053 
0054 ##############################################
0055 if __name__ == "__main__":
0056 ##############################################
0057 
0058     parser = optparse.OptionParser(usage = 'Usage: %prog [options] <file> [<file> ...]\n')
0059      
0060     parser.add_option('-t', '--validationTag',
0061                       dest = 'validationTag',
0062                       default = "SiStripApvGainAfterAbortGap_PCL_multirun_v0_prompt",
0063                       help = 'validation tag',
0064                       )
0065      
0066     parser.add_option('-s', '--since',
0067                       dest = 'since',
0068                       default = -1,
0069                       help = 'sinces to copy from validation tag',
0070                       )
0071      
0072     (options, arguments) = parser.parse_args()
0073 
0074 
0075     FCSR = getFCSR()
0076     promptGT  = getPromptGT()
0077     expressGT = getExpressGT() 
0078     print ("Current FCSR:",FCSR,"| Express Global Tag",expressGT,"| Prompt Global Tag",promptGT)
0079 
0080     con = conddb.connect(url = conddb.make_url("pro"))
0081     session = con.session()
0082     IOV     = session.get_dbtype(conddb.IOV)
0083     TAG     = session.get_dbtype(conddb.Tag)
0084     GT      = session.get_dbtype(conddb.GlobalTag)
0085     GTMAP   = session.get_dbtype(conddb.GlobalTagMap)
0086     RUNINFO = session.get_dbtype(conddb.RunInfo)
0087 
0088     myGTMap = session.query(GTMAP.record, GTMAP.label, GTMAP.tag_name).\
0089         filter(GTMAP.global_tag_name == str(expressGT)).\
0090         order_by(GTMAP.record, GTMAP.label).\
0091         all()
0092 
0093     ## connect to prep DB and get the list of IOVs to look at
0094     con2 = conddb.connect(url = conddb.make_url("dev"))
0095     session2 = con2.session()
0096     validationTagIOVs = session2.query(IOV.since,IOV.payload_hash,IOV.insertion_time).filter(IOV.tag_name == options.validationTag).all()
0097 
0098     ### fill the list of IOVs to be validated
0099     IOVsToValidate=[]
0100     if(options.since==-1):
0101         IOVsToValidate.append(validationTagIOVs[-1][0])
0102         print("changing the default validation tag since to:",IOVsToValidate[0])
0103         
0104     else:
0105         for entry in validationTagIOVs:
0106             if(options.since!=1 and int(entry[0])>=int(options.since)):
0107                 print("appending to the validation list:",entry[0],entry[1],entry[2])
0108                 IOVsToValidate.append(entry[0])
0109             
0110     for element in myGTMap:
0111     #print element
0112         Record = element[0]
0113         Label  = element[1]
0114         Tag = element[2]
0115         if(Record=="SiStripApvGain2Rcd"):
0116             TagIOVs = session.query(IOV.since,IOV.payload_hash,IOV.insertion_time).filter(IOV.tag_name == Tag).all()
0117             lastG2Payload = TagIOVs[-1]
0118             print("last payload has IOV since:",lastG2Payload[0],"payload hash:",lastG2Payload[1],"insertion time:",lastG2Payload[2])
0119             command = 'conddb_import -c sqlite_file:toCompare.db -f frontier://FrontierProd/CMS_CONDITIONS -i '+str(Tag) +' -t '+str(Tag)+' -b '+str(lastG2Payload[0])
0120             print(command)
0121             getCommandOutput(command)
0122 
0123             for i,theValidationTagSince in enumerate(IOVsToValidate):
0124 
0125                 command = 'conddb_import -c sqlite_file:toCompare.db -f frontier://FrontierPrep/CMS_CONDITIONS -i '+str(options.validationTag) +' -t '+str(Tag)+' -b '+str(theValidationTagSince)
0126                 if(theValidationTagSince < lastG2Payload[0]):
0127                     print("the last available IOV in the validation tag is older than the current last express IOV, taking FCSR as a since!")
0128                     command = 'conddb_import -c sqlite_file:toCompare.db -f frontier://FrontierPrep/CMS_CONDITIONS -i '+str(options.validationTag) +' -t '+str(Tag)+' -b '+str(FCSR+i)
0129 
0130                 print(command)
0131                 getCommandOutput(command)
0132 
0133                 command = './testCompare.sh SiStripApvGain_FromParticles_GR10_v1_express '+str(lastG2Payload[0])+' '+str(theValidationTagSince)+ ' toCompare.db'
0134                 if(theValidationTagSince < lastG2Payload[0]):
0135                     command = './testCompare.sh SiStripApvGain_FromParticles_GR10_v1_express '+str(lastG2Payload[0])+' '+str(FCSR+i)+ ' toCompare.db'
0136                 print(command)
0137                 getCommandOutput(command)