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 17 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 55 of file AtlRunQueryCOMA.py.

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

◆ get_all_periods()

def python.AtlRunQueryCOMA.ARQ_COMA.get_all_periods (   cls)

Definition at line 111 of file AtlRunQueryCOMA.py.

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

◆ get_periods()

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

Definition at line 93 of file AtlRunQueryCOMA.py.

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

◆ get_periods_for_run()

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

Definition at line 77 of file AtlRunQueryCOMA.py.

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

◆ get_runs()

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

Definition at line 143 of file AtlRunQueryCOMA.py.

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

◆ getUsedTables()

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

Definition at line 30 of file AtlRunQueryCOMA.py.

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

◆ query()

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

Definition at line 42 of file AtlRunQueryCOMA.py.

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

Member Data Documentation

◆ __cursor

python.AtlRunQueryCOMA.ARQ_COMA.__cursor = None
staticprivate

Definition at line 22 of file AtlRunQueryCOMA.py.

◆ __schema

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

Definition at line 23 of file AtlRunQueryCOMA.py.

◆ __store

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

Definition at line 19 of file AtlRunQueryCOMA.py.

◆ __tables

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

Definition at line 25 of file AtlRunQueryCOMA.py.

◆ all_periods

python.AtlRunQueryCOMA.ARQ_COMA.all_periods = None
static

Definition at line 20 of file AtlRunQueryCOMA.py.


The documentation for this class was generated from the following file:
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
python.utils.AtlRunQueryTriggerUtils.interpretConnection
def interpretConnection(connection, debug=False, resolveAlias=True)
Definition: AtlRunQueryTriggerUtils.py:230
python.utils.AtlRunQueryUtils.get_runs
def get_runs(start, end=None)
Definition: AtlRunQueryUtils.py:596
query_example.query
query
Definition: query_example.py:15
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
python.utils.AtlRunQueryTriggerUtils.getUsedTables
def getUsedTables(output, condition, schemaname, tables)
Definition: AtlRunQueryTriggerUtils.py:393
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:224
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
dqt_zlumi_pandas.update
update
Definition: dqt_zlumi_pandas.py:42
query_example.cursor
cursor
Definition: query_example.py:21
str
Definition: BTagTrackIpAccessor.cxx:11