]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTCalibrationProcessor.cxx
- workaround for copying and merging of ESDs: The HLTOUT contains ESDs for every...
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTCalibrationProcessor.cxx
1 /**************************************************************************
2  * This file is property of and copyright by the ALICE HLT Project        * 
3  * ALICE Experiment at CERN, All rights reserved.                         *
4  *                                                                        *
5  * Primary Authors: Jochen Thaeder <thaeder@kip.uni-heidelberg.de>        *
6  *                  Sebastian Bablok                                      *
7  *                  for The ALICE HLT Project.                            *
8  *                                                                        *
9  * Permission to use, copy, modify and distribute this software and its   *
10  * documentation strictly for non-commercial purposes is hereby granted   *
11  * without fee, provided that the above copyright notice appears in all   *
12  * copies and that both the copyright notice and this permission notice   *
13  * appear in the supporting documentation. The authors make no claims     *
14  * about the suitability of this software for any purpose. It is          *
15  * provided "as is" without express or implied warranty.                  *
16  **************************************************************************/
17
18 /** 
19  * @file   AliHLTCalibrationProcessor.cxx
20  * @author Jochen Thaeder, Sebastian Bablok
21  * @date 
22  * @brief  Base class of HLT calibration components.  */
23
24 // see header file for class documentation
25 // or
26 // refer to README to build package
27 // or
28 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
29
30 #if __GNUC__ >= 3
31 using namespace std;
32 #endif
33
34 #include "AliHLTCalibrationProcessor.h"
35 #include "AliHLTMemoryFile.h"
36
37 #include <cstdlib>
38 #include <cerrno>
39 #include <string.h>
40 #include <TObjString.h>
41 #include <TFile.h>
42
43 ClassImp(AliHLTCalibrationProcessor);
44
45
46 const AliHLTUInt32_t AliHLTCalibrationProcessor::fgkFXSProtocolHeaderSize = 204;
47 const AliHLTUInt32_t AliHLTCalibrationProcessor::fgkFXSProtocolHeaderVersion = 1;
48
49 /*
50  * ################ Constructor / Destructor ####################
51  */
52
53 AliHLTCalibrationProcessor::AliHLTCalibrationProcessor() : 
54   fEventModulo(0),
55   fUseCorruptEvents(kFALSE),
56   fEventCounter(0),
57   fDDLNumber(),
58   fDummy(0) {
59
60   // see header file for class documentation
61   // or
62   // refer to README to build package
63   // or
64   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
65 }
66
67 AliHLTCalibrationProcessor::~AliHLTCalibrationProcessor() {
68   // see header file for class documentation
69 }
70
71 /*
72  * ######################## InitCalibration #####################
73  */
74
75 Int_t AliHLTCalibrationProcessor::DoInit( int argc, const char** argv ) {
76   // see header file for class documentation
77
78   Int_t iResult = 0;
79   TString argument = "";
80   TString parameter = "";
81   Int_t bMissingParam=0;
82   
83   for ( Int_t ii=0; ii<argc && iResult>=0; ii++ ) {
84     argument = argv[ii];
85
86     if ( argument.IsNull() ) continue;
87
88     // -eventmodulo
89     if ( argument.CompareTo("-eventmodulo") == 0 ) {
90       if ( ( bMissingParam=( ++ii >= argc ) ) ) break;
91       parameter = argv[ii];  
92       parameter.Remove(TString::kLeading, ' '); // remove all blanks
93       if (parameter.IsDigit()) {
94         fEventModulo = parameter.Atoi();
95         HLTInfo("EventModulo is set to %d.", fEventModulo);
96       } 
97       else {
98         HLTError("Cannot convert EventModulo specifier '%s'.", argv[ii]);
99         iResult = -EINVAL;
100         break;
101       }
102     } 
103     // -usecorruptevents
104     else if ( argument.CompareTo( "-usecorruptevents" ) == 0 ) {
105       HLTInfo( "Passing through of corrupted events enabled." );
106       fUseCorruptEvents = kTRUE;
107     } 
108     // not known by calibration processor
109     else {
110       if ( ( iResult = ScanArgument( argc-ii, &argv[ii] ) ) == -EINVAL ) {
111         HLTError( "unknown argument %s", argument.Data() );
112         break;
113       } 
114       else if ( iResult == -EPROTO ) {
115         bMissingParam = 1;
116         break;
117       } 
118       else if ( iResult >= 0 ) {
119         ii += iResult;
120         iResult = 0;
121       }
122     }
123   }
124   
125   if ( bMissingParam ) {
126     HLTError( "missing parameter for argument %s", argument.Data() );
127     iResult = -EPROTO;
128   }
129
130   if ( iResult >= 0 ) {
131     iResult = InitCalibration();
132   }
133
134   // Reset the DDLNumberList
135   memset( fDDLNumber, 0, gkAliHLTFXSHeaderfDDLNumberSize);
136
137   return iResult;
138 }
139
140 Int_t AliHLTCalibrationProcessor::InitCalibration() {
141   // see header file for class documentation
142   
143   // fDummy is just touched here to avoid coding convention violation RC11. 
144   // The function can not be declared  const since it is just the default implementation, 
145   // overloaded virtual function might not be const.
146   fDummy = 0;
147
148   return 0;
149 }
150
151
152 Int_t AliHLTCalibrationProcessor::ScanArgument(int argc, const char** argv) {
153   // see header file for class documentation
154   
155   // there are no other arguments than the standard ones
156   if ( argc == 0 && argv == NULL) {
157     // this is just to get rid of the warning "unused parameter"
158   }
159   
160   // fDummy is just touched here to avoid coding convention violation RC11. 
161   // The function can not be declared  const since it is just the default implementation, 
162   // overloaded virtual function might not be const.
163   fDummy = 0;
164
165   return -EINVAL;
166 }
167
168 /*
169  * ######################## DeinitCalibration #####################
170  */
171
172 Int_t AliHLTCalibrationProcessor::DoDeinit() {
173   // see header file for class documentation
174  
175   int iResult = DeinitCalibration();
176  
177   return iResult;
178 }
179
180 Int_t AliHLTCalibrationProcessor::DeinitCalibration() {
181   // see header file for class documentation
182
183   // fDummy is just touched here to avoid coding convention violation RC11. 
184   // The function can not be declared  const since it is just the default implementation, 
185   // overloaded virtual function might not be const.
186   fDummy = 0;
187
188   return 0;
189 }
190
191 /*
192  * ######################## DoEvent #####################
193  */
194
195 Int_t AliHLTCalibrationProcessor::DoEvent( const AliHLTComponentEventData& evtData,
196                const AliHLTComponentBlockData* blocks, 
197                AliHLTComponentTriggerData& trigData,
198                AliHLTUInt8_t* outputPtr, 
199                AliHLTUInt32_t& size,
200                vector<AliHLTComponentBlockData>& outputBlocks )
201 {
202   // see header file for class documentation
203
204   Int_t iResult = 0;
205
206   const AliHLTComponentBlockData* blkSOR = NULL;
207   blkSOR = GetFirstInputBlock( kAliHLTDataTypeSOR );
208   const AliHLTComponentBlockData* blkEOR = NULL;
209   blkEOR = GetFirstInputBlock( kAliHLTDataTypeEOR );
210
211   // ** if event Type is not SOR or EOR -> fill DDLNumber list and process data
212   if ( ! blkEOR  && !blkSOR ) {
213     
214     // ** Set DDLNumber List
215     if ( trigData.fData != NULL) {
216       AliHLTEventTriggerData* trg = ( AliHLTEventTriggerData* ) trigData.fData;
217       if ( trg != NULL) {
218         AliHLTEventDDL list = (AliHLTEventDDL) trg->fReadoutList;        
219           
220         Int_t wordNdx = GetFirstUsedDDLWord(list);
221         if ( wordNdx >=0 ) {
222           
223           Int_t wordCount = 1;
224           // Handle special TPC and TOF case
225           if ( wordNdx == 3 )
226             wordCount = 8;
227           else if ( wordNdx == 12 )
228             wordCount = 3;
229           
230           // check word for word and binary OR it with existing DDLNumberList
231           for ( Int_t ndx = 0; ndx < wordCount; ndx++ ) {
232             AliHLTUInt32_t word = list.fList[wordNdx+ndx];
233         
234             // set only 4 bit into one Char_t
235             for ( Int_t charNdx = 0; charNdx < 8; charNdx++) {
236               fDDLNumber[(8*ndx)+charNdx] |= (Char_t) word & 0x0000000F;
237               word = word >> 4;
238             }
239           }
240         } // if ( wordNdx > 0 ) {
241       } // if ( trg != NULL) {
242     } // if ( trigData.fData != NULL) {
243     
244     // ** ProcessData
245     iResult = ProcessCalibration( evtData, blocks, trigData, outputPtr, size, outputBlocks );
246     fEventCounter++; 
247   }  
248
249   // - if event Type is EOR or event modulo is set -> ship data to FXS
250   // - use event modulo ship data also during the run 
251   if ( ( fEventModulo > 0 && fEventCounter == fEventModulo ) || blkEOR ){
252     HLTDebug ( "Ship Data to FXS!" );
253     iResult = ShipDataToFXS( evtData, blocks, trigData, outputPtr, size, outputBlocks );
254     fEventCounter = 0;
255   }
256
257   return iResult;
258 }
259
260 /*
261  * ######################## ProcessCalibration #####################
262  */
263
264 Int_t AliHLTCalibrationProcessor::ProcessCalibration( const AliHLTComponentEventData& evtData,
265                                                       const AliHLTComponentBlockData* /*blocks*/, 
266                                                       AliHLTComponentTriggerData& trigData,
267                                                       AliHLTUInt8_t* /*outputPtr*/, 
268                                                       AliHLTUInt32_t& /*size*/,
269                                                       vector<AliHLTComponentBlockData>& /*outputBlocks*/ ) {
270   // see header file for class documentation
271
272   // we just forward to the high level method, all other parameters already
273   // have been stored internally
274   return ProcessCalibration( evtData, trigData );
275 }
276
277 Int_t AliHLTCalibrationProcessor::ProcessCalibration( const AliHLTComponentEventData& /*evtData*/, 
278                                                       AliHLTComponentTriggerData& /*trigData*/) {
279   // see header file for class documentation
280
281   HLTFatal( "no processing method implemented" );
282   return -ENOSYS;
283 }
284
285 /*
286  * ######################## ShipDataToFXS #####################
287  */
288
289 Int_t AliHLTCalibrationProcessor::ShipDataToFXS( const AliHLTComponentEventData& evtData,
290                                                  const AliHLTComponentBlockData* /*blocks*/, 
291                                                  AliHLTComponentTriggerData& trigData,
292                                                  AliHLTUInt8_t* /*outputPtr*/, 
293                                                  AliHLTUInt32_t& /*size*/,
294                                                  vector<AliHLTComponentBlockData>& /*outputBlocks*/ ) {
295   // see header file for class documentation
296
297   // we just forward to the high level method, all other parameters already
298   // have been stored internally
299   return ShipDataToFXS( evtData, trigData );
300 }
301
302
303 Int_t AliHLTCalibrationProcessor::ShipDataToFXS( const AliHLTComponentEventData& /*evtData*/, 
304                                                  AliHLTComponentTriggerData& /*trigData*/) {
305   // see header file for class documentation
306
307   HLTFatal( "no processing method implemented" );
308   return -ENOSYS;
309 }
310
311 /*
312  * ######################## CreateFXSHeader #####################
313  */
314
315 Int_t AliHLTCalibrationProcessor::CreateFXSHeader( AliHLTFXSHeader &pHeader, const char* pDetector, const char* pFileID, AliHLTEventDDL* pDDLList ) {
316   // see header file for class documentation
317
318   Int_t iResult = 0;
319
320   // ** Fill header version
321   pHeader.fHeaderVersion = AliHLTCalibrationProcessor::fgkFXSProtocolHeaderVersion;
322
323   // ** Fill run number
324   pHeader.fRunNumber = GetRunNo(); 
325   
326   // ** Fill origin
327   HLTDebug( "FXS Header Detector  size max %i - actual %i .",gkAliHLTFXSHeaderfOriginSize, strlen( pDetector ) );
328   strncpy ( pHeader.fOrigin, pDetector, gkAliHLTFXSHeaderfOriginSize ) ; 
329
330   // To take care if fileIDs which are longer than gkAliHLTFXSHeaderfOriginSize, write one 0 is cheaper than an if.
331   pHeader.fOrigin[gkAliHLTFXSHeaderfOriginSize] = 0;
332
333   // ** Fill file ID
334   HLTInfo( "FXS Header FileID size max %i - actual %i .",gkAliHLTFXSHeaderfFileIDSize, strlen( pFileID ) );
335   strncpy ( pHeader.fFileID, pFileID, gkAliHLTFXSHeaderfFileIDSize ) ; 
336
337   // To take care if fileIDs which are longer than gkAliHLTFXSHeaderfFileIDSize, write one 0 is cheaper than an if.
338   pHeader.fFileID[gkAliHLTFXSHeaderfFileIDSize] = 0;
339
340   // ** Fill DDL number
341
342   // -- if component provides list, convert to fDDLNumber
343   if ( pDDLList ) {
344     // use user list
345     
346     Int_t wordNdx = GetFirstUsedDDLWord( *(pDDLList) );
347     if ( wordNdx >=0 ) {
348           
349       Int_t wordCount = 1;
350       // Handle special TPC and TOF case
351       if ( wordNdx == 3 )
352         wordCount = 8;
353       else if ( wordNdx == 12 )
354         wordCount = 3;
355           
356       // check word for word 
357       for ( Int_t ndx = 0; ndx < wordCount; ndx++ ) {
358         AliHLTUInt32_t word = pDDLList->fList[wordNdx+ndx];
359         
360         // set only 4 bit into one Char_t
361         for ( Int_t charNdx = 0; charNdx < 8; charNdx++) {
362           fDDLNumber[(8*ndx)+charNdx] = (Char_t) word & 0x0000000F;
363           word = word >> 4;
364         }
365       }
366     } // if ( wordNdx > 0 ) {
367     else
368       iResult = wordNdx;
369   } //   if ( pDDLList ) {
370
371   // -- fill header with ascii chars
372   for (Int_t ndx = 0; ndx < gkAliHLTFXSHeaderfDDLNumberSize; ndx++ ){
373     Int_t numberToChar = (Int_t) fDDLNumber[ndx];
374     // Get ASCII
375     if ( numberToChar > 9 ) numberToChar += 55;
376     else numberToChar += 48;
377     
378     pHeader.fDDLNumber[ndx] = (Char_t) numberToChar;
379   }
380   
381   return iResult;
382 }  // Int_t AliHLTCalibrationProcessor::CreateFXSHeader( AliHLTXSHeader &pHeader, const char* pDetector, const char* pFileID, AliHLTEventDDL* pDDLList ) {
383
384 /*
385  * ######################## PushToFXS #####################
386  */
387
388 Int_t AliHLTCalibrationProcessor::PushToFXS(TObject* pObject, const char* pDetector, const char* pFileID, AliHLTEventDDL* pDDLList ) {
389   // see header file for class documentation
390
391   Int_t iResult = 0;
392   
393   AliHLTFXSHeader pHeader;
394
395   CreateFXSHeader( pHeader, pDetector, pFileID, pDDLList );
396   
397   if ( pObject ) {
398     
399     AliHLTMemoryFile* pMemFile = CreateMemoryFile( kAliHLTDataTypeFXSCalib, kAliHLTVoidDataSpec );
400     if ( pMemFile ) {
401       
402       iResult = pMemFile->WriteHeaderBuffer( (const char*) &pHeader, AliHLTCalibrationProcessor::fgkFXSProtocolHeaderSize );
403
404       if ( iResult ) {
405         HLTError( "Buffer size to small - for header!" ); 
406       }
407       else {
408         iResult = Write( pMemFile, pObject );
409         if ( !iResult ) {
410           HLTError( "Buffer size to small - for data!" ); 
411         }
412         else {
413           iResult = CloseMemoryFile( pMemFile );  
414         }
415       }
416     } 
417     else {
418       iResult = -ENOMEM;
419     }
420   } 
421   else {
422     iResult=-EINVAL;
423   }
424
425   return iResult;
426
427 } // Int_t AliHLTCalibrationProcessor::PushToFXS(TObject* pObject, const char* detector, const char* pFileID, AliHLTEventDDL* pDDLList ) {
428
429 Int_t AliHLTCalibrationProcessor::PushToFXS( void* pBuffer, int iSize, const char* pDetector, const char* pFileID, AliHLTEventDDL* pDDLList ) {
430   // see header file for class documentation
431
432   Int_t iResult = 0;
433   
434   AliHLTFXSHeader pHeader;
435
436   CreateFXSHeader( pHeader, pDetector, pFileID, pDDLList );
437   
438   iResult = PushBack( pBuffer, iSize, kAliHLTDataTypeFXSCalib, kAliHLTVoidDataSpec, (void*) (&pHeader), AliHLTCalibrationProcessor::fgkFXSProtocolHeaderSize );
439
440   return iResult;
441
442 } // Int_t AliHLTCalibrationProcessor::PushToFXS(void* pBuffer, int iSize, const char* pDdetector, const char* pFileID, AliHLTEventDDL* pDDLList ) {
443