Beispiel #1
0
def load_xtcav_calib_file(fpath) :
    """Returns object retrieved from hdf5 file by XtcavConstants.Load method.

       Xtcav constants are wrapped in python object and accessible through attributes with arbitrary names.
       list of attribute names can be retrieved as dir(o) 
       and filtred from system names like '__*__' by the comprehension list [p for p in dir(o) if p[:2] != '__']
       access to attributes can be done through the python built-in method getattr(o, name, None), etc...
    """
    logger.info('Load xtcav calib object from file: %s'%fpath)
    return Load(fpath)
Beispiel #2
0
 def test_serialize_xtcav_dict():
     from psana.pscalib.calib.MDBConvertUtils import print_dict
     #fname = '/reg/d/psdm/AMO/amox23616/calib/'\
     #        'Xtcav::CalibV1/XrayTransportDiagnostic.0:Opal1000.0/lasingoffreference/56-end.data'
     #fname = '/reg/g/psdm/detector/data_test/calib/'\
     #        'Xtcav::CalibV1/XrayTransportDiagnostic.0:Opal1000.0/lasingoffreference/56-end.data'
     fname = '/reg/g/psdm/detector/data_test/calib/'\
             'Xtcav::CalibV1/XrayTransportDiagnostic.0:Opal1000.0/pedestals/104-end.data'
     o = Load(fname)
     dico = dict_from_xtcav_calib_object(o)
     serialize_dict(dico)
     #print('dico: %s' % dico)
     print(80*'_')
     print_dict(dico)
     print(80*'_')
Beispiel #3
0
def test_xtcav_calib_constants(
    fname='/reg/d/psdm/XPP/xpptut15/calib/Xtcav::CalibV1/XrayTransportDiagnostic.0:Opal1000.0/pedestals/101-102.data'
):

    _, exp, _, cvers, detname, ctype, cfname = fname.rsplit('/', 6)
    resp = parse_calib_file_name(cfname)
    begin, end, ext = resp if resp is not None else (None, None, None)
    det = detname_conversion(detname)
    run = begin
    dbname_exp = dbu.db_prefixed_name(exp)
    dbname_det = dbu.db_prefixed_name(det)

    print('LCLS1 Xtcav calibration file: %s' % fname)
    print('Parameters form path: exp:%s det:%s ctype:%s run:%s dbname_exp:%s dbname_det:%s'%\
          (exp, det, ctype, run, dbname_exp, dbname_det))

    #Save(ct,fname)
    o1 = Load(fname)
    d1 = dict_from_xtcav_calib_object(o1)
    print('Xtcav calibration constants as dict:\n', d1)

    #---- Delete databases for experiment and detector

    client = dbu.connect_to_server(HOST, PORT)
    print('Open client on host:%s port:%s' % (HOST, PORT))

    print('Delete database %s' % dbname_exp)
    dbu.delete_database(client, dbname_exp)

    print('Delete database %s' % dbname_det)
    dbu.delete_database(client, dbname_det)

    #---- Add data to experiment and detector dbs
    print('Add Xtcav constants')

    kwargs = {'host' : HOST,\
              'port' : PORT,\
              'version' : 'V01',\
              'comment' : 'test of add-retrieve xtcav constants'
             }
    #insert_calib_data(data, *kwargs)
    dbu.insert_constants(o1,
                         exp,
                         det,
                         ctype,
                         run,
                         time_sec='1000000000',
                         **kwargs)

    #msg = dbu.database_info(client, dbname_exp, level=10)
    #print(msg)

    print(
        'Xtcav constants inserted, now retrieve them from db:%s collection:%s'
        % (dbname_exp, det))

    db, fs = dbu.db_and_fs(client, dbname_exp)
    col = dbu.collection(db, det)

    #for doc in col.find() :
    #    print(doc)

    doc = dbu.find_doc(col, query={'ctype': ctype, 'run': run})
    print('Found doc:\n', doc)

    o2 = dbu.get_data_for_doc(fs, doc)
    d2 = dict_from_xtcav_calib_object(o2)
    print('Xtcav calib object converted to dict:\n', d2)

    #print('cmp(d1,d2) :', str(d1==d2))

    print(
        '\nCompare dictionaries for Xtcav calib objects loaded directly from calib file and passed through the CDB'
    )
    compare_dicts(d1, d2)

    client.close()
    return
Beispiel #4
0
 def test_const():
   ct = ConstTest()
   Save(ct,'ConstTest.h5')
   data = Load('ConstTest.h5')
   print('***',dir(data),data.parameters)
Beispiel #5
0
def load_xtcav_calib_file(fname) :
    """Returns dict made of xtcav object loaded from hdf5 file by XtcavConstants.Load method.
    """
    logger.info('Load xtcav calib object from file: %s'%fname)
    o = Load(fname)
    return dict_from_xtcav_calib_object(o)