6 Periods are assigned an ordinate by which they can be sorted 
    9 from functools 
import cache
 
   12 pat_last   = re.compile(
r"(?:l|la|las|last) (\d*)$")  
 
   13 pat_number = re.compile(
r"\d{5,8}[+-]?$")  
 
   14 pat_range  = re.compile(
r"\d{5,8}-\d{5,8}$")  
 
   15 pat_short  = re.compile(
r"(?:(?:\d{2})(\d{2})\.)?([a-zA-Z]+\d*)$")
 
   16 pshort     = re.compile(
r"(?P<first>(data|20)?(?P<year>\d{2})(_.*)?\.)?(period)?(?P<period>[a-zA-Z])(?P<subperiod>\d+)?$",re.I) 
 
   23     returns the last two digits of current year  
   25     from time 
import gmtime
 
   26     return gmtime().tm_year - 2000
 
   32     find the run numbers for given period(s) 
   34     list_of_periods   periods in format  [('10','B1'),('11','A'),...] 
   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))
 
   45     from CoolRunQuery.AtlRunQueryCOMA 
import ARQ_COMA
 
   46     available_periods = ARQ_COMA.get_all_periods()
 
   47     available_periods.sort()
 
   51     return available_periods
 
   56     requiredProjectName e.g. data15_13TeV, data15_cos, data15_hip, etc. . If None then it is required that the project name ends in TeV 
   63         (year, period, ordcode, projname) = p
 
   65         if requiredProjectName 
is None:
 
   66             if not projname.endswith(
"TeV"):
 
   69             if projname != requiredProjectName:
 
   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")
 
   80         if ordcode % 100 == 0:  
 
   83         if ordcode < begin 
or ordcode>end:
 
   86         list_of_periods += [ (year, period, full_name) ]
 
   87         print (p,
"--> include")
 
   88     return list_of_periods
 
   94     m1 = pshort.match(period_range[0])
 
   95     m2 = pshort.match(period_range[1])
 
   97     if m1 
is None or m2 
is None:
 
   99             print (
"Invalid specification of begin of range",period_range[0])
 
  101             print (
"Invalid specification of end of range",  period_range[1])
 
  109     m2[
'year'] = 
int(m2[
'year']) 
if m2[
'year'] 
else m1[
'year']
 
  111     m1[
'subperiod'] = 
int(m1[
'subperiod']) 
if m1[
'subperiod'] 
else 0
 
  112     m2[
'subperiod'] = 
int(m2[
'subperiod']) 
if m2[
'subperiod'] 
else 99
 
  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']
 
  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 !! 
  135     for tag 
in arg.split(
','):
 
  138         m = pat_last.match(arg)
 
  141             list_of_runs += [ 
"last%s" % m.group(1) ]
 
  145         if pat_number.match(tag):
 
  147             list_of_runs += [tag]
 
  151         if pat_range.match(tag):
 
  153             list_of_runs += [tag]
 
  165         if '.' not in tag 
or tag.endswith(
".All") 
or tag.endswith(
".AllYear") 
or tag.endswith(
".periodAllYear"):
 
  170             m = re.match(
r"20(?P<year>\d{2})(.All|.AllYear|.periodAllYear)?$", tag, re.I)
 
  172                 allyear = 
int(m.groupdict()[
'year'])
 
  174                 m = re.match(
r"(?P<proj>data(?P<year>\d{2})_.*?)(.All|.AllYear|.periodAllYear)?$", tag, re.I)
 
  176                     allyear = 
int(m.groupdict()[
'year'])
 
  177                     projectName = m.groupdict()[
'proj']
 
  180                 raise RuntimeError(
"Can't interpret run period %s" % tag)
 
  182             print (
"Interpret period: AllYear for %i" % (2000+allyear))
 
  186             p2c = 10000*(allyear+1) - 1
 
  190             print (list_of_periods)
 
  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 )
 
  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 )
 
  206             d.update( m.groupdict() )
 
  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 )
 
  211                 d.update( m.groupdict() )
 
  216             d[
'subperiod'] = 
int(d[
'subperiod']) 
if d[
'subperiod'] 
else 0
 
  218             print (
"Interpret period: %r" % d)
 
  219             if len(d[
'period'])==1:
 
  221                 p1c = 10000*
int(d[
'year']) + 100*(ord(d[
'period'].
upper())-65) + d[
'subperiod']
 
  222                 if d[
'subperiod'] != 0:
 
  229                 sp = 
'' if d[
'subperiod']==0 
else str(d[
'subperiod'])
 
  235     if len(list_of_runs)==0:
 
  236         print (
"No runs matching pattern")
 
  245 if __name__==
'__main__':
 
  248     if len(sys.argv) <= 1:
 
  249         print (
'No data period argument given, try\n%s data15_13TeV.A')