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 **************************************************************************/
20 * @file AliHLTCalibrationProcessor.cxx
21 * @author Jochen Thaeder, Sebastian Bablok
23 * @brief Base class of HLT calibration components. */
25 // see header file for class documentation
27 // refer to README to build package
29 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
35 #include "AliHLTCalibrationProcessor.h"
36 #include "AliHLTMemoryFile.h"
37 #include "AliHLTReadoutList.h"
42 #include <TObjString.h>
45 ClassImp(AliHLTCalibrationProcessor);
48 const AliHLTUInt32_t AliHLTCalibrationProcessor::fgkFXSProtocolHeaderSize = 204;
49 const AliHLTUInt32_t AliHLTCalibrationProcessor::fgkFXSProtocolHeaderVersion = 1;
52 * ################ Constructor / Destructor ####################
55 AliHLTCalibrationProcessor::AliHLTCalibrationProcessor() :
57 fUseCorruptEvents(kFALSE),
62 // see header file for class documentation
64 // refer to README to build package
66 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
69 AliHLTCalibrationProcessor::~AliHLTCalibrationProcessor() {
70 // see header file for class documentation
74 * ######################## InitCalibration #####################
77 Int_t AliHLTCalibrationProcessor::DoInit( int argc, const char** argv ) {
78 // see header file for class documentation
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
85 TString argument = "";
86 TString parameter = "";
87 Int_t bMissingParam=0;
89 for ( Int_t ii=0; ii<argc && iResult>=0; ii++ ) {
92 if ( argument.IsNull() ) continue;
95 if ( argument.CompareTo("-eventmodulo") == 0 ) {
96 if ( ( bMissingParam=( ++ii >= argc ) ) ) break;
98 parameter.Remove(TString::kLeading, ' '); // remove all blanks
99 if (parameter.IsDigit()) {
100 fEventModulo = parameter.Atoi();
101 HLTInfo("EventModulo is set to %d.", fEventModulo);
104 HLTError("Cannot convert EventModulo specifier '%s'.", argv[ii]);
110 else if ( argument.CompareTo( "-usecorruptevents" ) == 0 ) {
111 HLTInfo( "Passing through of corrupted events enabled." );
112 fUseCorruptEvents = kTRUE;
114 // not known by calibration processor
116 if ( ( iResult = ScanArgument( argc-ii, &argv[ii] ) ) == -EINVAL ) {
117 HLTError( "unknown argument %s", argument.Data() );
120 else if ( iResult == -EPROTO ) {
124 else if ( iResult >= 0 ) {
131 if ( bMissingParam ) {
132 HLTError( "missing parameter for argument %s", argument.Data() );
136 if ( iResult >= 0 ) {
137 iResult = InitCalibration();
140 // Reset the DDLNumberList
141 memset( fDDLNumber, 0, gkAliHLTFXSHeaderfDDLNumberSize);
146 Int_t AliHLTCalibrationProcessor::InitCalibration() {
147 // see header file for class documentation
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.
158 Int_t AliHLTCalibrationProcessor::ScanArgument(int argc, const char** argv) {
159 // see header file for class documentation
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"
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.
175 * ######################## DeinitCalibration #####################
178 Int_t AliHLTCalibrationProcessor::DoDeinit() {
179 // see header file for class documentation
181 int iResult = DeinitCalibration();
186 Int_t AliHLTCalibrationProcessor::DeinitCalibration() {
187 // see header file for class documentation
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.
198 * ######################## DoEvent #####################
201 Int_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 )
208 // see header file for class documentation
212 const AliHLTComponentBlockData* blkSOR = NULL;
213 blkSOR = GetFirstInputBlock( kAliHLTDataTypeSOR );
214 const AliHLTComponentBlockData* blkEOR = NULL;
215 blkEOR = GetFirstInputBlock( kAliHLTDataTypeEOR );
217 // ** if event Type is not SOR or EOR -> fill DDLNumber list and process data
218 if ( ! blkEOR && !blkSOR ) {
220 iResult = ProcessCalibration( evtData, blocks, trigData, outputPtr, size, outputBlocks );
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 );
236 * ######################## ProcessCalibration #####################
239 Int_t AliHLTCalibrationProcessor::ProcessCalibration( const AliHLTComponentEventData& evtData,
240 const AliHLTComponentBlockData* /*blocks*/,
241 AliHLTComponentTriggerData& trigData,
242 AliHLTUInt8_t* /*outputPtr*/,
243 AliHLTUInt32_t& /*size*/,
244 vector<AliHLTComponentBlockData>& /*outputBlocks*/ ) {
245 // see header file for class documentation
247 // we just forward to the high level method, all other parameters already
248 // have been stored internally
249 return ProcessCalibration( evtData, trigData );
252 Int_t AliHLTCalibrationProcessor::ProcessCalibration( const AliHLTComponentEventData& /*evtData*/,
253 AliHLTComponentTriggerData& /*trigData*/) {
254 // see header file for class documentation
256 HLTFatal( "no processing method implemented" );
261 * ######################## ShipDataToFXS #####################
264 Int_t AliHLTCalibrationProcessor::ShipDataToFXS( 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 ShipDataToFXS( evtData, trigData );
278 Int_t AliHLTCalibrationProcessor::ShipDataToFXS( const AliHLTComponentEventData& /*evtData*/,
279 AliHLTComponentTriggerData& /*trigData*/) {
280 // see header file for class documentation
282 HLTFatal( "no processing method implemented" );
287 * ######################## CreateFXSHeader #####################
290 Int_t AliHLTCalibrationProcessor::CreateFXSHeader( AliHLTFXSHeader &pHeader, const char* pDetector, const char* pFileID, const AliHLTReadoutList* pDDLList ) {
291 // see header file for class documentation
295 // ** Fill header version
296 pHeader.fHeaderVersion = AliHLTCalibrationProcessor::fgkFXSProtocolHeaderVersion;
298 // ** Fill run number
299 pHeader.fRunNumber = GetRunNo();
302 HLTDebug( "FXS Header Detector size max %i - actual %i .",gkAliHLTFXSHeaderfOriginSize, strlen( pDetector ) );
303 strncpy ( pHeader.fOrigin, pDetector, gkAliHLTFXSHeaderfOriginSize ) ;
305 // To take care if fileIDs which are longer than gkAliHLTFXSHeaderfOriginSize, write one 0 is cheaper than an if.
306 pHeader.fOrigin[gkAliHLTFXSHeaderfOriginSize-1] = 0;
309 HLTDebug( "FXS Header FileID size max %i - actual %i .",gkAliHLTFXSHeaderfFileIDSize, strlen( pFileID ) );
310 strncpy ( pHeader.fFileID, pFileID, gkAliHLTFXSHeaderfFileIDSize ) ;
312 // To take care if fileIDs which are longer than gkAliHLTFXSHeaderfFileIDSize, write one 0 is cheaper than an if.
313 pHeader.fFileID[gkAliHLTFXSHeaderfFileIDSize-1] = 0;
315 // ** Fill DDL number
317 // -- if component provides list, convert to fDDLNumber
321 AliHLTReadoutList::EDetectorId detid = pDDLList->GetFirstUsedDetector();
322 Int_t wordNdx = AliHLTReadoutList::GetFirstWord(detid);
323 Int_t wordCount = AliHLTReadoutList::GetWordCount(detid);
325 if (pDDLList->GetFirstUsedDetector(detid) != AliHLTReadoutList::kNoDetector or wordNdx < 0)
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))
335 // check word for word
336 for ( Int_t ndx = 0; ndx < wordCount; ndx++ ) {
337 AliHLTUInt32_t word = pDDLList->Buffer()->fList[wordNdx+ndx];
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;
346 } // if ( pDDLList ) {
348 // -- fill header with ascii chars
349 for (Int_t ndx = 0; ndx < gkAliHLTFXSHeaderfDDLNumberSize; ndx++ ){
350 Int_t numberToChar = (Int_t) fDDLNumber[ndx];
352 if ( numberToChar > 9 ) numberToChar += 55;
353 else numberToChar += 48;
355 pHeader.fDDLNumber[ndx] = (Char_t) numberToChar;
359 } // Int_t AliHLTCalibrationProcessor::CreateFXSHeader( AliHLTXSHeader &pHeader, const char* pDetector, const char* pFileID, const AliHLTReadoutList* pDDLList ) {
362 * ######################## PushToFXS #####################
365 Int_t AliHLTCalibrationProcessor::PushToFXS(TObject* pObject, const char* pDetector, const char* pFileID, const AliHLTReadoutList* pDDLList ) {
366 // see header file for class documentation
370 AliHLTFXSHeader pHeader;
372 CreateFXSHeader( pHeader, pDetector, pFileID, pDDLList );
376 AliHLTMemoryFile* pMemFile = CreateMemoryFile( kAliHLTDataTypeFXSCalib, kAliHLTVoidDataSpec );
379 iResult = pMemFile->WriteHeaderBuffer( (const char*) &pHeader, AliHLTCalibrationProcessor::fgkFXSProtocolHeaderSize );
382 HLTError( "Buffer size to small - for header!" );
385 iResult = Write( pMemFile, pObject );
387 HLTError( "Buffer size to small - for data!" );
390 iResult = CloseMemoryFile( pMemFile );
404 } // Int_t AliHLTCalibrationProcessor::PushToFXS(TObject* pObject, const char* detector, const char* pFileID, const AliHLTReadoutList* pDDLList ) {
406 Int_t AliHLTCalibrationProcessor::PushToFXS( void* pBuffer, int iSize, const char* pDetector, const char* pFileID, const AliHLTReadoutList* pDDLList ) {
407 // see header file for class documentation
411 AliHLTFXSHeader pHeader;
413 CreateFXSHeader( pHeader, pDetector, pFileID, pDDLList );
415 iResult = PushBack( pBuffer, iSize, kAliHLTDataTypeFXSCalib, kAliHLTVoidDataSpec, (void*) (&pHeader), AliHLTCalibrationProcessor::fgkFXSProtocolHeaderSize );
419 } // Int_t AliHLTCalibrationProcessor::PushToFXS(void* pBuffer, int iSize, const char* pDdetector, const char* pFileID, const AliHLTReadoutList* pDDLList ) {