CMS 3D CMS Logo

G2GainsValidator.py
Go to the documentation of this file.
1 from __future__ import print_function
2 
3 import configparser as ConfigParser
4 import glob
5 import os
6 import numpy
7 import re
8 import ROOT
9 import string
10 import subprocess
11 import sys
12 import optparse
13 import time
14 import json
15 import datetime
16 from datetime import datetime
17 import CondCore.Utilities.conddblib as conddb
18 
19 
20 def getCommandOutput(command):
21 
22  """This function executes `command` and returns it output.
23  Arguments:
24  - `command`: Shell command to be invoked by this function.
25  """
26  child = os.popen(command)
27  data = child.read()
28  err = child.close()
29  if err:
30  print ('%s failed w/ exit code %d' % (command, err))
31  return data
32 
33 
34 def getFCSR():
35 
36  out = subprocess.check_output(["curl", "-k", "-s", "https://cmsweb.cern.ch/t0wmadatasvc/prod/firstconditionsaferun"])
37  response = json.loads(out)["result"][0]
38  return int(response)
39 
40 
42 
43  out = subprocess.check_output(["curl", "-k", "-s", "https://cmsweb.cern.ch/t0wmadatasvc/prod/reco_config"])
44  response = json.loads(out)["result"][0]['global_tag']
45  return response
46 
47 
49 
50  out = subprocess.check_output(["curl", "-k", "-s", "https://cmsweb.cern.ch/t0wmadatasvc/prod/express_config"])
51  response = json.loads(out)["result"][0]['global_tag']
52  return response
53 
54 
55 if __name__ == "__main__":
56 
57 
58  parser = optparse.OptionParser(usage = 'Usage: %prog [options] <file> [<file> ...]\n')
59 
60  parser.add_option('-t', '--validationTag',
61  dest = 'validationTag',
62  default = "SiStripApvGainAfterAbortGap_PCL_multirun_v0_prompt",
63  help = 'validation tag',
64  )
65 
66  parser.add_option('-s', '--since',
67  dest = 'since',
68  default = -1,
69  help = 'sinces to copy from validation tag',
70  )
71 
72  (options, arguments) = parser.parse_args()
73 
74 
75  FCSR = getFCSR()
76  promptGT = getPromptGT()
77  expressGT = getExpressGT()
78  print ("Current FCSR:",FCSR,"| Express Global Tag",expressGT,"| Prompt Global Tag",promptGT)
79 
80  con = conddb.connect(url = conddb.make_url("pro"))
81  session = con.session()
82  IOV = session.get_dbtype(conddb.IOV)
83  TAG = session.get_dbtype(conddb.Tag)
84  GT = session.get_dbtype(conddb.GlobalTag)
85  GTMAP = session.get_dbtype(conddb.GlobalTagMap)
86  RUNINFO = session.get_dbtype(conddb.RunInfo)
87 
88  myGTMap = session.query(GTMAP.record, GTMAP.label, GTMAP.tag_name).\
89  filter(GTMAP.global_tag_name == str(expressGT)).\
90  order_by(GTMAP.record, GTMAP.label).\
91  all()
92 
93 
94  con2 = conddb.connect(url = conddb.make_url("dev"))
95  session2 = con2.session()
96  validationTagIOVs = session2.query(IOV.since,IOV.payload_hash,IOV.insertion_time).filter(IOV.tag_name == options.validationTag).all()
97 
98 
99  IOVsToValidate=[]
100  if(options.since==-1):
101  IOVsToValidate.append(validationTagIOVs[-1][0])
102  print("changing the default validation tag since to:",IOVsToValidate[0])
103 
104  else:
105  for entry in validationTagIOVs:
106  if(options.since!=1 and int(entry[0])>=int(options.since)):
107  print("appending to the validation list:",entry[0],entry[1],entry[2])
108  IOVsToValidate.append(entry[0])
109 
110  for element in myGTMap:
111  #print element
112  Record = element[0]
113  Label = element[1]
114  Tag = element[2]
115  if(Record=="SiStripApvGain2Rcd"):
116  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])
119  command = 'conddb_import -c sqlite_file:toCompare.db -f frontier://FrontierProd/CMS_CONDITIONS -i '+str(Tag) +' -t '+str(Tag)+' -b '+str(lastG2Payload[0])
120  print(command)
121  getCommandOutput(command)
122 
123  for i,theValidationTagSince in enumerate(IOVsToValidate):
124 
125  command = 'conddb_import -c sqlite_file:toCompare.db -f frontier://FrontierPrep/CMS_CONDITIONS -i '+str(options.validationTag) +' -t '+str(Tag)+' -b '+str(theValidationTagSince)
126  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!")
128  command = 'conddb_import -c sqlite_file:toCompare.db -f frontier://FrontierPrep/CMS_CONDITIONS -i '+str(options.validationTag) +' -t '+str(Tag)+' -b '+str(FCSR+i)
129 
130  print(command)
131  getCommandOutput(command)
132 
133  command = './testCompare.sh SiStripApvGain_FromParticles_GR10_v1_express '+str(lastG2Payload[0])+' '+str(theValidationTagSince)+ ' toCompare.db'
134  if(theValidationTagSince < lastG2Payload[0]):
135  command = './testCompare.sh SiStripApvGain_FromParticles_GR10_v1_express '+str(lastG2Payload[0])+' '+str(FCSR+i)+ ' toCompare.db'
136  print(command)
137  getCommandOutput(command)
def all(container)
workaround iterator generators for ROOT classes
Definition: cmstools.py:25
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def getCommandOutput(command)
#define str(s)