ATLAS Offline Software
Public Member Functions | Static Public Attributes | Static Private Attributes | List of all members
python.AtlRunQueryAMI.ARQ_AMI Class Reference
Collaboration diagram for python.AtlRunQueryAMI.ARQ_AMI:

Public Member Functions

def getAmiClient (cls, amiconf=None, verbose=False)
 
def amiclient (cls)
 
def OpenAMIConnection (cls)
 
def amiexec (cls, cmdList)
 
def get_periods_for_run (cls, run)
 
def get_periods (cls, year, level)
 
def get_all_periods (cls)
 
def get_runs (cls, period, year)
 

Static Public Attributes

dictionary store = {}
 
 all_periods = None
 

Static Private Attributes

 _amiclient = None
 

Detailed Description

Definition at line 16 of file AtlRunQueryAMI.py.

Member Function Documentation

◆ amiclient()

def python.AtlRunQueryAMI.ARQ_AMI.amiclient (   cls)

Definition at line 82 of file AtlRunQueryAMI.py.

82  def amiclient(cls):
83  if cls._amiclient is None:
84  from os import getenv
85  from CoolRunQuery.utils.AtlRunQueryUtils import runsOnServer
86  if runsOnServer():
87  home = "/data/atrqadm/data/"
88  else:
89  home = getenv('HOME')
90  if not home:
91  home = '~'
92  conffilename = home + "/private/AMIConf.txt"
93  cls._amiclient = cls.getAmiClient(conffilename)
94  if cls._amiclient is None:
95  print ("ERROR: voms-proxy authentication not valid and no AMI configuration file",conffilename,"supplied. No access to AMI!")
96  cls._amiclient="No AMI"
97  return cls._amiclient
98 

◆ amiexec()

def python.AtlRunQueryAMI.ARQ_AMI.amiexec (   cls,
  cmdList 
)

Definition at line 112 of file AtlRunQueryAMI.py.

112  def amiexec(cls, cmdList):
113  try:
114  result = cls.amiclient().execute(cmdList)
115  return result.getDict()
116  except Exception as ex:
117  print ("AMI exception '",type(ex),"' occured")
118  import traceback
119  traceback.print_exc()
120  return {}
121 
122 

◆ get_all_periods()

def python.AtlRunQueryAMI.ARQ_AMI.get_all_periods (   cls)

Definition at line 162 of file AtlRunQueryAMI.py.

162  def get_all_periods(cls):
163  if cls.all_periods is not None:
164  return cls.all_periods
165  cls.all_periods = []
166  p = re.compile(r"(?P<period>(?P<periodletter>[A-Za-z]+)(?P<periodnumber>\d+)?)$")
167  try:
168  result = cls.get_periods(0, 0)
169  for period, projectName in result:
170  m = p.match(period)
171  if not m:
172  continue
173  year = int(projectName[4:6])
174  period_letter = m.group('periodletter')
175  period_number = int(m.group('periodnumber')) if m.group('periodnumber') else 0
176  if len(period_letter)!=1:
177  pc = 0
178  else:
179  pc = 10000*year + 100*(ord(period_letter.upper())-65) + period_number
180  cls.all_periods += [ ((year, period, pc), projectName+".period" + period) ]
181  cls.all_periods.sort()
182  except Exception:
183  import traceback
184  traceback.print_exc()
185  pass
186  return cls.all_periods
187 
188 

◆ get_periods()

def python.AtlRunQueryAMI.ARQ_AMI.get_periods (   cls,
  year,
  level 
)

Definition at line 143 of file AtlRunQueryAMI.py.

143  def get_periods(cls, year, level):
144  try:
145  cmd = ['ListDataPeriods', '-createdSince=2009-01-01 00:00:00' ]
146  if year>2000:
147  cmd += [ '-projectName=data%02i%%' % (year-2000) ]
148  if level in [1,2,3]:
149  cmd += [ '-periodLevel=%i' % level ]
150  #result = cls.amiclient().execute(cmd)
151  result = cls.amiexec(cmd)
152  #rows = [ (e['period'], e['projectName']) for e in result.getDict()['Element_Info'].values() ]
153  rows = [ (e['period'], e['projectName']) for e in result['Element_Info'].values() ]
154  return sorted(rows)
155  except Exception:
156  import traceback
157  traceback.printExc()
158  return []
159 
160 

◆ get_periods_for_run()

def python.AtlRunQueryAMI.ARQ_AMI.get_periods_for_run (   cls,
  run 
)

Definition at line 124 of file AtlRunQueryAMI.py.

124  def get_periods_for_run(cls, run):
125  try:
126  run = int(run)
127  except ValueError:
128  return []
129  if run not in cls.store:
130  try:
131  print ('GetDataPeriodsForRun', '-runNumber=%i' % run)
132  #result = cls.amiclient().execute(['GetDataPeriodsForRun', '-runNumber=%i' % run])
133  result = cls.amiexec(['GetDataPeriodsForRun', '-runNumber=%i' % run])
134  #cls.store[run] = sorted([ (int(e['periodLevel']),e['period'],e['project']) for e in result.getDict()['Element_Info'].values() ])
135  cls.store[run] = sorted([ (int(e['periodLevel']),e['period'],e['project']) for e in result['Element_Info'].values() ])
136  except Exception:
137  print ("Exception")
138  cls.store[run] = []
139  return [x[1] for x in cls.store[run]]
140 
141 

