PSCalib/src/DCDetectorId.py

Go to the documentation of this file.
00001 #-----------------------------------------------------------------------------
00002 # File and Version Information:
00003 #  $Id: DCDetectorId.py 12871 2016-11-14 22:19:31Z dubrovin@SLAC.STANFORD.EDU $
00004 #-----------------------------------------------------------------------------
00005 
00006 """
00007 :py:class:`PSCalib.DCDetectorId` - class for the Detector Calibration (DC) project.
00008 
00009 Usage::
00010 
00011     # Import
00012     from PSCalib.DCDetectorId import id_epix, id_cspad
00013 
00014     # Parameters
00015     dsn = 'exp=cxif5315:run=169'
00016     # or
00017     dsn = '/reg/g/psdm/detector/data_test/types/0003-CxiDs2.0-Cspad.0-fiber-data.xtc'
00018     ds = psana.DataSource(dsn)
00019     env = ds.env()
00020     src = psana.Source('CxiDs2.0:Cspad.0') # or unique portion of the name ':Cspad.' or alias 'DsaCsPad'
00021 
00022     # Access methods
00023     ide = id_epix(env, src)
00024     idc = id_cspad(env, src)
00025 
00026 @see project modules
00027     * :py:class:`PSCalib.DCStore`
00028     * :py:class:`PSCalib.DCType`
00029     * :py:class:`PSCalib.DCRange`
00030     * :py:class:`PSCalib.DCVersion`
00031     * :py:class:`PSCalib.DCBase`
00032     * :py:class:`PSCalib.DCInterface`
00033     * :py:class:`PSCalib.DCUtils`
00034     * :py:class:`PSCalib.DCDetectorId`
00035     * :py:class:`PSCalib.DCConfigParameters`
00036     * :py:class:`PSCalib.DCFileName`
00037     * :py:class:`PSCalib.DCLogger`
00038     * :py:class:`PSCalib.DCMethods`
00039     * :py:class:`PSCalib.DCEmail`
00040 
00041 This software was developed for the SIT project.
00042 If you use all or part of it, please give an appropriate acknowledgment.
00043 
00044 @version $Id: DCDetectorId.py 12871 2016-11-14 22:19:31Z dubrovin@SLAC.STANFORD.EDU $
00045 
00046 @author Mikhail S. Dubrovin
00047 """
00048 
00049 #---------------------------------
00050 __version__ = "$Revision: 12871 $"
00051 #---------------------------------
00052 
00053 #import os
00054 #import math
00055 #import numpy as np
00056 #from time import time
00057 
00058 from PSCalib.DCUtils import detector_full_name, psana_source
00059 
00060 from Detector.PyDataAccess import\
00061      get_cspad_config_object,\
00062      get_cspad2x2_config_object,\
00063      get_epix_config_object
00064 
00065 #------------------------------
00066 
00067 def id_epix(env, src) :
00068     """Returns Epix100 Id as a string, e.g., 3925999616-0996663297-3791650826-1232098304-0953206283-2655595777-0520093719"""
00069     psa_src = psana_source(env, src)
00070     o = get_epix_config_object(env, psa_src)
00071     fmt2 = '%010d-%010d'
00072     zeros = fmt2 % (0,0)
00073     version = '%010d' % (o.version()) if getattr(o, "version", None) is not None else '%010d' % 0
00074     carrier = fmt2 % (o.carrierId0(), o.carrierId1())\
00075               if getattr(o, "carrierId0", None) is not None else zeros
00076     digital = fmt2 % (o.digitalCardId0(), o.digitalCardId1())\
00077               if getattr(o, "digitalCardId0", None) is not None else zeros
00078     analog  = fmt2 % (o.analogCardId0(), o.analogCardId1())\
00079               if getattr(o, "analogCardId0", None) is not None else zeros
00080     return '%s-%s-%s-%s' % (version, carrier, digital, analog)
00081 
00082 #------------------------------
00083 
00084 def id_cspad(env, src) :
00085     """Returns detector full name for any src, e.g., XppGon.0:Cspad2x2.0"""
00086     return detector_full_name(env, src)
00087 
00088 #------------------------------
00089 
00090 def id_det_noid(env, src) :
00091     """Returns detector full name for any src, e.g., XppGon.0:Cspad2x2.0"""
00092     return detector_full_name(env, src)
00093 
00094 #------------------------------
00095 #------------------------------
00096 #------------------------------
00097 #------------------------------
00098 #------------------------------
00099 #------------------------------
00100 
00101 def test_id_epix() :
00102     dsn = '/reg/g/psdm/detector/data_test/types/0019-XppGon.0-Epix100a.0.xtc'
00103     src = 'XppGon.0:Epix100a.0'  
00104     ds = psana.DataSource(dsn)
00105     env = ds.env()
00106     print 20*'_', '\n%s:' % sys._getframe().f_code.co_name
00107     print 'dataset     : %s' % dsn
00108     print 'source      : %s' % src
00109     print 'Detector Id : %s' % id_epix(env, src)
00110 
00111 #------------------------------
00112 
00113 def test_id_cspad() :
00114     dsn = '/reg/g/psdm/detector/data_test/types/0003-CxiDs2.0-Cspad.0-fiber-data.xtc'
00115     src = ':Cspad.0' # 'CxiDs2.0:Cspad.0'
00116     ds = psana.DataSource(dsn)
00117     env = ds.env()
00118     print 20*'_', '\n%s:' % sys._getframe().f_code.co_name
00119     print 'dataset     : %s' % dsn
00120     print 'source      : %s' % src
00121     print 'Detector Id : %s' % id_cspad(env, src)
00122 
00123 #------------------------------
00124 
00125 def do_test() :
00126     tname = sys.argv[1] if len(sys.argv) > 1 else '0'
00127     print 50*'_', '\nTest %s:' % tname
00128     if   tname == '0' : test_id_epix(); test_id_cspad()
00129     elif tname == '1' : test_id_epix()        
00130     elif tname == '2' : test_id_cspad()        
00131     else : print 'Not-recognized test: %s' % tname
00132     sys.exit( 'End of test %s' % tname)
00133 
00134 #------------------------------
00135 
00136 if __name__ == "__main__" :
00137     import sys; global sys
00138     import psana; global psana
00139     do_test()
00140 
00141 #------------------------------

Generated on 19 Dec 2016 for PSANAmodules by  doxygen 1.4.7