9 import sys, re, os.path
12 from TileCalibBlobPython.TileCalibLogger
import getLogger
16 usage =
"Usage: integrator_ascii2db.py "
17 usage+=
"[-a author] [-c comment] "
18 usage+=
"[-from \"yyyy-mm-dd hh:mm:ss\"] "
19 usage+=
"file1 [file2 file3 ...]"
24 if (len(sys.argv)<2)
or (
"-h" in sys.argv)
or (
"--help" in sys.argv):
28 while len(sys.argv)>0:
30 if arg==
"-a" and len(sys.argv)>0:
31 author = sys.argv.pop(0)
32 elif arg==
"-c" and len(sys.argv)>0:
33 comment = sys.argv.pop(0)
34 elif arg==
"-from" and len(sys.argv)>0:
35 regFrom = sys.argv.pop(0)
38 if os.path.exists(arg):
41 log.error(
"File \"%s\" does not exist, ignoring input!", arg)
45 from TileCalibBlobPython
import TileCalibTools
48 db = TileCalibTools.openDb(
'SQLITE',
'CONDBR2',
'UPDATE')
51 blobWriter = TileCalibTools.TileBlobWriter(db,
"/TILE/ONL01/INTEGRATOR",
True,
False)
54 default = cppyy.gbl.std.vector(
'float')()
63 defVec = cppyy.gbl.std.vector(
'std::vector<float>')()
64 defVec.push_back(default)
65 defVec.push_back(default)
66 defVec.push_back(default)
67 defVec.push_back(default)
68 defVec.push_back(default)
69 defVec.push_back(default)
72 re_file = re.compile(
"int_gains_(\\D{3})(\\d{2})")
73 re_Res = re.compile(
"Res\\s*channel:\\s*(.*)\\s*gain:\\s*(.*)\\s*" +
74 "gain:\\s*(.*)\\s*\\+\\-\\s*(.*)\\s*" +
76 re_Ped = re.compile(
"Ped\\s*gain:\\s*(.*)\\s*dac:\\s*(.*)\\s*chan:\\s*(.*)\\s*" +
77 "pedestal:\\s*(.*)\\s*\\+\\-\\s*(.*)\\s*" +
78 "rms:\\s*(.*)\\s*\\+\\-\\s*(.*)\\s*" )
87 for fileName
in fileList:
90 result_file = re_file.search(fileName)
92 rosIdx = rosId[result_file.groups()[0]]
93 modIdx =
int(result_file.groups()[1]) - 1
95 log.error(
"Invalid file name \"%s\", skipping file..." , fileName)
97 log.info(
"Processing file %s", fileName)
100 flt = blobWriter.getDrawer(
'Flt',rosIdx,modIdx)
101 flt.init(defVec,48,0)
104 lines =
open(fileName,
"r").readlines()
109 result_Res = re_Res.search(line)
111 pmtIdx =
int( result_Res.groups()[0]) - 1
112 gainIdx =
int( result_Res.groups()[1]) - 1
113 gain =
float(result_Res.groups()[2])
114 gainErr =
float(result_Res.groups()[3])
115 chi2 =
float(result_Res.groups()[4])
117 flt.setData(pmtIdx,gainIdx,0,gain)
118 flt.setData(pmtIdx,gainIdx,1,gainErr)
119 flt.setData(pmtIdx,gainIdx,2,chi2)
123 result_Ped = re_Ped.search(line)
125 gainIdx =
int( result_Ped.groups()[0]) - 1
127 pmtIdx =
int( result_Ped.groups()[2]) - 1
129 pedErr =
float(result_Ped.groups()[4])
131 rmsErr =
float(result_Ped.groups()[6])
132 flt.setData(pmtIdx,gainIdx,3,dac)
133 flt.setData(pmtIdx,gainIdx,4,ped)
134 flt.setData(pmtIdx,gainIdx,5,pedErr)
135 flt.setData(pmtIdx,gainIdx,6,rms)
136 flt.setData(pmtIdx,gainIdx,7,rmsErr)
139 log.info(
"---> %s%s, registered %3i Res and %3i Ped lines", result_file.groups()[0],
140 result_file.groups()[1],
144 blobWriter.setComment(author,comment)
145 blobWriter.register(regFrom,-1)