◆ get_runs()

def python.AtlRunQueryAMI.ARQ_AMI.get_runs (   cls,
  period,
  year 
)

Definition at line 190 of file AtlRunQueryAMI.py.

190  def get_runs(cls, period, year):
191  try:
192  cmd = ['GetRunsForDataPeriod', '-period=%s' % period]
193  if year>2000:
194  cmd += [ '-projectName=data%02i%%' % (year-2000) ]
195  #result = cls.amiclient().execute(cmd)
196  result = cls.amiexec(cmd)
197  #print ("amiCommand",' '.join(cmd) )
198  #r = sorted([ int(e['runNumber']) for e in result.getDict()['Element_Info'].values() ])
199  r = sorted([ int(e['runNumber']) for e in result['Element_Info'].values() ])
200  return r
201  except (ValueError, KeyError):
202  pass
203 
204 
205 
206 # for testing purpose

◆ getAmiClient()

def python.AtlRunQueryAMI.ARQ_AMI.getAmiClient (   cls,
  amiconf = None,
  verbose = False 
)
get ami client
param amiconf: name of file with AMI user and pw

If a valid filename is specified, it tries to read the
username and password from there. If that does not succeed or
no filename is specified, voms based authentication is tried.

Definition at line 24 of file AtlRunQueryAMI.py.

24  def getAmiClient(cls, amiconf = None, verbose = False):
25  """get ami client
26  param amiconf: name of file with AMI user and pw
27 
28  If a valid filename is specified, it tries to read the
29  username and password from there. If that does not succeed or
30  no filename is specified, voms based authentication is tried.
31  """
32  from pyAMI.pyAMI import AMI,pyAMIEndPoint
33  from os import stat,path
34 
35  useConfigFile = False
36  if amiconf:
37  if not path.exists(amiconf):
38  if verbose:
39  print ("WARNING: AMI config file", amiconf, "does not exist. Need to rely on valid voms proxy.")
40  elif stat(amiconf).st_mode & path.stat.S_IRUSR == 0:
41  if verbose:
42  print ("WARNING: AMI config file", amiconf, "exists but is not readable. Need to rely on valid voms proxy.")
43  else:
44  useConfigFile = True
45 
46  if useConfigFile:
47  pyAMIEndPoint.setType("replica")
48  ami=AMI()
49  ami.readConfig(amiconf)
50  if ami.checkAuth():
51  print ("... connecting to CERN AMI replica with user+pw")
52  return ami
53  pyAMIEndPoint.setType("main")
54  ami.certAuth()
55  if ami.checkAuth():
56  print ("... connecting to AMI main server with user+pw")
57  return ami
58 
59  print ("WARNING: Authentication in config file",amiconf,"not valid, check format, user, pw. Need to rely on valid voms proxy.")
60 
61 
62  pyAMIEndPoint.setType("replica")
63  ami=AMI()
64  if ami.checkAuth():
65  print ("... connecting to CERN replica using voms-proxy")
66  return ami
67 
68 
69  pyAMIEndPoint.setType("main")
70  ami.certAuth()
71  if ami.checkAuth():
72  print ("... connecting to main server using voms-proxy")
73  return ami
74 
75 
76  if verbose:
77  print ("WARNING voms-proxy authentication not valid. No access to AMI.")
78  return None
79 
80 

◆ OpenAMIConnection()

def python.AtlRunQueryAMI.ARQ_AMI.OpenAMIConnection (   cls)

Definition at line 100 of file AtlRunQueryAMI.py.

100  def OpenAMIConnection(cls):
101  try:
102  from pyAMI.pyAMI import AMI
103  amiclient = AMI()
104  amiclient.readConfig("./AMIConf.txt")
105  return amiclient
106  except ImportError:
107  print ('ERROR: could not load pyAMI')
108  return None
109 
110 

Member Data Documentation

◆ _amiclient

python.AtlRunQueryAMI.ARQ_AMI._amiclient = None
staticprivate

Definition at line 18 of file AtlRunQueryAMI.py.

◆ all_periods

python.AtlRunQueryAMI.ARQ_AMI.all_periods = None
static

Definition at line 20 of file AtlRunQueryAMI.py.

◆ store

dictionary python.AtlRunQueryAMI.ARQ_AMI.store = {}
static

Definition at line 19 of file AtlRunQueryAMI.py.


The documentation for this class was generated from the following file:
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.
UploadDQAMITag.amiclient
amiclient
Definition: UploadDQAMITag.py:301
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
python.utils.AtlRunQueryUtils.runsOnServer
def runsOnServer()
Definition: AtlRunQueryUtils.py:47
python.Bindings.values
values
Definition: Control/AthenaPython/python/Bindings.py:808
LArG4FSStartPointFilterLegacy.execute
execute
Definition: LArG4FSStartPointFilterLegacy.py:20
python.utils.AtlRunQueryUtils.get_runs
def get_runs(start, end=None)
Definition: AtlRunQueryUtils.py:595
beamspotman.stat
stat
Definition: beamspotman.py:264
SCT_ConditionsAlgorithms::CoveritySafe::getenv
std::string getenv(const std::string &variableName)
get an environment variable
Definition: SCT_ConditionsUtilities.cxx:17
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45