1 | /* Data organisation on disk:
|
---|
2 |
|
---|
3 | Board 1 Board 2 ... Board 1 Board 2 ...
|
---|
4 | RH BS1 BS2 ... EH TC1 TC2 ... 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 TCx Trigger cell of chip x (int)
|
---|
9 | Cx Channel (0-19 for 2 chips), Channel data are written as shorts, length of event data is in event 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 | The convention for the header structure is that exisitng structure entries
|
---|
15 | should never be deleted. New items may only be added at the end.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef RAWDATACTX_H_SEEN
|
---|
19 | #define RAWDATACTX_H_SEEN
|
---|
20 |
|
---|
21 | #include <stdio.h>
|
---|
22 | #include <time.h>
|
---|
23 |
|
---|
24 | #define DATA_FORMAT 1
|
---|
25 | #define IDENTIFICATION 1 // Raw data file identification
|
---|
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 |
|
---|
41 | #pragma pack (1) // Switch padding off
|
---|
42 |
|
---|
43 | // Run header
|
---|
44 | typedef struct {
|
---|
45 | U32 MagicNum;
|
---|
46 | U32 DataFormat; // Increasing whenever format changes
|
---|
47 |
|
---|
48 | U32 RunHeaderSize;
|
---|
49 | U32 EventHeaderSize;
|
---|
50 | U32 BoardStructureSize;
|
---|
51 |
|
---|
52 | I32 SoftwareRevision; // Subversion revision number (negative for modified working copy)
|
---|
53 |
|
---|
54 | U32 Identification;
|
---|
55 | U32 Type; // Run type: 0=data, 1=pedestal, 3=test
|
---|
56 | U32 RunNumber;
|
---|
57 | U32 FileNumber;
|
---|
58 | I8 Description[100];
|
---|
59 |
|
---|
60 | U32 NBoards; // Number of used mezzanine boards
|
---|
61 | U32 NChips; // Number of DRS chips per board
|
---|
62 | U32 NChannels; // Number of channels per chip
|
---|
63 |
|
---|
64 | U32 Samples; // Number of samples
|
---|
65 | U32 Offset; // Offset from trigger
|
---|
66 |
|
---|
67 | U32 Events; // Number of events in the file
|
---|
68 | U32 NBytes; // Bytes per sample
|
---|
69 |
|
---|
70 | U32 StartSecond; // Opening and closing time of the file
|
---|
71 | U32 StartMicrosecond;
|
---|
72 | U32 EndSecond;
|
---|
73 | U32 EndMicrosecond;
|
---|
74 | } RunHeader;
|
---|
75 |
|
---|
76 | // Board structure
|
---|
77 | typedef struct {
|
---|
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 | U32 EventNumber;
|
---|
87 | U32 Second; // Event time stamp (result of gettimeofday())
|
---|
88 | U32 Microsecond;
|
---|
89 | U32 TriggerType;
|
---|
90 | U32 EventSize; // Size of following data in bytes
|
---|
91 | } EventHeader;
|
---|
92 |
|
---|
93 | #pragma pack () // Set default padding
|
---|
94 |
|
---|
95 | // Class definition
|
---|
96 | class RawDataCTX {
|
---|
97 | FILE *Rawfile;
|
---|
98 | bool FileOpen;
|
---|
99 | bool Silent; // No textual output if true
|
---|
100 |
|
---|
101 | public:
|
---|
102 | RunHeader *RHeader;
|
---|
103 | EventHeader *EHeader;
|
---|
104 | BoardStructure *BStruct;
|
---|
105 | char *Data;
|
---|
106 |
|
---|
107 | RawDataCTX(bool = false);
|
---|
108 | ~RawDataCTX();
|
---|
109 |
|
---|
110 | CTX_ErrCode OpenDataFile(char*, FILE* = NULL);
|
---|
111 | CTX_ErrCode CloseDataFile();
|
---|
112 | CTX_ErrCode ReadEvent(unsigned int = 0, FILE* = NULL);
|
---|
113 | bool IsFileOpen();
|
---|
114 | };
|
---|
115 | #endif
|
---|