Exemple #1
0
def print_data():
    db_file = rs.open("../datasets/test_xic_100invpb.root", 'r')
    ds = db_file["da_lc"]
    im   = ROOT.RooRealVar ('im', 'im'  , 2.43, 2.51)
    dh = (ds.reduce(ROOT.RooArgSet(im) , "im>0")).binnedClone()

    #Get full info about 11th event
    ds.get(11).Print("V")
    #Get mass info about 11th event
    print(ds.get(11).getRealValue("im"))
Exemple #2
0
def test_shelves():
    
    db_sql_name  = CU.CleanUp.tempfile ( suffix = '.sqldb'  )  
    db_zip_name  = CU.CleanUp.tempfile ( suffix = '.zipdb'  ) 
    db_bz2_name  = CU.CleanUp.tempfile ( suffix = '.bz2db'  )
    db_root_name = CU.CleanUp.tempfile ( suffix = '.root'   )
    db_lz_name   = CU.CleanUp.tempfile ( suffix = '.lzmadb' )

    db_sql  = sqliteshelve.open ( db_sql_name  , 'c' )
    db_zip  = zipshelve.open    ( db_zip_name  , 'c' )
    db_bz2  = bz2shelve.open    ( db_bz2_name  , 'c' )
    db_root = rootshelve.open   ( db_root_name , 'c' )
    
    if lzshelve : db_lz = lzshelve.open ( db_lz_name , 'c' )
    else        : db_ls = None 
        
        
    for k in data :
        db_sql  [ k ] = data[k]
        db_zip  [ k ] = data[k]
        db_bz2  [ k ] = data[k]
        if lzshelve :
            db_lz  [ k ] = data[k]
        db_root [ k ] = data[k]
        
    logger.info('SQLiteShelve #keys: %s' % len ( list ( db_sql .keys() ) ) ) 
    logger.info('ZipShelve    #keys: %s' % len ( db_zip .keys() ) )
    logger.info('Bz2Shelve    #keys: %s' % len ( db_bz2 .keys() ) )
    logger.info('RootShelve   #keys: %s' % len ( db_root.keys() ) )
    if lzshelve :
        logger.info('LzShelve     #keys: %s' % len ( db_lz .keys() ) )

    db_sql  .close() 
    db_zip  .close()
    db_bz2  .close()
    db_root .close()
    if lzshelve : db_lz .close()

    logger.info('SQLiteShelve size: %d|%d ' % dbsize ( db_sql_name  ) ) 
    logger.info('ZipShelve    size: %d|%d ' % dbsize ( db_zip_name  ) )   
    logger.info('Bz2Shelve    size: %d|%d ' % dbsize ( db_bz2_name  ) ) 
    logger.info('RootShelve   size: %d|%d'  % dbsize ( db_root_name ) )  
    if lzshelve :
        logger.info('LzShelve     size: %d|%d ' % dbsize ( db_lz_name    ) ) 
    
    db_sql  = sqliteshelve.open    ( db_sql_name  , 'r' )
    db_zip  = zipshelve.open       ( db_zip_name  , 'r' )
    db_bz2  = bz2shelve.open       ( db_bz2_name  , 'r' )
    if lzshelve :
        db_lz  = lzshelve.open     ( db_lz_name   , 'r' )
    db_root = rootshelve.open      ( db_root_name , 'r' )

    logger.info('SQLiteShelve #keys: %s' % len ( list ( db_sql .keys() ) ) ) 
    logger.info('ZipShelve    #keys: %s' % len ( db_zip .keys() ) )
    logger.info('Bz2Shelve    #keys: %s' % len ( db_bz2 .keys() ) )
    if lzshelve :
        logger.info('LzShelve     #keys: %s' % len ( db_lz  .keys() ) )
    logger.info('RootShelve   #keys: %s' % len ( db_root.keys() ) )

    
    with timing ( 'h2-read/SQL'  ) : h2_sql  = db_sql  [ 'histo-2D']
    with timing ( 'h2_read/ZIP'  ) : h2_zip  = db_zip  [ 'histo-2D']
    with timing ( 'h2_read/BZ2'  ) : h2_bz2  = db_bz2  [ 'histo-2D']
    if lzshelve :
        with timing ( 'h2_read/LZ'  ) :
            h2_lz = db_lz  [ 'histo-2D']
    with timing ( 'h2_read/ROOT' ) : h2_root = db_root [ 'histo-2D']

    with timing ( 'tu-read/SQL'  ) : tu_sql  = db_sql  [ 'both'    ]
    with timing ( 'tu_read/ZIP'  ) : tu_zip  = db_zip  [ 'both'    ] 
    with timing ( 'tu_read/BZ2'  ) : tu_bz2  = db_bz2  [ 'both'    ] 
    if lzshelve :
        with timing ( 'tu_read/LZ'   ) :
            tu_lz   = db_lz   [ 'both'    ] 
    with timing ( 'tu_read/ROOT' ) : tu_root = db_root [ 'both'    ]

    with timing ( 'h1-read/SQL'  ) : h1_sql  = db_sql  [ 'histo-1D']
    with timing ( 'h1-read/ZIP'  ) : h1_zip  = db_zip  [ 'histo-1D']
    with timing ( 'h1-read/BZ2'  ) : h1_bz2  = db_bz2  [ 'histo-1D']
    if lzshelve : 
        with timing ( 'h1-read/LZ'   ) :
            h1_lz   = db_lz   [ 'histo-1D']
    with timing ( 'h1-read/ROOT' ) : h1_root = db_root [ 'histo-1D']

    for i in h1_sql : 
        v = h1_sql  [i] - h1_zip [i] 
        if not iszero ( v.value() ) :
            logger.error('Large difference for 1D histogram(1)!')
        v = h1_sql  [i] - h1     [i] 
        if not iszero ( v.value() ) :
            logger.error('Large difference for 1D histogram(2)!')
        v = h1_root [i] - h1     [i] 
        if not iszero ( v.value() ) :
            logger.error('Large difference for 1D histogram(3)!')
        v = h1_bz2  [i] - h1     [i] 
        if not iszero ( v.value() ) :
            logger.error('Large difference for 1D histogram(4)!')
        if lzshelve :
            v = h1_lz  [i] - h1     [i] 
            if not iszero ( v.value() ) :
                logger.error('Large difference for 1D histogram(5)!')
                
    
    for i in h2_sql : 
        v = h2_sql  [i] - h2_zip[i] 
        if not iszero ( v.value() ) :
            logger.error('Large difference for 2D histogram(1)!')
        v = h2_sql  [i] - h2    [i] 
        if not iszero ( v.value() ) :
            logger.error('Large difference for 2D histogram(2)!')
        v = h2_root [i] - h2    [i] 
        if not iszero ( v.value() ) :
            logger.error('Large difference for 2D histogram(3)!')
        v = h2_bz2  [i] - h2    [i] 
        if not iszero ( v.value() ) :
            logger.error('Large difference for 2D histogram(4)!')
        if lzshelve :
            v = h2_lz  [i] - h2    [i] 
            if not iszero ( v.value() ) :
                logger.error('Large difference for 2D histogram(5)!')
            

    h1tq = tu_sql [1]
    h1tz = tu_zip [1]
    h1tr = tu_root[1]

    ## clone them 
    dbs = [ db_sql , db_zip , db_bz2 , db_root ]
    if lzshelve : dbs.append ( db_lz )
    
    for db in dbs :
        cdb = db.clone ( CU.CleanUp.tempfile ( suffix = '.db'  ) )
        logger.info('Cloned:')
        cdb.ls()
    del dbs 
        
                         
    with timing('Close SQL'  ) : db_sql .close() 
    with timing('Close ZIP'  ) : db_zip .close()
    with timing('Close BZ2'  ) : db_bz2 .close()
    if lzshelve : 
        with timing('Close LZ'   ) : db_lz  .close()
    with timing('Close ROOT' ) : db_root.close()


    for dbase in ( sqliteshelve . tmpdb () ,
                   zipshelve    . tmpdb () ,
                   bz2shelve    . tmpdb () ,
                   ## lzshelve     . tmpdb () ,
                   rootshelve   . tmpdb () ) :

        with timing () :
            
            with dbase as db :
                
                db [ 'h1'    ] = h1
                db [ 'h2'    ] = h2
                db [ 'data'  ] = data
                db [ 'histos'] = data['histos']
                db.ls()
