6 from os.path
import join
as pjoin
7 import xml.etree.cElementTree
as cElementTree
9 from .events
import process_iovs
10 from .sugar
import define_iov_type, IOVSet, RunLumi, RunLumiType
14 "Represent a good run region"
18 Loads valid IOV ranges if they appear in any grl file whose name ends with ".xml"
21 for f
in listdir(xmldir)
if f.endswith(
".xml")))
25 Use IOV ranges from the input `files` xmls if the lumirange is set in any file
29 assert all(i.ordered
for i
in grl_iovsets)
32 for since, until, grl_states
in process_iovs(*grl_iovsets):
34 result.add(since, until)
36 return result.solidify(GRL_IOV)
39 with open(xml_file,
"rb")
as fd:
43 xml = cElementTree.fromstring(data)
46 for lbc
in xml.iter(
'LumiBlockCollection'):
47 run =
int(lbc.find(
'Run').text)
48 for lbr
in lbc.findall(
'LBRange'):
49 since, until =
int(lbr.get(
'Start')),
int(lbr.get(
'End')) + 1
53 return IOVSet_class(map(GRL_IOV._make,
sorted(result)))
55 def make_grl(iovset, name="unknown", version="unknown"):
56 assert len(iovset.channels) <= 1
58 from datetime
import datetime
59 from textwrap
import dedent
62 <?xml version="1.0" ?>
63 <!DOCTYPE LumiRangeCollection
64 SYSTEM 'http://atlas-runquery.cern.ch/LumiRangeCollection.dtd'>
65 <!-- Good-runs-list created by DQUtils on {time} -->
69 <Version>{version}</Version>""".
format(
70 name=name, version=version,
71 time=datetime.now().strftime(
"%Y-%m-%d %H:%M:%S.%f"))).strip()]
73 for run, iovs
in sorted(iovset.by_run.items()):
74 result.append(
" <LumiBlockCollection>")
75 result.append(
" <Run>%i</Run>" % run)
77 arg = iov.since.lumi, iov.until.lumi-1
78 result.append(
' <LBRange Start="%i" End="%i"/>' % arg)
79 result.append(
" </LumiBlockCollection>")
80 result.append(
" </NamedLumiRange>")
81 result.append(
"</LumiRangeCollection>")
82 return "\n".
join(result)
87 if isinstance(runlb, RunLumiType):
91 return any(_.contains_point(runlb_)
for _
in grl)
95 from warnings
import warn
96 warn(
"grl_iovs_from_xml was renamed to load_grl", DeprecationWarning)
100 path =
"/afs/cern.ch/user/b/beate/public/DQAna/StableBeams-periodC1.xml"
103 from pprint
import pprint
106 if __name__ ==
"__main__":