]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTCalibrationProcessor.cxx
coding conventions
[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   return iResult;
135 }
136
137 Int_t AliHLTCalibrationProcessor::InitCalibration() {
138   // see header file for class documentation
139   
140   // fDummy is just touched here to avoid coding convention violation RC11. 
141   // The function can not be declared  const since it is just the default implementation, 
142   // overloaded virtual function might not be const.
143   fDummy = 0;
144
145   return 0;
146 }
147
148
149 Int_t AliHLTCalibrationProcessor::ScanArgument(int argc, const char** argv) {
150   // see header file for class documentation
151   
152   // there are no other arguments than the standard ones
153   if ( argc == 0 && argv == NULL) {
154     // this is just to get rid of the warning "unused parameter"
155   }
156   
157   // fDummy is just touched here to avoid coding convention violation RC11. 
158   // The function can not be declared  const since it is just the default implementation, 
159   // overloaded virtual function might not be const.
160   fDummy = 0;
161
162   return -EINVAL;
163 }
164
165 /*
166  * ######################## DeinitCalibration #####################
167  */
168
169 Int_t AliHLTCalibrationProcessor::DoDeinit() {
170   // see header file for class documentation
171  
172   int iResult = DeinitCalibration();
173  
174   return iResult;
175 }
176
177 Int_t AliHLTCalibrationProcessor::DeinitCalibration() {
178   // see header file for class documentation
179
180   // fDummy is just touched here to avoid coding convention violation RC11. 
181   // The function can not be declared  const since it is just the default implementation, 
182   // overloaded virtual function might not be const.
183   fDummy = 0;
184
185   return 0;
186 }
187
188 /*
189  * ######################## DoEvent #####################
190  */
191
192 Int_t AliHLTCalibrationProcessor::DoEvent( const AliHLTComponentEventData& evtData,
193                const AliHLTComponentBlockData* blocks, 
194                AliHLTComponentTriggerData& trigData,
195                AliHLTUInt8_t* outputPtr, 
196                AliHLTUInt32_t& size,
197                vector<AliHLTComponentBlockData>& outputBlocks )
198 {
199   // see header file for class documentation
200
201   Int_t iResult = 0;
202   const AliHLTComponentBlockData* iter = NULL;
203
204   const AliHLTComponentBlockData* blkSOR = NULL;
205   const AliHLTComponentBlockData* blkEOR = NULL;
206   const AliHLTComponentBlockData* blkDDL = NULL;
207
208   HLTInfo( "Event ID: %lu", evtData.fEventID );
209
210   // ---------------  START OF RUN -----------------
211   blkSOR = GetFirstInputBlock( kAliHLTDataTypeSOR );
212   
213   // ----------------  END OF RUN ------------------
214   blkEOR = GetFirstInputBlock( kAliHLTDataTypeEOR );
215   
216   // --------------  GET DDLNumber -----------------
217   blkDDL = GetFirstInputBlock( kAliHLTDataTypeDDL );
218   
219   if ( blkDDL ) {
220     HLTInfo("DDLLIST block received, size: %u", iter->fSize );
221     //AliHLTEventDDL ddlList = ( AliHLTEventDDL* ) iter->fPtr;
222   }
223   
224   // ------------ decide which event type ----------
225
226   // - if event Type is not SOR or EOR -> process data
227   if ( ! blkEOR  && !blkSOR ) {
228     iResult = ProcessCalibration( evtData, blocks, trigData, outputPtr, size, outputBlocks );
229     fEventCounter++; 
230   }  
231
232   // - if event Type is EOR or event modulo is set -> ship data to FXS
233   // - use event modulo ship data also during the run 
234   if ( ( fEventModulo > 0 && fEventCounter == fEventModulo ) || blkEOR ){
235     HLTDebug ( "Ship Data to FXS!" );
236     iResult = ShipDataToFXS( evtData, blocks, trigData, outputPtr, size, outputBlocks );
237     fEventCounter = 0;
238   }
239
240   return iResult;
241 }
242
243 /*
244  * ######################## ProcessCalibration #####################
245  */
246
247 Int_t AliHLTCalibrationProcessor::ProcessCalibration( const AliHLTComponentEventData& evtData,
248                                                       const AliHLTComponentBlockData* /*blocks*/, 
249                                                       AliHLTComponentTriggerData& trigData,
250                                                       AliHLTUInt8_t* /*outputPtr*/, 
251                                                       AliHLTUInt32_t& /*size*/,
252                                                       vector<AliHLTComponentBlockData>& /*outputBlocks*/ ) {
253   // see header file for class documentation
254
255   // we just forward to the high level method, all other parameters already
256   // have been stored internally
257   return ProcessCalibration( evtData, trigData );
258 }
259
260 Int_t AliHLTCalibrationProcessor::ProcessCalibration( const AliHLTComponentEventData& /*evtData*/, 
261                                                       AliHLTComponentTriggerData& /*trigData*/) {
262   // see header file for class documentation
263
264   HLTFatal( "no processing method implemented" );
265   return -ENOSYS;
266 }
267
268 /*
269  * ######################## ShipDataToFXS #####################
270  */
271
272 Int_t AliHLTCalibrationProcessor::ShipDataToFXS( const AliHLTComponentEventData& evtData,
273                                                  const AliHLTComponentBlockData* /*blocks*/, 
274                                                  AliHLTComponentTriggerData& trigData,
275                                                  AliHLTUInt8_t* /*outputPtr*/, 
276                                                  AliHLTUInt32_t& /*size*/,
277                                                  vector<AliHLTComponentBlockData>& /*outputBlocks*/ ) {
278   // see header file for class documentation
279
280   // we just forward to the high level method, all other parameters already
281   // have been stored internally
282   return ShipDataToFXS( evtData, trigData );
283 }
284
285
286 Int_t AliHLTCalibrationProcessor::ShipDataToFXS( const AliHLTComponentEventData& /*evtData*/, 
287                                                  AliHLTComponentTriggerData& /*trigData*/) {
288   // see header file for class documentation
289
290   HLTFatal( "no processing method implemented" );
291   return -ENOSYS;
292 }
293
294 /*
295  * ######################## CreateFXSHeader #####################
296  */
297
298 Int_t AliHLTCalibrationProcessor::CreateFXSHeader( AliHLTFXSHeader &pHeader, const char* pDetector, const char* pFileID, const char* pDDLNumber ) {
299   // see header file for class documentation
300
301   Int_t iResult = 0;
302
303   AliHLTUInt32_t runNumber = GetRunNo();         //  debug : 2176;  
304
305   HLTDebug( "RunNumber = %d", runNumber );
306
307   /* STILL TO BE DONE .. but interface fixed   */
308
309   //  if ( pDDLNumber  != "" ) {
310   char ddltmp[5] = "4444";
311   strncpy ( fDDLNumber, ddltmp, gkAliHLTFXSHeaderfDDLNumberSize );
312   //}
313   //else {
314   //strncpy ( fDDLNumber, pDDLNumber, gkAliHLTFXSHeaderfDDLNumberSize );
315   //}
316   
317   fDDLNumber[gkAliHLTFXSHeaderfDDLNumberSize] = 0;
318   
319   // -- Fill Header
320
321   // Fill header version
322   pHeader.fHeaderVersion = AliHLTCalibrationProcessor::fgkFXSProtocolHeaderVersion;
323
324   // Fill run number
325   pHeader.fRunNumber = runNumber;
326   
327   // Fill origin
328   HLTDebug( "FXS Header Detector  size max %i - actual %i .",gkAliHLTFXSHeaderfOriginSize, strlen( pDetector ) );
329   strncpy ( pHeader.fOrigin, pDetector, gkAliHLTFXSHeaderfOriginSize ) ; 
330
331   // To take care if fileIDs which are longer than gkAliHLTFXSHeaderfOriginSize, write one 0 is cheaper than an if.
332   pHeader.fOrigin[gkAliHLTFXSHeaderfOriginSize] = 0;
333
334   // Fill file ID
335   HLTInfo( "FXS Header FileID size max %i - actual %i .",gkAliHLTFXSHeaderfFileIDSize, strlen( pFileID ) );
336   strncpy ( pHeader.fFileID, pFileID, gkAliHLTFXSHeaderfFileIDSize ) ; 
337
338   // To take care if fileIDs which are longer than gkAliHLTFXSHeaderfFileIDSize, write one 0 is cheaper than an if.
339   pHeader.fFileID[gkAliHLTFXSHeaderfFileIDSize] = 0;
340
341   // Fill DDL number
342   HLTInfo( "FXS Header DDLNumber size max %i - actual %i .", gkAliHLTFXSHeaderfDDLNumberSize, strlen( pDDLNumber ) );
343   strncpy ( pHeader.fDDLNumber, fDDLNumber, gkAliHLTFXSHeaderfDDLNumberSize) ; 
344
345   // To take care if DDLNumber which are longer than gkAliHLTFXSHeaderfDDLNumberSize, write one 0 is cheaper than an if.
346   pHeader.fDDLNumber[gkAliHLTFXSHeaderfDDLNumberSize] = 0;
347
348   return iResult;
349 }  // Int_t AliHLTCalibrationProcessor::CreateFXSHeader( AliHLTXSHeader &pHeader, const char* pDetector, const char* pFileID, const char* pDDLNumber ) {
350
351 /*
352  * ######################## PushToFXS #####################
353  */
354
355 Int_t AliHLTCalibrationProcessor::PushToFXS(TObject* pObject, const char* pDetector, const char* pFileID, const char* pDDLNumber ) {
356   // see header file for class documentation
357
358   Int_t iResult = 0;
359   
360   AliHLTFXSHeader pHeader;
361
362   CreateFXSHeader( pHeader, pDetector, pFileID, pDDLNumber );
363   
364   if ( pObject ) {
365     
366     AliHLTMemoryFile* pMemFile = CreateMemoryFile( kAliHLTDataTypeFXSCalib, kAliHLTVoidDataSpec );
367     if ( pMemFile ) {
368       
369       iResult = pMemFile->WriteHeaderBuffer( (const char*) &pHeader, AliHLTCalibrationProcessor::fgkFXSProtocolHeaderSize );
370
371       if ( iResult ) {
372         HLTError( "Buffer size to small - for header!" ); 
373       }
374       else {
375         iResult = Write( pMemFile, pObject );
376         if ( !iResult ) {
377           HLTError( "Buffer size to small - for data!" ); 
378         }
379         else {
380           iResult = CloseMemoryFile( pMemFile );  
381         }
382       }
383     } 
384     else {
385       iResult = -ENOMEM;
386     }
387   } 
388   else {
389     iResult=-EINVAL;
390   }
391
392   return iResult;
393
394 } // Int_t AliHLTCalibrationProcessor::PushToFXS(TObject* pObject, const char* detector, const char* pFileID, const char* pDDLNumber ) {
395
396 Int_t AliHLTCalibrationProcessor::PushToFXS( void* pBuffer, int iSize, const char* pDetector, const char* pFileID, const char* pDDLNumber ) {
397   // see header file for class documentation
398
399   Int_t iResult = 0;
400   
401   AliHLTFXSHeader pHeader;
402
403   CreateFXSHeader( pHeader, pDetector, pFileID, pDDLNumber );
404   
405   iResult = PushBack( pBuffer, iSize, kAliHLTDataTypeFXSCalib, kAliHLTVoidDataSpec, (void*) (&pHeader), AliHLTCalibrationProcessor::fgkFXSProtocolHeaderSize );
406
407   return iResult;
408
409 } // Int_t AliHLTCalibrationProcessor::PushToFXS(void* pBuffer, int iSize, const char* pDdetector, const char* pFileID, const char* pDDLNumber = "") {
410