]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLTCalibrationProcessor.cxx
Bug Fix.
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTCalibrationProcessor.cxx
CommitLineData
1c2013e0 1// $Id$
9d9ffd37 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
3a7c0444 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
9d9ffd37 31#if __GNUC__ >= 3
32using namespace std;
33#endif
34
35#include "AliHLTCalibrationProcessor.h"
36#include "AliHLTMemoryFile.h"
89413559 37#include "AliHLTReadoutList.h"
9d9ffd37 38
39#include <cstdlib>
40#include <cerrno>
41#include <string.h>
42#include <TObjString.h>
43#include <TFile.h>
44
773aff84 45ClassImp(AliHLTCalibrationProcessor);
9d9ffd37 46
47
48const AliHLTUInt32_t AliHLTCalibrationProcessor::fgkFXSProtocolHeaderSize = 204;
49const AliHLTUInt32_t AliHLTCalibrationProcessor::fgkFXSProtocolHeaderVersion = 1;
50
51/*
52 * ################ Constructor / Destructor ####################
53 */
54
55AliHLTCalibrationProcessor::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
69AliHLTCalibrationProcessor::~AliHLTCalibrationProcessor() {
70 // see header file for class documentation
71}
72
73/*
74 * ######################## InitCalibration #####################
75 */
76
7c4091c1 77Int_t AliHLTCalibrationProcessor::DoInit( int argc, const char** argv ) {
9d9ffd37 78 // see header file for class documentation
79
1c2013e0 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
9d9ffd37 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
ed504011 140 // Reset the DDLNumberList
141 memset( fDDLNumber, 0, gkAliHLTFXSHeaderfDDLNumberSize);
142
9d9ffd37 143 return iResult;
144}
145
146Int_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
7c4091c1 158Int_t AliHLTCalibrationProcessor::ScanArgument(int argc, const char** argv) {
9d9ffd37 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
178Int_t AliHLTCalibrationProcessor::DoDeinit() {
179 // see header file for class documentation
180
181 int iResult = DeinitCalibration();
182
183 return iResult;
184}
185
186Int_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
201Int_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;
9d9ffd37 211
212 const AliHLTComponentBlockData* blkSOR = NULL;
1a04dcde 213 blkSOR = GetFirstInputBlock( kAliHLTDataTypeSOR );
9d9ffd37 214 const AliHLTComponentBlockData* blkEOR = NULL;
1a04dcde 215 blkEOR = GetFirstInputBlock( kAliHLTDataTypeEOR );
216
ed504011 217 // ** if event Type is not SOR or EOR -> fill DDLNumber list and process data
9d9ffd37 218 if ( ! blkEOR && !blkSOR ) {
ed504011 219 // ** ProcessData
9d9ffd37 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
239Int_t AliHLTCalibrationProcessor::ProcessCalibration( const AliHLTComponentEventData& evtData,
29312178 240 const AliHLTComponentBlockData* /*blocks*/,
241 AliHLTComponentTriggerData& trigData,
242 AliHLTUInt8_t* /*outputPtr*/,
243 AliHLTUInt32_t& /*size*/,
244 vector<AliHLTComponentBlockData>& /*outputBlocks*/ ) {
9d9ffd37 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
29312178 252Int_t AliHLTCalibrationProcessor::ProcessCalibration( const AliHLTComponentEventData& /*evtData*/,
253 AliHLTComponentTriggerData& /*trigData*/) {
9d9ffd37 254 // see header file for class documentation
255
256 HLTFatal( "no processing method implemented" );
257 return -ENOSYS;
258}
259
260/*
261 * ######################## ShipDataToFXS #####################
262 */
263
264Int_t AliHLTCalibrationProcessor::ShipDataToFXS( const AliHLTComponentEventData& evtData,
29312178 265 const AliHLTComponentBlockData* /*blocks*/,
266 AliHLTComponentTriggerData& trigData,
267 AliHLTUInt8_t* /*outputPtr*/,
268 AliHLTUInt32_t& /*size*/,
269 vector<AliHLTComponentBlockData>& /*outputBlocks*/ ) {
9d9ffd37 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
29312178 278Int_t AliHLTCalibrationProcessor::ShipDataToFXS( const AliHLTComponentEventData& /*evtData*/,
279 AliHLTComponentTriggerData& /*trigData*/) {
9d9ffd37 280 // see header file for class documentation
281
282 HLTFatal( "no processing method implemented" );
283 return -ENOSYS;
284}
285
286/*
287 * ######################## CreateFXSHeader #####################
288 */
289
89413559 290Int_t AliHLTCalibrationProcessor::CreateFXSHeader( AliHLTFXSHeader &pHeader, const char* pDetector, const char* pFileID, const AliHLTReadoutList* pDDLList ) {
9d9ffd37 291 // see header file for class documentation
292
293 Int_t iResult = 0;
294
ed504011 295 // ** Fill header version
9d9ffd37 296 pHeader.fHeaderVersion = AliHLTCalibrationProcessor::fgkFXSProtocolHeaderVersion;
297
ed504011 298 // ** Fill run number
299 pHeader.fRunNumber = GetRunNo();
9d9ffd37 300
ed504011 301 // ** Fill origin
9d9ffd37 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.
3f0a35a7 306 pHeader.fOrigin[gkAliHLTFXSHeaderfOriginSize-1] = 0;
9d9ffd37 307
ed504011 308 // ** Fill file ID
d3e0be03 309 HLTDebug( "FXS Header FileID size max %i - actual %i .",gkAliHLTFXSHeaderfFileIDSize, strlen( pFileID ) );
9d9ffd37 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.
3f0a35a7 313 pHeader.fFileID[gkAliHLTFXSHeaderfFileIDSize-1] = 0;
9d9ffd37 314
ed504011 315 // ** Fill DDL number
9d9ffd37 316
ed504011 317 // -- if component provides list, convert to fDDLNumber
318 if ( pDDLList ) {
319 // use user list
320
89413559 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 {
ed504011 335 // check word for word
336 for ( Int_t ndx = 0; ndx < wordCount; ndx++ ) {
89413559 337 AliHLTUInt32_t word = pDDLList->Buffer()->fList[wordNdx+ndx];
ed504011 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 }
89413559 345 }
ed504011 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
e83e889b 358 return iResult;
89413559 359} // Int_t AliHLTCalibrationProcessor::CreateFXSHeader( AliHLTXSHeader &pHeader, const char* pDetector, const char* pFileID, const AliHLTReadoutList* pDDLList ) {
9d9ffd37 360
361/*
362 * ######################## PushToFXS #####################
363 */
364
89413559 365Int_t AliHLTCalibrationProcessor::PushToFXS(TObject* pObject, const char* pDetector, const char* pFileID, const AliHLTReadoutList* pDDLList ) {
9d9ffd37 366 // see header file for class documentation
367
368 Int_t iResult = 0;
369
370 AliHLTFXSHeader pHeader;
371
ed504011 372 CreateFXSHeader( pHeader, pDetector, pFileID, pDDLList );
9d9ffd37 373
374 if ( pObject ) {
375
376 AliHLTMemoryFile* pMemFile = CreateMemoryFile( kAliHLTDataTypeFXSCalib, kAliHLTVoidDataSpec );
377 if ( pMemFile ) {
378
29312178 379 iResult = pMemFile->WriteHeaderBuffer( (const char*) &pHeader, AliHLTCalibrationProcessor::fgkFXSProtocolHeaderSize );
9d9ffd37 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
89413559 404} // Int_t AliHLTCalibrationProcessor::PushToFXS(TObject* pObject, const char* detector, const char* pFileID, const AliHLTReadoutList* pDDLList ) {
9d9ffd37 405
89413559 406Int_t AliHLTCalibrationProcessor::PushToFXS( void* pBuffer, int iSize, const char* pDetector, const char* pFileID, const AliHLTReadoutList* pDDLList ) {
3a7c0444 407 // see header file for class documentation
9d9ffd37 408
409 Int_t iResult = 0;
410
411 AliHLTFXSHeader pHeader;
412
ed504011 413 CreateFXSHeader( pHeader, pDetector, pFileID, pDDLList );
9d9ffd37 414
415 iResult = PushBack( pBuffer, iSize, kAliHLTDataTypeFXSCalib, kAliHLTVoidDataSpec, (void*) (&pHeader), AliHLTCalibrationProcessor::fgkFXSProtocolHeaderSize );
416
417 return iResult;
418
89413559 419} // Int_t AliHLTCalibrationProcessor::PushToFXS(void* pBuffer, int iSize, const char* pDdetector, const char* pFileID, const AliHLTReadoutList* pDDLList ) {
9d9ffd37 420