| 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 | #ifndef RAWDATACTX_H_SEEN
|
|---|
| 16 | #define RAWDATACTX_H_SEEN
|
|---|
| 17 |
|
|---|
| 18 | #include <stdio.h>
|
|---|
| 19 |
|
|---|
| 20 | #define DATA_FORMAT 1
|
|---|
| 21 |
|
|---|
| 22 | typedef char I8;
|
|---|
| 23 | typedef unsigned char U8;
|
|---|
| 24 | typedef short I16;
|
|---|
| 25 | typedef unsigned short U16;
|
|---|
| 26 | typedef int I32;
|
|---|
| 27 | typedef unsigned int U32;
|
|---|
| 28 | typedef float F32;
|
|---|
| 29 |
|
|---|
| 30 | #define MAGICNUM_OPEN 0xe0e1 // Magic number for run header while file open
|
|---|
| 31 | #define MAGICNUM_CLOSED 0xe0e0 // ... and when file is closed
|
|---|
| 32 | #define MAGICNUM_ERROR 0xe0e2 // ... and when an error occurred
|
|---|
| 33 |
|
|---|
| 34 | // Error codes
|
|---|
| 35 | enum CTX_ErrCode {CTX_OK, CTX_FOPEN, CTX_FCLOSE, CTX_NOTOPEN, CTX_RHEADER,
|
|---|
| 36 | CTX_BSTRUCT, CTX_EHEADER, CTX_DATA, CTX_SEEK, CTX_EOF};
|
|---|
| 37 |
|
|---|
| 38 | #pragma pack (1) // Switch padding off
|
|---|
| 39 |
|
|---|
| 40 | // Run header
|
|---|
| 41 | typedef struct {
|
|---|
| 42 | U32 MagicNum;
|
|---|
| 43 | U32 DataFormat; // Increasing whenever header format changes
|
|---|
| 44 |
|
|---|
| 45 | U32 RunHeaderSize;
|
|---|
| 46 | U32 EventHeaderSize;
|
|---|
| 47 | U32 BoardStructureSize;
|
|---|
| 48 |
|
|---|
| 49 | I8 DAQVersion[12]; // contains result of __DATE__ macro
|
|---|
| 50 |
|
|---|
| 51 | I8 Source[16];
|
|---|
| 52 | I8 Type; // run type (char): pedestal, data, ...
|
|---|
| 53 |
|
|---|
| 54 | U32 RunNumber;
|
|---|
| 55 | U32 FileNumber;
|
|---|
| 56 |
|
|---|
| 57 | U32 StartYear;
|
|---|
| 58 | U32 StartMonth;
|
|---|
| 59 | U32 StartDay;
|
|---|
| 60 | U32 StartHour;
|
|---|
| 61 | U32 StartMinute;
|
|---|
| 62 | U32 StartSecond;
|
|---|
| 63 |
|
|---|
| 64 | U32 EndYear;
|
|---|
| 65 | U32 EndMonth;
|
|---|
| 66 | U32 EndDay;
|
|---|
| 67 | U32 EndHour;
|
|---|
| 68 | U32 EndMinute;
|
|---|
| 69 | U32 EndSecond;
|
|---|
| 70 |
|
|---|
| 71 | F32 SourceRA;
|
|---|
| 72 | F32 SourceDEC;
|
|---|
| 73 | F32 TelescopeRA;
|
|---|
| 74 | F32 TelescopeDEC;
|
|---|
| 75 |
|
|---|
| 76 | U32 Events; // Number of events in the file
|
|---|
| 77 | U32 NCMCBoards; // Number of used boards
|
|---|
| 78 | U32 NChips; // Number of DRS chips per board
|
|---|
| 79 | U32 NChannels; // Number of channels per chip
|
|---|
| 80 | U32 Samples; // Number of samples
|
|---|
| 81 | I32 Offset; // Offset from first sample
|
|---|
| 82 | } RunHeader;
|
|---|
| 83 |
|
|---|
| 84 | // Board structure
|
|---|
| 85 | typedef struct {
|
|---|
| 86 | I32 SerialNo; // Board serial number
|
|---|
| 87 | F32 NomFreq; // Nominal sampling frequency [GHz]
|
|---|
| 88 | F32 BoardTemp; // Board temperature [deg C]
|
|---|
| 89 | F32 ScaleFactor; // Factor for conversion to mV
|
|---|
| 90 | } BoardStructure;
|
|---|
| 91 |
|
|---|
| 92 | // Event header
|
|---|
| 93 | typedef struct {
|
|---|
| 94 | I8 Name[5]; // "EVTH", NULL-terminated
|
|---|
| 95 | U32 EventNumber;
|
|---|
| 96 | F32 TimeSec; // event time stamp in seconds, ms precision
|
|---|
| 97 | U16 TriggerType;
|
|---|
| 98 | } EventHeader;
|
|---|
| 99 |
|
|---|
| 100 | #pragma pack () // Set default padding
|
|---|
| 101 |
|
|---|
| 102 | // Class definition
|
|---|
| 103 | class RawDataCTX {
|
|---|
| 104 | FILE *Rawfile;
|
|---|
| 105 | bool FileOpen;
|
|---|
| 106 | bool Silent;
|
|---|
| 107 |
|
|---|
| 108 | public:
|
|---|
| 109 | RunHeader *RHeader;
|
|---|
| 110 | EventHeader *EHeader;
|
|---|
| 111 | BoardStructure *BStruct;
|
|---|
| 112 | short *Data;
|
|---|
| 113 |
|
|---|
| 114 | RawDataCTX(bool = false);
|
|---|
| 115 | ~RawDataCTX();
|
|---|
| 116 |
|
|---|
| 117 | CTX_ErrCode OpenDataFile(char*, FILE* = NULL);
|
|---|
| 118 | CTX_ErrCode CloseDataFile();
|
|---|
| 119 | CTX_ErrCode ReadEvent(int = 0, FILE* = NULL);
|
|---|
| 120 | bool IsFileOpen();
|
|---|
| 121 | };
|
|---|
| 122 | #endif
|
|---|