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

Public Member Functions

def getUsedTables (cls, output, condition)
 
def query (cls, output, condition, bindvars, verbose=False)
 
def cursor (cls)
 
def get_periods_for_run (cls, run)
 
def get_periods (cls, year=0, level=0)
 
def get_all_periods (cls)
 
def get_runs (cls, period, year)
 

Static Public Attributes

 all_periods = None
 

Static Private Attributes

dictionary __store = {}
 
 __cursor = None
 
string __schema = "ATLAS_TAGS_METADATA"
 
dictionary __tables
 

Detailed Description

Definition at line 16 of file AtlRunQueryCOMA.py.

Member Function Documentation

◆ cursor()

def python.AtlRunQueryCOMA.ARQ_COMA.cursor (   cls)
get COMA connection
any connection to ATLR is fine, we use Trigger DB

Definition at line 54 of file AtlRunQueryCOMA.py.

54  def cursor(cls):
55  """get COMA connection
56  any connection to ATLR is fine, we use Trigger DB
57  """
58  if not cls.__cursor:
59 
60  from CoolRunQuery.utils.AtlRunQueryTriggerUtils import interpretConnection
61  connectionParameters = interpretConnection("TRIGGERDB")
62 
63  from cx_Oracle import connect
64  connection = connect ( connectionParameters["user"],
65  connectionParameters["passwd"],
66  connectionParameters["server"], threaded=True)
67  cls.__cursor = connection.cursor()
68 
69  return cls.__cursor
70 
71 
72 
73 
74 

◆ get_all_periods()

def python.AtlRunQueryCOMA.ARQ_COMA.get_all_periods (   cls)

Definition at line 110 of file AtlRunQueryCOMA.py.

110  def get_all_periods(cls):
111  if cls.all_periods is not None:
112  return cls.all_periods
113  cls.all_periods = []
114  p = re.compile(r"(?P<periodletter>[A-Za-z]+)(?P<periodnumber>\d+)?$")
115  try:
116  result = cls.get_periods(0, 0)
117  for period, projectName in result:
118  year = int(projectName[4:6])
119  m = p.match(period)
120  if not m:
121  print ("Period '%s'does not match pattern [A-Za-z]+\\d+" % period)
122  continue
123 
124  period_letter = m.group('periodletter')
125  period_number = int(m.group('periodnumber')) if m.group('periodnumber') else 0
126  if len(period_letter)!=1:
127  pc = 0
128  else:
129  pc = 10000*year + 100*(ord(period_letter.upper())-65) + period_number
130 
131  cls.all_periods += [ ((year, period, pc, projectName), projectName+".period" + period) ]
132 
133  cls.all_periods.sort()
134  except Exception:
135  import traceback
136  traceback.print_exc()
137  pass
138  return cls.all_periods
139 
140 

◆ get_periods()

def python.AtlRunQueryCOMA.ARQ_COMA.get_periods (   cls,
  year = 0,
  level = 0 
)

Definition at line 92 of file AtlRunQueryCOMA.py.

92  def get_periods(cls, year=0, level=0):
93  output = ['PR.P_PERIOD', 'PR.P_PROJECT' ]
94  condition = []
95  bindvars = {}
96 
97  if level>0:
98  condition += [ "PR.P_LEVEL=:lvl" ]
99  bindvars["lvl"] = level
100 
101  if year>2000:
102  project = 'data%02i%%' % (year-2000)
103  condition += [ "PR.P_PROJECT like :proj" ]
104  bindvars["proj"] = project
105 
106  return sorted( cls.query(output, condition, bindvars) )
107 
108 

◆ get_periods_for_run()

def python.AtlRunQueryCOMA.ARQ_COMA.get_periods_for_run (   cls,
  run 
)

Definition at line 76 of file AtlRunQueryCOMA.py.

76  def get_periods_for_run(cls, run):
77  try:
78  run = int(run)
79  except ValueError:
80  return []
81  if run not in cls.__store:
82  output = ['PR.P_LEVEL', 'PR.P_PERIOD', 'PR.P_PROJECT' ]
83  condition = [ "PR.RUN_INDEX = :run" ]
84  bindvars = { "run": run }
85 
86  cls.__store[run] = sorted( cls.query(output, condition, bindvars) )
87 
88  return [x[1] for x in cls.__store[run]]
89 
90 

