ATLAS Offline Software
Loading...
Searching...
No Matches
TileCalibBlobPython_writeOfc.py
Go to the documentation of this file.
1#!/bin/env python
2
3# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
4#
5# TileCalibBlobPython_writeOfc.py
6# Nils Gollub <nils.gollub@cern.ch>, 2007-11-19
7# change: Yuri Smirnov <iouri.smirnov@cern.ch>, 2014-12-24
8
9import cppyy
10
11from PyCool import cool
12from TileCalibBlobPython import TileCalibTools, TileCalibLogger
13import re
14
15#==================================================
16#===
17#=== Configuration section
18#===
19#==================================================
20#=== Input files with OFCs
21ofcDataPath = "/afs/cern.ch/user/t/tiledaq/public/tilercd/tile-7.1.0.0/TileDSPofc/share/"
22ofcFiles = [ofcDataPath+'W_OF2_PHYSICS_7s.dat',
23 ofcDataPath+'W_OF1_PHYSICS_7s.dat',
24 ofcDataPath+'W_OF2_LED_7s.dat',
25 ofcDataPath+'W_OF1_LED_7s.dat',
26 ofcDataPath+'W_OF2_CIS_7s.dat',
27 ofcDataPath+'W_OF1_CIS_7s.dat']
28#=== pattern to decode filenames
29re_fileName = re.compile("W_(OF\\d)_(.*)_7s\\.dat")
30
31#=== IOV range for all folders
32iovSince = cool.ValidityKeyMin
33iovUntil = cool.ValidityKeyMax
34#=== values for the comment channel
35author = "ngollub"
36comment = "OFC weights (7 samples) imported from TileDSPofc v4r1p4"
37
38
39#==================================================
40#===
41#=== Code starts below here
42#===
43#==================================================
44#=== set shortcut
45g = cppyy.gbl
46
47#=== get a logger
48log = TileCalibLogger.getLogger("WriteOfc")
49
50#=== (re-)create the database
51db = TileCalibTools.openDb('SQLITE', 'CONDBR2', 'UPDATE')
52#=== creating folder specifications
53spec = cool.RecordSpecification()
54#=== Note special name '*Ofc' and 16M instead of 64k for OFCs
55spec.extend( 'TileCalibBlobOfc', cool.StorageType.Blob16M )
56
57folderMode = cool.FolderVersioning.SINGLE_VERSION
58folderSpec = cool.FolderSpecification(folderMode, spec)
59
60#=== loop over all input files
61for fileName in [ofcFiles[0]]:
62 log.info( "Reading file: %s", fileName )
63
64 #=== determine COOL folder from input file name
65 fileNameParts = re_fileName.search(fileName).groups()
66 ofMethod = fileNameParts[0]
67 ofRun = fileNameParts[1][:3]
68 #=== fix LED->LAS
69 if ofRun=="LED":
70 ofRun="LAS"
71 objVersion = int(ofMethod[2])
72 folderPath = TileCalibTools.getTilePrefix(False)+"FILTER/"+ofMethod+"/"+ofRun
73 log.info( "Filling COOL folder %s", folderPath )
74 desc = TileCalibTools.getAthenaFolderDescr()
75 folder = db.createFolder(folderPath, folderSpec, desc, True)
76
77 #=== loop over all drawers (COOL channels)
78 for chan in range(276):
79
80 data = cool.Record( spec )
81 blob = data['TileCalibBlobOfc']
82
83 #=== only fill defaults in COOL channel 0
84 if chan==0:
85 #=== initialize with negative nPhases, so only one common table is stored
86 #=== for all channels
87 drawerOfc = g.TileCalibDrawerOfc.getInstance(blob,objVersion,7,-2001,1,2)
88 #=== set phases as ints: phase[ns] * 10
89 phases = g.std.vector('float')()
90 for phase in range(-1000,1001):
91 phases.push_back(phase/10.)
92 drawerOfc.setPhases(0,0,phases)
93
94 #=== read file and fill OFCs
95 phase = -1000
96 channel = 0
97 adc = 0
98 sample = 0
99 lines = open(fileName,"r").readlines()
100 for line in lines:
101
102 #=== check for consistency
103 if phase>1000:
104 raise Exception("Phase out of range: %i" % phase)
105 phaseF=phase/10.
106
107 ofc = line.split()
108 #=== fill OFCs depending on OF version number
109 if objVersion==1:
110 if len(ofc)!=3:
111 raise Exception ("OF1, but len(ofc)=%i" % len(ofc))
112 drawerOfc.setOfc(drawerOfc.FieldA,channel,adc,phaseF,sample,float(ofc[0]))
113 drawerOfc.setOfc(drawerOfc.FieldB,channel,adc,phaseF,sample,float(ofc[1]))
114 drawerOfc.setOfc(drawerOfc.FieldG,channel,adc,phaseF,sample,float(ofc[2]))
115 elif objVersion==2:
116 if len(ofc)!=4:
117 raise Exception ("OF2, but len(ofc)=%i" % len(ofc))
118 drawerOfc.setOfc(drawerOfc.FieldA,channel,adc,phaseF,sample,float(ofc[0]))
119 drawerOfc.setOfc(drawerOfc.FieldB,channel,adc,phaseF,sample,float(ofc[1]))
120 drawerOfc.setOfc(drawerOfc.FieldC,channel,adc,phaseF,sample,float(ofc[2]))
121 drawerOfc.setOfc(drawerOfc.FieldG,channel,adc,phaseF,sample,float(ofc[3]))
122 else:
123 raise Exception ("Impossible objVersion: %i" % objVersion)
124
125 #=== increment counters
126 adc += 1
127 if adc>1:
128 adc = 0
129 sample += 1
130 if sample>6:
131 sample = 0
132 phase += 1
133
134 #=== store blob in folder/channel
135 channelId = cool.ChannelId(chan)
136 folder.storeObject(iovSince, iovUntil, data, channelId)
137 #<--end of chan loop
138
139 #=== add comment to comment channel
140 data = cool.Record( spec )
141 blob = data['TileCalibBlobOfc']
142 cmt = g.TileCalibDrawerCmt.getInstance(blob,author,comment)
143 channelId = cool.ChannelId(g.TileCalibUtils.getCommentChannel())
144 folder.storeObject(iovSince, iovUntil, data, channelId)
145 #<---end of file loop
146
147db.closeDatabase()