Exemple #3
0
def test_shelves():

    db_sql = sqliteshelve.open(db_sql_name, 'c')
    db_zip = zipshelve.open(db_zip_name, 'c')
    db_root = rootshelve.open(db_root_name, 'c')

    for k in data:
        db_sql[k] = data[k]
        db_zip[k] = data[k]
        db_root[k] = data[k]

    logger.info('SQLiteShelve keys: %s' % list(db_sql.keys()))
    logger.info('ZipShelve    keys: %s' % list(db_zip.keys()))
    logger.info('RootShelve   keys: %s' % list(db_root.keys()))

    db_sql.close()
    db_zip.close()
    db_root.close()

    logger.info('SQLiteShelve size: %d ' % os.path.getsize(db_sql_name))
    logger.info('ZipShelve    size: %d ' % os.path.getsize(db_zip_name))
    logger.info('RootShelve   size: %d ' % os.path.getsize(db_root_name))

    db_sql = sqliteshelve.open(db_sql_name, 'r')
    db_zip = zipshelve.open(db_zip_name, 'r')
    db_root = rootshelve.open(db_root_name, 'r')

    logger.info('SQLiteShelve keys: %s' % list(db_sql.keys()))
    logger.info('ZipShelve    keys: %s' % list(db_zip.keys()))
    logger.info('RootShelve   keys: %s' % list(db_root.keys()))

    with timing('h2-read/SQL'):
        h2_sql = db_sql['histo-2D']
    with timing('h2_read/ZIP'):
        h2_zip = db_zip['histo-2D']
    with timing('h2_read/ROOT'):
        h2_root = db_root['histo-2D']

    with timing('tu-read/SQL'):
        tu_sql = db_sql['both']
    with timing('tu_read/ZIP'):
        tu_zip = db_zip['both']
    with timing('tu_read/ROOT'):
        tu_root = db_root['both']

    with timing('h1-read/SQL'):
        h1_sql = db_sql['histo-1D']
    with timing('h1-read/ZIP'):
        h1_zip = db_zip['histo-1D']
    with timing('h1-read/ROOT'):
        h1_root = db_root['histo-1D']

    for i in h1_sql:
        v = h1_sql[i] - h1_zip[i]
        if not iszero(v.value()):
            logger.error('Large difference for 1D histogram(1)!')
        v = h1_sql[i] - h1[i]
        if not iszero(v.value()):
            logger.error('Large difference for 1D histogram(2)!')
        v = h1_root[i] - h1[i]
        if not iszero(v.value()):
            logger.error('Large difference for 1D histogram(3)!')

    for i in h2_sql:
        v = h2_sql[i] - h2_zip[i]
        if not iszero(v.value()):
            logger.error('Large difference for 2D histogram(1)!')
        v = h2_sql[i] - h2[i]
        if not iszero(v.value()):
            logger.error('Large difference for 2D histogram(2)!')
        v = h2_root[i] - h2[i]
        if not iszero(v.value()):
            logger.error('Large difference for 2D histogram(3)!')

    h1tq = tu_sql[1]
    h1tz = tu_zip[1]
    h1tr = tu_root[1]

    with timing('Close SQL'):
        db_sql.close()
    with timing('Close ZIP'):
        db_zip.close()
    with timing('Close ROOT'):
        db_root.close()

    with timing('Remove SQL'):
        os.remove(db_sql_name)
    with timing('Remove ZIP'):
        os.remove(db_zip_name)
    with timing('Remove ROOT'):
        os.remove(db_root_name)

    for dbase in (sqliteshelve.tmpdb(), zipshelve.tmpdb(), rootshelve.tmpdb()):

        with dbase as db:

            db['h1'] = h1
            db['h2'] = h2
            db.ls()