All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ICARUSservices.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 __doc__ = """
4 Provides a service manager preconfigured with ICARUS service providers.
5 
6 A `ServiceManager` object bridges the access to the service providers.
7 In the most straightforward cases, getting a service provider is as simple as
8 calling `ServiceManager(providerName)` with the name of the service as string
9 (e.g. `larProp = ServiceManager('LArProperties')`).
10 
11 
12 
13 If this module is executed as a script, the service manager is loaded and a
14 python interactive session is started. The main code also show how to override
15 the service manager setup by choosing a different service configuration.
16 """
17 
18 __all__ = [ 'ServiceManager', 'geometry', ]
19 
20 
21 import ICARUSutils # loadICARUSgeometry()
22 import LArSoftUtils
23 
24 
25 ################################################################################
26 ### special known services
27 ###
28 
30 
31  def __init__(self):
33 
34  def load(self, manager):
35  return ICARUSutils.loadICARUSgeometry(registry=manager.registry())
36 
37 # class ICARUSGeometryServiceGetter
38 
39 
40 ################################################################################
41 ### module setup - part I
42 ###
43 ### Where global service manager is set up.
44 ###
45 
47 
48  DefaultConfigPath = "services_basic_icarus.fcl"
49  DefaultServiceTable = "icarus_basic_services"
50 
52  """
53 
54  Configuration:
55 
56  If `serviceTable` is not `None`, a new configuration is created with the
57  service table as `serviceTable`, and `configPath` is included in that
58  configuration (presumably to define `serviceTable`). In this case, if
59  `configPath` is `None`, "services_icarus_simulation.fcl" is included.
60 
61  If both `configPath` and `serviceTable` are `None`, the configuration is
62  created as above, using "icarus_simulation_services" as `serviceTable`.
63 
64  Finally, if only `serviceTable` is `None`, the configuration file in
65  `configPath` is included directly, and it is assumed that it already
66  properly defines a `services` table.
67  """
68  return DefaultConfigPath, DefaultServiceTable
69  # defaultConfiguration()
70 
71  def __init__(self):
73  self.setConfiguration(
74  configFile=ICARUSserviceManagerClass.DefaultConfigPath,
75  serviceTable=ICARUSserviceManagerClass.DefaultServiceTable,
76  )
77  # __init__()
78 
79  def setup(self):
80  """Prepares for ICARUS service provider access in python/Gallery."""
81 
83 
84  #
85  # register the services we know about;
86  # some are already known
87  # (`LArSoftUtils.ServiceManagerClass.StandardLoadingTable`), including
88  # 'Geometry', 'LArProperties', 'DetectorClocks' and 'DetectorProperties',
89  # but se override the former with our flavor of it
90  #
91 
92  self.manager.registerLoader('Geometry', ICARUSGeometryServiceGetter())
93 
94  return self.manager
95 
96  # setup()
97 
98 # class ICARUSserviceManagerClass
99 
100 
101 ServiceManager = ICARUSserviceManagerClass()
102 
103 
104 ################################################################################
105 
106 def geometry(): return ServiceManager.get('Geometry')
107 
108 
109 ################################################################################
110 
111 if __name__ == "__main__":
112 
113  #
114  # unfortunately, ROOT module interferes with command line arguments.
115  #
116  import argparse
117 
118  Parser = argparse.ArgumentParser(
119  description=
120  "Starts a python interactive session with `ServiceManager` available."
121  )
122 
123  Parser.add_argument("--config", "-c", dest="configPath",
124  help="configuration file path (must define `services` or host serviceTable below)"
125  )
126  Parser.add_argument("--servicetable", "-T", dest="serviceTable",
127  help="name of the FHiCL table where all services are configured")
128 
129  args = Parser.parse_args()
130 
131  if args.configPath is not None:
132  ServiceManager.setConfiguration(args.configPath, args.serviceTable)
133 
134  # we want ROOT module known in the interactive session;
135  # and we keep the good habit of loading it via ROOTutils
136  from ROOTutils import ROOT
137 
138  try:
139  import IPython
140  IPython.embed()
141  except ImportError:
142  import code
143  code.interact(local=dict(globals(), **locals()))
144  # try ... except
145 
146 # main
def loadICARUSgeometry
Definition: ICARUSutils.py:141