ATLAS Offline Software
Loading...
Searching...
No Matches
DetStatusCoolLib.py
Go to the documentation of this file.
1# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
2
3# DetStatusCoolLib.py
4# python functions for dealing with detector status read from COOL
5# Richard Hawkings, 22/10/07
6
7from PyCool import cool
8from CoolConvUtilities.AtlCoolLib import indirectOpen,RangeList
9from DetectorStatus.DetStatusLib import DetStatusReq
10
11def statusCutsToRange(dbconn,foldername,since,until,tag,statusreq):
12 """Return a RangeList giving the good IOV range corresponding to the
13 specified set of daetector status cuts, using the given DB and folder"""
14 range=RangeList(since,until)
15 reqs=DetStatusReq()
16 reqs.setFromString(statusreq)
17 folder=dbconn.getFolder(foldername)
18 # loop over all requested status cuts
19 for (ichan,req) in reqs.getDict().items():
20 itr=folder.browseObjects(since,until,cool.ChannelSelection(ichan),tag)
21 lastiov=since
22 while itr.goToNext():
23 obj=itr.currentRef()
24 status=obj.payload()['Code']
25 if (lastiov<obj.since()):
26 # veto gaps where no status data was provided - assume bad
27 range.vetoRange(lastiov,obj.since())
28 if (status<req):
29 range.vetoRange(obj.since(),obj.until())
30 lastiov=obj.until()
31 # veto final gap (if any)
32 range.vetoRange(lastiov,until)
33 itr.close()
34 return range
35
36def testStatusCutsToRange():
37 dbconn=indirectOpen('COOLOFL_GLOBAL/COMP200')
38 statusCutsToRange(dbconn,'/GLOBAL/DETSTATUS/LBSUMM',0,cool.ValidityKeyMax,'TRTB 3')
39
40if __name__=='__main__':
41 testStatusCutsToRange()
statusCutsToRange(dbconn, foldername, since, until, tag, statusreq)