ATLAS Offline Software
ReadOfcFromCool.py
Go to the documentation of this file.
1 #!/bin/env python
2 
3 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
4 #
5 # ReadOfcFromCool.py
6 # Lukas Pribyl <lukas.pribyl@cern.ch>, 2008-07-25
7 
8 import getopt,sys,os
9 os.environ['TERM'] = 'linux'
10 
11 def usage():
12  print ("Usage: ",sys.argv[0]," [OPTION] ... ")
13  print ("Dumps the TileCal OFC values various schemas / folders / tags")
14  print ("")
15  print ("-h, --help shows this help")
16  print ("-f, --folder= specify status folder to use CIS, LAS, PHY ")
17  print ("-r, --run= specify run number, by default uses latest iov")
18  print ("-l, --lumi= specify lumi block number, default is 0")
19  print ("-p, --ros= specify partition (ros number), default is 1")
20  print ("-d, --drawer= specify drawer number, default is 0")
21  print ("-c, --channel= specify channel number, default is 0")
22  print ("-g, -a, --adc= specify gain (adc number), default is 0")
23  print ("-i, --field= specify field number, default is 0")
24  print ("-s, --schema= specify schema to use, like 'COOLONL_TILE/CONDBR2' or 'sqlite://;schema=tileSqlite.db;dbname=CONDBR2'")
25  print ("-S, --server= specify server - ORACLE or FRONTIER, default is FRONTIER")
26 
27 letters = "hr:l:S:s:t:f:p:d:c:a:g:i:"
28 keywords = ["help","run=","lumi=","server=","schema=","tag=","folder=","ros=","drawer=","channel=","adc=","gain=","field="]
29 
30 try:
31  opts, extraparams = getopt.getopt(sys.argv[1:],letters,keywords)
32 except getopt.GetoptError as err:
33  print (str(err))
34  usage()
35  sys.exit(2)
36 
37 # defaults
38 run = 2147483647
39 lumi = 0
40 server = ''
41 schema = 'COOLONL_TILE/CONDBR2'
42 folderPath = "/TILE/ONL01/FILTER/OF2/PHY"
43 tag = ""
44 ros = 1
45 drawer = 0
46 channel = 0
47 adc = 0
48 field = 0
49 
50 for o, a in opts:
51  a = a.strip()
52  if o in ("-f","--folder"):
53  if a.startswith("/TILE"):
54  folderPath = a
55  elif a.startswith("OF"):
56  folderPath = "/TILE/ONL01/FILTER/%s" % a
57  else:
58  folderPath = "/TILE/ONL01/FILTER/OF2/%s" % a
59  elif o in ("-t","--tag"):
60  tag = a
61  elif o in ("-S","--server"):
62  server = a
63  elif o in ("-s","--schema"):
64  schema = a
65  elif o in ("-p","--ros"):
66  ros = int(a)
67  elif o in ("-d","--drawer"):
68  drawer = int(a)
69  elif o in ("-c","--channel"):
70  channel = int(a)
71  elif o in ("-a","--adc","-g","--gain"):
72  adc = int(a)
73  elif o in ("-i","--field"):
74  field = int(a)
75  elif o in ("-r","--run"):
76  run = int(a)
77  elif o in ("-l","--lumi"):
78  lumi = int(a)
79  elif o in ("-h","--help"):
80  usage()
81  sys.exit(2)
82  else:
83  raise RuntimeError("unhandled option")
84 
85 
86 from TileCalibBlobPython import TileCalibTools
87 from TileCalibBlobObjs.Classes import TileCalibUtils
88 
89 from TileCalibBlobPython.TileCalibLogger import getLogger
90 log = getLogger("ReadOfc")
91 import logging
92 log.setLevel(logging.DEBUG)
93 
94 
95 #=== set database
96 db = TileCalibTools.openDbConn(schema,server)
97 folderTag = TileCalibTools.getFolderTag(schema if 'COMP200' in schema or 'OFLP200' in schema else db, folderPath, tag)
98 
99 #=== required OF2 folder
100 if len(tag)>0:
101  log.info("Initializing folder %s with tag %s", folderPath, folderTag)
102 else:
103  log.info("Initializing folder %s", folderPath)
104 blobReader = TileCalibTools.TileBlobReader(db,folderPath, folderTag)
105 #blobReader.log().setLevel(logging.DEBUG)
106 
107 #=== get drawer with status at given run
108 log.info("Initializing ros %d, drawer %d for run %d, lumiblock %d", ros,drawer,run,lumi)
109 log.info("... %s", blobReader.getComment((run,lumi)))
110 ofc = blobReader.getDrawer(ros, drawer,(run,lumi))
111 
112 #=== get other OFC parameters
113 nchann = ofc.getNChans()
114 nfields = ofc.getNFields()
115 nsamples = ofc.getNSamples()
116 nphases = ofc.getNPhases()
117 log.info( "" )
118 log.info( "nchann = %d", nchann )
119 log.info( "nfields = %d", nfields )
120 log.info( "nphases = %d", nphases )
121 log.info( "nsamples = %d", nsamples)
122 log.info( "" )
123 log.info( "OFC for %s channel %d adc %d field %d\n", TileCalibUtils.getDrawerString(ros,drawer),channel,adc,field)
124 
125 #=== get OFC field for given adc, sample and phase
126 for iphase in range(abs(nphases)):
127  phase = ofc.getPhase(channel, adc, iphase)
128  msg = "phase %6.1f ns :" % phase
129  for smp in range(0, nsamples):
130  msg += " %f" % ofc.getOfc(field, channel, adc, phase, smp)
131  print (msg)
132 
133 #=== close DB
134 db.closeDatabase()
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
ReadOfcFromCool.usage
def usage()
Definition: ReadOfcFromCool.py:11
TileCalibUtils::getDrawerString
static std::string getDrawerString(unsigned int ros, unsigned int drawer)
Return the drawer name, e.g.
Definition: TileCalibUtils.cxx:145
str
Definition: BTagTrackIpAccessor.cxx:11
python.CaloCondLogger.getLogger
def getLogger(name="CaloCond")
Definition: CaloCondLogger.py:16