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