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"
36 #include "AliHLTReadoutList.h"
41 #include <TObjString.h>
44 ClassImp(AliHLTCalibrationProcessor);
47 const AliHLTUInt32_t AliHLTCalibrationProcessor::fgkFXSProtocolHeaderSize = 204;
48 const AliHLTUInt32_t AliHLTCalibrationProcessor::fgkFXSProtocolHeaderVersion = 1;
51 * ################ Constructor / Destructor ####################
54 AliHLTCalibrationProcessor::AliHLTCalibrationProcessor() :
56 fUseCorruptEvents(kFALSE),
61 // see header file for class documentation
63 // refer to README to build package
65 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
68 AliHLTCalibrationProcessor::~AliHLTCalibrationProcessor() {
69 // see header file for class documentation
73 * ######################## InitCalibration #####################
76 Int_t AliHLTCalibrationProcessor::DoInit( int argc, const char** argv ) {
77 // see header file for class documentation
80 TString argument = "";
81 TString parameter = "";
82 Int_t bMissingParam=0;
84 for ( Int_t ii=0; ii<argc && iResult>=0; ii++ ) {
87 if ( argument.IsNull() ) continue;
90 if ( argument.CompareTo("-eventmodulo") == 0 ) {
91 if ( ( bMissingParam=( ++ii >= argc ) ) ) break;
93 parameter.Remove(TString::kLeading, ' '); // remove all blanks
94 if (parameter.IsDigit()) {
95 fEventModulo = parameter.Atoi();
96 HLTInfo("EventModulo is set to %d.", fEventModulo);
99 HLTError("Cannot convert EventModulo specifier '%s'.", argv[ii]);
105 else if ( argument.CompareTo( "-usecorruptevents" ) == 0 ) {
106 HLTInfo( "Passing through of corrupted events enabled." );
107 fUseCorruptEvents = kTRUE;
109 // not known by calibration processor
111 if ( ( iResult = ScanArgument( argc-ii, &argv[ii] ) ) == -EINVAL ) {
112 HLTError( "unknown argument %s", argument.Data() );
115 else if ( iResult == -EPROTO ) {
119 else if ( iResult >= 0 ) {
126 if ( bMissingParam ) {
127 HLTError( "missing parameter for argument %s", argument.Data() );
131 if ( iResult >= 0 ) {
132 iResult = InitCalibration();
135 // Reset the DDLNumberList
136 memset( fDDLNumber, 0, gkAliHLTFXSHeaderfDDLNumberSize);
141 Int_t AliHLTCalibrationProcessor::InitCalibration() {
142 // see header file for class documentation
144 // fDummy is just touched here to avoid coding convention violation RC11.
145 // The function can not be declared const since it is just the default implementation,
146 // overloaded virtual function might not be const.
153 Int_t AliHLTCalibrationProcessor::ScanArgument(int argc, const char** argv) {
154 // see header file for class documentation
156 // there are no other arguments than the standard ones
157 if ( argc == 0 && argv == NULL) {
158 // this is just to get rid of the warning "unused parameter"
161 // fDummy is just touched here to avoid coding convention violation RC11.
162 // The function can not be declared const since it is just the default implementation,
163 // overloaded virtual function might not be const.
170 * ######################## DeinitCalibration #####################
173 Int_t AliHLTCalibrationProcessor::DoDeinit() {
174 // see header file for class documentation
176 int iResult = DeinitCalibration();
181 Int_t AliHLTCalibrationProcessor::DeinitCalibration() {
182 // see header file for class documentation
184 // fDummy is just touched here to avoid coding convention violation RC11.
185 // The function can not be declared const since it is just the default implementation,
186 // overloaded virtual function might not be const.
193 * ######################## DoEvent #####################
196 Int_t AliHLTCalibrationProcessor::DoEvent( const AliHLTComponentEventData& evtData,
197 const AliHLTComponentBlockData* blocks,
198 AliHLTComponentTriggerData& trigData,
199 AliHLTUInt8_t* outputPtr,
200 AliHLTUInt32_t& size,
201 vector<AliHLTComponentBlockData>& outputBlocks )
203 // see header file for class documentation
207 const AliHLTComponentBlockData* blkSOR = NULL;
208 blkSOR = GetFirstInputBlock( kAliHLTDataTypeSOR );
209 const AliHLTComponentBlockData* blkEOR = NULL;
210 blkEOR = GetFirstInputBlock( kAliHLTDataTypeEOR );
212 // ** if event Type is not SOR or EOR -> fill DDLNumber list and process data
213 if ( ! blkEOR && !blkSOR ) {
215 iResult = ProcessCalibration( evtData, blocks, trigData, outputPtr, size, outputBlocks );
219 // - if event Type is EOR or event modulo is set -> ship data to FXS
220 // - use event modulo ship data also during the run
221 if ( ( fEventModulo > 0 && fEventCounter == fEventModulo ) || blkEOR ){
222 HLTDebug ( "Ship Data to FXS!" );
223 iResult = ShipDataToFXS( evtData, blocks, trigData, outputPtr, size, outputBlocks );
231 * ######################## ProcessCalibration #####################
234 Int_t AliHLTCalibrationProcessor::ProcessCalibration( const AliHLTComponentEventData& evtData,
235 const AliHLTComponentBlockData* /*blocks*/,
236 AliHLTComponentTriggerData& trigData,
237 AliHLTUInt8_t* /*outputPtr*/,
238 AliHLTUInt32_t& /*size*/,
239 vector<AliHLTComponentBlockData>& /*outputBlocks*/ ) {
240 // see header file for class documentation
242 // we just forward to the high level method, all other parameters already
243 // have been stored internally
244 return ProcessCalibration( evtData, trigData );
247 Int_t AliHLTCalibrationProcessor::ProcessCalibration( const AliHLTComponentEventData& /*evtData*/,
248 AliHLTComponentTriggerData& /*trigData*/) {
249 // see header file for class documentation
251 HLTFatal( "no processing method implemented" );
256 * ######################## ShipDataToFXS #####################
259 Int_t AliHLTCalibrationProcessor::ShipDataToFXS( const AliHLTComponentEventData& evtData,
260 const AliHLTComponentBlockData* /*blocks*/,
261 AliHLTComponentTriggerData& trigData,
262 AliHLTUInt8_t* /*outputPtr*/,
263 AliHLTUInt32_t& /*size*/,
264 vector<AliHLTComponentBlockData>& /*outputBlocks*/ ) {
265 // see header file for class documentation
267 // we just forward to the high level method, all other parameters already
268 // have been stored internally
269 return ShipDataToFXS( evtData, trigData );
273 Int_t AliHLTCalibrationProcessor::ShipDataToFXS( const AliHLTComponentEventData& /*evtData*/,
274 AliHLTComponentTriggerData& /*trigData*/) {
275 // see header file for class documentation
277 HLTFatal( "no processing method implemented" );
282 * ######################## CreateFXSHeader #####################
285 Int_t AliHLTCalibrationProcessor::CreateFXSHeader( AliHLTFXSHeader &pHeader, const char* pDetector, const char* pFileID, const AliHLTReadoutList* pDDLList ) {
286 // see header file for class documentation
290 // ** Fill header version
291 pHeader.fHeaderVersion = AliHLTCalibrationProcessor::fgkFXSProtocolHeaderVersion;
293 // ** Fill run number
294 pHeader.fRunNumber = GetRunNo();
297 HLTDebug( "FXS Header Detector size max %i - actual %i .",gkAliHLTFXSHeaderfOriginSize, strlen( pDetector ) );
298 strncpy ( pHeader.fOrigin, pDetector, gkAliHLTFXSHeaderfOriginSize ) ;
300 // To take care if fileIDs which are longer than gkAliHLTFXSHeaderfOriginSize, write one 0 is cheaper than an if.
301 pHeader.fOrigin[gkAliHLTFXSHeaderfOriginSize-1] = 0;
304 HLTDebug( "FXS Header FileID size max %i - actual %i .",gkAliHLTFXSHeaderfFileIDSize, strlen( pFileID ) );
305 strncpy ( pHeader.fFileID, pFileID, gkAliHLTFXSHeaderfFileIDSize ) ;
307 // To take care if fileIDs which are longer than gkAliHLTFXSHeaderfFileIDSize, write one 0 is cheaper than an if.
308 pHeader.fFileID[gkAliHLTFXSHeaderfFileIDSize-1] = 0;
310 // ** Fill DDL number
312 // -- if component provides list, convert to fDDLNumber
316 AliHLTReadoutList::EDetectorId detid = pDDLList->GetFirstUsedDetector();
317 Int_t wordNdx = AliHLTReadoutList::GetFirstWord(detid);
318 Int_t wordCount = AliHLTReadoutList::GetWordCount(detid);
320 if (pDDLList->GetFirstUsedDetector(detid) != AliHLTReadoutList::kNoDetector or wordNdx < 0)
322 HLTError("DDLIDs for minimum of TWO detectors ( %s, %s ) set, this function works only for ONE detector.",
323 AliHLTReadoutList::DetectorIdToString(detid),
324 AliHLTReadoutList::DetectorIdToString(pDDLList->GetFirstUsedDetector(detid))
330 // check word for word
331 for ( Int_t ndx = 0; ndx < wordCount; ndx++ ) {
332 AliHLTUInt32_t word = pDDLList->Buffer()->fList[wordNdx+ndx];
334 // set only 4 bit into one Char_t
335 for ( Int_t charNdx = 0; charNdx < 8; charNdx++) {
336 fDDLNumber[(8*ndx)+charNdx] = (Char_t) word & 0x0000000F;
341 } // if ( pDDLList ) {
343 // -- fill header with ascii chars
344 for (Int_t ndx = 0; ndx < gkAliHLTFXSHeaderfDDLNumberSize; ndx++ ){
345 Int_t numberToChar = (Int_t) fDDLNumber[ndx];
347 if ( numberToChar > 9 ) numberToChar += 55;
348 else numberToChar += 48;
350 pHeader.fDDLNumber[ndx] = (Char_t) numberToChar;
354 } // Int_t AliHLTCalibrationProcessor::CreateFXSHeader( AliHLTXSHeader &pHeader, const char* pDetector, const char* pFileID, const AliHLTReadoutList* pDDLList ) {
357 * ######################## PushToFXS #####################
360 Int_t AliHLTCalibrationProcessor::PushToFXS(TObject* pObject, const char* pDetector, const char* pFileID, const AliHLTReadoutList* pDDLList ) {
361 // see header file for class documentation
365 AliHLTFXSHeader pHeader;
367 CreateFXSHeader( pHeader, pDetector, pFileID, pDDLList );
371 AliHLTMemoryFile* pMemFile = CreateMemoryFile( kAliHLTDataTypeFXSCalib, kAliHLTVoidDataSpec );
374 iResult = pMemFile->WriteHeaderBuffer( (const char*) &pHeader, AliHLTCalibrationProcessor::fgkFXSProtocolHeaderSize );
377 HLTError( "Buffer size to small - for header!" );
380 iResult = Write( pMemFile, pObject );
382 HLTError( "Buffer size to small - for data!" );
385 iResult = CloseMemoryFile( pMemFile );
399 } // Int_t AliHLTCalibrationProcessor::PushToFXS(TObject* pObject, const char* detector, const char* pFileID, const AliHLTReadoutList* pDDLList ) {
401 Int_t AliHLTCalibrationProcessor::PushToFXS( void* pBuffer, int iSize, const char* pDetector, const char* pFileID, const AliHLTReadoutList* pDDLList ) {
402 // see header file for class documentation
406 AliHLTFXSHeader pHeader;
408 CreateFXSHeader( pHeader, pDetector, pFileID, pDDLList );
410 iResult = PushBack( pBuffer, iSize, kAliHLTDataTypeFXSCalib, kAliHLTVoidDataSpec, (void*) (&pHeader), AliHLTCalibrationProcessor::fgkFXSProtocolHeaderSize );
414 } // Int_t AliHLTCalibrationProcessor::PushToFXS(void* pBuffer, int iSize, const char* pDdetector, const char* pFileID, const AliHLTReadoutList* pDDLList ) {