00001 import _psana
00002 import os
00003
00004 _cfgFile = None
00005 _options = {}
00006 _global_env = None
00007
00008 def setConfigFile(name):
00009 """
00010 Set the name of the psana configuration file, default configuration
00011 file name is psana.cfg. If you want to avoid reading any configuration
00012 file then set it to empty string.
00013
00014 Configuration file name set with setConfigFile() is used in a next call to DataSource().
00015 """
00016 global _cfgFile
00017 _cfgFile = name
00018
00019 def setOption(name, value):
00020 """
00021 Set the psana configuration option, this will override any configuration
00022 option in a file. Option name has format "section.option" where "section"
00023 is the name of the section in configuration file (such as "psana" or
00024 "psana_examples.DumpPrinceton"). Value can be any string, possibly empty,
00025 non-string values will be converted to strings using str() call.
00026
00027 Configuration options set with setOption() are used in a next call to DataSource().
00028 """
00029 global _options
00030 _options[name] = str(value)
00031
00032 def setOptions(mapping):
00033 """
00034 Set the psana configuration option, this will override any configuration
00035 option in a file. Argument to this calls is a mapping (dictionary) whose
00036 keys are option names. Option name has format "section.option" where "section"
00037 is the name of the section in configuration file (such as "psana" or
00038 "psana_examples.DumpPrinceton"). Value can be any string, possibly empty,
00039 non-string values will be converted to strings using str() call.
00040
00041 Configuration options set with setOptions() are used in a next call to DataSource().
00042 """
00043 global _options
00044 for key, val in mapping.items():
00045 _options[key] = str(val)
00046
00047 def DataSource(*args,**kwargs):
00048 """
00049 Makes an instance of the data source object (:py:class:`psana._DataSource`).
00050 Arguments can be either a single list of strings or any number of strings,
00051 each string represents either an input file name or event collection.
00052 """
00053 global _options, _cfgFile, _global_env
00054
00055 cfgFile = _cfgFile
00056 if cfgFile is None:
00057 if os.path.exists("psana.cfg"):
00058 cfgFile = "psana.cfg"
00059 else:
00060 cfgFile = ""
00061 fwk = _psana.PSAna(cfgFile, _options)
00062
00063
00064
00065 ds = fwk.dataSource(*args)
00066
00067
00068
00069
00070 if 'module' in kwargs:
00071
00072 try :
00073 for module in kwargs['module'] :
00074 ds.__add_module(module)
00075 except TypeError:
00076
00077 ds.__add_module(kwargs['module'])
00078
00079
00080 _global_env = ds.env()
00081
00082
00083 return ds