ATLAS Offline Software
GoodRunsListTool.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 import os, sys
6 
7 def importModule(moduleName,className,objectName=""):
8  if len(objectName)==0: objectName=className
9  if len(moduleName)>0:
10  modname = '%s.%s' % (moduleName,className)
11  else:
12  modname = className
13  import importlib
14  mod = importlib.import_module (modname)
15  return getattr (mod, objectName)
16 
17 def getObjectOfClass(moduleName,className=""):
18  moduleArr = moduleName.split(".")
19  if len(moduleArr)==2:
20  libraryName = moduleArr[0]
21  else: libraryName = "GoodRunsLists"
22  configModule = moduleArr[len(moduleArr)-1]
23  if len(className)==0: className=configModule
24 
25  try:
26  cls = importModule (libraryName,configModule,className)
27  except Exception:
28  try:
29  cls = importModule (configModule,className)
30  except Exception:
31  print ("Could not import configuration module \'" + configModule + "\'")
32  sys.exit(1)
33 
34  return cls()
35 
36 def createAndVerifyGRL(configModule,prefix=""):
37  xmlfile = createGRL(configModule,prefix)
38  allOk = verifyGRL(xmlfile)
39  return (allOk,xmlfile)
40 
41 def createGRL(configModule,prefix=""):
42  from CoolRunQuery.AtlRunQueryLib import AtlRunQuery
43  from CoolRunQuery.AtlRunQueryOptions import AtlRunQueryOptions
44  from CoolRunQuery.AtlRunQueryParser import ArgumentParser
45 
46 
47  config = getObjectOfClass(configModule)
48  config.setPrefix(prefix)
49  query = config.getsearchquery()
50  print (">> Calling cmd equivalent of: ")
51  print ("%s \"%s\"" % (config.querytool,query))
52 
53 
54  ap = ArgumentParser()
55  atlqueryarg = config.querytool + " " + ap.ParseArgument( query )
56  (options, args) = AtlRunQueryOptions().parse(atlqueryarg)
57 
58  #print (atlqueryarg)
59  #print (options)
60 
61 
62  AtlRunQuery(options, html="NO", origQuery=query) # html can be "YES", "NO", "AUTO"
63 
64  xmlfile = 'data/'+config.listname
65  print (">> Good-run list stored as: \'%s\'" % xmlfile)
66  return xmlfile
67 
68 def verifyGRL(xmlfile):
69 
70  CWD = os.getcwd()
71 
74  from ROOT import gSystem
75  os.chdir(CWD)
76 
77  gSystem.Load('libGoodRunsListsLib')
78  from ROOT import Root
79 
80  reader = Root.TGoodRunsListReader()
81 
82  reader.SetXMLFile(xmlfile)
83  reader.Interpret()
84 
85  grlcollection = reader.GetMergedGRLCollection()
86  print (">> Found %d independent good-run list(s). Now checking content." % len(grlcollection))
87 
88  allOk = True
89 
90 
91  for idx in range(len(grlcollection)):
92  grl = grlcollection[idx]
93  grlName = grl.GetName()
94  grlVersion = grl.GetVersion()
95  grlMDSize = grl.GetMetaDataSize()
96  grlIsEmpty = grl.IsEmpty()
97  if len(grlName)==0:
98  print (">> ERROR: good run list %d has no name." % (idx))
99  allOk = False
100  if len(grlVersion)==0:
101  print (">> ERROR: good run list %d, with name \'%s\', has no version." % (idx,grlName))
102  allOk = False
103  if grlMDSize==0:
104  print (">> ERROR: good run list %d, with name \'%s\', has no metadata." % (idx,grlName))
105  allOk = False
106  if grlIsEmpty:
107  print (">> ERROR: good run list %d, with name \'%s\', has no run(s) and lumi-block range(s)." % (idx,grlName))
108  allOk = False
109 
110  if allOk:
111  print (">> Content okay.")
112 
113  return allOk
114 
python.GoodRunsListTool.getObjectOfClass
def getObjectOfClass(moduleName, className="")
Definition: GoodRunsListTool.py:17
Root::TGoodRunsListReader
Definition: TGoodRunsListReader.h:34
python.GoodRunsListTool.createGRL
def createGRL(configModule, prefix="")
Definition: GoodRunsListTool.py:41
parse
std::map< std::string, std::string > parse(const std::string &list)
Definition: egammaLayerRecalibTool.cxx:1054
CaloClusterListBadChannel.cls
cls
Definition: CaloClusterListBadChannel.py:8
python.GoodRunsListTool.createAndVerifyGRL
def createAndVerifyGRL(configModule, prefix="")
Definition: GoodRunsListTool.py:36
python.GoodRunsListTool.importModule
def importModule(moduleName, className, objectName="")
Definition: GoodRunsListTool.py:7
AtlRunQuery
Definition: AtlRunQuery.py:1
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
python.GoodRunsListTool.verifyGRL
def verifyGRL(xmlfile)
Definition: GoodRunsListTool.py:68