]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLTCalibrationProcessor.cxx
More protections
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTCalibrationProcessor.cxx
CommitLineData
9d9ffd37 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
3a7c0444 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
9d9ffd37 30#if __GNUC__ >= 3
31using 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
773aff84 43ClassImp(AliHLTCalibrationProcessor);
9d9ffd37 44
45
46const AliHLTUInt32_t AliHLTCalibrationProcessor::fgkFXSProtocolHeaderSize = 204;
47const AliHLTUInt32_t AliHLTCalibrationProcessor::fgkFXSProtocolHeaderVersion = 1;
48
49/*
50 * ################ Constructor / Destructor ####################
51 */
52
53AliHLTCalibrationProcessor::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
67AliHLTCalibrationProcessor::~AliHLTCalibrationProcessor() {
68 // see header file for class documentation
69}
70
71/*
72 * ######################## InitCalibration #####################
73 */
74
7c4091c1 75Int_t AliHLTCalibrationProcessor::DoInit( int argc, const char** argv ) {
9d9ffd37 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
137Int_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
7c4091c1 149Int_t AliHLTCalibrationProcessor::ScanArgument(int argc, const char** argv) {
9d9ffd37 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
169Int_t AliHLTCalibrationProcessor::DoDeinit() {
170 // see header file for class documentation
171
172 int iResult = DeinitCalibration();
173
174 return iResult;
175}
176
177Int_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
192Int_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;
9d9ffd37 202
203 const AliHLTComponentBlockData* blkSOR = NULL;
1a04dcde 204 blkSOR = GetFirstInputBlock( kAliHLTDataTypeSOR );
9d9ffd37 205 const AliHLTComponentBlockData* blkEOR = NULL;
1a04dcde 206 blkEOR = GetFirstInputBlock( kAliHLTDataTypeEOR );
207
208 // const AliHLTComponentBlockData* blkDDL = NULL;
9d9ffd37 209
210 HLTInfo( "Event ID: %lu", evtData.fEventID );
211
1a04dcde 212
9d9ffd37 213 // -------------- GET DDLNumber -----------------
1a04dcde 214 // blkDDL = GetFirstInputBlock( kAliHLTDataTypeDDL );
9d9ffd37 215
1a04dcde 216 // if ( blkDDL ) {
217 //HLTInfo("DDLLIST block received, size: %u", blkDDL->fSize );
218 //AliHLTEventDDL ddlList = ( AliHLTEventDDL* ) blkDDL->fPtr;
219 //}
9d9ffd37 220
221 // ------------ decide which event type ----------
222
223 // - if event Type is not SOR or EOR -> process data
224 if ( ! blkEOR && !blkSOR ) {
225 iResult = ProcessCalibration( evtData, blocks, trigData, outputPtr, size, outputBlocks );
226 fEventCounter++;
227 }
228
229 // - if event Type is EOR or event modulo is set -> ship data to FXS
230 // - use event modulo ship data also during the run
231 if ( ( fEventModulo > 0 && fEventCounter == fEventModulo ) || blkEOR ){
232 HLTDebug ( "Ship Data to FXS!" );
233 iResult = ShipDataToFXS( evtData, blocks, trigData, outputPtr, size, outputBlocks );
234 fEventCounter = 0;
235 }
236
237 return iResult;
238}
239
240/*
241 * ######################## ProcessCalibration #####################
242 */
243
244Int_t AliHLTCalibrationProcessor::ProcessCalibration( const AliHLTComponentEventData& evtData,
29312178 245 const AliHLTComponentBlockData* /*blocks*/,
246 AliHLTComponentTriggerData& trigData,
247 AliHLTUInt8_t* /*outputPtr*/,
248 AliHLTUInt32_t& /*size*/,
249 vector<AliHLTComponentBlockData>& /*outputBlocks*/ ) {
9d9ffd37 250 // see header file for class documentation
251
252 // we just forward to the high level method, all other parameters already
253 // have been stored internally
254 return ProcessCalibration( evtData, trigData );
255}
256
29312178 257Int_t AliHLTCalibrationProcessor::ProcessCalibration( const AliHLTComponentEventData& /*evtData*/,
258 AliHLTComponentTriggerData& /*trigData*/) {
9d9ffd37 259 // see header file for class documentation
260
261 HLTFatal( "no processing method implemented" );
262 return -ENOSYS;
263}
264
265/*
266 * ######################## ShipDataToFXS #####################
267 */
268
269Int_t AliHLTCalibrationProcessor::ShipDataToFXS( const AliHLTComponentEventData& evtData,
29312178 270 const AliHLTComponentBlockData* /*blocks*/,
271 AliHLTComponentTriggerData& trigData,
272 AliHLTUInt8_t* /*outputPtr*/,
273 AliHLTUInt32_t& /*size*/,
274 vector<AliHLTComponentBlockData>& /*outputBlocks*/ ) {
9d9ffd37 275 // see header file for class documentation
276
277 // we just forward to the high level method, all other parameters already
278 // have been stored internally
279 return ShipDataToFXS( evtData, trigData );
280}
281
282
29312178 283Int_t AliHLTCalibrationProcessor::ShipDataToFXS( const AliHLTComponentEventData& /*evtData*/,
284 AliHLTComponentTriggerData& /*trigData*/) {
9d9ffd37 285 // see header file for class documentation
286
287 HLTFatal( "no processing method implemented" );
288 return -ENOSYS;
289}
290
291/*
292 * ######################## CreateFXSHeader #####################
293 */
294
295Int_t AliHLTCalibrationProcessor::CreateFXSHeader( AliHLTFXSHeader &pHeader, const char* pDetector, const char* pFileID, const char* pDDLNumber ) {
296 // see header file for class documentation
297
298 Int_t iResult = 0;
299
300 AliHLTUInt32_t runNumber = GetRunNo(); // debug : 2176;
301
302 HLTDebug( "RunNumber = %d", runNumber );
303
304 /* STILL TO BE DONE .. but interface fixed */
305
306 // if ( pDDLNumber != "" ) {
307 char ddltmp[5] = "4444";
308 strncpy ( fDDLNumber, ddltmp, gkAliHLTFXSHeaderfDDLNumberSize );
309 //}
310 //else {
311 //strncpy ( fDDLNumber, pDDLNumber, gkAliHLTFXSHeaderfDDLNumberSize );
312 //}
313
314 fDDLNumber[gkAliHLTFXSHeaderfDDLNumberSize] = 0;
315
316 // -- Fill Header
317
318 // Fill header version
319 pHeader.fHeaderVersion = AliHLTCalibrationProcessor::fgkFXSProtocolHeaderVersion;
320
321 // Fill run number
322 pHeader.fRunNumber = runNumber;
323
324 // Fill origin
325 HLTDebug( "FXS Header Detector size max %i - actual %i .",gkAliHLTFXSHeaderfOriginSize, strlen( pDetector ) );
326 strncpy ( pHeader.fOrigin, pDetector, gkAliHLTFXSHeaderfOriginSize ) ;
327
328 // To take care if fileIDs which are longer than gkAliHLTFXSHeaderfOriginSize, write one 0 is cheaper than an if.
329 pHeader.fOrigin[gkAliHLTFXSHeaderfOriginSize] = 0;
330
331 // Fill file ID
332 HLTInfo( "FXS Header FileID size max %i - actual %i .",gkAliHLTFXSHeaderfFileIDSize, strlen( pFileID ) );
333 strncpy ( pHeader.fFileID, pFileID, gkAliHLTFXSHeaderfFileIDSize ) ;
334
335 // To take care if fileIDs which are longer than gkAliHLTFXSHeaderfFileIDSize, write one 0 is cheaper than an if.
336 pHeader.fFileID[gkAliHLTFXSHeaderfFileIDSize] = 0;
337
338 // Fill DDL number
339 HLTInfo( "FXS Header DDLNumber size max %i - actual %i .", gkAliHLTFXSHeaderfDDLNumberSize, strlen( pDDLNumber ) );
340 strncpy ( pHeader.fDDLNumber, fDDLNumber, gkAliHLTFXSHeaderfDDLNumberSize) ;
341
342 // To take care if DDLNumber which are longer than gkAliHLTFXSHeaderfDDLNumberSize, write one 0 is cheaper than an if.
343 pHeader.fDDLNumber[gkAliHLTFXSHeaderfDDLNumberSize] = 0;
344
e83e889b 345 return iResult;
9d9ffd37 346} // Int_t AliHLTCalibrationProcessor::CreateFXSHeader( AliHLTXSHeader &pHeader, const char* pDetector, const char* pFileID, const char* pDDLNumber ) {
347
348/*
349 * ######################## PushToFXS #####################
350 */
351
352Int_t AliHLTCalibrationProcessor::PushToFXS(TObject* pObject, const char* pDetector, const char* pFileID, const char* pDDLNumber ) {
353 // see header file for class documentation
354
355 Int_t iResult = 0;
356
357 AliHLTFXSHeader pHeader;
358
359 CreateFXSHeader( pHeader, pDetector, pFileID, pDDLNumber );
360
361 if ( pObject ) {
362
363 AliHLTMemoryFile* pMemFile = CreateMemoryFile( kAliHLTDataTypeFXSCalib, kAliHLTVoidDataSpec );
364 if ( pMemFile ) {
365
29312178 366 iResult = pMemFile->WriteHeaderBuffer( (const char*) &pHeader, AliHLTCalibrationProcessor::fgkFXSProtocolHeaderSize );
9d9ffd37 367
368 if ( iResult ) {
369 HLTError( "Buffer size to small - for header!" );
370 }
371 else {
372 iResult = Write( pMemFile, pObject );
373 if ( !iResult ) {
374 HLTError( "Buffer size to small - for data!" );
375 }
376 else {
377 iResult = CloseMemoryFile( pMemFile );
378 }
379 }
380 }
381 else {
382 iResult = -ENOMEM;
383 }
384 }
385 else {
386 iResult=-EINVAL;
387 }
388
389 return iResult;
390
391} // Int_t AliHLTCalibrationProcessor::PushToFXS(TObject* pObject, const char* detector, const char* pFileID, const char* pDDLNumber ) {
392
393Int_t AliHLTCalibrationProcessor::PushToFXS( void* pBuffer, int iSize, const char* pDetector, const char* pFileID, const char* pDDLNumber ) {
3a7c0444 394 // see header file for class documentation
9d9ffd37 395
396 Int_t iResult = 0;
397
398 AliHLTFXSHeader pHeader;
399
400 CreateFXSHeader( pHeader, pDetector, pFileID, pDDLNumber );
401
402 iResult = PushBack( pBuffer, iSize, kAliHLTDataTypeFXSCalib, kAliHLTVoidDataSpec, (void*) (&pHeader), AliHLTCalibrationProcessor::fgkFXSProtocolHeaderSize );
403
404 return iResult;
405
406} // Int_t AliHLTCalibrationProcessor::PushToFXS(void* pBuffer, int iSize, const char* pDdetector, const char* pFileID, const char* pDDLNumber = "") {
407