ATLAS Offline Software
MuonSpectrometer/MuonCalib/MuonCalibDbOperations/python/ReadCool.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
2 
3 from __future__ import print_function
4 
5 import CoolConvUtilities.AtlCoolLib as AtlCoolLib
6 from PyCool import cool,coral
7 import zlib,StringIO
8 import sys
9 import re
10 from MuonCalibDbOperations.MuonCalibResolveTag import ResolveTag
11 from MuonCalibDbOperations.MuonCalibConvertTimeSlewing import TimeSlewingApplied, NoTs2Ts, GasmonDriftTimeOffsetT0
12 
13 sys.argv=[sys.argv[0], '-b']
14 
15 from ROOT import TGraphErrors, TSpline3, gDirectory
16 from MuonCalibIdentifier.MuonFixedIdUnpack import MuonFixedIdUnpack
17 
18 def UnpackData(data):
19  if type(data)==str:
20  return data
21  if type(data)==coral.Blob:
22  blob=StringIO.StringIO()
23  for i in range(data.size()):
24  blob.write(chr(data[i]))
25  unpacked=zlib.decompress(blob.getvalue())
26  return unpacked
27 
28 def iov_keygen(iov):
29  return iov[0]*10000000 + iov[1]
30 
31 def DumpFolderSummary(db_string, folder, tag, run=None):
32 
33  try:
34  db=AtlCoolLib.indirectOpen(db_string, readOnly=True, debug=True)
35  except Exception as e:
36  print ('Problem opening database',e)
37  sys.exit(-1)
38 
39 #get folder and tag
40  cool_folder=db.getFolder(folder)
41  cool_tag=ResolveTag(cool_folder, tag)
42 
43  counters={}
44  if run:
45  objs=cool_folder.browseObjects((run<<32), ((run+1)<<32), cool.ChannelSelection.all(), cool_tag)
46  else:
47  objs=cool_folder.browseObjects(0, (999999<<32), cool.ChannelSelection.all(), cool_tag)
48  for obj in objs:
49  file_col=obj.payload()['file']
50  file_items=re.split('[A-Z,a-z]*', file_col)
51  site="default"
52  head_id=-1
53  if len(file_items)==2:
54  try:
55  head_id = int(file_items[1])
56  site = re.sub("[0-9]", "", file_col)
57  except ValueError:
58  site=file_col
59  ts="NOTS"
60  if TimeSlewingApplied(obj):
61  ts="TS"
62  ident=(obj.since()>>32, obj.until()>>32, site, head_id, ts)
63  if ident not in counters:
64  counters[ident] = 0
65  counters[ident] +=1
66  for ident in sorted(counters.keys(), key=iov_keygen):
67  print ("[", ident[0], ",", ident[1], "[", ident[2], ident[3], ident[4], ":" , counters[ident])
68 
69 
70 def ReadRtCool(db_string, folder, tag, run_number):
71 
72  try:
73  db=AtlCoolLib.indirectOpen(db_string, readOnly=True, debug=True)
74  except Exception as e:
75  print ('Problem opening database',e)
76  sys.exit(-1)
77 
78 #get folder and tag
79  cool_folder=db.getFolder(folder)
80  cool_tag=ResolveTag(cool_folder, tag)
81 
82 #data to be filled
83  graphs={}
84  splines={}
85  iovs=set([])
86 
87  myiov=(run_number<<32)
88 
89  objs=cool_folder.browseObjects(myiov,myiov, cool.ChannelSelection.all(), cool_tag)
90  for obj in objs:
91  iov=(obj.since(), obj.until())
92  iovs.add(iov)
93  sp=UnpackData(obj.payload()['data']).split('\n')
94  sp1=sp[0].split(',')
95  chamber=int(sp1[0])
96  n_points=int(sp1[1])
97  sp2=sp[1].split(',')
98  graphs[chamber]=TGraphErrors(n_points)
99  up=MuonFixedIdUnpack(chamber)
100  if up.stationNameString()=='XXX':
101  print ("Invalid station name in ", obj.payload()['file'])
102  sys.exit(1)
103  nm=up.stationNameString() + "_" + str(up.stationPhi()) + "_" + str(up.stationEta())
104 # print (nm)
105  ts_applied=TimeSlewingApplied(obj)
106  for i in range(0, n_points):
107  r=float(sp2[3*i])
108  t=float(sp2[3*i+1])
109  s=float(sp2[3*i+2])
110  if not ts_applied:
111  t_new=NoTs2Ts(r, t)
112  t=t_new
113  graphs[chamber].SetPoint(i, r, t)
114  graphs[chamber].SetPointError(i, 0, s)
115  splines[chamber]=TSpline3("sp_" + nm, graphs[chamber])
116  if gDirectory.IsWritable():
117  splines[chamber].Write("sp_" + nm)
118  graphs[chamber].Write("gr_" + nm)
119 
120  return graphs, splines, iovs
121 
122 
123 def ReadT0Cool(db_string, folder, tag, run_number):
124 
125  try:
126  db=AtlCoolLib.indirectOpen(db_string, readOnly=True, debug=True)
127  except Exception as e:
128  print ('Problem opening database',e)
129  sys.exit(-1)
130 
131 #get folder and tag
132  cool_folder=db.getFolder(folder)
133  cool_tag=ResolveTag(cool_folder, tag)
134  myiov=(run_number<<32)
135 #data
136  t0_values={}
137 
138  objs=cool_folder.browseObjects(myiov,myiov, cool.ChannelSelection.all(), cool_tag)
139 
140  for obj in objs:
141  sp=UnpackData(obj.payload()['data']).split('\n')
142  sp1=sp[0].split(',')
143  ch_sp=sp1[0][2:].split("_")
144  ch_id=(ch_sp[0], int(ch_sp[1]), int(ch_sp[2]))
145  ntubes=int(sp1[-1])
146 
147  t0_items=sp[1].split(",")
148  t0_values[ch_id] = []
149  ts_applied=TimeSlewingApplied(obj)
150  for i in range(0, ntubes):
151  t0=float(t0_items[3*i+0])
152  if not ts_applied:
153  t0+= GasmonDriftTimeOffsetT0
154  t0_values[ch_id].append((t0, int(t0_items[3*i+1]), float(t0_items[3*i+2])))
155 
156  return t0_values
157 
158 
159 def GetFolderTag(db_string, folder):
160  dbSvc=cool.DatabaseSvcFactory.databaseService()
161  try:
162  db=dbSvc.openDatabase(db_string)
163  except Exception as e:
164  print ('Problem opening database',e)
165  sys.exit(-1)
166 
167 #get folder and tag
168  cool_folder=db.getFolder(folder)
169  for x in cool_folder.listTags():
170  return x
171 
MuonCalibConvertTimeSlewing.NoTs2Ts
def NoTs2Ts(r, t)
Definition: MuonCalibConvertTimeSlewing.py:24
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
MuonFixedIdUnpack
Definition: MuonFixedIdUnpack.py:1
ReadCool.DumpFolderSummary
def DumpFolderSummary(db_string, folder, tag, run=None)
Definition: MuonSpectrometer/MuonCalib/MuonCalibDbOperations/python/ReadCool.py:31
dumpHVPathFromNtuple.append
bool append
Definition: dumpHVPathFromNtuple.py:91
ReadCool.ReadT0Cool
def ReadT0Cool(db_string, folder, tag, run_number)
Definition: MuonSpectrometer/MuonCalib/MuonCalibDbOperations/python/ReadCool.py:123
ReadCool.UnpackData
def UnpackData(data)
Definition: MuonSpectrometer/MuonCalib/MuonCalibDbOperations/python/ReadCool.py:18
MuonFixedIdUnpack
MuonCalibConvertTimeSlewing.TimeSlewingApplied
def TimeSlewingApplied(obj)
Definition: MuonCalibConvertTimeSlewing.py:27
ReadCool.iov_keygen
def iov_keygen(iov)
Definition: MuonSpectrometer/MuonCalib/MuonCalibDbOperations/python/ReadCool.py:28
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
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.
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
ReadCool.GetFolderTag
def GetFolderTag(db_string, folder)
Definition: MuonSpectrometer/MuonCalib/MuonCalibDbOperations/python/ReadCool.py:159
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
str
Definition: BTagTrackIpAccessor.cxx:11
ReadCool.ReadRtCool
def ReadRtCool(db_string, folder, tag, run_number)
Definition: MuonSpectrometer/MuonCalib/MuonCalibDbOperations/python/ReadCool.py:70
MuonCalibResolveTag.ResolveTag
def ResolveTag(folder, tag)
Definition: MuonCalibResolveTag.py:5
readCCLHist.float
float
Definition: readCCLHist.py:83
Trk::split
@ split
Definition: LayerMaterialProperties.h:38