ATLAS Offline Software
periodInfo.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
4 
5 
6 """
7  Generate run list for each period using the pyAMI interface to the COMA db.
8 
9  Need to authenticate (once) and setup pyami via:
10 
11 source /afs/cern.ch/atlas/software/tools/atlasmeta/setup.sh
12 export PYAMI_CONFIG_DIR=~/private/.pyami
13 ami auth
14 """
15 
16 __author__ = 'Carl Gwilliam'
17 __version__ = ''
18 __usage__ = '''%prog [options]'''
19 
20 import os,sys
21  # the above line needed to ensure correct python environment since pyAMI 4.0.3
22 import pyAMI.client
23 
24 from optparse import OptionParser
25 parser = OptionParser(usage=__usage__, version=__version__)
26 parser.add_option('-c', '--config', dest='config', default='', help='AMI authentication file')
27 (options,args) = parser.parse_args()
28 
29 class AMIWrapper:
30  def __init__(self):
31  "Initalise AMI"
32  self.ami=pyAMI.client.Client('atlas')
33  #if options.config:
34  # self.configFileName = os.path.expanduser(options.config)
35  #else:
36  #sys.exit('No authentication file specified')
37  #self.ami.readConfig(self.configFileName)
38  if options.config:
39  self.configFileName = os.path.expanduser(options.config)
40  else:
41  sys.exit('No authentication file specified')
42  print (self.configFileName)
43  #self.ami=pyAMI.client.Client('atlas',key_file=self.configFileName,ignore_proxy=True,verbose=True)
44 
45  def run(self, cmd):
46  """
47  Execute an AMI command given as a list of command and paramters (ami format) or
48  space separated string (for convenience)
49  """
50  if isinstance(cmd, str):
51  cmd = cmd.split()
52 
53  print ('PRINT AMI CMD', cmd )
54  results = self.ami.execute(cmd,format='dict_object')
55 
56  return results.get_rows()
57 
58  def periods(self, period=None, level=None, project=None, status=None):
59  "Get list of periods. By default return all periods"
60 
61  cmd = 'ListDataPeriods'
62  if period: cmd += ' period='+period
63  if level: cmd += ' periodLevel='+level
64  if project: cmd += ' projectName='+project
65  if status: cmd += ' status='+status
66  return self.run(cmd)
67 
68  def runsForPeriod(self, period, project):
69  "Get info on runs for a particular period"
70 
71  cmd = 'GetRunsForDataPeriod period='+period
72  cmd += ' projectName='+project
73  print (cmd)
74  return self.run(cmd)
75 
76  def runListsPerPeriod(self, location='/afs/cern.ch/user/a/atlidbs/nt/DataPeriods/'):
77  """
78  Generate files containing run lists for periods if they don't already exist
79  """
80  # Don't only update unlocked periods since they may change as looked so need to check at least once more
81  # Need to find a better way fo doing this but for now update all
82  periods = self.periods() #status='unlocked')
83  path = os.path
84  num = 0
85 
86  for p in periods:
87  #print ('Looking at period: ', p )
88  projectDir =path.normpath(location + '/' + p['projectName'])
89 
90  if not path.exists(projectDir):
91  os.makedirs(projectDir)
92 
93  filename = '%s/%s.runs.list' % (projectDir,p['period'])
94 
95  #if path.exists(filename): continue
96 
97  # Need to remove the file as it might have changed from last time
98  if path.exists(filename):
99  os.system('rm ' + filename)
100 
101  print ('* Creating run list for %(projectName)s %(period)s ...' % p)
102 
103  num += 1
104  #if p['period'] == 'A1' and p['projectName'] == 'data15_1beam':
105  # continue
106  try:
107  runs = self.runsForPeriod(p['period'], p['projectName'])
108  except:
109  continue
110  runList = '\n'.join(sorted([r['runNumber'] for r in runs]))
111  runList += '\n' # Needed for cat to work!
112  print (runList)
113  with open(filename, 'w') as f:
114  f.write(runList)
115 
116  print (' ... written to', filename, '\n' )
117 
118  if not num:
119  print ('* No new period infomation to create')
120 
121 if __name__ == '__main__':
122  ami = AMIWrapper()
123  ami.runListsPerPeriod()
124 
125 
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename R::value_type > sorted(const R &r, PROJ proj={})
Helper function to create a sorted vector from an unsorted range.
periodInfo.AMIWrapper.run
def run(self, cmd)
Definition: periodInfo.py:45
periodInfo.AMIWrapper.runListsPerPeriod
def runListsPerPeriod(self, location='/afs/cern.ch/user/a/atlidbs/nt/DataPeriods/')
Definition: periodInfo.py:76
periodInfo.AMIWrapper.configFileName
configFileName
Definition: periodInfo.py:39
periodInfo.AMIWrapper
Definition: periodInfo.py:29
periodInfo.AMIWrapper.__init__
def __init__(self)
Definition: periodInfo.py:30
LArG4FSStartPointFilterLegacy.execute
execute
Definition: LArG4FSStartPointFilterLegacy.py:20
periodInfo.AMIWrapper.ami
ami
Definition: periodInfo.py:32
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
Trk::open
@ open
Definition: BinningType.h:40
periodInfo.AMIWrapper.periods
def periods(self, period=None, level=None, project=None, status=None)
Definition: periodInfo.py:58
periodInfo.AMIWrapper.runsForPeriod
def runsForPeriod(self, period, project)
Definition: periodInfo.py:68