◆ get_runs()

def python.AtlRunQueryCOMA.ARQ_COMA.get_runs (   cls,
  period,
  year 
)

Definition at line 142 of file AtlRunQueryCOMA.py.

142  def get_runs(cls, period, year):
143  output = ['PR.RUN_INDEX', 'PR.P_LEVEL', 'PR.P_PERIOD', 'PR.P_PROJECT' ]
144 
145  condition = [ "PR.P_PERIOD=:period" ]
146  bindvars = { "period" : period }
147  if year>2000:
148  project = 'data%02i%%' % (year-2000)
149  condition += [ "PR.P_PROJECT like :proj" ]
150  bindvars["proj"] = project
151  result = cls.query(output, condition, bindvars)
152 
153  tmpstore = {}
154 
155  for record in result:
156  run = record[0]
157  info = record[1:4]
158  if run not in tmpstore:
159  tmpstore[run] = []
160  tmpstore[run] += [info]
161 
162  cls.__store.update(tmpstore)
163 
164  return sorted( [r[0] for r in result] )
165 
166 
167 
168 # for testing purpose

◆ getUsedTables()

def python.AtlRunQueryCOMA.ARQ_COMA.getUsedTables (   cls,
  output,
  condition 
)

Definition at line 29 of file AtlRunQueryCOMA.py.

29  def getUsedTables(cls, output, condition):
30  usedtables = set( [o.split('.')[0] for o in output] ) # all tables specified in output fields
31 
32  for c in condition:
33  for p in c.split():
34  if '.' in p and '\'' not in p:
35  usedtables.add(p.split('.')[0].lstrip('(')) # all tables specified in conditions
36 
37  return ["%s.%s %s" % (cls.__schema,cls.__tables[t],t) for t in usedtables] # prefix schema name to table name
38 
39 

◆ query()

def python.AtlRunQueryCOMA.ARQ_COMA.query (   cls,
  output,
  condition,
  bindvars,
  verbose = False 
)

Definition at line 41 of file AtlRunQueryCOMA.py.

41  def query(cls, output, condition, bindvars, verbose=False):
42  query = 'select distinct %s from %s' % (', '.join(output),
43  ', '.join(cls.getUsedTables(output, condition)))
44  if condition:
45  query += ' where ' + ' and '.join(condition)
46  if verbose:
47  print ("="*80,"\n",query)
48  c = cls.cursor()
49  c.execute(str(query),bindvars)
50  return c.fetchall()
51 
52 

Member Data Documentation

◆ __cursor

python.AtlRunQueryCOMA.ARQ_COMA.__cursor = None
staticprivate

Definition at line 21 of file AtlRunQueryCOMA.py.

◆ __schema

string python.AtlRunQueryCOMA.ARQ_COMA.__schema = "ATLAS_TAGS_METADATA"
staticprivate

Definition at line 22 of file AtlRunQueryCOMA.py.

◆ __store

dictionary python.AtlRunQueryCOMA.ARQ_COMA.__store = {}
staticprivate

Definition at line 18 of file AtlRunQueryCOMA.py.

◆ __tables

dictionary python.AtlRunQueryCOMA.ARQ_COMA.__tables
staticprivate
Initial value:
= {
'PR' : 'COMA_V_PERIOD_RUNS',
}

Definition at line 24 of file AtlRunQueryCOMA.py.

◆ all_periods

python.AtlRunQueryCOMA.ARQ_COMA.all_periods = None
static

Definition at line 19 of file AtlRunQueryCOMA.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.
python.utils.AtlRunQueryTriggerUtils.interpretConnection
def interpretConnection(connection, debug=False, resolveAlias=True)
Definition: AtlRunQueryTriggerUtils.py:229
checkCorrelInHIST.cursor
cursor
Definition: checkCorrelInHIST.py:26
python.utils.AtlRunQueryUtils.get_runs
def get_runs(start, end=None)
Definition: AtlRunQueryUtils.py:595
python.utils.AtlRunQueryTriggerUtils.getUsedTables
def getUsedTables(output, condition, schemaname, tables)
Definition: AtlRunQueryTriggerUtils.py:392
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:232
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
index.query
query
Definition: index.py:72
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
str
Definition: BTagTrackIpAccessor.cxx:11