| 1 | /* Data organisation on disk:
|
|---|
| 2 |
|
|---|
| 3 | Board 1 Board 2 ... Board 1 Board 2 ...
|
|---|
| 4 | RH BS1 BS2 ... EH C1 C2 C3 ... C1 C2 C3 ... ... EH C1 C2 C3 ... C1 C2 C3 ... ...
|
|---|
| 5 | -------------------------------- --------------------------------
|
|---|
| 6 | Event 1 Event 2
|
|---|
| 7 |
|
|---|
| 8 | RH Run header BSx Board structures EV Event header Cx Channel (0-19 for 2 chips)
|
|---|
| 9 | Channel data are written as shorts, lenght of channel data is in the run header
|
|---|
| 10 |
|
|---|
| 11 | Structures are defined using #pragma pack (1) to not include any padding. Note that
|
|---|
| 12 | using the gcc attribute __attribute__((__packed__)) is incompatible with root.
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 | The convention for the header structure is that exisitng structure entries
|
|---|
| 16 | should never be deleted. New items may only be added at the end.
|
|---|
| 17 | */
|
|---|
| 18 |
|
|---|
| 19 | #ifndef RAWDATACTX_H_SEEN
|
|---|
| 20 | #define RAWDATACTX_H_SEEN
|
|---|
| 21 |
|
|---|
| 22 | #include <stdio.h>
|
|---|
| 23 | #include <time.h>
|
|---|
| 24 |
|
|---|
| 25 | #define DATA_FORMAT 1
|
|---|
| 26 |
|
|---|
| 27 | typedef char I8;
|
|---|
| 28 | typedef int I32;
|
|---|
| 29 | typedef unsigned int U32;
|
|---|
| 30 | typedef float F32;
|
|---|
| 31 |
|
|---|
| 32 | #define MAGICNUM_OPEN 0xe0e1 // Magic number for run header while file open
|
|---|
| 33 | #define MAGICNUM_CLOSED 0xe0e0 // ... and when file is closed
|
|---|
| 34 | #define MAGICNUM_ERROR 0xe0e2 // ... and when an error occurred
|
|---|
| 35 |
|
|---|
| 36 | // Error codes
|
|---|
| 37 | enum CTX_ErrCode {CTX_OK, CTX_FOPEN, CTX_FCLOSE, CTX_NOTOPEN, CTX_RHEADER,
|
|---|
| 38 | CTX_BSTRUCT, CTX_EHEADER, CTX_DATA, CTX_SEEK, CTX_EOF, CTX_VERSION};
|
|---|
| 39 |
|
|---|
| 40 | #pragma pack (1) // Switch padding off
|
|---|
| 41 |
|
|---|
| 42 | // Run header
|
|---|
| 43 | typedef struct {
|
|---|
| 44 | U32 MagicNum;
|
|---|
| 45 | U32 DataFormat; // Increasing whenever format changes
|
|---|
| 46 | I32 SoftwareRevision; // Subversion revision number (negative for modified working copy)
|
|---|
| 47 |
|
|---|
| 48 | U32 RunHeaderSize;
|
|---|
| 49 | U32 EventHeaderSize;
|
|---|
| 50 | U32 BoardStructureSize;
|
|---|
| 51 |
|
|---|
| 52 | I8 Description[48];
|
|---|
| 53 | U32 Type; // Run type: 0=pedestal, 1=data, 2=test
|
|---|
| 54 |
|
|---|
| 55 | U32 RunNumber;
|
|---|
| 56 | U32 FileNumber;
|
|---|
| 57 |
|
|---|
| 58 | U32 Events; // Number of events in the file
|
|---|
| 59 | U32 NBoards; // Number of used mezzanine boards
|
|---|
| 60 | U32 NChips; // Number of DRS chips per board
|
|---|
| 61 | U32 NChannels; // Number of channels per chip
|
|---|
| 62 | U32 Samples; // Number of samples
|
|---|
| 63 | U32 Offset; // Offset from first sample
|
|---|
| 64 |
|
|---|
| 65 | U32 StartSecond; // Opening and closing time of the file
|
|---|
| 66 | U32 StartMicrosecond;
|
|---|
| 67 | U32 EndSecond;
|
|---|
| 68 | U32 EndMicrosecond;
|
|---|
| 69 | } RunHeader;
|
|---|
| 70 |
|
|---|
| 71 | // Board structure
|
|---|
| 72 | typedef struct {
|
|---|
| 73 | I32 SerialNo; // Board serial number
|
|---|
| 74 | F32 NomFreq; // Nominal sampling frequency [GHz]
|
|---|
| 75 | F32 BoardTemp; // Board temperature [deg C]
|
|---|
| 76 | F32 ScaleFactor; // Factor for conversion to mV
|
|---|
| 77 | } BoardStructure;
|
|---|
| 78 |
|
|---|
| 79 | // Event header
|
|---|
| 80 | typedef struct {
|
|---|
| 81 | U32 EventNumber;
|
|---|
| 82 | U32 Second; // Event time stamp (result of gettimeofday())
|
|---|
| 83 | U32 Microsecond;
|
|---|
| 84 | U32 TriggerType;
|
|---|
| 85 | U32 EventSize; // Size of following data in bytes
|
|---|
| 86 | } EventHeader;
|
|---|
| 87 |
|
|---|
| 88 | #pragma pack () // Set default padding
|
|---|
| 89 |
|
|---|
| 90 | // Class definition
|
|---|
| 91 | class RawDataCTX {
|
|---|
| 92 | FILE *Rawfile;
|
|---|
| 93 | bool FileOpen;
|
|---|
| 94 | bool Silent; // No textual output if true
|
|---|
| 95 |
|
|---|
| 96 | public:
|
|---|
| 97 | RunHeader *RHeader;
|
|---|
| 98 | EventHeader *EHeader;
|
|---|
| 99 | BoardStructure *BStruct;
|
|---|
| 100 | char *Data;
|
|---|
| 101 |
|
|---|
| 102 | RawDataCTX(bool = false);
|
|---|
| 103 | ~RawDataCTX();
|
|---|
| 104 |
|
|---|
| 105 | CTX_ErrCode OpenDataFile(char*, FILE* = NULL);
|
|---|
| 106 | CTX_ErrCode CloseDataFile();
|
|---|
| 107 | CTX_ErrCode ReadEvent(unsigned int = 0, FILE* = NULL);
|
|---|
| 108 | bool IsFileOpen();
|
|---|
| 109 | };
|
|---|
| 110 | #endif
|
|---|