source: drsdaq/RawDataCTX.h@ 73

Last change on this file since 73 was 68, checked in by ogrimm, 15 years ago
Introduced dummy, zero initialized items in raw data format to align with MAGIC format ordering, changed date rollover to 13:00 UTC
File size: 3.6 KB
Line 
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
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 Items named _res are introduced for compatibility with the MAGIC data format and are set to zero.
18*/
19
20#ifndef RAWDATACTX_H_SEEN
21#define RAWDATACTX_H_SEEN
22
23#include <stdio.h>
24#include <time.h>
25
26#define DATA_FORMAT 1
27#define IDENTIFICATION 1 // Raw data file identification
28
29
30typedef char I8;
31typedef int I32;
32typedef unsigned int U32;
33typedef float F32;
34
35#define MAGICNUM_OPEN 0xc0c1 // Magic number for run header while file open
36#define MAGICNUM_CLOSED 0xc0c0 // ... and when file is closed
37#define MAGICNUM_ERROR 0xc0c2 // ... 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
44#pragma pack (1) // Switch padding off
45
46// Run header
47typedef struct {
48 U32 MagicNum;
49 U32 DataFormat; // Increasing whenever format changes
50
51 U32 RunHeaderSize;
52 U32 EventHeaderSize;
53 U32 BoardStructureSize;
54
55 I32 SoftwareRevision; // Subversion revision number (negative for modified working copy)
56
57 U32 _res1[2];
58 U32 Identification;
59 U32 Type; // Run type: 0=data, 1=pedestal, 3=test
60 U32 RunNumber;
61 U32 FileNumber;
62
63 I8 Description[100];
64 I8 _res2[140];
65 U32 _res3[6];
66
67 U32 NBoards; // Number of used mezzanine boards
68 U32 NChips; // Number of DRS chips per board
69 U32 NChannels; // Number of channels per chip
70
71 U32 Samples; // Number of samples
72 U32 Offset; // Offset from trigger
73
74 U32 Events; // Number of events in the file
75 U32 _res4;
76 U32 NBytes;
77 I8 _res5[20];
78
79 U32 StartSecond; // Opening and closing time of the file
80 U32 StartMicrosecond;
81 U32 EndSecond;
82 U32 EndMicrosecond;
83} RunHeader;
84
85// Board structure
86typedef struct {
87 I8 _res[17];
88 I32 SerialNo; // Board serial number
89 F32 NomFreq; // Nominal sampling frequency [GHz]
90 F32 BoardTemp; // Board temperature [deg C]
91 F32 ScaleFactor; // Factor for conversion to mV
92} BoardStructure;
93
94// Event header
95typedef struct {
96 U32 EventNumber;
97 U32 Second; // Event time stamp (result of gettimeofday())
98 U32 Microsecond;
99 U32 _res[4];
100 U32 TriggerType;
101 U32 EventSize; // Size of following data in bytes
102} EventHeader;
103
104#pragma pack () // Set default padding
105
106// Class definition
107class RawDataCTX {
108 FILE *Rawfile;
109 bool FileOpen;
110 bool Silent; // No textual output if true
111
112 public:
113 RunHeader *RHeader;
114 EventHeader *EHeader;
115 BoardStructure *BStruct;
116 char *Data;
117
118 RawDataCTX(bool = false);
119 ~RawDataCTX();
120
121 CTX_ErrCode OpenDataFile(char*, FILE* = NULL);
122 CTX_ErrCode CloseDataFile();
123 CTX_ErrCode ReadEvent(unsigned int = 0, FILE* = NULL);
124 bool IsFileOpen();
125};
126#endif
Note: See TracBrowser for help on using the repository browser.