예제 #1
0
def delete_ctype(evt,
                 env,
                 src='Epix100a.',
                 ctype=gu.PIXEL_MASK,
                 calibdir=None,
                 cmt=None,
                 verb=False):
    """Delete specified ctype from calibration constants.
    
    Parameters
    
    - evt      : psana.Event -> event time
    - env      : psana.Env -> full detector name for psana.Source 
    - src      : str - source short/full name, alias or full
    - ctype    : gu.CTYPE - enumerated calibration type, e.g.: gu.PIXEL_MASK
    - calibdir : str - fallback path to calib dir (if xtc file is copied - calib and experiment name are lost)
    - cmt      : str - comment
    - verb     : bool - verbousity

    See :py:class:`DCMethods`
    """
    metname = sys._getframe().f_code.co_name

    str_ctype = gu.dic_calib_type_to_name[ctype]
    if verb:        print '  %s.delete_ctype  src: %s\n  ctype: %s\n  range: %s\n  calibdir:%s'%\
              (metname, src, str_ctype, range, calibdir)

    ofn = DCFileName(env, src, calibdir)
    if verb: ofn.print_attrs()

    fname = ofn.calib_file_path()

    return delete_ctype_from_file(fname, ctype, cmt, verb)
예제 #2
0
def print_content(env, src='Epix100a.', calibdir=None):
    """Defines the file name and prints file content.
    
    Parameters
    
    - env : psana.Env -> full detector name for psana.Source 
    - src : str - source short/full name, alias or full
    - calibdir : str - fallback path to calib dir (if xtc file is copied - calib and experiment name are lost)

    See :py:class:`DCMethods`
    """
    #metname = sys._getframe().f_code.co_name

    ofn = DCFileName(env, src, calibdir)
    fname = ofn.calib_file_path()
    ofn.print_attrs()

    print_content_from_file(fname)
예제 #3
0
def get_constants(par,
                  env,
                  src='Epix100a.',
                  ctype=gu.PIXEL_MASK,
                  calibdir=None,
                  vers=None,
                  verb=False):
    """
    Returns specified array of calibration constants.

    Parameters

    - par: psana.Event | float - tsec event time
    - env: psana.Env - to get full detector name for psana.Source 
    - src: str - source short/full name, alias or full
    - ctype: gu.CTYPE - enumerated calibration type, e.g.: gu.PIXEL_MASK
    - calibdir: str - fallback path to calib dir (if xtc file is copied - calib and experiment name are lost)
    - vers: int - calibration version

    Return 

    numpy.array - array of calibratiopn constatnts.

    See :py:class:`DCMethods`
    """
    metname = sys._getframe().f_code.co_name

    str_ctype = gu.dic_calib_type_to_name[ctype]
    if verb:        print '  %s.get_constants  src: %s\n  ctype: %s\n  vers: %s\n  calibdir:%s'%\
              (metname, src, str_ctype, vers, calibdir)

    ofn = DCFileName(env, src, calibdir)
    if verb: ofn.print_attrs()

    fname = ofn.calib_file_path()

    return get_constants_from_file(fname, par, ctype, vers, verb)
예제 #4
0
def add_constants(data, par, env, src='Epix100a.', ctype=gu.PIXEL_MASK, calibdir=None,\
                  vers=None,\
                  pred=None,\
                  succ=None,\
                  cmt=None,\
                  verb=False) :
    """Adds specified numpy array to the hdf5 file.

    Parameters
    
    - data : numpy.array or str - array or string of calibration constants/data to save in file
    - env  : psana.Env -> full detector name for psana.Source -> hdf5 file name
    - par  : psana.Event | float time -> event time
    - src  : str - source short/full name, alias or full -> hdf5 file name
    - ctype: gu.CTYPE - enumerated calibration type, e.g.: gu.PIXEL_MASK
    - calibdir : str - fallback path to calib dir (if xtc file is copied - calib and experiment name are lost)
    - vers : int - calibration version
    - pred : str - predecessor name
    - succ : str - successor name
    - cmt  : str - comment saved as a history record within DCRange
    - verb : bool - verbosity, default=False - do not prnt any message

    See :py:class:`DCMethods`
    """
    metname = sys._getframe().f_code.co_name

    str_ctype = gu.dic_calib_type_to_name[ctype]

    if verb:        print '  %s.add_constants  src: %s\n  ctype: %s\n  vers: %s\n  calibdir:%s'%\
              (metname, src, str_ctype, vers, calibdir)

    ofn = DCFileName(env, src, calibdir)
    if verb: ofn.print_attrs()
    ofn.make_path_to_calib_file()  # depth=2, mode=0775)

    fname = ofn.calib_file_path()

    add_constants_to_file(data, fname, par, env, ctype, vers, pred, succ, cmt,
                          verb)
예제 #5
0
    def CreateForEvtEnv(self, calibdir, group, source, par, env, pbits=0):
        """ Factory method
            This method makes access to the calibration store with fallback access to hdf5 file.

            Parameters

            - calibdir : string - calibration directory, ex: /reg/d/psdm/AMO/amoa1214/calib
            - group    : string - group, ex: PNCCD::CalibV1
            - source   : string - data source, ex: Camp.0:pnCCD.0
            - par      : int runnum or psana.Event - is used to get run number
            - env      : psana.Env   - environment object - is used to retrieve file name to get dataset time to retrieve DCRange
            - pbits=0  : int         - print control bits, ex: 255

            Returns

            - GenericCalibPars object
        """
        from PSCalib.DCFileName import DCFileName
        from PSCalib.DCUtils import env_time  #, evt_time

        runnum = par if isinstance(par, int) else par.run()

        #fnexpc, fnrepo, tsec = None, None, None

        ofn = DCFileName(env, source, calibdir)
        if pbits & 512: ofn.print_attrs()
        fnexpc = ofn.calib_file_path()
        fnrepo = ofn.calib_file_path_repo()
        tsec = env_time(env)

        #if True :
        if pbits:
            print '%s.CreateForEvtEnv: for tsec: %s' % (self.name, str(tsec))
            print '  expected hdf5 file name repo : "%s"' % (fnrepo)
            print '  expected hdf5 file name local: "%s"' % (fnexpc)

        return self.Create(calibdir, group, source, runnum, pbits, fnexpc,
                           fnrepo, tsec)
예제 #6
0
def get_constants_v0(*par, **opt):
    ofn = DCFileName(par[0], opt['src'])