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