CMS 3D CMS Logo

conddb_serialization_metadata.py
Go to the documentation of this file.
1 __author__ = 'Giacomo Govi'
2 
3 import subprocess
4 import json
5 import os
6 import re
7 
8 
9 
10 def check_cmssw_version( cmssw_version ):
11  if cmssw_version.find('CMSSW_')==-1:
12  raise Exception("CMSSW version '%s' has not been found in the expected format" %cmssw_version)
13  ver = cmssw_version
14  p = re.compile('(CMSSW_.*_X)(_.*)?$')
15  m = p.match(ver)
16  if not m is None:
17  gs = m.groups()
18  if gs[1] != None:
19  raise Exception("IB version can't be processed.")
20  return ver
21 
22 def is_release_cycle( cmssw_version ):
23  ind = cmssw_version.find('_X')
24  return not ind == -1
25 
26 def strip_cmssw_version( cmssw_version ):
27  ver = cmssw_version
28  if not cmssw_version.find('_X') == -1:
29  ver = ver.replace('X','0')
30  ind = ver.find('_pre')
31  if not ind == -1:
32  ver = ver[0:ind]
33  return ver
34 
35 def cmssw_version_to_int( cmssw_version ):
36  ver = cmssw_version.split('CMSSW_')[1]
37  ip = 0
38  f = ver.find('_patch')
39  if not f == -1:
40  ip = int(ver[f+6:])
41  ver = ver[0:f]
42  dgs = ver.split('_')
43  return int('%d%02d%02d%02d' %(int(dgs[0]),int(dgs[1]),int(dgs[2]),ip))
44 
45 def cmp_cmssw_version( ver1, ver2 ):
46  intVer1 = cmssw_version_to_int(ver1)
47  intVer2 = cmssw_version_to_int(ver2)
48  if intVer1<intVer2:
49  return -1
50  elif intVer1>intVer2:
51  return 1
52  else:
53  return 0
54 
55 def strip_boost_version( boost_version ):
56  bver = boost_version
57  f = bver.find('_')
58  if not f==-1:
59  bver = boost_version.replace('_','.')
60  f = bver.find('-')
61  if not f==-1:
62  bver = bver[0:f]
63  return bver
64 
65 def boost_version_to_int( boost_version ):
66  bver = strip_boost_version( boost_version )
67  dgs = bver.split('.')
68  tmpl = '%d%02d%02d'
69  pars = [0,0,0]
70  ind = 0
71  for d in dgs:
72  if ind <=2:
73  pars[ind] = int(d)
74  ind += 1
75  return int(tmpl %(pars[0],pars[1],pars[2]))
76 
77 def cmp_boost_version( ver1, ver2 ):
78  intVer1 = boost_version_to_int(ver1)
79  intVer2 = boost_version_to_int(ver2)
80  if intVer1<intVer2:
81  return -1
82  elif intVer1>intVer2:
83  return 1
84  else:
85  return 0
86 
87 archs = { 3070000 : ['slc5_amd64_gcc434'], 5010100 : ['slc5_amd64_gcc462'], 6000000 : ['slc6_amd64_gcc472'],
88  7000000 : ['slc6_amd64_gcc481'], 7020000 : ['slc6_amd64_gcc491'], 7060000 : ['slc6_amd64_gcc493'],
89  8000000 : ['slc6_amd64_gcc493','slc6_amd64_gcc530'], 9030000 : ['slc6_amd64_gcc630']}
90 
91 cmsPath = '/cvmfs/cms.cern.ch'
92 
93 def get_production_arch( version ):
94  nv = cmssw_version_to_int( version )
95  rbound = None
96  for r in sorted(archs.keys()):
97  if r <= nv:
98  rbound = r
99  else:
100  break
101  if not rbound is None:
102  return archs[rbound]
103  return None
104 
105 def get_release_root( cmssw_version, arch ):
106  cmssw_folder = 'cmssw'
107  if cmssw_version.find('_patch') != -1:
108  cmssw_folder= 'cmssw-patch'
109  ret = '%s/%s/cms/%s' %(cmsPath,arch,cmssw_folder)
110  return ret
111 
112 def get_cmssw_boost( arch, releaseDir ):
113  cmd = 'source %s/cmsset_default.sh; export SCRAM_ARCH=%s; cd %s/src ; eval `scram runtime -sh`; scram tool info boost; ' %(cmsPath,arch,releaseDir)
114  pipe = subprocess.Popen( cmd, shell=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
115  out = pipe.communicate()[0]
116  cfgLines = out.split('\n')
117  boost_version = None
118  for line in cfgLines:
119  if line.startswith('Version'):
120  boost_version = line.split('Version :')[1].strip()
121  break
122  if not boost_version is None:
123  boost_version = strip_boost_version(boost_version)
124  return boost_version
125 
126 def lookup_boost_for_run( iov, timeType, boost_run_map ):
127  if timeType == 'Lumi':
128  iov = iov >> 32
129  timeType = 'Run'
130  if iov == 0:
131  iov=1
132  entry = None
133  try:
134  if timeType == 'Time':
135  entry = max([x for x in boost_run_map if x[1]<=iov])
136  elif timeType == 'Run':
137  entry = max([x for x in boost_run_map if x[0]<=iov])
138  else:
139  raise Exception('TimeType %s cannot be processed' %timeType)
140  except Exception as e:
141  raise e
142  return entry[2]
143 
145  streamer_info = s_info.decode()
146  streamer_info = streamer_info.replace('\x00','')
147  iovBoostVersion = None
148  if streamer_info == '0':
149  iovBoostVersion = '1.51.0'
150  else:
151  try:
152  iovBoostVersion = str(json.loads(streamer_info)['tech_version'])
153  iovBoostVersion = strip_boost_version(iovBoostVersion)
154  except ValueError as e:
155  raise Exception("Could not parse streamer info [%s]: %s" %(streamer_info,str(e)))
156  return iovBoostVersion
157 
158 def do_update_tag_boost_version( tagBoostVersion, minIov, iovBoostVersion, iov, timetype, boost_run_map ):
159  # for hash timetype we need to take the greatest version of the set
160  if timetype == 'Hash':
161  if tagBoostVersion is None or cmp_boost_version(tagBoostVersion,iovBoostVersion)<0:
162  tagBoostVersion = iovBoostVersion
163  # for run, lumi and time we lookup in the boost_run_map to find the reference
164  else:
165  if tagBoostVersion is None:
166  tagBoostVersion = iovBoostVersion
167  else:
168  iovRefBoost = lookup_boost_for_run( iov, timetype, boost_run_map )
169  # the case when the iov does not follow the standard run history
170  if cmp_boost_version( iovRefBoost, iovBoostVersion )<0:
171  if cmp_boost_version( tagBoostVersion, iovBoostVersion )<0:
172  tagBoostVersion = iovBoostVersion
173  # iov in agreement witjh the standard run history
174  else:
175  tagRefBoost = lookup_boost_for_run( minIov, timetype, boost_run_map )
176  # also the current tag follows the standard run history
177  if cmp_boost_version( tagRefBoost, tagBoostVersion )>=0:
178  # in this case the min boost version should decrease to
179  if cmp_boost_version( tagBoostVersion, iovRefBoost )>0:
180  tagBoostVersion = iovRefBoost
181  return tagBoostVersion
182 
183 def update_tag_boost_version( tagBoostVersion, minIov, streamer_info, iov, timetype, boost_run_map ):
184  iovBoostVersion = get_boost_version_from_streamer_info( streamer_info )
185  return iovBoostVersion, do_update_tag_boost_version( tagBoostVersion, minIov, iovBoostVersion, iov, timetype, boost_run_map )
186 
187 
def do_update_tag_boost_version(tagBoostVersion, minIov, iovBoostVersion, iov, timetype, boost_run_map)
def lookup_boost_for_run(iov, timeType, boost_run_map)
def update_tag_boost_version(tagBoostVersion, minIov, streamer_info, iov, timetype, boost_run_map)
#define str(s)