1 /**************************************************************************
2 * This file is property of and copyright by the ALICE HLT Project *
3 * ALICE Experiment at CERN, All rights reserved. *
5 * Primary Authors: Jochen Thaeder <thaeder@kip.uni-heidelberg.de> *
7 * for The ALICE HLT Project. *
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 **************************************************************************/
19 * @file AliHLTCalibrationProcessor.cxx
20 * @author Jochen Thaeder, Sebastian Bablok
22 * @brief Base class of HLT calibration components. */
24 // see header file for class documentation
26 // refer to README to build package
28 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
34 #include "AliHLTCalibrationProcessor.h"
35 #include "AliHLTMemoryFile.h"
40 #include <TObjString.h>
43 ClassImp(AliHLTCalibrationProcessor);
46 const AliHLTUInt32_t AliHLTCalibrationProcessor::fgkFXSProtocolHeaderSize = 204;
47 const AliHLTUInt32_t AliHLTCalibrationProcessor::fgkFXSProtocolHeaderVersion = 1;
50 * ################ Constructor / Destructor ####################
53 AliHLTCalibrationProcessor::AliHLTCalibrationProcessor() :
55 fUseCorruptEvents(kFALSE),
60 // see header file for class documentation
62 // refer to README to build package
64 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
67 AliHLTCalibrationProcessor::~AliHLTCalibrationProcessor() {
68 // see header file for class documentation
72 * ######################## InitCalibration #####################
75 Int_t AliHLTCalibrationProcessor::DoInit( int argc, const char** argv ) {
76 // see header file for class documentation
79 TString argument = "";
80 TString parameter = "";
81 Int_t bMissingParam=0;
83 for ( Int_t ii=0; ii<argc && iResult>=0; ii++ ) {
86 if ( argument.IsNull() ) continue;
89 if ( argument.CompareTo("-eventmodulo") == 0 ) {
90 if ( ( bMissingParam=( ++ii >= argc ) ) ) break;
92 parameter.Remove(TString::kLeading, ' '); // remove all blanks
93 if (parameter.IsDigit()) {
94 fEventModulo = parameter.Atoi();
95 HLTInfo("EventModulo is set to %d.", fEventModulo);
98 HLTError("Cannot convert EventModulo specifier '%s'.", argv[ii]);
104 else if ( argument.CompareTo( "-usecorruptevents" ) == 0 ) {
105 HLTInfo( "Passing through of corrupted events enabled." );
106 fUseCorruptEvents = kTRUE;
108 // not known by calibration processor
110 if ( ( iResult = ScanArgument( argc-ii, &argv[ii] ) ) == -EINVAL ) {
111 HLTError( "unknown argument %s", argument.Data() );
114 else if ( iResult == -EPROTO ) {
118 else if ( iResult >= 0 ) {
125 if ( bMissingParam ) {
126 HLTError( "missing parameter for argument %s", argument.Data() );
130 if ( iResult >= 0 ) {
131 iResult = InitCalibration();
134 // Reset the DDLNumberList
135 memset( fDDLNumber, 0, gkAliHLTFXSHeaderfDDLNumberSize);
140 Int_t AliHLTCalibrationProcessor::InitCalibration() {
141 // see header file for class documentation
143 // fDummy is just touched here to avoid coding convention violation RC11.
144 // The function can not be declared const since it is just the default implementation,
145 // overloaded virtual function might not be const.
152 Int_t AliHLTCalibrationProcessor::ScanArgument(int argc, const char** argv) {
153 // see header file for class documentation
155 // there are no other arguments than the standard ones
156 if ( argc == 0 && argv == NULL) {
157 // this is just to get rid of the warning "unused parameter"
160 // fDummy is just touched here to avoid coding convention violation RC11.
161 // The function can not be declared const since it is just the default implementation,
162 // overloaded virtual function might not be const.
169 * ######################## DeinitCalibration #####################
172 Int_t AliHLTCalibrationProcessor::DoDeinit() {
173 // see header file for class documentation
175 int iResult = DeinitCalibration();
180 Int_t AliHLTCalibrationProcessor::DeinitCalibration() {
181 // see header file for class documentation
183 // fDummy is just touched here to avoid coding convention violation RC11.
184 // The function can not be declared const since it is just the default implementation,
185 // overloaded virtual function might not be const.
192 * ######################## DoEvent #####################
195 Int_t AliHLTCalibrationProcessor::DoEvent( const AliHLTComponentEventData& evtData,
196 const AliHLTComponentBlockData* blocks,
197 AliHLTComponentTriggerData& trigData,
198 AliHLTUInt8_t* outputPtr,
199 AliHLTUInt32_t& size,
200 vector<AliHLTComponentBlockData>& outputBlocks )
202 // see header file for class documentation
206 const AliHLTComponentBlockData* blkSOR = NULL;
207 blkSOR = GetFirstInputBlock( kAliHLTDataTypeSOR );
208 const AliHLTComponentBlockData* blkEOR = NULL;
209 blkEOR = GetFirstInputBlock( kAliHLTDataTypeEOR );
211 // ** if event Type is not SOR or EOR -> fill DDLNumber list and process data
212 if ( ! blkEOR && !blkSOR ) {
214 // ** Set DDLNumber List
215 if ( trigData.fData != NULL) {
216 AliHLTEventTriggerData* trg = ( AliHLTEventTriggerData* ) trigData.fData;
218 AliHLTEventDDL list = (AliHLTEventDDL) trg->fReadoutList;
220 Int_t wordNdx = GetFirstUsedDDLWord(list);
224 // Handle special TPC and TOF case
227 else if ( wordNdx == 12 )
230 // check word for word and binary OR it with existing DDLNumberList
231 for ( Int_t ndx = 0; ndx < wordCount; ndx++ ) {
232 AliHLTUInt32_t word = list.fList[wordNdx+ndx];
234 // set only 4 bit into one Char_t
235 for ( Int_t charNdx = 0; charNdx < 8; charNdx++) {
236 fDDLNumber[(8*ndx)+charNdx] |= (Char_t) word & 0x0000000F;
240 } // if ( wordNdx > 0 ) {
241 } // if ( trg != NULL) {
242 } // if ( trigData.fData != NULL) {
245 iResult = ProcessCalibration( evtData, blocks, trigData, outputPtr, size, outputBlocks );
249 // - if event Type is EOR or event modulo is set -> ship data to FXS
250 // - use event modulo ship data also during the run
251 if ( ( fEventModulo > 0 && fEventCounter == fEventModulo ) || blkEOR ){
252 HLTDebug ( "Ship Data to FXS!" );
253 iResult = ShipDataToFXS( evtData, blocks, trigData, outputPtr, size, outputBlocks );
261 * ######################## ProcessCalibration #####################
264 Int_t AliHLTCalibrationProcessor::ProcessCalibration( 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
272 // we just forward to the high level method, all other parameters already
273 // have been stored internally
274 return ProcessCalibration( evtData, trigData );
277 Int_t AliHLTCalibrationProcessor::ProcessCalibration( const AliHLTComponentEventData& /*evtData*/,
278 AliHLTComponentTriggerData& /*trigData*/) {
279 // see header file for class documentation
281 HLTFatal( "no processing method implemented" );
286 * ######################## ShipDataToFXS #####################
289 Int_t AliHLTCalibrationProcessor::ShipDataToFXS( const AliHLTComponentEventData& evtData,
290 const AliHLTComponentBlockData* /*blocks*/,
291 AliHLTComponentTriggerData& trigData,
292 AliHLTUInt8_t* /*outputPtr*/,
293 AliHLTUInt32_t& /*size*/,
294 vector<AliHLTComponentBlockData>& /*outputBlocks*/ ) {
295 // see header file for class documentation
297 // we just forward to the high level method, all other parameters already
298 // have been stored internally
299 return ShipDataToFXS( evtData, trigData );
303 Int_t AliHLTCalibrationProcessor::ShipDataToFXS( const AliHLTComponentEventData& /*evtData*/,
304 AliHLTComponentTriggerData& /*trigData*/) {
305 // see header file for class documentation
307 HLTFatal( "no processing method implemented" );
312 * ######################## CreateFXSHeader #####################
315 Int_t AliHLTCalibrationProcessor::CreateFXSHeader( AliHLTFXSHeader &pHeader, const char* pDetector, const char* pFileID, AliHLTEventDDL* pDDLList ) {
316 // see header file for class documentation
320 // ** Fill header version
321 pHeader.fHeaderVersion = AliHLTCalibrationProcessor::fgkFXSProtocolHeaderVersion;
323 // ** Fill run number
324 pHeader.fRunNumber = GetRunNo();
327 HLTDebug( "FXS Header Detector size max %i - actual %i .",gkAliHLTFXSHeaderfOriginSize, strlen( pDetector ) );
328 strncpy ( pHeader.fOrigin, pDetector, gkAliHLTFXSHeaderfOriginSize ) ;
330 // To take care if fileIDs which are longer than gkAliHLTFXSHeaderfOriginSize, write one 0 is cheaper than an if.
331 pHeader.fOrigin[gkAliHLTFXSHeaderfOriginSize] = 0;
334 HLTInfo( "FXS Header FileID size max %i - actual %i .",gkAliHLTFXSHeaderfFileIDSize, strlen( pFileID ) );
335 strncpy ( pHeader.fFileID, pFileID, gkAliHLTFXSHeaderfFileIDSize ) ;
337 // To take care if fileIDs which are longer than gkAliHLTFXSHeaderfFileIDSize, write one 0 is cheaper than an if.
338 pHeader.fFileID[gkAliHLTFXSHeaderfFileIDSize] = 0;
340 // ** Fill DDL number
342 // -- if component provides list, convert to fDDLNumber
346 Int_t wordNdx = GetFirstUsedDDLWord( *(pDDLList) );
350 // Handle special TPC and TOF case
353 else if ( wordNdx == 12 )
356 // check word for word
357 for ( Int_t ndx = 0; ndx < wordCount; ndx++ ) {
358 AliHLTUInt32_t word = pDDLList->fList[wordNdx+ndx];
360 // set only 4 bit into one Char_t
361 for ( Int_t charNdx = 0; charNdx < 8; charNdx++) {
362 fDDLNumber[(8*ndx)+charNdx] = (Char_t) word & 0x0000000F;
366 } // if ( wordNdx > 0 ) {
369 } // if ( pDDLList ) {
371 // -- fill header with ascii chars
372 for (Int_t ndx = 0; ndx < gkAliHLTFXSHeaderfDDLNumberSize; ndx++ ){
373 Int_t numberToChar = (Int_t) fDDLNumber[ndx];
375 if ( numberToChar > 9 ) numberToChar += 55;
376 else numberToChar += 48;
378 pHeader.fDDLNumber[ndx] = (Char_t) numberToChar;
382 } // Int_t AliHLTCalibrationProcessor::CreateFXSHeader( AliHLTXSHeader &pHeader, const char* pDetector, const char* pFileID, AliHLTEventDDL* pDDLList ) {
385 * ######################## PushToFXS #####################
388 Int_t AliHLTCalibrationProcessor::PushToFXS(TObject* pObject, const char* pDetector, const char* pFileID, AliHLTEventDDL* pDDLList ) {
389 // see header file for class documentation
393 AliHLTFXSHeader pHeader;
395 CreateFXSHeader( pHeader, pDetector, pFileID, pDDLList );
399 AliHLTMemoryFile* pMemFile = CreateMemoryFile( kAliHLTDataTypeFXSCalib, kAliHLTVoidDataSpec );
402 iResult = pMemFile->WriteHeaderBuffer( (const char*) &pHeader, AliHLTCalibrationProcessor::fgkFXSProtocolHeaderSize );
405 HLTError( "Buffer size to small - for header!" );
408 iResult = Write( pMemFile, pObject );
410 HLTError( "Buffer size to small - for data!" );
413 iResult = CloseMemoryFile( pMemFile );
427 } // Int_t AliHLTCalibrationProcessor::PushToFXS(TObject* pObject, const char* detector, const char* pFileID, AliHLTEventDDL* pDDLList ) {
429 Int_t AliHLTCalibrationProcessor::PushToFXS( void* pBuffer, int iSize, const char* pDetector, const char* pFileID, AliHLTEventDDL* pDDLList ) {
430 // see header file for class documentation
434 AliHLTFXSHeader pHeader;
436 CreateFXSHeader( pHeader, pDetector, pFileID, pDDLList );
438 iResult = PushBack( pBuffer, iSize, kAliHLTDataTypeFXSCalib, kAliHLTVoidDataSpec, (void*) (&pHeader), AliHLTCalibrationProcessor::fgkFXSProtocolHeaderSize );
442 } // Int_t AliHLTCalibrationProcessor::PushToFXS(void* pBuffer, int iSize, const char* pDdetector, const char* pFileID, AliHLTEventDDL* pDDLList ) {