ATLAS Offline Software
CalibDbCool2Calib.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 from __future__ import print_function
4 
5 import getopt
6 import sys
7 import os
8 import CalibDbDefaults
9 
10 cool_database_string = CalibDbDefaults.cool_database_string
11 dbname = CalibDbDefaults.cool_dbname
12 t0_cool_folder=None
13 rt_cool_folder=None
14 cool_tag='CURRENT'
15 
16 
17 def printhelp(argv0):
18  sys.stderr.write("Usage: " + argv0 + " [-h] [-s <cool database string>] [-o <t0 cool folder>] [-r <rt cool folder>] [-t <cool tag>] <run nr>\n")
19  sys.exit(1)
20 
21 optlist, args = getopt.gnu_getopt(sys.argv, 'hs:o:r:t:')
22 
23 for opt, oa in optlist:
24  if opt=='-s':
25  if oa[-2:]=='db':
26  cool_database_string = 'sqlite://;schema=' + oa + ';dbname=' + dbname
27  cool_tag=''
28  else:
29  cool_database_string = oa
30  continue
31  if opt=='-o':
32  t0_cool_folder=oa
33  continue
34  if opt=='-r':
35  rt_cool_folder=oa
36  continue
37  if opt=='-t':
38  cool_tag=oa
39  continue
40  if opt=='-h':
41  printhelp(sys.argv[0])
42 
43 if not len(args)==2:
44  sys.stderr.write("Need Run Number\n")
45  print (len(args), args)
46  printhelp(sys.argv[0])
47 
48 try:
49  run_number=int(args[1])
50 except ValueError:
51  sys.stderr.write("Cannot parse run number " + run_number + "\n")
52  printhelp(sys.argv[0])
53 
54 sys.argv=[ sys.argv[0], '-b' ]
57 from ROOT import *
58 
59 
60 def dump_rt(ident, rt):
61  up=MuonFixedIdUnpack(ident)
62  if up.stationNameString()=="XXX":
63  sys.stderr.write("WARNING: Unknown station found!\n")
64  return
65  f=file("calibration/rts/Rt_" + str(up.stationNameString()) + "_" + str(up.stationPhi()) + "_" + str(up.stationEta()) + ".dat", "w")
66  f.write("v1.0 1 Resolution 1 20000 0 0 0 0 dummy 800 ")
67  f.write(str(rt.GetN()))
68  f.write("\n")
69  for i in range(rt.GetN()):
70  f.write(str(rt.GetX()[i]) + " " + str(rt.GetY()[i]) + " " + str(rt.GetEY()[i]))
71  f.write("\n")
72 
73 
74 
75 
76 
77 if rt_cool_folder:
78  graphs=ReadRtCool(cool_database_string, rt_cool_folder, cool_tag, run_number)[0]
79  try:
80  os.makedirs("calibration/rts")
81  except OSError:
82  try:
83  os.stat("calibration/rts")
84  except OSError:
85  sys.stderr.write("ERROR: Cannot create calibration directory!\n")
86  sys.exit(1)
87  for ident, rt in graphs.items():
88  dump_rt(ident, rt)
89 
90 
CalibDbCool2Calib.printhelp
def printhelp(argv0)
Definition: CalibDbCool2Calib.py:17
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
MuonFixedIdUnpack
Definition: MuonFixedIdUnpack.py:1
CalibDbCool2Calib.dump_rt
def dump_rt(ident, rt)
Definition: CalibDbCool2Calib.py:60
MuonFixedIdUnpack
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
file
TFile * file
Definition: tile_monitor.h:29
ReadCool
str
Definition: BTagTrackIpAccessor.cxx:11
ReadCool.ReadRtCool
def ReadRtCool(db_string, folder, tag, run_number)
Definition: MuonSpectrometer/MuonCalib/MuonCalibDbOperations/python/ReadCool.py:70