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