corrected trigger structs to comply with PubSub
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTDataTypes.h
1 // @(#) $Id$
2
3 #ifndef ALIHLTDATATYPES_H
4 #define ALIHLTDATATYPES_H
5 /* This file is property of and copyright by the ALICE HLT Project        * 
6  * ALICE Experiment at CERN, All rights reserved.                         *
7  * See cxx source for full Copyright notice                               */
8
9 /** @file   AliHLTDataTypes.h
10     @author Matthias Richter, Timm Steinbeck, Jochen Thaeder
11     @date   
12     @brief  Data type declaration for the HLT module.
13 */
14
15 //////////////////////////////////////////////////////////////////////////
16 //
17 // version no of HLT data types
18 //
19 //////////////////////////////////////////////////////////////////////////
20
21 /* Version   Description
22  *   1       first version until June 07; implicite, not tagged
23  *   2       introduced June 07, enhanced/cleaned/arranged structure
24  *   3       2007-11-15 RAW DDL data type added; some inconsistencies fixed
25  *           ('void' and 'any' origins); added signed HLT basic data types
26  *           2007-11-23 origin defines have become variables in conjunction
27  *           to be used with the operator| (AliHLTComponentDataType)
28  *           2007-11-24 added trigger structs and ESD tree data type
29  */
30 #define ALIHLT_DATA_TYPES_VERSION 3
31
32 //////////////////////////////////////////////////////////////////////////
33 //
34 // HLT data origin variables.
35 //
36 // By converting from defines to variables, the origins can be used with
37 // the operator|
38 //
39 // AliHLTComponentDataType dt;
40 // dt = kAliHLTDataTypeDDLRaw | gkAliHLTDataOriginTPC;
41 //
42 //////////////////////////////////////////////////////////////////////////
43
44 /** field size of datat type origin */
45 const int kAliHLTComponentDataTypefOriginSize=4;
46
47
48 /** invalid data origin */
49 # define kAliHLTDataOriginVoid "\0\0\0"
50 /** old invalid data origin, kept for backward compatibility */
51 # define kAliHLTVoidDataOrigin "\0\0\0"
52
53 /** wildcard data type origin */
54 # define kAliHLTDataOriginAny "***"
55 /** old wildcard data type origin, kept for backward compatibility */
56 # define kAliHLTAnyDataOrigin "***"
57
58 /** HLT out */
59 extern const char kAliHLTDataOriginOut[kAliHLTComponentDataTypefOriginSize];
60
61 /** HLT/PubSub private internal */
62 extern const char kAliHLTDataOriginPrivate[kAliHLTComponentDataTypefOriginSize];
63
64 /** TPC */
65 extern const char kAliHLTDataOriginTPC[kAliHLTComponentDataTypefOriginSize];
66
67 /** PHOS */
68 extern const char kAliHLTDataOriginPHOS[kAliHLTComponentDataTypefOriginSize];
69
70 /** MUON */
71 extern const char kAliHLTDataOriginMUON[kAliHLTComponentDataTypefOriginSize];
72
73 /** TRD */
74 extern const char kAliHLTDataOriginTRD[kAliHLTComponentDataTypefOriginSize];
75
76 /** ITS */
77 extern const char kAliHLTDataOriginITS[kAliHLTComponentDataTypefOriginSize];
78
79 //////////////////////////////////////////////////////////////////////////
80 //
81 // HLT common data type defines
82 //
83 //////////////////////////////////////////////////////////////////////////
84
85 /** field size of data type id */
86 const int kAliHLTComponentDataTypefIDsize=8;
87
88
89 /** invalid data type id */
90 # define kAliHLTVoidDataTypeID "\0\0\0\0\0\0\0"
91
92 /** special id for any data type id */
93 # define kAliHLTAnyDataTypeID "*******"
94
95 /** DDL RAW data */
96 # define kAliHLTDDLRawDataTypeID   {'D','D','L','_','R','A','W',' '}
97
98 /** calibration data for file exchange subscriber */
99 # define kAliHLTFXSCalibDataTypeID {'F','X','S','_','C','A','L',' '}
100
101 /** start of run (SOR) event 
102  * @ref AliHLTRunDesc
103  */
104 # define kAliHLTSORDataTypeID      {'S','T','A','R','T','O','F','R'}
105
106 /** end of run (EOR) event 
107  * @ref AliHLTRunDesc
108  */
109 # define kAliHLTEORDataTypeID      {'E','N','D','O','F','R','U','N'}
110
111 /** DDL list event 
112  * @ref AliHLTEventDDL
113  */
114 # define kAliHLTDDLDataTypeID      {'D','D','L','L','I','S','T',' '}
115
116 /** EventType event 
117  * - empty payload, specification gives eventType
118  */
119 # define kAliHLTEventDataTypeID    {'E','V','E','N','T','T','Y','P'}
120
121 /** ESD data block
122  * an AliESD object of varying origin
123  */
124 # define kAliHLTESDTreeDataTypeID      {'E','S','D','_','T','R','E','E'}
125
126 using namespace std;
127
128 extern "C" {
129   //////////////////////////////////////////////////////////////////////////
130   //
131   // Basic HLT data types
132   //
133   //////////////////////////////////////////////////////////////////////////
134
135   typedef unsigned char AliHLTUInt8_t;
136
137   typedef signed char AliHLTInt8_t;
138
139   typedef unsigned short AliHLTUInt16_t;
140
141   typedef signed short AliHLTInt16_t;
142
143   typedef unsigned int AliHLTUInt32_t;
144
145   typedef signed int AliHLTInt32_t;
146
147   typedef unsigned long long AliHLTUInt64_t;
148
149   typedef signed long long AliHLTInt64_t;
150
151   typedef float AliHLTFloat32_t;
152
153   typedef double AliHLTFloat64_t;
154
155   typedef AliHLTUInt64_t AliHLTEventID_t;
156
157   //////////////////////////////////////////////////////////////////////////
158   //
159   // HLT logging levels
160   //
161   //////////////////////////////////////////////////////////////////////////
162
163   enum AliHLTComponentLogSeverity { 
164     kHLTLogNone      = 0,
165     kHLTLogBenchmark = 0x1,
166     kHLTLogDebug     = 0x2,
167     kHLTLogInfo      = 0x4,
168     kHLTLogWarning   = 0x8,
169     kHLTLogError     = 0x10,
170     kHLTLogFatal     = 0x20,
171     kHLTLogAll       = 0x3f,
172     kHLTLogDefault   = 0x3d 
173 };
174
175   //////////////////////////////////////////////////////////////////////////
176   //
177   // HLT data structures for data exchange and external interface
178   //
179   //////////////////////////////////////////////////////////////////////////
180
181   /**
182    * @struct AliHLTComponentEventData
183    * Event descriptor
184    */
185   struct AliHLTComponentEventData
186   {
187     AliHLTUInt32_t fStructSize;
188     AliHLTEventID_t fEventID;
189     AliHLTUInt32_t fEventCreation_s;
190     AliHLTUInt32_t fEventCreation_us;
191     AliHLTUInt32_t fBlockCnt;
192   };
193
194   /**
195    * @struct AliHLTComponentShmData
196    * Shared memory descriptor.
197    * Irrelevant for analysis components.
198    */
199   struct AliHLTComponentShmData
200   {
201     AliHLTUInt32_t fStructSize;
202     AliHLTUInt32_t fShmType;
203     AliHLTUInt64_t fShmID;
204   };
205
206   /**
207    * @struct AliHLTComponentDataType
208    * Data type descriptor for data blocks transferred through the processing
209    * chain.
210    */
211   struct AliHLTComponentDataType
212   {
213     AliHLTUInt32_t fStructSize;
214     char fID[kAliHLTComponentDataTypefIDsize];                      //!
215     char fOrigin[kAliHLTComponentDataTypefOriginSize];              //!
216   };
217
218   /**
219    * @struct AliHLTComponentBlockData
220    * This is the decription of data blocks exchanged between components.
221    * \b IMPORTANT: The validity of fPtr and fOffset is different for input and
222    * output blocks:
223    * - input blocks: The \em fPtr member always points to the beginning of the data
224    *                 of size \em fSize. fOffset is ignored and should be in most
225    *                 case 0.
226    * - output blocks: The \em fPtr member is ignored by the framework. \em fOffset
227    *                  must specify the start of the data relative to the output
228    *                  buffer. The data block has size \em fSize.
229    */
230   struct AliHLTComponentBlockData
231   {
232     /* size and version of the struct */
233     AliHLTUInt32_t fStructSize;
234     /* shared memory key, ignored by processing components */
235     AliHLTComponentShmData fShmKey;
236     /* offset of output data relative to the output buffer */
237     AliHLTUInt32_t fOffset;
238     /* start of the data for input data blocks, fOffset to be ignored*/
239     void* fPtr;
240     /* size of the data block */
241     AliHLTUInt32_t fSize;
242     /* data type of the data block */
243     AliHLTComponentDataType fDataType;
244     /* data specification of the data block */
245     AliHLTUInt32_t fSpecification;
246   };
247
248   /**
249    * @struct AliHLTComponentEventDoneData
250    * 
251    */
252   struct AliHLTComponentEventDoneData
253   {
254     AliHLTUInt32_t fStructSize;
255     AliHLTUInt32_t fDataSize;
256     void* fData;
257   };
258
259   /**
260    * @struct AliHLTRunDesc
261    * Event descriptor.
262    * The struct is send with the SOR and EOR events.
263    */
264   struct AliHLTRunDesc
265   {
266     AliHLTUInt32_t fStructSize;
267     AliHLTUInt32_t fRunNo;
268     AliHLTUInt32_t fRunType;
269   };
270
271   //////////////////////////////////////////////////////////////////////////
272   //
273   // Trigger meta information
274   //
275   //////////////////////////////////////////////////////////////////////////
276
277   /** field size of fAttribute */
278   static const int gkAliHLTBlockDAttributeCount = 8;
279
280   /** field size of fCommonHeader */
281   static const int gkAliHLTCommonHeaderCount = 8;
282
283   /** size of the DDL list */
284   static const int gkAliHLTDDLListSize = 29;
285
286   /**
287    * @struct AliHLTEventDDL
288    * DDL list event.
289    * The struct is send with the DDLLIST event.
290    * Used in the trigger structure for internal apperance of 
291    * the DLLs as well as for the HLT readout list send to DAQ 
292    * ( as DataType : kAliHLTDataTypeDDL )
293    */
294   struct AliHLTEventDDL
295   {
296     AliHLTUInt32_t fCount;
297     AliHLTUInt32_t fList[gkAliHLTDDLListSize];
298   };
299
300   /**
301    * @struct AliHLTEventTriggerData
302    */
303   struct AliHLTEventTriggerData
304   {
305     AliHLTUInt8_t  fAttributes[gkAliHLTBlockDAttributeCount]; 
306     AliHLTUInt64_t fHLTStatus; // Bit field 
307     AliHLTUInt32_t fCommonHeaderWordCnt;
308     AliHLTUInt32_t fCommonHeader[gkAliHLTCommonHeaderCount]; 
309     AliHLTEventDDL fReadoutList;
310   };
311
312   /**
313    * @struct AliHLTComponentTriggerData
314    * Trigger data
315    */
316   struct AliHLTComponentTriggerData
317   {
318     AliHLTUInt32_t fStructSize;
319     AliHLTUInt32_t fDataSize;
320     void* fData;
321   };
322
323   //////////////////////////////////////////////////////////////////////////
324   //
325   // HLT Event Type Specification
326   //
327   //////////////////////////////////////////////////////////////////////////
328
329   /** Unknown eventType specification */
330   static const AliHLTUInt32_t gkAliEventTypeUnknown = ~(AliHLTUInt32_t)0;
331   /** SOR eventType specification */ 
332   static const AliHLTUInt32_t gkAliEventTypeStartOfRun=1;
333   /** Data eventType specification */
334   static const AliHLTUInt32_t gkAliEventTypeData=2;
335   /** EOR eventType specification */ 
336   static const AliHLTUInt32_t gkAliEventTypeEndOfRun=4;
337   /** Corrupt eventType specification */
338   static const AliHLTUInt32_t gkAliEventTypeCorruptID=8;
339   /** Calibration eventType specification */ 
340   static const AliHLTUInt32_t gkAliEventTypeCalibration=16;
341   /** DataReplay eventType specification */
342   static const AliHLTUInt32_t gkAliEventTypeDataReplay=32;
343   /** Tick eventType specification */ 
344   static const AliHLTUInt32_t gkAliEventTypeTick=64;
345   /** Max eventType specification */ 
346   static const AliHLTUInt32_t gkAliEventTypeMax=64;
347
348   //////////////////////////////////////////////////////////////////////////
349   //
350   // HLT defines and defaults
351   //
352   //////////////////////////////////////////////////////////////////////////
353
354   /** invalid event id */
355   const AliHLTEventID_t kAliHLTVoidEventID=~(AliHLTEventID_t)0;
356
357   /** invalid data specification */
358   const AliHLTUInt32_t kAliHLTVoidDataSpec = ~(AliHLTUInt32_t)0;
359
360   /** invalid shared memory type */
361   const AliHLTUInt32_t gkAliHLTComponentInvalidShmType = 0;
362
363   /** invalid shared memory id */
364   const AliHLTUInt64_t gkAliHLTComponentInvalidShmID = ~(AliHLTUInt64_t)0;
365
366   /** invalid data type */
367   const AliHLTComponentDataType kAliHLTVoidDataType = {
368     sizeof(AliHLTComponentDataType),
369     kAliHLTVoidDataTypeID,
370     kAliHLTDataOriginVoid
371   };
372
373   // there is currently a problem with rootcint if the predefined ids
374   // (commented below) are used. rootcint does not find the id if they
375   // are char arrays defined with {} and individual chars. If strings
376   // are used it works fine
377   /** any data type */
378   const AliHLTComponentDataType kAliHLTAnyDataType = {
379     sizeof(AliHLTComponentDataType),
380     kAliHLTAnyDataTypeID,
381     kAliHLTDataOriginAny
382   };
383
384   /** multiple output data types */
385   extern const AliHLTComponentDataType kAliHLTMultipleDataType;
386
387   /** data to file exchange subscriber */
388   extern const AliHLTComponentDataType kAliHLTDataTypeFXSCalib;
389
390   /** DDL list data type */
391   extern const AliHLTComponentDataType kAliHLTDataTypeDDL;
392
393   /** SOR data type */
394   extern const AliHLTComponentDataType kAliHLTDataTypeSOR;
395
396   /** EOR data type */
397   extern const AliHLTComponentDataType kAliHLTDataTypeEOR;
398
399   /** Event type specification */
400   extern const AliHLTComponentDataType kAliHLTDataTypeEvent;
401
402   /** RAW DDL data specification, origin is 'any', data publisher origin correctly */
403   extern const AliHLTComponentDataType kAliHLTDataTypeDDLRaw;
404
405   /** ESD Tree data specification, origin is 'any' */
406   extern const AliHLTComponentDataType kAliHLTDataTypeESDTree;
407
408   //////////////////////////////////////////////////////////////////////////
409   //
410   // FXS subscriber meta information
411   //
412   //////////////////////////////////////////////////////////////////////////
413
414   static const int gkAliHLTFXSHeaderfOriginSize = 4;
415   static const int gkAliHLTFXSHeaderfFileIDSize = 128;
416   static const int gkAliHLTFXSHeaderfDDLNumberSize = 64;
417
418   /** Header in front of the data payload, in order to sent data to the FXS. */
419   struct AliHLTFXSHeader
420   {
421     AliHLTUInt32_t fHeaderVersion;
422     AliHLTUInt32_t fRunNumber;
423     char fOrigin[gkAliHLTFXSHeaderfOriginSize];
424     char fFileID[gkAliHLTFXSHeaderfFileIDSize];
425     char fDDLNumber[gkAliHLTFXSHeaderfDDLNumberSize];
426   };  
427
428   //////////////////////////////////////////////////////////////////////////
429   //
430   // Component running environment
431   //
432   //////////////////////////////////////////////////////////////////////////
433
434   /** logging function */
435   typedef int (*AliHLTfctLogging)( void* param, 
436                                    AliHLTComponentLogSeverity severity,
437                                    const char* origin,
438                                    const char* keyword,
439                                    const char* message);
440
441   /**
442    * @struct AliHLTComponentEnvironment
443    * Running environment for analysis components.
444    * The struct describes function callbacks for 
445    */
446   struct AliHLTComponentEnvironment
447   {
448     AliHLTUInt32_t fStructSize;
449     void* fParam;
450     void* (*fAllocMemoryFunc)( void* param, unsigned long size );
451 #if 0
452     // future addition already foreseen/envisioned
453     // IMPORTANT: don not just remove the defines as this breaks the binary
454     // compatibility
455     int (*fAllocShmMemoryFunc)( void* param, unsigned long size, AliHLTComponentBlockData* blockLocation );
456 #endif
457     int (*fGetEventDoneDataFunc)( void* param, AliHLTEventID_t eventID, unsigned long size, AliHLTComponentEventDoneData** edd );
458     AliHLTfctLogging fLoggingFunc;
459   };
460 }
461
462 //////////////////////////////////////////////////////////////////////////
463 //
464 // Data type helper functions
465 //
466 //////////////////////////////////////////////////////////////////////////
467
468 inline bool operator==( const AliHLTComponentDataType& dt1, const AliHLTComponentDataType& dt2 )
469     {
470     for ( int i = 0; i < kAliHLTComponentDataTypefIDsize; i++ )
471         if ( dt1.fID[i] != dt2.fID[i] )
472             return false;
473     for ( int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++ )
474         if ( dt1.fOrigin[i] != dt2.fOrigin[i] )
475             return false;
476     return true;
477     }
478
479 inline bool operator!=( const AliHLTComponentDataType& dt1, const AliHLTComponentDataType& dt2 )
480     {
481     for ( int i = 0; i < kAliHLTComponentDataTypefIDsize; i++ )
482         if ( dt1.fID[i] != dt2.fID[i] )
483             return true;
484     for ( int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++ )
485         if ( dt1.fOrigin[i] != dt2.fOrigin[i] )
486             return true;
487     return false;
488     }
489
490 inline AliHLTComponentDataType operator|(const AliHLTComponentDataType srcdt, const char origin[kAliHLTComponentDataTypefOriginSize])
491     {
492     AliHLTComponentDataType dt=srcdt;
493     for ( int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++ )
494       dt.fOrigin[i]=origin[i];
495     return dt;
496     }
497
498 #endif