コード例 #1
0
ファイル: cwn2.py プロジェクト: alexhsamuel/pyhep
import hep.table
from   hep.cernlib.hbook import create, createTable
from   hep.test import compare

#-----------------------------------------------------------------------
# test
#-----------------------------------------------------------------------

# HBOOK requires correct data alignment of columns.  If this is not
# handled correctly when the schema is used to book the CWN, a schema
# such as this one will cause problems, since the float64 columns are
# not 64-bit-aligned.

schema = hep.table.Schema()
schema.addColumn("index1", "int32")
schema.addColumn("value1", "float64")
schema.addColumn("index2", "int32")
schema.addColumn("value2", "float64")
schema.addColumn("index3", "int32")
schema.addColumn("value3", "float64")
schema.addColumn("index4", "int32")
schema.addColumn("value4", "float64")
schema.addColumn("index5", "int32")
schema.addColumn("value5", "float64")
schema.addColumn("index6", "int32")
schema.addColumn("value6", "float64")

hbook_file = create("cwn2.hbook")
table = createTable("cwn", hbook_file, schema, column_wise=1)
compare(len(table.schema), 12)
コード例 #2
0
ファイル: hbookcp.py プロジェクト: alexhsamuel/pyhep
from hep.cernlib import hbook


def copy(src_dir, dest_dir):
    # Loop over directory elements in 'path'.
    for name in src_dir.keys():
        info = src_dir.getInfo(name)
        if info.is_directory:
            # It's a directory.  Make the destination directory, and
            # call ourselves recursively to copy its contents.
            copy(src_dir[name], dest_dir.mkdir(name))
        elif info.type in ("1D histogram", "2D histogram"):
            # It's a histogram.  Load it, and save it to the destination.
            dest_dir[name] = src_dir[name]
        # Ignore other types of entries.


if __name__ == "__main__":
    import sys

    copy(hbook.open(sys.argv[1]), hbook.create(sys.argv[2]))
コード例 #3
0
ファイル: cwn1.py プロジェクト: alexhsamuel/pyhep
import hep.table
from   hep.cernlib.hbook import create, createTable, open
from   random import random
from   hep.test import compare, assert_

#-----------------------------------------------------------------------
# test
#-----------------------------------------------------------------------

# Create a row-wise ntuple in an HBOOK file.
schema = hep.table.Schema()
schema.addColumn("index", "int32")
schema.addColumn("value32", "float32")
schema.addColumn("value64", "float64")
hbook_file = create("cwn1.hbook")
table = createTable("cwn", hbook_file, schema, column_wise=1)

# Fill it with random values, saving these in an array.
values = []
for i in xrange(0, 100):
    value = random()
    values.append(value)
    table.append(index=i, value32=value, value64=value)
del table, hbook_file

# Open the ntuple.
table = open("cwn1.hbook")["cwn"]
assert_(table.column_wise)
compare(len(table), 100)
# Compare the values in it to the array.
コード例 #4
0
ファイル: remove2.py プロジェクト: alexhsamuel/pyhep
#-----------------------------------------------------------------------
# imports
#-----------------------------------------------------------------------

from   hep.bool import *
from   hep.cernlib import hbook
from   hep.test import compare

#-----------------------------------------------------------------------
# test
#-----------------------------------------------------------------------

hbook_file = hbook.create("remove2.hbook")
hbook_file.mkdir("dir1")
hbook_file.mkdir("dir2")
hbook_file.mkdir("dir3")
hbook_file.mkdir("dir3/dir4")
del hbook_file

def ls(hbook_path, path):
    keys = hbook.open(hbook_path)[path].keys()
    keys.sort()
    return keys


compare(ls("remove2.hbook", ""), ["dir1", "dir2", "dir3"])
compare(ls("remove2.hbook", "dir3"), ["dir4"])
del hbook.open("remove2.hbook", writable=True)["dir2"]
compare(ls("remove2.hbook", ""), ["dir1", "dir3"])
compare(ls("remove2.hbook", "dir3"), ["dir4"])
del hbook.open("remove2.hbook", writable=True)["dir3/dir4"]