9 import os, sys, getopt, cppyy, logging
10 os.environ[
'TERM'] =
'linux'
13 print (
"How to use: ",sys.argv[0],
" [OPTION] ... ")
14 print (
"Write pulse shapes to COOL")
16 print (
"-h, --help shows this help")
17 print (
"-f, --folder= specify folder to use f.i. /TILE/OFL02/PULSESHAPE/PHY or only PHY")
18 print (
"-t, --tag= specify tag to use, f.i. RUN2-HLT-UPD1-00")
19 print (
"-r, --run= specify run number, default is 0")
20 print (
"-m, --module= specify module name for which pulse shape will be written, default is AUX01")
21 print (
"-L, --lowgain= specify the text file with new pulse shape for low gain")
22 print (
"-H, --highgain= specify the text file with new pulse shape for high gain")
23 print (
"-s, --schema= specify schema to use, f.i. 'sqlite://;schema=tileSqlite.db;dbname=CONDBR2'")
24 print (
"-D, --dbname= specify dbname part of schema if schema only contains file name, default is tileSqlite.db")
25 print (
"-U, --user= specify username for comment")
26 print (
"-C, --comment= specify comment which should be written to DB")
27 print (
"-z, --zero if present, means that zero-sized blob is written for missing drawers")
28 print (
"-u --update set this flag if output sqlite file should be updated, otherwise it'll be recreated")
31 letters =
"L:H:s:D:U:C:f:t:m:r:hzu"
32 words = [
"lowgain=",
"highgain=",
"schema=",
"dbname=",
"user=",
"comment=",
"folder=",
"tag=",
"module=",
"run=",
"help",
"zero",
"update"]
35 options,args = getopt.getopt(sys.argv[1:],letters,words)
36 except getopt.GetoptError
as err:
47 pulseLG =
"pulselo_physics.dat"
48 pulseHG =
"pulsehi_physics.dat"
51 dbname =
"tileSqlite.db"
54 folder =
"/TILE/OFL02/PULSESHAPE/PHY"
57 tag =
"RUN2-HLT-UPD1-00"
87 if o
in (
"-h",
"--help"):
90 elif o
in (
"-L",
"--lowgain"):
92 elif o
in (
"-H",
"--highgain"):
94 elif o
in (
"-s",
"--schema"):
96 elif o
in (
"-D",
"--dbname"):
98 elif o
in (
"-f",
"--folder"):
100 elif o
in (
"-t",
"--tag"):
102 elif o
in (
"-m",
"--module"):
104 elif o
in (
"-U",
"--user"):
106 elif o
in (
"-C",
"--comment"):
108 elif o
in (
"-r",
"--run"):
110 elif o
in (
"-z",
"--zero"):
112 elif o
in (
"-u",
"--update"):
115 raise RuntimeError(
"unhandled option")
118 part=[
'AUX',
'LBA',
'LBC',
'EBA',
'EBC']
119 ros=part.index(module[:3])
123 schema =
'sqlite://;schema=%s;dbname=CONDBR2' % (dbname)
125 if '/TILE' not in folder:
126 folder=
'/TILE/OFL02/PULSESHAPE/'+folder
129 comment =
"Pulses from %s %s for module %s" % (pulseLG,pulseHG,module)
135 lines =
open(pulseLG,
"r").readlines()
141 if fields[0].startswith(
"#"):
143 if fields[0].startswith(
"*"):
145 if len(fields) != 2 :
148 xlo.append(
float(fields[0]))
149 ylo.append(
float(fields[1]))
154 lines =
open(pulseHG,
"r").readlines()
156 fields = line.strip().
split()
160 if fields[0].startswith(
"#"):
162 if fields[0].startswith(
"*"):
164 if len(fields) != 2 :
167 xhi.append(
float(fields[0]))
168 yhi.append(
float(fields[1]))
171 vecLo = cppyy.gbl.std.vector(
'float')()
176 vecHi = cppyy.gbl.std.vector(
'float')()
181 newPulse = cppyy.gbl.std.vector(
'std::vector<float>')()
182 newPulse.push_back(vecLo)
183 newPulse.push_back(vecHi)
187 from TileCalibBlobPython
import TileCalibTools
188 from TileCalibBlobObjs.Classes
import TileCalibUtils
189 from TileCalibBlobPython.TileCalibTools
import MINRUN, MINLBK, MAXRUN, MAXLBK
192 db = TileCalibTools.openDbConn(schema,(
'UPDATE' if update
else 'RECREATE'))
193 blobWriter = TileCalibTools.TileBlobWriter(db,folder,
'Flt')
194 blobWriter.setLogLvl(logging.DEBUG)
198 util = cppyy.gbl.TileCalibUtils()
199 for r
in range(util.max_ros()):
200 for d
in range(util.getMaxDrawer(r)):
201 blobWriter.zeroBlob(r,d)
204 det = blobWriter.getDrawer(ros,drawer)
205 det.init(newPulse,1,200)
207 blobWriter.setComment(user,comment)
209 blobWriter.register((run,0),(MAXRUN,MAXLBK),folderTag)