ATLAS Offline Software
Loading...
Searching...
No Matches
AtlRunQueryInterpretDataPeriods.py
Go to the documentation of this file.
1#!/usr/bin/env python
2
3# Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
4
5"""
6Periods are assigned an ordinate by which they can be sorted
7"""
8
9from functools import cache
10import re,sys
11
12pat_last = re.compile(r"(?:l|la|las|last) (\d*)$") # l(ast) NN runs
13pat_number = re.compile(r"\d{5,8}[+-]?$") # run number (5-8 digits), possibly followed by a + or -
14pat_range = re.compile(r"\d{5,8}-\d{5,8}$") # range of run numbers (each 5-8 digits)
15pat_short = re.compile(r"(?:(?:\d{2})(\d{2})\.)?([a-zA-Z]+\d*)$")
16pshort = re.compile(r"(?P<first>(data|20)?(?P<year>\d{2})(_.*)?\.)?(period)?(?P<period>[a-zA-Z])(?P<subperiod>\d+)?$",re.I) # 2015_periodA5
17
18
19
20
22 """
23 returns the last two digits of current year
24 """
25 from time import gmtime
26 return gmtime().tm_year - 2000
27
28
29
30def getRunsFromPeriods(list_of_periods):
31 """
32 find the run numbers for given period(s)
33
34 list_of_periods periods in format [('10','B1'),('11','A'),...]
35 """
36 runlist = []
37 from CoolRunQuery.AtlRunQueryCOMA import ARQ_COMA
38 for year, period, fname in list_of_periods:
39 runlist += ARQ_COMA.get_runs(period, 2000+int(year))
40 return runlist
41
42
43@cache
45 from CoolRunQuery.AtlRunQueryCOMA import ARQ_COMA
46 available_periods = ARQ_COMA.get_all_periods()
47 available_periods.sort()
48 #print ('\nAvailable periods:\n')
49 #for i,p in enumerate(available_periods):
50 # print (p)
51 return available_periods
52
53
54def getListOfPeriodsFromOrdinateRange(begin, end, requiredProjectName, specialData=None ):
55 """
56 requiredProjectName e.g. data15_13TeV, data15_cos, data15_hip, etc. . If None then it is required that the project name ends in TeV
57 """
58 if begin>end:
59 sys.exit(0)
60 list_of_periods = []
61
62 for p,full_name in getSortedAvailablePeriods():
63 (year, period, ordcode, projname) = p
64
65 if requiredProjectName is None:
66 if not projname.endswith("TeV"):
67 continue
68 else:
69 if projname != requiredProjectName:
70 continue
71
72 if ordcode == 0: # no special VdM or AllYear stuff periods
73 if specialData is not None:
74 (vdmyear, vdmperiod, vdmsubperiod) = specialData
75 if year==vdmyear and (vdmperiod+vdmsubperiod)==period:
76 list_of_periods += [ (year, period, full_name) ]
77 print (p,"--> include")
78 continue
79
80 if ordcode % 100 == 0: # no full periods as they are already listed in the numbered periods
81 continue
82
83 if ordcode < begin or ordcode>end:
84 continue
85
86 list_of_periods += [ (year, period, full_name) ]
87 print (p,"--> include")
88 return list_of_periods
89
90
91
92def getDataPeriodsWithinRange( period_range ):
93
94 m1 = pshort.match(period_range[0])
95 m2 = pshort.match(period_range[1])
96
97 if m1 is None or m2 is None:
98 if m1 is None:
99 print ("Invalid specification of begin of range",period_range[0])
100 if m2 is None:
101 print ("Invalid specification of end of range", period_range[1])
102 sys.exit(0)
103
104 m1 = m1.groupdict()
105 m2 = m2.groupdict()
106
107 # year
108 m1['year'] = int(m1['year']) if m1['year'] else getCurrentYear()
109 m2['year'] = int(m2['year']) if m2['year'] else m1['year']
110 # sub-period
111 m1['subperiod'] = int(m1['subperiod']) if m1['subperiod'] else 0
112 m2['subperiod'] = int(m2['subperiod']) if m2['subperiod'] else 99
113
114 #print ("Interpret run range: %r - %r" % (m1,m2))
115
116 # ordinate
117 p1c = 10000*m1['year'] + 100*(ord(m1['period'].upper())-65) + m1['subperiod']
118 p2c = 10000*m2['year'] + 100*(ord(m2['period'].upper())-65) + m2['subperiod']
119
120 return getListOfPeriodsFromOrdinateRange( p1c, p2c, None )
121
122
123
124def GetRuns( arg ):
125 """
126 arg: 'run data10_7TeV.periodA' or 'run periodA' (where 'data11_7TeV' is assumed)
127 # or 'data10_7TeV.periodA-periodC' or 'data10_7TeV.periodA,data10_7TeV.periodB,...'
128 # This is case sensitive !!
129 """
130
131 # final result in here
132 list_of_runs = []
133
134 # are their any commas?
135 for tag in arg.split(','):
136
137 # last X runs pattern
138 m = pat_last.match(arg)
139 if m:
140 #print ("Pattern 'Last N'")
141 list_of_runs += [ "last%s" % m.group(1) ]
142 continue
143
144 # run numbers
145 if pat_number.match(tag):
146 #print ("Pattern 'List of runs'")
147 list_of_runs += [tag]
148 continue
149
150 # run number range
151 if pat_range.match(tag):
152 #print ("Pattern 'Range of runs'")
153 list_of_runs += [tag]
154 continue
155
156
157 if '-' in tag: # range
158 #print ("Pattern 'Range of periods'")
159 list_of_periods = getDataPeriodsWithinRange( tag.split('-') )
160 list_of_runs += getRunsFromPeriods(list_of_periods)
161 continue
162
163
164 # various AllYear versions
165 if '.' not in tag or tag.endswith(".All") or tag.endswith(".AllYear") or tag.endswith(".periodAllYear"):
166 #print ("Pattern 'AllYear'")
167 allyear = 0
168 projectName = None
169 # no tag means AllYear
170 m = re.match(r"20(?P<year>\d{2})(.All|.AllYear|.periodAllYear)?$", tag, re.I)
171 if m:
172 allyear = int(m.groupdict()['year'])
173 else:
174 m = re.match(r"(?P<proj>data(?P<year>\d{2})_.*?)(.All|.AllYear|.periodAllYear)?$", tag, re.I)
175 if m:
176 allyear = int(m.groupdict()['year'])
177 projectName = m.groupdict()['proj']
178
179 if allyear==0:
180 raise RuntimeError("Can't interpret run period %s" % tag)
181
182 print ("Interpret period: AllYear for %i" % (2000+allyear))
183
184 # ordinate
185 p1c = 10000*allyear
186 p2c = 10000*(allyear+1) - 1
187
188 list_of_periods = getListOfPeriodsFromOrdinateRange(p1c, p2c, projectName)
189
190 print (list_of_periods)
191
192 list_of_runs += getRunsFromPeriods(list_of_periods)
193 continue
194
195
196
197 m = re.match( r"(?P<first>(data|20)?(?P<year>\d{2})(_.*)?\.)?(period)?(?P<period>[a-zA-Z])(?P<subperiod>\d+)?$", tag, re.I )
198
199 #projPeriod = re.compile(r"(?P<first>(data|20)?(?P<year>\d{2})(_.*)?\.)?(period)?(?P<period>[a-zA-Z])(?P<subperiod>\d+)?$",re.I) # 2015_periodA5
200
201
202 d = { 'projname' : None }
203 m = re.match( r"20(?P<year>\d{2})\.(period)?(?P<period>[a-zA-Z]|VdM)(?P<subperiod>\d+)?$", tag, re.I )
204 if m:
205 #print ("Pattern '2015.(period)A1'")
206 d.update( m.groupdict() )
207 else:
208 m = re.match( r"(?P<projname>data(?P<year>\d{2})_.*?)\.(period)?(?P<period>[a-zA-Z]|VdM)(?P<subperiod>\d+)?$", tag, re.I )
209 if m:
210 #print ("Pattern 'dataYY_TTT.(period)A1'")
211 d.update( m.groupdict() )
212 else:
213 d = None
214
215 if d:
216 d['subperiod'] = int(d['subperiod']) if d['subperiod'] else 0
217
218 print ("Interpret period: %r" % d)
219 if len(d['period'])==1:
220 # ordinate
221 p1c = 10000*int(d['year']) + 100*(ord(d['period'].upper())-65) + d['subperiod']
222 if d['subperiod'] != 0:
223 p2c = p1c
224 else:
225 p2c = p1c+99
226 list_of_periods = getListOfPeriodsFromOrdinateRange(p1c, p2c, d['projname'])
227 else:
228 # VdM
229 sp = '' if d['subperiod']==0 else str(d['subperiod'])
230 list_of_periods = getListOfPeriodsFromOrdinateRange( 0, 0, d['projname'], (int(d['year']), d['period'],sp) )
231
232 list_of_runs += getRunsFromPeriods(list_of_periods)
233 continue
234
235 if len(list_of_runs)==0:
236 print ("No runs matching pattern")
237
238 return list_of_runs
239
240
241
242
243
244# command line driver for convenience
245if __name__=='__main__':
246
247
248 if len(sys.argv) <= 1:
249 print ('No data period argument given, try\n%s data15_13TeV.A')
250 sys.exit(1)
251
252
253 print (GetRuns( sys.argv[1] ))
254
int upper(int c)
getListOfPeriodsFromOrdinateRange(begin, end, requiredProjectName, specialData=None)