AliMiniHeader structure and executables addMiniHeader and printMiniHeader removed
[u/mrichter/AliRoot.git] / RAW / DateEvent.h
CommitLineData
5ea08be4 1/****************************************************************************
2 *
3 * event.h: DATE event data format
4 *
5 * Revision History:
6 * V01.00 RD PVV 09-Jan-97 Initial version
7 * V01.01 AV 24-Feb-97 Added START_OF_RUN_FILES and triggerNb
8 * V02.02 RD 13-Mar-97 Detector ID mask type added
9 * V02.03 PVV 20-Mar-97 Detector ID on 128 bits
10 * V02.03 RD PVV 20-Mar-97 Added EVENT_DATA_TRUNCATED
11 * V02.04 PVV 06-May-97 Added EVENT_TYPE_MASK
12 * V02.05 RD PVV 09-May-97 Increase EVENT_DATA_MAX_SIZE to 50 K
13 * V02.06 WB MG 22-May-97 Added END_OF_RUN_FILES
14 * V02.07 WB 23-May-97 Added errorCode, deadTime, deadTimeusec
15 * EVENT_DATA_MAX_SIZE set to 100 * 1024
16 * MAX_DETECTORS set to 126
17 * V02.08 PVV 02-Jun-97 Modify the encoding of types
18 * V02.09 WB RD PVV 28-Jul-98 Add fileSeqNb in the header.
19 * Reduce detector mask to 3 long
20 * V02.10 RD 31-Jul-98 (start|end)OfRunFiles added to eventType
21 * V02.11 PVV RD 02-Sep-98 Event type re-numbered
22 * Equipment bit added to event type
23 * V02.12 AV PVV RD 03-Sep-98 FileSeqNo moved before detectorId
24 * V02.13 RD 08-Oct-98 32 bits fields defined as long32
25 * V02.13 RD 19-Feb-99 Endianness/swap definitions added
26 * V02.14 WB PVV RD 21-Jun-99 typeAttribute added
27 * V02.15 RD 27-Jul-99 Macros for typeAttribute handling added
28 * V02.16 RD 19-Nov-99 Bug in Attributes test/set fixed
29 * V02.17 WB PVV RD 08-May-00 System attributes for SOR and EOR added
30 * V02.18 RD 18-May-00 EVENT_H_ID added
31 * V02.19 RD 10-Aug-00 Macros for detectorId handling added
32 * V03.00 RD 23-Nov-00 Version for DATE V4
33 *
34 * Preprocessor definitions:
35 * NDEBUG Define BEFORE including this file to disable run-time checks on
36 * various parameters
37 *
38 * Related facilities:
39 * validateEvent.c Validation program, should be run after EACH change to
40 * the definitions given here below
41 ***************************************************************************/
42#ifndef __event_h__
43#define __event_h__
44
45#define EVENT_MAJOR_VERSION_NUMBER 0x0003
46#define EVENT_MINOR_VERSION_NUMBER 0x0000
47
48/* ========== System includes ========= */
49#include <string.h> /* Needed by: memset, memcpy */
50#include <assert.h> /* Needed by: assert */
51
52/* ========== Definitions for the event header ========== */
53
54/* ---------- Header base size ---------- */
55/* This value must be updated for each change in the eventHeaderStruct */
56#define EVENT_HEAD_BASE_SIZE 64
57
58/* ---------- Event size ---------- */
59typedef unsigned long32 eventSizeType;
60
61/* ---------- Magic signature and its byte-swapped version ---------- */
62#define EVENT_MAGIC_NUMBER ((eventMagicType)0xDA1E5AFE)
63#define EVENT_MAGIC_NUMBER_SWAPPED ((eventMagicType)0xFE5A1EDA)
64typedef unsigned long32 eventMagicType;
65
66/* ---------- Header size ---------- */
67typedef unsigned long32 eventHeadSizeType;
68
69/* ---------- Unique version identifier ---------- */
70#define EVENT_CURRENT_VERSION \
71 (((EVENT_MAJOR_VERSION_NUMBER<<16)&0xffff0000)|\
72 (EVENT_MINOR_VERSION_NUMBER&0x0000ffff))
73typedef unsigned long32 eventVersionType;
74
75/* ---------- Event type ---------- */
76typedef unsigned long32 eventTypeType;
77#define START_OF_RUN ((eventTypeType)1)
78#define END_OF_RUN ((eventTypeType)2)
79#define START_OF_RUN_FILES ((eventTypeType)3)
80#define END_OF_RUN_FILES ((eventTypeType)4)
81#define START_OF_BURST ((eventTypeType)5)
82#define END_OF_BURST ((eventTypeType)6)
83#define PHYSICS_EVENT ((eventTypeType)7)
84#define CALIBRATION_EVENT ((eventTypeType)8)
85#define EVENT_FORMAT_ERROR ((eventTypeType)9)
86#define EVENT_TYPE_MIN 1
87#define EVENT_TYPE_MAX 9
88enum eventTypeEnum {
89 startOfRun = START_OF_RUN,
90 endOfRun = END_OF_RUN,
91 startOfRunFiles = START_OF_RUN_FILES,
92 endOfRunFiles = END_OF_RUN_FILES,
93 startOfBurst = START_OF_BURST,
94 endOfBurst = END_OF_BURST,
95 physicsEvent = PHYSICS_EVENT,
96 calibrationEvent = CALIBRATION_EVENT,
97 formatError = EVENT_FORMAT_ERROR
98};
99#define EVENT_TYPE_OK(t) (((t) >= EVENT_TYPE_MIN) && (((t) <= EVENT_TYPE_MAX)))
100
101/* ---------- Run number ---------- */
102typedef unsigned long32 eventRunNbType;
103
104/* ---------- The eventId field ---------- */
105#define EVENT_ID_BYTES 8
106#define EVENT_ID_WORDS ((EVENT_ID_BYTES) >> 2)
107typedef unsigned long32 eventIdType[EVENT_ID_WORDS];
108
109 /* PERIOD - ORBIT - BUNCH crossing type events */
110#define EVENT_ID_MAX_PERIOD 0x0fffffff
111#define EVENT_ID_MAX_ORBIT 0x00ffffff
112#define EVENT_ID_MAX_BUNCH_CROSSING 0x00000fff
113#define LOAD_EVENT_ID(id,s,o,bc) \
114 (EVENT_ID_SET_PERIOD(id,s), \
115 EVENT_ID_SET_ORBIT(id,o), \
116 EVENT_ID_SET_BUNCH_CROSSING(id,bc))
117#define EVENT_ID_GET_BUNCH_CROSSING(id) ((id)[1]&0x00000fff)
118#define EVENT_ID_GET_ORBIT(id) \
119 ((((id)[0]<<20)&0xf00000)|(((id)[1]>>12)&0xfffff))
120#define EVENT_ID_GET_PERIOD(id) (((id)[0]>>4)&0x0fffffff)
121
122#define EVENT_ID_SET_BUNCH_CROSSING(id,v) \
123 (assert(((v)>=0)&&((v)<=EVENT_ID_MAX_BUNCH_CROSSING)), \
124 (id)[1]=((id)[1]&0xfffff000)|((v)&0xfff))
125#define EVENT_ID_SET_ORBIT(id,v) \
126 (assert(((v)>=0)&&((v)<=EVENT_ID_MAX_ORBIT)), \
127 (id)[0]=(((id)[0])&0xfffffff0)|(((v)&0x00f00000)>>20), \
128 (id)[1]=(((id)[1])&0x00000fff)|(((v)&0x000fffff)<<12))
129#define EVENT_ID_SET_PERIOD(id,v) \
130 (assert(((v)>=0)&&((v)<=EVENT_ID_MAX_PERIOD)), \
131 (id)[0]=(((id)[0])&0x0000000f)|(((v)&0x0fffffff)<<4))
132
133 /* RAW type event */
134#define EVENT_ID_MAX_NB_IN_RUN 0xffffffff
135#define EVENT_ID_MAX_BURST_NB 0x00000fff
136#define EVENT_ID_MAX_NB_IN_BURST 0x000fffff
137#define LOAD_RAW_EVENT_ID(id,nir,bn,nib) \
138 (assert(((nir)>=0) && ((nir) <= EVENT_ID_MAX_NB_IN_RUN) && \
139 ((bn)>=0) && ((bn)<=EVENT_ID_MAX_BURST_NB) && \
140 ((nib)>=0) && ((nib)<=EVENT_ID_MAX_NB_IN_BURST)), \
141 (id)[0]=nir, \
142 (id)[1]=((bn<<20)&0xfff00000)|(nib&0x000fffff))
143#define EVENT_ID_SET_NB_IN_RUN(id,nir) \
144 (assert(((nir)>=0)&&((nir)<=EVENT_ID_MAX_NB_IN_RUN)), \
145 (id)[0]=(nir))
146#define EVENT_ID_SET_BURST_NB(id,bn) \
147 (assert(((bn)>=0)&&((bn)<=EVENT_ID_MAX_BURST_NB)), \
148 (id)[1]=((id)[1]&0x000fffff)|(((bn)<<20)&0xfff00000))
149#define EVENT_ID_SET_NB_IN_BURST(id,nib) \
150 (assert(((nib)>=0)&&((nib)<=EVENT_ID_MAX_NB_IN_BURST)), \
151 (id)[1]=((id)[1]&0xfff00000)|((nib)&0x000fffff))
152#define EVENT_ID_GET_NB_IN_RUN(id) ((id)[0])
153#define EVENT_ID_GET_BURST_NB(id) (((id)[1]>>20)&0x00000fff)
154#define EVENT_ID_GET_NB_IN_BURST(id) ((id)[1]&0x000fffff)
155
156 /* All events */
157#define EQ_EVENT_ID(a,b) ((((a)[0])==((b)[0]))&&(((a)[1])==((b)[1])))
158#define GT_EVENT_ID(a,b) \
159 (((((a)[0])>((b)[0])))||((((a)[0])==((b)[0]))&&(((a)[1])>((b)[1]))))
160#define LT_EVENT_ID(a,b) \
161 ((((a)[0])<((b)[0])) || ((((a)[0])==((b)[0]))&&(((a)[1])<((b)[1]))))
162#define GE_EVENT_ID(a,b) (!LT_EVENT_ID(a,b))
163#define LE_EVENT_ID(a,b) (!GT_EVENT_ID(a,b))
164#define COPY_EVENT_ID(from,to) \
165 memcpy((void*)to,(const void*)from,EVENT_ID_BYTES)
166#define ADD_EVENT_ID(a,b) ((a)[1]+=(b)[1],(a)[0]+=(b)[0])
167#define SUB_EVENT_ID(a,b) ((a)[1]-=(b)[1],(a)[0]-=(b)[0])
168#define ZERO_EVENT_ID(id) memset(id,0,EVENT_ID_BYTES)
169
170/* ---------- Trigger pattern (and relative masks) ---------- */
171#define EVENT_TRIGGER_PATTERN_BYTES 8
172#define EVENT_TRIGGER_PATTERN_WORDS ((EVENT_TRIGGER_PATTERN_BYTES)>>2)
173typedef unsigned long32 eventTriggerPatternType[EVENT_TRIGGER_PATTERN_WORDS];
174#define EVENT_TRIGGER_ID_MIN 1
175#define EVENT_TRIGGER_ID_MAX 50
176#define CHECK_TRIGGER(t) (assert(((t)>=EVENT_TRIGGER_ID_MIN) && \
177 ((t)<=EVENT_TRIGGER_ID_MAX)))
178#define TRIGGER_TO_BIT(t) (1<<((t)&0x1f))
179#define TRIGGER_TO_WORD(t) (CHECK_TRIGGER(t), (t)>>5)
180#define ZERO_TRIGGER_PATTERN(p) memset(p,0,EVENT_TRIGGER_PATTERN_BYTES)
181#define SET_TRIGGER_IN_PATTERN(p,id) (p)[TRIGGER_TO_WORD(id)] |= \
182 TRIGGER_TO_BIT(id)
183#define CLEAR_TRIGGER_IN_PATTERN(p,id) (p)[TRIGGER_TO_WORD(id)] &= \
184 ~(TRIGGER_TO_BIT(id))
185#define FLIP_TRIGGER_IN_PATTERN(p,id) (p)[TRIGGER_TO_WORD(id)] ^= \
186 TRIGGER_TO_BIT(id)
187#define TEST_TRIGGER_IN_PATTERN(p,id) (((p)[TRIGGER_TO_WORD(id)] & \
188 TRIGGER_TO_BIT(id)) != 0)
189#define TRIGGER_PATTERN_INVALID(p) (((p)[0] & 1) == 0)
190#define TRIGGER_PATTERN_VALID(p) (((p)[0] & 1) != 0)
191#define VALIDATE_TRIGGER_PATTERN(p) ((p)[0] |= 1)
192#define INVALIDATE_TRIGGER_PATTERN(p) ((p)[0] &= 0xfffffffe)
193#define COPY_TRIGGER_PATTERN(f,t) memcpy(t,f,EVENT_TRIGGER_PATTERN_BYTES)
194#define TRIGGER_PATTERN_OK(p) (((p)[1] & 0xfff80000) == 0)
195
196/* ---------- Detectors cluster (and relative masks) ---------- */
197#define EVENT_DETECTOR_PATTERN_BYTES 4
198#define EVENT_DETECTOR_PATTERN_WORDS (EVENT_DETECTOR_PATTERN_BYTES>>2)
199typedef unsigned long32 eventDetectorPatternType[EVENT_DETECTOR_PATTERN_WORDS];
200#define EVENT_DETECTOR_ID_MIN 1
201#define EVENT_DETECTOR_ID_MAX 24
202#define CHECK_DETECTOR(d) (assert(((d) >= EVENT_DETECTOR_ID_MIN) &&\
203 ((d) <= EVENT_DETECTOR_ID_MAX)))
204#define DETECTOR_TO_BIT(d) (CHECK_DETECTOR(d), 1<<(d))
205#define ZERO_DETECTOR_PATTERN(p) ((p)[0] = 0)
206#define SET_DETECTOR_IN_PATTERN(p,d) ((p)[0] |= DETECTOR_TO_BIT(d))
207#define CLEAR_DETECTOR_IN_PATTERN(p,d) ((p)[0] &= ~(DETECTOR_TO_BIT(d)))
208#define FLIP_DETECTOR_IN_PATTERN(p,d) ((p)[0] ^= DETECTOR_TO_BIT(d))
209#define TEST_DETECTOR_IN_PATTERN(p,d) (((p)[0] & DETECTOR_TO_BIT(d))!=0)
210#define DETECTOR_PATTERN_INVALID(p) (((p)[0] & 1) == 0)
211#define DETECTOR_PATTERN_VALID(p) (((p)[0] & 1) != 0)
212#define VALIDATE_DETECTOR_PATTERN(p) ((p)[0] |= 1)
213#define INVALIDATE_DETECTOR_PATTERN(p) ((p)[0] &= 0xfffffffe)
214#define COPY_DETECTOR_PATTERN(f,t) ((t)[0] = (f)[0])
215#define DETECTOR_PATTERN_OK(p) (((p)[0] & 0xfe000000) == 0)
216
217/* ---------- The sizes and positions of the typeAttribute field ---------- */
218#define ALL_ATTRIBUTE_WORDS 3
219#define ALL_ATTRIBUTE_BYTES (ALL_ATTRIBUTE_WORDS * 4)
220#define ALL_ATTRIBUTE_BITS (ALL_ATTRIBUTE_BYTES * 8)
221#define USER_ATTRIBUTE_WORDS 2
222#define USER_ATTRIBUTE_BYTES (USER_ATTRIBUTE_WORDS * 4)
223#define USER_ATTRIBUTE_BITS (USER_ATTRIBUTE_BYTES * 8)
224#define FIRST_USER_ATTRIBUTE 0
225#define LAST_USER_ATTRIBUTE (USER_ATTRIBUTE_BITS - 1)
226#define SYSTEM_ATTRIBUTE_WORDS 1
227#define SYSTEM_ATTRIBUTE_BYTES (SYSTEM_ATTRIBUTE_WORDS * 4)
228#define SYSTEM_ATTRIBUTE_BITS (SYSTEM_ATTRIBUTE_BYTES * 8)
229#define FIRST_SYSTEM_ATTRIBUTE USER_ATTRIBUTE_BITS
230#define LAST_SYSTEM_ATTRIBUTE (USER_ATTRIBUTE_BITS + \
231 SYSTEM_ATTRIBUTE_BITS - 1)
232typedef unsigned long32 eventTypeAttributeType[ALL_ATTRIBUTE_WORDS];
233
234 /* Word and bit definitions */
235#define SYS_ATTR_2_W(b) (assert(((b)>=64)&&((b)<=95)),2)
236#define USR_ATTR_2_W(b) (assert(((b)>= 0)&&((b)<=63)),(b)>>5)
237#define ATTR_2_W(b) (assert(((b)>= 0)&&((b)<=95)),(b)>>5)
238#define ATTR_2_B(b) (1<<((b)&0x1f))
239
240 /* Macros to handle all attributes without distinction */
241#define RESET_ATTRIBUTES(m) ((m)[2] = (m)[1] = (m)[0] = 0)
242#define SET_ANY_ATTRIBUTE(m,b) (m)[ATTR_2_W(b)] |= ATTR_2_B(b)
243#define CLEAR_ANY_ATTRIBUTE(m,b) (m)[ATTR_2_W(b)] &= ~(ATTR_2_B(b))
244#define FLIP_ANY_ATTRIBUTE(m,b) (m)[ATTR_2_W(b)] ^= ATTR_2_B(b)
245#define TEST_ANY_ATTRIBUTE(m,b) (((m)[ATTR_2_W(b)] & ATTR_2_B(b))!= 0)
246#define COPY_ALL_ATTRIBUTES( from, to )\
247 memcpy((void *)&to[0], (const void *)&from[0], ALL_ATTRIBUTE_BYTES)
248
249 /* Macros to handle SYSTEM attributes */
250#define RESET_SYSTEM_ATTRIBUTES(m) ((m)[2] = 0)
251#define SET_SYSTEM_ATTRIBUTE(m,b) (m)[SYS_ATTR_2_W(b)] |= ATTR_2_B(b)
252#define CLEAR_SYSTEM_ATTRIBUTE(m,b) (m)[SYS_ATTR_2_W(b)] &= ~(ATTR_2_B(b))
253#define FLIP_SYSTEM_ATTRIBUTE(m,b) (m)[SYS_ATTR_2_W(b)] ^= ATTR_2_B(b)
254#define TEST_SYSTEM_ATTRIBUTE(m,b) (((m)[SYS_ATTR_2_W(b)] & ATTR_2_B(b)) != 0)
255#define COPY_SYSTEM_ATTRIBUTES( from, to ) \
256 memcpy((void *)&to[2], (const void *)&from[2], SYSTEM_ATTRIBUTE_BYTES)
257
258 /* Macros to handle USER attributes */
259#define RESET_USER_ATTRIBUTES(m) ((m)[0] = (m)[1] = 0)
260#define SET_USER_ATTRIBUTE(m,b) (m)[USR_ATTR_2_W(b)] |= ATTR_2_B(b)
261#define CLEAR_USER_ATTRIBUTE(m,b) (m)[USR_ATTR_2_W(b)] &= ~(ATTR_2_B(b))
262#define FLIP_USER_ATTRIBUTE(m,b) (m)[USR_ATTR_2_W(b)] ^= ATTR_2_B(b)
263#define TEST_USER_ATTRIBUTE(m,b) (((m)[USR_ATTR_2_W(b)] & ATTR_2_B(b)) != 0)
264#define COPY_USER_ATTRIBUTES( from, to ) \
265 memcpy((void *)&to[0], (const void *)&from[0], USER_ATTRIBUTE_BYTES)
266
267 /* System attributes assignment */
268#define ATTR_P_START 64 /* Start of a phase */
269#define ATTR_P_END 65 /* End of a phase */
270#define ATTR_START_OF_RUN_START ATTR_P_START/* Start of SOR phase */
271#define ATTR_START_OF_RUN_END ATTR_P_END /* End of SOR phase */
272#define ATTR_END_OF_RUN_START ATTR_P_START/* Start of EOR phase */
273#define ATTR_END_OF_RUN_END ATTR_P_END /* End of SOR phase */
274#define ATTR_EVENT_SWAPPED 66 /* Swapped event header */
275#define ATTR_EVENT_PAGED 67 /* Paged event */
276#define ATTR_SUPER_EVENT 68 /* Super event */
277#define ATTR_ORBIT_BC 69 /* Orbit/bunch crossing in ID*/
278
279#define ATTR_EVENT_DATA_TRUNCATED 94 /* Truncated payload */
280#define ATTR_EVENT_ERROR 95 /* Invalid event content */
281
282#define SYSTEM_ATTRIBUTES_OK(m) \
283 ((((m)[2]) & ~(ATTR_2_B(ATTR_P_START) | \
284 ATTR_2_B(ATTR_P_END) | \
285 ATTR_2_B(ATTR_EVENT_SWAPPED) | \
286 ATTR_2_B(ATTR_EVENT_PAGED) | \
287 ATTR_2_B(ATTR_SUPER_EVENT) | \
288 ATTR_2_B(ATTR_ORBIT_BC) | \
289 ATTR_2_B(ATTR_EVENT_DATA_TRUNCATED) | \
290 ATTR_2_B(ATTR_EVENT_ERROR))) == 0)
291
292/* ---------- LDC and GDC identifier ---------- */
293typedef unsigned long32 eventHostIdType;
294typedef eventHostIdType eventLdcIdType;
295typedef eventHostIdType eventGdcIdType;
296#define HOST_ID_MIN ((eventHostIdType)0) /* The minimum allowed ID */
297#define HOST_ID_MAX ((eventHostIdType)511) /* The maximum allowed ID */
298#define VOID_ID ((eventHostIdType)-1) /* Unloaded ID */
299
300/* ---------- The event header structure (with + without data) ---------- */
301struct eventHeaderStruct {
302 eventSizeType eventSize;
303 eventMagicType eventMagic;
304 eventHeadSizeType eventHeadSize;
305 eventVersionType eventVersion;
306 eventTypeType eventType;
307 eventRunNbType eventRunNb;
308 eventIdType eventId;
309 eventTriggerPatternType eventTriggerPattern;
310 eventDetectorPatternType eventDetectorPattern;
311 eventTypeAttributeType eventTypeAttribute;
312 eventLdcIdType eventLdcId;
313 eventGdcIdType eventGdcId;
314};
315
316struct eventStruct {
317 struct eventHeaderStruct eventHeader;
318 unsigned short eventRawData[1];
319};
320
321/* ========== Definitions for the Vector ========== */
322typedef short eventVectorBankIdType;
323typedef unsigned int eventVectorSizeType;
324typedef unsigned int eventVectorOffsetType;
325
326struct eventVectorStruct {
327 eventVectorBankIdType eventVectorBankId;
328 unsigned eventVectorPointsToVector : 1;
329 eventVectorSizeType eventVectorSize;
330 eventVectorOffsetType eventVectorStartOffset;
331};
332
333/* ========== Definitions for the payload descriptor ========== */
334typedef unsigned long32 eventNumEquipmentsType;
335typedef struct eventVectorStruct eventExtensionVectorType;
336
337struct vectorPayloadDescriptorStruct {
338 eventNumEquipmentsType eventNumEquipments;
339 eventExtensionVectorType eventExtensionVector;
340};
341
342/* ========== Definitions for the equipment header ========== */
343typedef long32 equipmentSizeType;
344typedef long32 equipmentTypeType;
345typedef long32 equipmentIdType;
346typedef eventTypeAttributeType equipmentTypeAttributeType;
347typedef long32 equipmentBasicElementSizeType;
348
349struct equipmentHeaderStruct {
350 equipmentSizeType equipmentSize;
351 equipmentTypeType equipmentType;
352 equipmentIdType equipmentId;
353 equipmentTypeAttributeType equipmentTypeAttribute;
354 equipmentBasicElementSizeType equipmentBasicElementSize;
355};
356
357struct equipmentDescriptorStruct {
358 struct equipmentHeaderStruct equipmentHeader;
359 struct eventVectorStruct equipmentVector;
360};
361
362struct equipmentStruct {
363 struct equipmentHeaderStruct equipmentHeader;
364 unsigned short equipmentRawData[1];
365};
366
367/* ========== Global macros ========== */
368
369/* The macro PAGED_EVENT_SIZE receives in input the ADDRESS of a paged
370 event and returns the size (in bytes) of the first page of the
371 event */
372#define PAGED_EVENT_SIZE( event ) \
373 (EVENT_HEAD_BASE_SIZE +sizeof( struct vectorPayloadDescriptorStruct ) + \
374 ((*(eventNumEquipmentsType *)((void*)event+EVENT_HEAD_BASE_SIZE))* \
375 (sizeof( struct equipmentDescriptorStruct ))))
376
377#endif