9 print (
"Usage: ",sys.argv[0],
" [OPTION] ... ")
10 print (
"Write the TileCal drawer trips probabilities from ASCII file into local sqlite file")
11 print (
"ASCII file format:")
12 print (
"#CondId | frag | trip probability")
13 print (
"Trip 0x100 0.01")
15 print (
"-h, --help shows this help")
16 print (
"-t, --tag= specify tag to use, by default TEST-00")
17 print (
"-i, --input= input ASCII file, by default Tile.trips")
18 print (
"-f, --folder= specify status folder to use OFL01 or OFL02, by default OFL01 ")
22 keywords = [
"help",
"tag=",
"input=",
"folder="]
25 opts, extraparams = getopt.getopt(sys.argv[1:], letters, keywords)
26 except getopt.GetoptError
as err:
33 folderPath =
"/TILE/OFL01/STATUS/ADC"
35 fileName =
"Tile.trips"
39 if o
in (
"-i",
"--input"):
41 elif o
in (
"-t",
"--tag"):
43 elif o
in (
"-f",
"--folder"):
44 folderPath =
"/TILE/%s/STATUS/ADC" % a
45 elif o
in (
"-h",
"--help"):
49 raise RuntimeError(
"unhandled option")
54 from TileCalibBlobPython
import TileCalibTools
55 from TileCalibBlobObjs.Classes
import TileCalibUtils
58 from TileCalibBlobPython.TileCalibLogger
import getLogger
61 log.setLevel(logging.DEBUG)
66 , until=(TileCalibTools.MAXRUN, TileCalibTools.MAXLBK)):
72 util = cppyy.gbl.TileCalibUtils()
74 default = cppyy.gbl.std.vector(
'unsigned int')()
75 for i
in range(util.max_drawer() + 1):
76 default.push_back( 0 )
78 defVec = cppyy.gbl.std.vector(
'std::vector<unsigned int>')()
79 defVec.push_back(default)
84 writer = TileCalibTools.TileBlobWriter(db, folderPath,
'Bch')
86 precisions = [[0
for drawer
in range(util.max_drawer())]
for ros
in range(util.max_ros())]
87 trips = [[0
for drawer
in range(util.max_drawer())]
for ros
in range(util.max_ros())]
89 parser = TileCalibTools.TileASCIIParser3(fileTrips,
"Trip")
90 dict = parser.getDict()
91 log.info(
"Updating dictionary from file with %i entries", len(dict))
92 log.info(
"... filename: %s", fileTrips )
93 for key, trip
in list(dict.items()):
96 precisions[ros][mod] = len(trip[0]) - 2
97 trips[ros][mod] =
float(trip[0])
100 tripsCalibDrawer = writer.getDrawer(util.trips_ros(), util.trips_drawer())
101 tripsCalibDrawer.init(defVec, util.max_ros(), 1)
103 for ros
in range(util.max_ros()):
104 denominator = 10**
max(precisions[ros])
105 for mod
in range(util.max_drawer()):
106 trip =
int(trips[ros][mod] * denominator)
107 tripsCalibDrawer.setData(ros, 0, mod, trip)
108 tripsCalibDrawer.setData(ros, 0, util.max_drawer(), denominator)
113 writer.register(since, until, folderTag)
121 db = TileCalibTools.openDb(
'SQLITE',
'OFLP200',
'UPDATE')