Package python :: Module fileio
[hide private]
[frames] | no frames]

Module fileio

source code

Functions [hide private]
 
write(file_handle, ev)
The write function is responsible for writing an event to a file.
source code
 
read(file_handle)
This function is responsible for reading an event from a file and returning an Event object.
source code
Variables [hide private]
  FLOAT_SIZE = 8
  INT_SIZE = 4
  LONG_SIZE = 8
Function Details [hide private]

write(file_handle, ev)

source code 

The write function is responsible for writing an event to a file.

Parameters:
  • file_handle - The file_handle is a file object and can be a standard file, a gzip file handle, or anything with a write method really.
  • ev - The Event object to be written to the frame. There is some type checking performed since it's critical that the bytestream be consistent and well-defined.

read(file_handle)

source code 

This function is responsible for reading an event from a file and returning an Event object. The order is assumed to be correct as well as the file type. Otherwise this function will load garbage without warning. Since it's assuming a simple well-defined bytestream there's no way of verifying it's well-formed and uncorrupted. What would be better is a dedicated serialization library that stores type and class information along with the data. This should be the next thing to do. The byte stream is assumed as follows in this order:

  1. 4 bytes - runID(unsigned int)
  2. 4 bytes - year(unsigned int)
  3. 8 bytes - startTime (long) - Number of tenths of nanoseconds since the beginning of the year.
  4. 8 bytes - eventLength(float) - Units of microseconds.
  5. 4 bytes - (long) - Number of triggers. This is not a member of the Event class, since it's simply the size of the trigger list. For each trigger the byte structure is given as :
    • 8 bytes - trigger time (float) - Time of the trigger with respect to the start of the event.
    • 4 bytes - nchar (int) - Number of characters in the trigger name.
    • nchar * 1 byte - The characters that make up the trigger name.
  6. 8 bytes - nhits (long) - Number of hits in the event. The next set consists of nhits*5*8 bytes (one chunk of 8 bytes for each float of q,t,x,y,z).

To Do: Make a robust serialization library that stores the type information so that it is more generic and robust. Something closer to boost's serialization library. We won't regret it.