psana/src/datasource.py

Go to the documentation of this file.
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     # make instance of the framework
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     # Create the PSANA datasource object
00065     ds = fwk.dataSource(*args)
00066 
00067 
00068     # Check if any keyword arguments given    
00069     # module keyword -- add module or list of modules
00070     if 'module' in kwargs:    
00071         # Add modules
00072         try :        
00073             for module in kwargs['module'] :
00074                 ds.__add_module(module)
00075         except TypeError:
00076             # Incase a single module is added
00077             ds.__add_module(kwargs['module'])
00078 
00079     # inject the environment into the global namespace --TJL
00080     _global_env = ds.env()    
00081         
00082     # --> return the datasource object
00083     return ds

Generated on 19 Dec 2016 for PSANAclasses by  doxygen 1.4.7