Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-09 23:01:06

0001 __author__ = 'Giacomo Govi'
0002 
0003 import subprocess
0004 import json
0005 import os
0006 import re
0007 
0008 
0009 
0010 def check_cmssw_version( cmssw_version ):
0011     if cmssw_version.find('CMSSW_')==-1:
0012         raise Exception("CMSSW version '%s' has not been found in the expected format" %cmssw_version)
0013     ver = cmssw_version
0014     p = re.compile('(CMSSW_.*_X)(_.*)?$')
0015     m = p.match(ver)
0016     if not m is None:
0017         gs = m.groups()
0018         if gs[1] != None:
0019             raise Exception("IB version can't be processed.")
0020     return ver
0021 
0022 def is_release_cycle( cmssw_version ):
0023     ind = cmssw_version.find('_X')
0024     return not ind == -1
0025 
0026 def strip_cmssw_version( cmssw_version ):
0027     ver = cmssw_version
0028     if not cmssw_version.find('_X') == -1: 
0029         ver = ver.replace('X','0')
0030     ind = ver.find('_pre')
0031     if not ind == -1:
0032         ver = ver[0:ind]
0033     return ver    
0034 
0035 def cmssw_version_to_int( cmssw_version ):
0036     ver = cmssw_version.split('CMSSW_')[1]
0037     ip = 0
0038     f = ver.find('_patch')
0039     if not f == -1:
0040         ip = int(ver[f+6:])
0041         ver = ver[0:f]
0042     dgs = ver.split('_')
0043     return int('%d%02d%02d%02d' %(int(dgs[0]),int(dgs[1]),int(dgs[2]),ip))
0044 
0045 def cmp_cmssw_version( ver1, ver2 ):
0046     intVer1 = cmssw_version_to_int(ver1)
0047     intVer2 = cmssw_version_to_int(ver2)
0048     if intVer1<intVer2:
0049         return -1
0050     elif intVer1>intVer2:
0051         return 1
0052     else:
0053         return 0
0054 
0055 def strip_boost_version( boost_version ):
0056     bver = boost_version
0057     f = bver.find('_')
0058     if not f==-1:
0059         bver = boost_version.replace('_','.')
0060     f = bver.find('-')
0061     if not f==-1:
0062         bver = bver[0:f]
0063     return bver    
0064 
0065 def boost_version_to_int( boost_version ):
0066     bver = strip_boost_version( boost_version )
0067     dgs = bver.split('.')    
0068     tmpl = '%d%02d%02d'
0069     pars = [0,0,0]
0070     ind = 0
0071     for d in dgs:
0072         if ind <=2:
0073             pars[ind] = int(d)
0074         ind += 1
0075     return int(tmpl %(pars[0],pars[1],pars[2]))
0076 
0077 def cmp_boost_version( ver1, ver2 ):
0078     intVer1 = boost_version_to_int(ver1)
0079     intVer2 = boost_version_to_int(ver2)
0080     if intVer1<intVer2:
0081         return -1
0082     elif intVer1>intVer2:
0083         return 1
0084     else:
0085         return 0
0086 
0087 archs = { 3070000 : ['slc5_amd64_gcc434'], 5010100 : ['slc5_amd64_gcc462'], 6000000 : ['slc6_amd64_gcc472'], 
0088           7000000 : ['slc6_amd64_gcc481'], 7020000 : ['slc6_amd64_gcc491'], 7060000 : ['slc6_amd64_gcc493'],
0089           8000000 : ['slc6_amd64_gcc493','slc6_amd64_gcc530'], 9030000 : ['slc6_amd64_gcc630']}
0090 
0091 cmsPath = '/cvmfs/cms.cern.ch'
0092 
0093 def get_production_arch( version ):
0094     nv = cmssw_version_to_int( version )
0095     rbound = None
0096     for r in sorted(archs.keys()):
0097         if r <= nv:
0098             rbound = r
0099         else:
0100             break
0101     if not rbound is None:
0102         return archs[rbound]
0103     return None
0104 
0105 def get_release_root( cmssw_version, arch ):
0106     cmssw_folder = 'cmssw'
0107     if cmssw_version.find('_patch') != -1:
0108         cmssw_folder= 'cmssw-patch'
0109     ret = '%s/%s/cms/%s' %(cmsPath,arch,cmssw_folder)
0110     return ret 
0111 
0112 def get_cmssw_boost( arch, releaseDir ):
0113     cmd =  'source %s/cmsset_default.sh; export SCRAM_ARCH=%s; cd %s/src ; eval `scram runtime -sh`; scram tool info boost; ' %(cmsPath,arch,releaseDir)
0114     pipe = subprocess.Popen( cmd, shell=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
0115     out = pipe.communicate()[0]
0116     cfgLines = out.split('\n')
0117     boost_version = None
0118     for line in cfgLines:
0119         if line.startswith('Version'):
0120             boost_version = line.split('Version :')[1].strip()
0121             break
0122     if not boost_version is None:
0123         boost_version = strip_boost_version(boost_version)
0124     return boost_version
0125 
0126 def lookup_boost_for_run( iov, timeType, boost_run_map ):
0127     if timeType == 'Lumi':
0128         iov = iov >> 32
0129         timeType = 'Run'
0130     if iov == 0:
0131         iov=1
0132     entry = None
0133     try:
0134         if timeType == 'Time':
0135             entry = max([x for x in boost_run_map if x[1]<=iov])
0136         elif timeType == 'Run':
0137             entry = max([x for x in boost_run_map if x[0]<=iov])
0138         else:
0139             raise Exception('TimeType %s cannot be processed' %timeType)
0140     except Exception as e:
0141         raise e
0142     return entry[2]
0143 
0144 def get_boost_version_from_streamer_info( s_info ):
0145     streamer_info = s_info.decode()
0146     streamer_info = streamer_info.replace('\x00','')
0147     iovBoostVersion = None
0148     if streamer_info == '0':
0149         iovBoostVersion = '1.51.0'
0150     else:
0151         try:
0152             iovBoostVersion = str(json.loads(streamer_info)['tech_version'])
0153             iovBoostVersion = strip_boost_version(iovBoostVersion)
0154         except ValueError as e:
0155             raise Exception("Could not parse streamer info [%s]: %s" %(streamer_info,str(e)))
0156     return iovBoostVersion
0157 
0158 def do_update_tag_boost_version( tagBoostVersion, minIov, iovBoostVersion, iov, timetype, boost_run_map ):
0159     # for hash timetype we need to take the greatest version of the set                                                                                                                 
0160     if timetype == 'Hash':
0161         if tagBoostVersion is None or cmp_boost_version(tagBoostVersion,iovBoostVersion)<0:
0162             tagBoostVersion = iovBoostVersion
0163     # for run, lumi and time we lookup in the boost_run_map to find the reference
0164     else:
0165         if tagBoostVersion is None:
0166             tagBoostVersion = iovBoostVersion
0167         else:
0168             iovRefBoost = lookup_boost_for_run( iov, timetype, boost_run_map )
0169             # the case when the iov does not follow the standard run history
0170             if cmp_boost_version( iovRefBoost, iovBoostVersion )<0:
0171                 if cmp_boost_version(  tagBoostVersion, iovBoostVersion )<0:
0172                     tagBoostVersion = iovBoostVersion
0173             # iov in agreement witjh the standard run history
0174             else:
0175                 tagRefBoost = lookup_boost_for_run( minIov, timetype, boost_run_map )
0176                 # also the current tag follows the standard run history
0177                 if cmp_boost_version( tagRefBoost, tagBoostVersion )>=0:
0178                     # in this case the min boost version should decrease to 
0179                     if cmp_boost_version(  tagBoostVersion, iovRefBoost )>0:
0180                         tagBoostVersion = iovRefBoost
0181     return tagBoostVersion
0182 
0183 def update_tag_boost_version( tagBoostVersion, minIov, streamer_info, iov, timetype, boost_run_map ):
0184     iovBoostVersion = get_boost_version_from_streamer_info( streamer_info )
0185     return iovBoostVersion, do_update_tag_boost_version( tagBoostVersion, minIov, iovBoostVersion, iov, timetype, boost_run_map )
0186 
0187