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