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