API
Note
Page under development
This module provides classes and functions for handling HIPO files with ease.
- hipopy.hipopy.create(filename)
Parameters
filename : string, required
Description
Open a HIPO file to write (overwrites existing files).
- class hipopy.hipopy.hipochain(names, banks=None, step=100, tags=None, experimental=True)
Bases:
objectAttributes
- nameslist
List of file names in hipochain
- bankslist
List of bank names to be read
- stepint
Batch size for reading banks
- modestring
Currently fixed to always be in read mode (“r”)
- tagsint or list of ints
Set bank tags for reader to use. 0 works for most banks. 1 is needed for scaler banks.
- experimentalbool
Do bank and event looping in C++ for added speed (see hipopybind package).
Description
Chains files together so they may be read continuously.
- class hipopy.hipopy.hipochainIterator(chain)
Bases:
objectAttributes
- chainhipopy.hipopy.hipochain
Hipochain object overwhich to iterate
- idxint
Index of current file in hipochain
- counterint
Event counter for batching data
- filehipopy.hipopy.hipoFile
Current file in hipochain
- itemsdict
Dictionary of bank names to item names to read
- dictdict
Dictionary into which Hipo bank data is read
Methods
switchFile
Description
Iterator for hipopy.hipopy.hipochain class
- class hipopy.hipopy.hipochainIteratorExperimental(chain)
Bases:
objectAttributes
- chainhipopy.hipopy.hipochain
Hipochain object overwhich to iterate
- idxint
Index of current file in hipochain
- counterint
Event counter for batching data
- filehipopy.hipopy.hipoFile
Current file in hipochain
- itemsdict
Dictionary of bank names to item names to read
- dictdict
Dictionary into which Hipo bank data is read
Methods
getAllBanks
Description
Experimental iterator for hipopy.hipopy.hipochain class
- class hipopy.hipopy.hipofile(filename, mode='r', tags=None)
Bases:
objectAttributes
- filenamestring
Full path name of HIPO file
- modestring
File mode (“r” : read, “a” : append, “w” : write)
- readerhipopybind.Reader
HIPO file reader
- writerhipopybind.Writer
HIPO file writer
- dictionaryhipopybind.Dictionary
HIPO file schema dictionary
- eventhipopybind.Event
HIPO event for reading and writing banks
- groupint
Group number for current HIPO bank (not unique)
- itemint
Item number for current HIPO bank (unique)
- dtypesdict
Dictionary to datatypes
- buffextstring
Extension for buffer file
- buffnamestring
Name of buffer file
- banklistdict
Dictionary to hipopybind.Bank objects
- addSchema(name, namesAndTypes, group=1, item=-1)
Parameters
- namestring, required
Bank name
- namesAndTypesdictionary, required
Map of column names to types (“D” : double, “F” : float, “I” : int, “B” : byte, “S” : short, “L” : long)
- groupint, optional
Group number for bank (not unique) Default : 1
- itemint, optional
Item number for bank (unique) Default : -1
Description
Add a schema structure to HIPO file writer dictionary for a bank you wish to write. NOTE: Do this BEFORE opening the file in write mode.
- close()
Parameters
- modestring, optional
Default : “r”
Description
Close osstream for an open file.
- extend(datadict)
Parameters
- datadictdictionary, required
Dictionary of bank names to data arrays of shape (nEvents,nEntries,nRows)
Description
Add batched data to banks in a file. Mimics uproot extend function.
- getBytes(bankName, item)
Parameters
- bankNamestring, required
Name of bank to be read
- itemstring, required
Column name to read in bank
Returns
- datalist
List of bytes from bank entry
Description
Get a column of bytes from the data table in the current event’s bank.
- getDoubles(bankName, item)
Parameters
- bankNamestring, required
Name of bank to be read
- itemstring, required
Column name to read in bank
Returns
- datalist
List of doubles from bank entry
Description
Get a column of doubles from the data table in the current event’s bank.
- getEntries(bankName)
Parameters
bankName : string, required
Description
Get number of entries in bank. Make sure you read bank first with readBank(bankName) method above.
- getFloats(bankName, item)
Parameters
- bankNamestring, required
Name of bank to be read
- itemstring, required
Column name to read in bank
Returns
- datalist
List of floats from bank entry
Description
Get a column of floats from the data table in the current event’s bank.
- getInts(bankName, item)
Parameters
- bankNamestring, required
Name of bank to be read
- itemstring, required
Column name to read in bank
Returns
- datalist
List of ints from bank entry
Description
Get a column of ints from the data table in the current event’s bank.
- getItem()
Description
Get highest number item of all existing schema in reader for initiating file in append mode.
- getLongs(bankName, item)
Parameters
- bankNamestring, required
Name of bank to be read
- itemstring, required
Column name to read in bank
Returns
- datalist
List of longs from bank entry
Description
Get a column of longs from the data table in the current event’s bank.
- getNames(bankName)
Parameters
bankName : string, required
Returns
- datalist
List of entry names in bank
Description
Get a list of the entry names from the data table in the current event’s bank.
- getNamesAndTypes(bankName)
Parameters
bankName : string, required
Returns
- datadict
Dictionary of bank entry names to types (represented as strings)
Description
Get a list of the entry names from the data table in the current event’s bank.
- getRows(bankName)
Parameters
bankName : string, required
Description
Get number of rows in bank. Make sure you read bank first with readBank(bankName) method above.
- getShorts(bankName, item)
Parameters
- bankNamestring, required
Name of bank to be read
- itemstring, required
Column name to read in bank
Returns
- datalist
List of shorts from bank entry
Description
Get a column of shorts from the data table in the current event’s bank.
- getTypes(bankName)
Parameters
bankName : string, required
Returns
- datalist
List of entry types (represented as strings) in bank
Description
Get a list of the entry types from the data table in the current event’s bank.
- goToEvent(event)
Parameters
- eventint, required
Integer number indicating event number in file (starts at 0)
Returns
- boolean
True if requested event exists, otherwise False
Description
Move to requested HIPO event in a file in read mode.
- hasBank(bankName)
Parameters
bankName : string, required
Description
Check if bank exists for current file.
- newTree(bank, bankdict, group=None, item=None)
Parameters
- bankstring, required
Bank name
- bankdictdictionary, required
Dictionary of bank entry names to data types (“D”:double, “F”:float, “I”:int, “B”:byte, “S”:short, “L”:long)
- groupint, optional
Group identifier for bank (does not have to be unique) Default : None
- itemint, optional
Item identifier for bank (must be unique) Default : None
Description
Create a new bank to which to add data. Mimics uproot newtree function.
- nextEvent()
Returns
- boolean
True if next event exists else False
Description
Move to next HIPO event from a file in read mode.
- open()
Description
Open a HIPO file to read, write (from scratch), or append data. IMPORTANT: Make sure you add schema before opening a file to write!
- readBank(bankName)
Parameters
- bankNamestring, required
Name of bank to be read
Description
Setup to read bank contents for each event into memory.
- showBank(bankName)
Parameters
bankName : string, required
Description
Print out bank contents for current event.
- update(datadict)
Parameters
- datadictdictionary, required
Dictionary of bank names to data arrays of shape (nEntries,nRows)
Description
Append one set of event banks at a time and do not progress to the next event automatically.
- writeBank(name, names, data, dtypes='D')
Parameters
- namestring, required
Bank name
- nameslist, required
Column names
- datanumpy.ndarray, required
2D NumPy array of dimension (columns,rows)
- dtypestring, optional
Data type (“D” : double, “F” : float, “I” : int, “B” : byte, “S” : short, “L” : long) Default : “D”
Description
Fill an event bank with data and write to buffer.
- class hipopy.hipopy.hipofileIterator(hpfile)
Bases:
objectDescription
Iterator class for hipopy.hipopy.hipoFile class
- hipopy.hipopy.iterate(files, banks=None, step=100, tags=None, experimental=True)
Parameters
- fileslist, required
List of file names
- bankslist, optional
List of bank names to read Default : None
- stepint, optional
Batch size for iterating through file events Default : 100
- tagsint or list of ints, optional
Set bank tags for reader to use. 0 works for most banks. 1 is needed for scaler banks. Default : None
- experimentalbool, optional
Whether to use experimental hipopybind.HipoFileIterator to iterate files Default : True
Description
Iterate through a list of hipofiles reading all banks unless specific banks are specified. Iteration is broken into batches of step events.
- hipopy.hipopy.open(filename, mode='r', tags=None)
Parameters
filename : string, required mode : string, optional
File mode (“r” : read, “w” : write, “a” : append) Default : “r”
- tagsint or list of ints, optional
Set bank tags for reader to use. 0 works for most banks. 1 is needed for scaler banks. Default : None
Description
Open a HIPO file to read.