ATLAS Offline Software
Loading...
Searching...
No Matches
CaloBlobWriter.py
Go to the documentation of this file.
1#!/bin/env python
2# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3
4import ROOT
5from PyCool import cool
6import os
7
8
9def CaloCondBlobWriter(spec,valuePairs,defaultValue):
10
11 vec=getattr(ROOT,'vector<float>')
12 vecvec=getattr(ROOT,'vector<vector<float> >')
13
14 #Build the defintion vector (1 value per gain)
15 gainDefVec = vec()#g.std.vector('float')()
16 gainDefVec.push_back(defaultValue)
17 defVec = vecvec()
18 defVec.push_back(gainDefVec)
19
20 nLArChannels=182468 # Connected LAr cells
21 nAllChannels=187652 # Connected LAr + Tile cells
22
23 if len(valuePairs)>nLArChannels: #input data apparently includes also Tile
24 nChannels=nAllChannels
25 else:
26 nChannels=nLArChannels
27 pass
28
29
30 print ("Build CaloCondBlob object")
31 data = cool.Record( spec )
32 blob = data['CaloCondBlob16M']
33 fltClass=ROOT.CaloCondBlobFlt
34 flt=fltClass.getInstance(blob)
35 flt.init(defVec,nChannels,1)
36
37 print ("Filling CaloCondBlob object")
38 dvec=vec()
39 dvec.push_back(defaultValue)
40
41 foundChans=set()
42
43
44 for (hashid,value) in valuePairs:
45 if hashid>=nChannels:
46 print ("ERROR: Invalid hash id",hashid)
47 continue
48
49 if hashid in foundChans:
50 print ("WARNING: Channel with hash",hashid,"encountered twice!")
51 else:
52 foundChans.add(hashid)
53 pass
54 dvec[0]=value
55 flt.setData(hashid,0,dvec)
56 pass
57
58 if len(foundChans)<nChannels:
59 print ("WARNING No values found for",nChannels-len(foundChans),"channels. Left at default value",defaultValue)
60
61
62 return data
63
64
65
66def CaloCondBlobWriterFromFile(spec,filename, defaultvalue):
67
68 fromfile=[]
69 rein=open(filename)
70 for line in rein:
71 beforecomment=line.split('#')[0].strip()
72 if len(beforecomment)==0:
73 continue
74
75 tok=beforecomment.split()
76 if len(tok)!=2:
77 print ("ERROR: Unexpected syntax:", line)
78 continue
79
80 try:
81 h=int(tok[0])
82 v=float(tok[1])
83 except ValueError:
84 print ("ERROR: Expected numbers, got",tok[0],tok[1] )
85 continue
86
87 fromfile.append((h,v))
88 pass
89 rein.close()
90 #print (fromfile)
91 return CaloCondBlobWriter(spec,fromfile,defaultvalue)
92
93
94
95
96def createSqlite(sqliteName,folderName,foldertag,iovMin=cool.ValidityKeyMin,iovMax=cool.ValidityKeyMax,inputFileName=None,defaultvalue=1.0):
97
98 dbSvc = cool.DatabaseSvcFactory.databaseService()
99
100 if os.access(sqliteName,os.R_OK):
101 print ("UPDATING existing sqlite file",sqliteName)
102 db=dbSvc.openDatabase("sqlite://;schema="+sqliteName+";dbname=CONDBR2",False)
103 else:
104 print ("Creating new sqlite file",sqliteName)
105 db=dbSvc.createDatabase("sqlite://;schema="+sqliteName+";dbname=CONDBR2")
106
107
108 spec = cool.RecordSpecification()
109 spec.extend('CaloCondBlob16M', cool.StorageType.Blob16M )
110
111 desc= '<timeStamp>run-lumi</timeStamp><addrHeader><address_header service_type="71" clid="40774348" /></addrHeader><typeName>AthenaAttributeList</typeName>'
112
113 if db.existsFolder(folderName):
114 folder=db.getFolder(folderName)
115 else:
116 print ("Creating COOL folder/tag %s/%s" % (folderName,foldertag))
117 #folder = db.createFolder(folderName, spec, desc, cool.FolderVersioning.MULTI_VERSION, True)
118 folderSpec = cool.FolderSpecification(cool.FolderVersioning.MULTI_VERSION, spec)
119 folder = db.createFolder(folderName, folderSpec, desc, True)
120 pass
121
122 if inputFileName is None or len(inputFileName)==0:
123 print ("No input given. Create empty blob")
124 data = cool.Record(spec)
125 else:
126 data=CaloCondBlobWriterFromFile(spec,inputFileName,defaultvalue)
127
128 print ("Storing CaloCondBlob object")
129 folder.storeObject(iovMin, iovMax, data, cool.ChannelId(0), foldertag,True)
130
131 db.closeDatabase()
STL class.
CaloCondBlobWriterFromFile(spec, filename, defaultvalue)
CaloCondBlobWriter(spec, valuePairs, defaultValue)
createSqlite(sqliteName, folderName, foldertag, iovMin=cool.ValidityKeyMin, iovMax=cool.ValidityKeyMax, inputFileName=None, defaultvalue=1.0)