CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
cmsswRelease.py
Go to the documentation of this file.
1 import os
2 import re
3 
5  #return os.environ['CMSSW_BASE'].split('/')[-1]
6  #this also works when the CMSSW directory is renamed
7  return os.environ['CMSSW_VERSION']
8 
9 def cmsswIs44X():
10  return cmsswRelease().find('CMSSW_4_4_') != -1
11 
12 def cmsswIs52X():
13  if cmsswRelease().find('CMSSW_5_2_') != -1 or \
14  cmsswRelease().find('CMSSW_5_3_') != -1:
15  return True
16  else:
17  return False
18 
19 def releaseNumber(release = None):
20  # first check if this is an integration build
21  if release is None:
22  release = cmsswRelease()
23  ibrel = re.compile('^CMSSW_(\d+)_(\d+)_X.*$')
24  m = ibrel.match(release)
25  if m:
26  big = int(m.group(1))
27  medium = int(m.group(2))
28  return big, medium
29  rerel = re.compile('^CMSSW_(\d+)_(\d+)_(\d+)(_\S+)*$')
30  m = rerel.match(release)
31  if m is None:
32  raise ValueError('malformed release string '+release)
33  big = int(m.group(1))
34  medium = int(m.group(2))
35  small = int(m.group(3))
36  if m.group(4): # that's either a patch or prerelease
37  prel = re.compile('_pre(\d+)')
38  patch = re.compile('_patch(\d+)')
39  pm = prel.match(m.group(4))
40  if pm: # prerelease
41  pre = int(pm.group(1))
42  return big, medium, small, pre
43  else: # patch
44  pm2 = patch.match(m.group(4))
45  if pm2:
46  pat = int(pm2.group(1))
47  return big, medium, small, pat
48  else:
49  raise ValueError('patch or prerelease string malformed '+m.group(4))
50  else:
51  return big, medium, small
52 
53 def isNewerThan(release1, release2=None):
54  """Checks the orders of two releases. If release2 is not set, it is taken as the current release"""
55  return releaseNumber(release2) >= releaseNumber(release1)
56 
57 
58 if __name__ == '__main__':
59 
60  import unittest
61 
62  class CMSSWReleaseTest(unittest.TestCase):
63  def test_cmsswRelease(self):
64  rel = cmsswRelease()
65  self.assertTrue(rel.startswith('CMSSW_'))
66  def test_releaseNumber(self):
67  out = releaseNumber('CMSSW_7_2_1')
68  self.assertEqual(out, (7,2,1))
69  out = releaseNumber('CMSSW_10_2_1_patch4')
70  self.assertEqual(out, (10,2,1,4))
71  out = releaseNumber('CMSSW_7_3_X_2014-10-30-0200')
72  self.assertEqual(out, (7,3))
73  out = releaseNumber('CMSSW_7_3_0_pre2')
74  self.assertEqual(out, (7,3,0,2))
75  self.assertRaises(ValueError, releaseNumber, 'foobar')
76  self.assertRaises(ValueError, releaseNumber, 'CMSSW_1_2_3_xat3')
77  self.assertRaises(ValueError, releaseNumber, 'CMSSW_1_2_a')
78  def test_isNewerThan(self):
79  self.assertTrue( isNewerThan('CMSSW_5_3_1','CMSSW_7_1_0') )
80  self.assertTrue( isNewerThan('CMSSW_5_3_1','CMSSW_5_3_1_patch1') )
81  self.assertTrue( isNewerThan('CMSSW_5_3_1','CMSSW_5_3_1_pre1') )
82  self.assertTrue( isNewerThan('CMSSW_5_3_1_pre1','CMSSW_5_3_1_pre2') )
83 
84 
85 
86  unittest.main()
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
def cmsswRelease
Definition: cmsswRelease.py:4