ATLAS Offline Software
DQCDispatch.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
2 
3 # This holds the method that returns an appropriate DataQualityConfiguration
4 # module for the specified input string
5 # Algorithm: exact match to input if exists, otherwise dispatch based on end
6 # of string, or to pattern data[0-9]{2}
7 #
8 # 2012-12-05 Peter Onyisi
9 
10 def getmodule(modname):
11  import six
12  assert isinstance(modname, six.string_types), 'Argument to getmodule must be a string'
13 
14  # Local file?
15  try:
16  mod = __import__(modname)
17  components = modname.split('.')
18  for comp in components[1:]:
19  mod = getattr(mod,comp)
20  return mod
21  except ImportError:
22  pass
23 
24  # Does it exist already?
25  try:
26  return getattr(__import__('DataQualityConfigurations.'+modname), modname)
27  except ImportError:
28  pass
29 
30  # Does it match a pattern?
31  if (modname.endswith('GeV')
32  or modname.endswith('TeV')
33  or modname.endswith('_calib')
34  or modname.endswith('_comm')):
35  from . import base_data; return base_data
36  if (modname.endswith('_hi')
37  or modname.endswith('_hip')):
38  from . import base_data_hi; return base_data_hi
39  elif (modname.endswith('_1beam') ):
40  from . import base_data_1beam; return base_data_1beam
41  #return __import__('base_data_1beam')
42  elif (modname.endswith('_cos')
43  or modname.endswith('_calocomm')
44  or modname.endswith('_idcomm')
45  or modname.endswith('_larcomm')
46  or modname.endswith('_muoncomm')
47  or modname.endswith('_tilecomm')):
48  from . import base_data_cos; return base_data_cos
49 
50  import re
51  # Does it look like datann_hip?
52  m = re.match(r'data\d{2}_hip', modname)
53  if m:
54  from . import base_data_hi; return base_data_hi
55  # Does it look like datann?
56  m = re.match(r'data\d{2}$', modname)
57  if m:
58  from . import base_data; return base_data
59 
60  raise ValueError('Unable to find a valid configuration for %s' % modname)
python.DQCDispatch.getmodule
def getmodule(modname)
Definition: DQCDispatch.py:10