ATLAS Offline Software
Loading...
Searching...
No Matches
AODFixHelper.py
Go to the documentation of this file.
1# Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
2
3import re
4from AthenaCommon.Logging import logging
5
6#Helper method to determine if the input release is in particular release range.
7#The boundaries rel1 and rel2 are inclusive.
8
9def releaseInRange(flags,rel1,rel2,inputRelease=None):
10 msg=logging.getLogger("releaseInRange")
11
12 #This regex matches 3 and 4 digit release numbers
13 #It also matches only something that start with Athena-xx
14 relPattern=re.compile(r"^Athena-(\d+(\.\d+){2,3}(\.\*)?)$")
15 relPattern_Nightly=re.compile(r"^Athena-\d+(\.\d+){2,3}-(?:\d+\.\d+|main)-\d{4}-\d{2}-\d{2}T\d{4}$")#in case of a Nightly release used for production of the sample
16
17 for r in (rel1,rel2):
18 if not relPattern.match(r):
19 raise RuntimeError("Release number %s doesn't match the expected format"%r)
20
21 if inputRelease is None:
22 inputRelease=flags.Input.Release
23
24 # protection against AOD with very old releases or not read correctly by MetaReader.py
25 if inputRelease == "" or not inputRelease.startswith("Athena-"):
26 msg.debug("flags.Input.Release is read as empty or it does not start with 'Athena-'")
27 return False
28
29 if not relPattern.match(inputRelease) and not relPattern_Nightly.match(inputRelease):
30 raise RuntimeError("Input release number %s doesn't match the expected format"%inputRelease)
31
32 # convert 3 digits releases to 4 digits
33 if rel1.count(".") == 2: rel1=f"{rel1}.0"
34 if rel2.count(".") == 2: rel2=f"{rel2}.0"
35 if relPattern_Nightly.match(inputRelease): inputRelease = re.sub(r"(-(?:\d+\.\d+|main)-\d{4}-\d{2}-\d{2}T\d{4})$", "", inputRelease) #removing the Nightly part (the usefull part of the release name should be remaining)
36 if inputRelease.count(".") == 2: inputRelease=f"{inputRelease}.0"
37
38 #By Atlas convention, the first number denotes the major release, the second one the purpose (Tier0, Generation, ... )
39 #the third one is the running version number, the fourth one the patch number
40 #We request that the first two numbers are identical and the (third*10000 + forth) ones are in range
41
42 def identifyMajorAndMinorRel(rel):
43 idx = rel.rfind(".", 0, rel.rfind("."))
44 return rel[:idx]
45
46 def mangleRunningAndPatch(rel):
47 rel_split = rel.split(".")
48 return int(rel_split[2])*10000 + int(rel_split[3]) # running*10000 should be safely high enough
49
50 if identifyMajorAndMinorRel(rel1) != identifyMajorAndMinorRel(rel2):
51 raise RuntimeError("Boundary releases not from the same release series, got %s and %s"%(rel1,rel2))
52
53 if identifyMajorAndMinorRel(rel1) != identifyMajorAndMinorRel(inputRelease):
54 msg.info("Input release %s not from the same release series %s.", inputRelease, rel1)
55 return False
56 msg.info("Input release %s from the same release series %s.", inputRelease, rel1)
57
58 #convert number to int for comparison
59 lower=mangleRunningAndPatch(rel1)
60 upper=mangleRunningAndPatch(rel2)
61 current=mangleRunningAndPatch(inputRelease)
62
63 if (lower > upper):
64 raise RuntimeError("Lower boundary releases %s larger then upper boundary release %s" % (rel1,rel2))
65
66 if (current >= lower and current <= upper):
67 return True
68 else:
69 return False
releaseInRange(flags, rel1, rel2, inputRelease=None)