source: drsdaq/RawDataCTX.h@ 44

Last change on this file since 44 was 44, checked in by ogrimm, 15 years ago
Raw data format streamlined, revision tracking in run header
File size: 3.3 KB
Line 
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
27typedef char I8;
28typedef unsigned char U8;
29typedef short I16;
30typedef unsigned short U16;
31typedef int I32;
32typedef unsigned int U32;
33typedef float F32;
34
35#define MAGICNUM_OPEN 0xe0e1 // Magic number for run header while file open
36#define MAGICNUM_CLOSED 0xe0e0 // ... and when file is closed
37#define MAGICNUM_ERROR 0xe0e2 // ... and when an error occurred
38
39// Error codes
40enum CTX_ErrCode {CTX_OK, CTX_FOPEN, CTX_FCLOSE, CTX_NOTOPEN, CTX_RHEADER,
41 CTX_BSTRUCT, CTX_EHEADER, CTX_DATA, CTX_SEEK, CTX_EOF, CTX_VERSION};
42
43#pragma pack (1) // Switch padding off
44
45// Run header
46typedef struct {
47 U32 MagicNum;
48 U32 DataFormat; // Increasing whenever format changes
49 U32 SoftwareRevision; // Subversion revision number
50
51 U32 RunHeaderSize;
52 U32 EventHeaderSize;
53 U32 BoardStructureSize;
54
55 I8 Description[48];
56 U32 Type; // Run type: 0=pedestal, 1=data, 2=test
57
58 U32 RunNumber;
59 U32 FileNumber;
60
61 U32 Events; // Number of events in the file
62 U32 NCMCBoards; // Number of used mezzanine boards
63 U32 NChips; // Number of DRS chips per board
64 U32 NChannels; // Number of channels per chip
65 U32 Samples; // Number of samples
66 U32 Offset; // Offset from first sample
67
68 U32 StartSecond; // Opening and closing time of the file
69 U32 StartMicrosecond;
70 U32 EndSecond;
71 U32 EndMicrosecond;
72} RunHeader;
73
74// Board structure
75typedef struct {
76 I32 SerialNo; // Board serial number
77 F32 NomFreq; // Nominal sampling frequency [GHz]
78 F32 BoardTemp; // Board temperature [deg C]
79 F32 ScaleFactor; // Factor for conversion to mV
80} BoardStructure;
81
82// Event header
83typedef struct {
84 U32 EventNumber;
85 U32 Seconds; // Event time stamp (result of gettimeofday())
86 U32 Microseconds;
87 U32 TriggerType;
88 U32 EventSize; // Size of following data in bytes
89} EventHeader;
90
91#pragma pack () // Set default padding
92
93// Class definition
94class RawDataCTX {
95 FILE *Rawfile;
96 bool FileOpen;
97 bool Silent; // No textual output if true
98
99 public:
100 RunHeader *RHeader;
101 EventHeader *EHeader;
102 BoardStructure *BStruct;
103 short *Data;
104
105 RawDataCTX(bool = false);
106 ~RawDataCTX();
107
108 CTX_ErrCode OpenDataFile(char*, FILE* = NULL);
109 CTX_ErrCode CloseDataFile();
110 CTX_ErrCode ReadEvent(unsigned int = 0, FILE* = NULL);
111 bool IsFileOpen();
112};
113#endif
Note: See TracBrowser for help on using the repository browser.