2 //**************************************************************************
3 //* This file is property of and copyright by the ALICE HLT Project *
4 //* ALICE Experiment at CERN, All rights reserved. *
6 //* Primary Authors: Jochen Thaeder <thaeder@kip.uni-heidelberg.de> *
8 //* for The ALICE HLT Project. *
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 //**************************************************************************
19 // @file AliHLTCalibrationProcessor.cxx
20 // @author Jochen Thaeder, Sebastian Bablok
22 // @brief Base class of HLT calibration components.
25 #include "AliHLTCalibrationProcessor.h"
26 #include "AliHLTMemoryFile.h"
27 #include "AliHLTReadoutList.h"
32 #include <TObjString.h>
35 ClassImp(AliHLTCalibrationProcessor);
37 const AliHLTUInt32_t AliHLTCalibrationProcessor::fgkFXSProtocolHeaderSize = 204;
38 const AliHLTUInt32_t AliHLTCalibrationProcessor::fgkFXSProtocolHeaderVersion = 1;
41 * ################ Constructor / Destructor ####################
44 AliHLTCalibrationProcessor::AliHLTCalibrationProcessor() :
46 fUseCorruptEvents(kFALSE),
51 // see header file for class documentation
53 // refer to README to build package
55 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
58 AliHLTCalibrationProcessor::~AliHLTCalibrationProcessor() {
59 // see header file for class documentation
63 * ######################## InitCalibration #####################
66 Int_t AliHLTCalibrationProcessor::DoInit( int argc, const char** argv ) {
67 // see header file for class documentation
69 // TODO: revision of argument scan needed, adjust to the new base class
70 // methods for argument scan
71 // call the configuration from the default OCDB object before the argument
72 // scan to override in correct sequence
74 TString argument = "";
75 TString parameter = "";
76 Int_t bMissingParam=0;
78 for ( Int_t ii=0; ii<argc && iResult>=0; ii++ ) {
81 if ( argument.IsNull() ) continue;
84 if ( argument.CompareTo("-eventmodulo") == 0 ) {
85 if ( ( bMissingParam=( ++ii >= argc ) ) ) break;
87 parameter.Remove(TString::kLeading, ' '); // remove all blanks
88 if (parameter.IsDigit()) {
89 fEventModulo = parameter.Atoi();
90 HLTInfo("EventModulo is set to %d.", fEventModulo);
93 HLTError("Cannot convert EventModulo specifier '%s'.", argv[ii]);
99 else if ( argument.CompareTo( "-usecorruptevents" ) == 0 ) {
100 HLTInfo( "Passing through of corrupted events enabled." );
101 fUseCorruptEvents = kTRUE;
103 // not known by calibration processor
105 if ( ( iResult = ScanArgument( argc-ii, &argv[ii] ) ) == -EINVAL ) {
106 HLTError( "unknown argument %s", argument.Data() );
109 else if ( iResult == -EPROTO ) {
113 else if ( iResult >= 0 ) {
120 if ( bMissingParam ) {
121 HLTError( "missing parameter for argument %s", argument.Data() );
125 if ( iResult >= 0 ) {
126 iResult = InitCalibration();
129 // Reset the DDLNumberList
130 memset( fDDLNumber, 0, gkAliHLTFXSHeaderfDDLNumberSize);
135 Int_t AliHLTCalibrationProcessor::InitCalibration() {
136 // see header file for class documentation
138 // fDummy is just touched here to avoid coding convention violation RC11.
139 // The function can not be declared const since it is just the default implementation,
140 // overloaded virtual function might not be const.
147 Int_t AliHLTCalibrationProcessor::ScanArgument(int argc, const char** argv) {
148 // see header file for class documentation
150 // there are no other arguments than the standard ones
151 if ( argc == 0 && argv == NULL) {
152 // this is just to get rid of the warning "unused parameter"
155 // fDummy is just touched here to avoid coding convention violation RC11.
156 // The function can not be declared const since it is just the default implementation,
157 // overloaded virtual function might not be const.
164 * ######################## DeinitCalibration #####################
167 Int_t AliHLTCalibrationProcessor::DoDeinit() {
168 // see header file for class documentation
170 int iResult = DeinitCalibration();
175 Int_t AliHLTCalibrationProcessor::DeinitCalibration() {
176 // see header file for class documentation
178 // fDummy is just touched here to avoid coding convention violation RC11.
179 // The function can not be declared const since it is just the default implementation,
180 // overloaded virtual function might not be const.
187 * ######################## DoEvent #####################
190 Int_t AliHLTCalibrationProcessor::DoEvent( const AliHLTComponentEventData& evtData,
191 const AliHLTComponentBlockData* blocks,
192 AliHLTComponentTriggerData& trigData,
193 AliHLTUInt8_t* outputPtr,
194 AliHLTUInt32_t& size,
195 vector<AliHLTComponentBlockData>& outputBlocks )
197 // see header file for class documentation
201 const AliHLTComponentBlockData* blkSOR = NULL;
202 blkSOR = GetFirstInputBlock( kAliHLTDataTypeSOR );
203 const AliHLTComponentBlockData* blkEOR = NULL;
204 blkEOR = GetFirstInputBlock( kAliHLTDataTypeEOR );
206 // ** if event Type is not SOR or EOR -> fill DDLNumber list and process data
207 if ( ! blkEOR && !blkSOR ) {
209 iResult = ProcessCalibration( evtData, blocks, trigData, outputPtr, size, outputBlocks );
213 // - if event Type is EOR or event modulo is set -> ship data to FXS
214 // - use event modulo ship data also during the run
215 if ( ( fEventModulo > 0 && fEventCounter == fEventModulo ) || blkEOR ){
216 HLTDebug ( "Ship Data to FXS!" );
217 iResult = ShipDataToFXS( evtData, blocks, trigData, outputPtr, size, outputBlocks );
225 * ######################## ProcessCalibration #####################
228 Int_t AliHLTCalibrationProcessor::ProcessCalibration( const AliHLTComponentEventData& evtData,
229 const AliHLTComponentBlockData* /*blocks*/,
230 AliHLTComponentTriggerData& trigData,
231 AliHLTUInt8_t* /*outputPtr*/,
232 AliHLTUInt32_t& /*size*/,
233 vector<AliHLTComponentBlockData>& /*outputBlocks*/ ) {
234 // see header file for class documentation
236 // we just forward to the high level method, all other parameters already
237 // have been stored internally
238 return ProcessCalibration( evtData, trigData );
241 Int_t AliHLTCalibrationProcessor::ProcessCalibration( const AliHLTComponentEventData& /*evtData*/,
242 AliHLTComponentTriggerData& /*trigData*/) {
243 // see header file for class documentation
245 HLTFatal( "no processing method implemented" );
250 * ######################## ShipDataToFXS #####################
253 Int_t AliHLTCalibrationProcessor::ShipDataToFXS( const AliHLTComponentEventData& evtData,
254 const AliHLTComponentBlockData* /*blocks*/,
255 AliHLTComponentTriggerData& trigData,
256 AliHLTUInt8_t* /*outputPtr*/,
257 AliHLTUInt32_t& /*size*/,
258 vector<AliHLTComponentBlockData>& /*outputBlocks*/ ) {
259 // see header file for class documentation
261 // we just forward to the high level method, all other parameters already
262 // have been stored internally
263 return ShipDataToFXS( evtData, trigData );
267 Int_t AliHLTCalibrationProcessor::ShipDataToFXS( const AliHLTComponentEventData& /*evtData*/,
268 AliHLTComponentTriggerData& /*trigData*/) {
269 // see header file for class documentation
271 HLTFatal( "no processing method implemented" );
276 * ######################## CreateFXSHeader #####################
279 Int_t AliHLTCalibrationProcessor::CreateFXSHeader( AliHLTFXSHeader &pHeader, const char* pDetector, const char* pFileID, const AliHLTReadoutList* pDDLList ) {
280 // see header file for class documentation
284 // ** Fill header version
285 pHeader.fHeaderVersion = AliHLTCalibrationProcessor::fgkFXSProtocolHeaderVersion;
287 // ** Fill run number
288 pHeader.fRunNumber = GetRunNo();
291 HLTDebug( "FXS Header Detector size max %i - actual %i .",gkAliHLTFXSHeaderfOriginSize, strlen( pDetector ) );
292 strncpy ( pHeader.fOrigin, pDetector, gkAliHLTFXSHeaderfOriginSize ) ;
294 // To take care if fileIDs which are longer than gkAliHLTFXSHeaderfOriginSize, write one 0 is cheaper than an if.
295 pHeader.fOrigin[gkAliHLTFXSHeaderfOriginSize-1] = 0;
298 HLTDebug( "FXS Header FileID size max %i - actual %i .",gkAliHLTFXSHeaderfFileIDSize, strlen( pFileID ) );
299 strncpy ( pHeader.fFileID, pFileID, gkAliHLTFXSHeaderfFileIDSize ) ;
301 // To take care if fileIDs which are longer than gkAliHLTFXSHeaderfFileIDSize, write one 0 is cheaper than an if.
302 pHeader.fFileID[gkAliHLTFXSHeaderfFileIDSize-1] = 0;
304 // ** Fill DDL number
306 // -- if component provides list, convert to fDDLNumber
310 AliHLTReadoutList::EDetectorId detid = pDDLList->GetFirstUsedDetector();
311 Int_t wordNdx = AliHLTReadoutList::GetFirstWord(detid);
312 Int_t wordCount = AliHLTReadoutList::GetWordCount(detid);
314 if (pDDLList->GetFirstUsedDetector(detid) != AliHLTReadoutList::kNoDetector or wordNdx < 0)
316 HLTError("DDLIDs for minimum of TWO detectors ( %s, %s ) set, this function works only for ONE detector.",
317 AliHLTReadoutList::DetectorIdToString(detid),
318 AliHLTReadoutList::DetectorIdToString(pDDLList->GetFirstUsedDetector(detid))
324 // check word for word
325 for ( Int_t ndx = 0; ndx < wordCount; ndx++ ) {
326 AliHLTUInt32_t word = pDDLList->Buffer()->fList[wordNdx+ndx];
328 // set only 4 bit into one Char_t
329 for ( Int_t charNdx = 0; charNdx < 8; charNdx++) {
330 fDDLNumber[(8*ndx)+charNdx] = (Char_t) word & 0x0000000F;
335 } // if ( pDDLList ) {
337 // -- fill header with ascii chars
338 for (Int_t ndx = 0; ndx < gkAliHLTFXSHeaderfDDLNumberSize; ndx++ ){
339 Int_t numberToChar = (Int_t) fDDLNumber[ndx];
341 if ( numberToChar > 9 ) numberToChar += 55;
342 else numberToChar += 48;
344 pHeader.fDDLNumber[ndx] = (Char_t) numberToChar;
348 } // Int_t AliHLTCalibrationProcessor::CreateFXSHeader( AliHLTXSHeader &pHeader, const char* pDetector, const char* pFileID, const AliHLTReadoutList* pDDLList ) {
351 * ######################## PushToFXS #####################
354 Int_t AliHLTCalibrationProcessor::PushToFXS(TObject* pObject, const char* pDetector, const char* pFileID, const AliHLTReadoutList* pDDLList ) {
355 // see header file for class documentation
359 AliHLTFXSHeader pHeader;
361 CreateFXSHeader( pHeader, pDetector, pFileID, pDDLList );
365 AliHLTMemoryFile* pMemFile = CreateMemoryFile( kAliHLTDataTypeFXSCalib, kAliHLTVoidDataSpec );
368 iResult = pMemFile->WriteHeaderBuffer( (const char*) &pHeader, AliHLTCalibrationProcessor::fgkFXSProtocolHeaderSize );
371 HLTError( "Buffer size to small - for header!" );
374 iResult = Write( pMemFile, pObject );
376 HLTError( "Buffer size to small - for data!" );
379 iResult = CloseMemoryFile( pMemFile );
393 } // Int_t AliHLTCalibrationProcessor::PushToFXS(TObject* pObject, const char* detector, const char* pFileID, const AliHLTReadoutList* pDDLList ) {
395 Int_t AliHLTCalibrationProcessor::PushToFXS( void* pBuffer, int iSize, const char* pDetector, const char* pFileID, const AliHLTReadoutList* pDDLList ) {
396 // see header file for class documentation
400 AliHLTFXSHeader pHeader;
402 CreateFXSHeader( pHeader, pDetector, pFileID, pDDLList );
404 iResult = PushBack( pBuffer, iSize, kAliHLTDataTypeFXSCalib, kAliHLTVoidDataSpec, (void*) (&pHeader), AliHLTCalibrationProcessor::fgkFXSProtocolHeaderSize );
408 } // Int_t AliHLTCalibrationProcessor::PushToFXS(void* pBuffer, int iSize, const char* pDdetector, const char* pFileID, const AliHLTReadoutList* pDDLList ) {