ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
LArCalorimeter
LArBadChannelTool
python
UpdateManyBadChannelIOVs.py
Go to the documentation of this file.
1
# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
2
3
4
from
PyCool
import
cool
5
from
struct
import
pack,unpack
6
from
copy
import
deepcopy
7
8
def
addAndRemove
(dbname,folder,tag,ts1,ts2,chansToAdd=dict(),chansToRemove=()):
9
10
print
(
"Add:"
,chansToAdd)
11
print
(
"Rem:"
,chansToRemove)
12
13
dbSvc = cool.DatabaseSvcFactory.databaseService()
14
15
try
:
16
db1= dbSvc.openDatabase(dbname,
False
)
17
except
Exception
as
e:
18
print
(
"Problems connecting to database:"
,e)
19
return
1
20
21
22
if
not
db1.existsFolder(folder):
23
print
(
"ERROR folder"
,folder,
"does not exist in"
,dbname)
24
return
25
26
fd1=db1.getFolder(folder)
27
28
itr=fd1.browseObjects(ts1,ts2,cool.ChannelSelection.all(),tag)
29
while
itr.goToNext():
30
obj=itr.currentRef()
31
payload=obj.payload()
32
since=obj.since()
33
cc=obj.channelId()
34
#print ("Working on channel %i valid since run %i" % (cc,since>>32))
35
if
since<ts1:
36
since=ts1
37
38
bcBlob=payload[
"Blob"
]
39
40
touched=
False
41
42
if
cc
in
chansToAdd:
43
toAdd=deepcopy(chansToAdd[cc])
44
touched=
True
45
else
:
46
toAdd=dict()
47
48
newData=()
49
for
i
in
range(int(bcBlob.size()/8)):
50
(ch,bc)=unpack(
'II'
,bcBlob.read(8))
51
if
ch
in
chansToRemove:
52
print
(
"Removing entry [0x%x 0x%x] from COOL channel %i, IOV start run %i"
% (ch,bc,cc, since>>32))
53
touched=
True
54
continue
55
56
if
ch
in
toAdd:
57
bc|=toAdd.pop(ch)
58
print
(
"Augmenting existing channel 0x%x to 0x%x in COOL channel %i, IOV start run %i"
% (ch,bc,cc, since>>32))
59
60
newData+=((ch,bc),)
61
62
#Adding channels:
63
for
(ch,bc)
in
toAdd.items():
64
print
(
"Adding entry [0x%x 0x%x] to COOL channel %i, IOV start run %i"
% (ch,bc,cc, since>>32))
65
newData+=((ch,bc),)
66
67
68
if
touched:
69
bcBlob.resize(8*len(newData))
70
bcBlob.seek(0)
71
for
i
in
range(len(newData)):
72
bcBlob.write(pack(
"II"
,newData[i][0],newData[i][1]))
73
74
print
(
"Storing changed object channel %i, valid from run %i to %i"
% (cc,since>>32,obj.until()>>32))
75
fd1.storeObject(since,obj.until(),payload,cc,tag,
True
)
76
77
itr.close()
78
db1.closeDatabase()
79
80
81
82
83
84
# Usage example:
85
86
toRemove=(0x380cf300,0x380cfc00,0x380cff00)
87
88
toAdd={1 : {0x380cf100 : 0x41, 940404992 : 0x41}}
89
90
addAndRemove
(
"sqlite://;schema=test.db;dbname=CONDBR2"
,
91
"/LAR/BadChannelsOfl/BadChannels"
,
"LARBadChannelsOflBadChannels-UPD4-00"
,170000<<32,cool.ValidityKeyMax,toAdd,toRemove)
92
python.UpdateManyBadChannelIOVs.addAndRemove
addAndRemove(dbname, folder, tag, ts1, ts2, chansToAdd=dict(), chansToRemove=())
Definition
UpdateManyBadChannelIOVs.py:8
Generated on
for ATLAS Offline Software by
1.17.0