From: szostak Date: Tue, 25 Sep 2007 09:29:37 +0000 (+0000) Subject: Bug fix: The component was not behaving correctly when processing empty DDL data... X-Git-Url: http://git.uio.no/git/?p=u%2Fmrichter%2FAliRoot.git;a=commitdiff_plain;h=29486e5ae0f2078b8ed3ae084a77be7491a87269 Bug fix: The component was not behaving correctly when processing empty DDL data and caused system errors. Also: 1) Added a optional flag for logging warnings if we receive an unexpected data block type. 2) Removing unecessary memory copy and temporary buffer. --- diff --git a/HLT/MUON/OnlineAnalysis/AliHLTMUONHitReconstructor.cxx b/HLT/MUON/OnlineAnalysis/AliHLTMUONHitReconstructor.cxx index 7f130ee66ae..1f597804831 100644 --- a/HLT/MUON/OnlineAnalysis/AliHLTMUONHitReconstructor.cxx +++ b/HLT/MUON/OnlineAnalysis/AliHLTMUONHitReconstructor.cxx @@ -186,13 +186,18 @@ bool AliHLTMUONHitReconstructor::SetBusToDDLMap(BusToDDL busToDDL) } -bool AliHLTMUONHitReconstructor::Run(int* rawData, int *rawDataSize, AliHLTMUONRecHitStruct recHit[], int *nofHit) -{ +bool AliHLTMUONHitReconstructor::Run( + const AliHLTUInt32_t* rawData, + AliHLTUInt32_t rawDataSize, + AliHLTMUONRecHitStruct* recHit, + AliHLTUInt32_t& nofHit + ) +{ // main function called by HLTReconstructor to perform DHLT Hitreconstruction - fRecPoints = &recHit[0]; - fMaxRecPointsCount = *nofHit; - fRecPointsCount = nofHit; + fRecPoints = recHit; + fMaxRecPointsCount = nofHit; + fRecPointsCount = &nofHit; *fRecPointsCount = 0; fPadData[0].fDetElemId = 0; @@ -208,7 +213,7 @@ bool AliHLTMUONHitReconstructor::Run(int* rawData, int *rawDataSize, AliHLTMUONR fPadData[0].fCharge = 0 ; - if(!ReadDDL(rawData,rawDataSize)){ + if(!ReadDDL(rawData, rawDataSize)){ HLTError("Failed to read the complete DDL file"); return false; } @@ -222,19 +227,17 @@ bool AliHLTMUONHitReconstructor::Run(int* rawData, int *rawDataSize, AliHLTMUONR } -bool AliHLTMUONHitReconstructor::ReadDDL(int *rawData, int *rawDataSize) +bool AliHLTMUONHitReconstructor::ReadDDL( + const AliHLTUInt32_t* rawData, + AliHLTUInt32_t rawDataSize + ) { //function to read Raw Data files - int ddlRawDataSize; - ddlRawDataSize = *rawDataSize; - - int *buffer = rawData ; - //new int[ddlRawDataSize]; - //buffer = (int *)rawData; + const int* buffer = reinterpret_cast(rawData); fIdOffSet= fgkMinIdManuChannel[(fDDLId%2)]; - fDetManuChannelIdList = new int[ddlRawDataSize]; + fDetManuChannelIdList = new int[rawDataSize]; int index = 0; int dataCount = 0; @@ -674,16 +677,18 @@ bool AliHLTMUONHitReconstructor::MergeRecHits() if(diffX < halfPadLengthX && diffY < halfPadLengthY ){//&& fPadData[idCentralB].fIY != 0){ + // First check that we have not overflowed the buffer. + if((*fRecPointsCount) == fMaxRecPointsCount){ + HLTError("Nof RecHit (i.e. %d) exceeds the max nof RecHit limit %d\n",(*fRecPointsCount),fMaxRecPointsCount); + return false; + } + //fRecPoints[(*fRecPointsCount)].fId = idCentralB; fRecPoints[(*fRecPointsCount)].fX = fRecX[nb]; fRecPoints[(*fRecPointsCount)].fY = fRecY[b]; fRecPoints[(*fRecPointsCount)].fZ = fPadData[idCentralB].fRealZ; //fRecPoints[(*fRecPointsCount)].fDetElemId = (AliHLTUInt32_t)fPadData[idCentralB].fDetElemId; (*fRecPointsCount)++; - if((*fRecPointsCount) == fMaxRecPointsCount){ - HLTError("Nof RecHit (i.e. %d) exceeds the max nof RecHit limit %d\n",(*fRecPointsCount),fMaxRecPointsCount); - return false; - } }//if lies wihtin 5.0 mm }// condn over fRecX ! = 0.0 }// loop over NB side diff --git a/HLT/MUON/OnlineAnalysis/AliHLTMUONHitReconstructor.h b/HLT/MUON/OnlineAnalysis/AliHLTMUONHitReconstructor.h index 15bf5ff90f3..8e23e12bbe8 100644 --- a/HLT/MUON/OnlineAnalysis/AliHLTMUONHitReconstructor.h +++ b/HLT/MUON/OnlineAnalysis/AliHLTMUONHitReconstructor.h @@ -26,6 +26,7 @@ // sukalyan.chattopadhyay@saha.ac.in /////////////////////////////////////////////// +#include "AliHLTMUONDataTypes.h" #include #include #include @@ -81,7 +82,12 @@ public: bool SetBusToDetMap(BusToDetElem busToDetElem); bool SetBusToDDLMap(BusToDDL busToDDL); - bool Run(int* rawData, int *rawDataSize, AliHLTMUONRecHitStruct recHit[], int *nofHit); + bool Run( + const AliHLTUInt32_t* rawData, + AliHLTUInt32_t rawDataSize, + AliHLTMUONRecHitStruct* recHit, + AliHLTUInt32_t& nofHit + ); void SetDCCut(int dcCut) {fDCCut = dcCut;} void SetDebugLevel(int debugLevel) {fDebugLevel = debugLevel;} int GetDebugLevel() const {return fDebugLevel;} @@ -124,8 +130,8 @@ private: DHLTLut* fLookUpTableData; // pointer to the array of Lookuptable data AliHLTMUONRecHitStruct *fRecPoints; // Reconstructed hits - int *fRecPointsCount; // nof reconstructed hit - int fMaxRecPointsCount; // max nof reconstructed hit + AliHLTUInt32_t *fRecPointsCount; // nof reconstructed hit + AliHLTUInt32_t fMaxRecPointsCount; // max nof reconstructed hit int fCentralCountB, fCentralCountNB; // centeral hits int fIdOffSet,fDDLId; // DDLId and DDL id offset @@ -142,7 +148,7 @@ private: BusToDetElem fBusToDDL; // Mapping between bus address and DDL. - bool ReadDDL(int* rawData, int *rawDataSize); + bool ReadDDL(const AliHLTUInt32_t* rawData, AliHLTUInt32_t rawDataSize); void FindCentralHits(int minPadId, int maxPadId); bool FindRecHits() ; void RecXRecY(); diff --git a/HLT/MUON/OnlineAnalysis/AliHLTMUONHitReconstructorComponent.cxx b/HLT/MUON/OnlineAnalysis/AliHLTMUONHitReconstructorComponent.cxx index d8be51c461a..148bab59d38 100644 --- a/HLT/MUON/OnlineAnalysis/AliHLTMUONHitReconstructorComponent.cxx +++ b/HLT/MUON/OnlineAnalysis/AliHLTMUONHitReconstructorComponent.cxx @@ -34,8 +34,9 @@ #include "AliHLTLogging.h" #include "AliHLTSystem.h" #include "AliHLTDefinitions.h" -#include -#include +#include +#include +#include namespace { @@ -47,12 +48,12 @@ namespace ClassImp(AliHLTMUONHitReconstructorComponent) -AliHLTMUONHitReconstructorComponent::AliHLTMUONHitReconstructorComponent() - : - fHitRec(NULL), - fDDLDir(""), - fDDL(0), - fReaderType(false) +AliHLTMUONHitReconstructorComponent::AliHLTMUONHitReconstructorComponent() : + fHitRec(NULL), + fDDLDir(""), + fDDL(0), + fReaderType(false), + fWarnForUnexpecedBlock(false) { } @@ -63,45 +64,45 @@ AliHLTMUONHitReconstructorComponent::~AliHLTMUONHitReconstructorComponent() const char* AliHLTMUONHitReconstructorComponent::GetComponentID() { - return "MUONHitRec"; // The ID of this component + return AliHLTMUONConstants::HitReconstructorId(); } void AliHLTMUONHitReconstructorComponent::GetInputDataTypes( std::vector& list) { - list.clear(); - list.push_back( AliHLTMUONConstants::TrackingDDLRawDataType() ); + list.clear(); + list.push_back( AliHLTMUONConstants::TrackingDDLRawDataType() ); } AliHLTComponentDataType AliHLTMUONHitReconstructorComponent::GetOutputDataType() { - return AliHLTMUONConstants::RecHitsBlockDataType(); + return AliHLTMUONConstants::RecHitsBlockDataType(); } void AliHLTMUONHitReconstructorComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) { - constBase = 0; - inputMultiplier = 1; + constBase = 0; + inputMultiplier = 1; } // Spawn function, return new instance of this class AliHLTComponent* AliHLTMUONHitReconstructorComponent::Spawn() { - return new AliHLTMUONHitReconstructorComponent; + return new AliHLTMUONHitReconstructorComponent; } -int AliHLTMUONHitReconstructorComponent::DoInit( int argc, const char** argv ) +int AliHLTMUONHitReconstructorComponent::DoInit(int argc, const char** argv) { // perform initialization. We check whether our relative output size is specified in the arguments. HLTInfo("Initialising DHLT HitReconstruction Component"); fHitRec = new AliHLTMUONHitReconstructor(); - + fWarnForUnexpecedBlock = false; // this is to get rid of the warning "unused parameter" if (argc==0 && argv==NULL) { @@ -177,6 +178,12 @@ int AliHLTMUONHitReconstructorComponent::DoInit( int argc, const char** argv ) i += 1; continue; } + + if ( !strcmp( argv[i], "-warn_on_unexpected_block" ) ) { + fWarnForUnexpecedBlock = true; + i++; + continue; + } HLTError("Unknown option '%s'", argv[i] ); return EINVAL; @@ -231,103 +238,112 @@ int AliHLTMUONHitReconstructorComponent::DoEvent( std::vector& outputBlocks ) { - // Process an event - unsigned long totalSize = 0; - - HLTDebug("Event : %d has : %lu blocks",(int)evtData.fEventID,evtData.fBlockCnt); - - // Loop over all input blocks in the event - for ( unsigned long n = 0; n < evtData.fBlockCnt; n++ ) - { - - HLTDebug("block : %d, block rawData : %p, block.fSize (bytes) : %d, blocks.fDataType.fID : %s, blocks.fDataType.fOrigin : %s, required type : %s\n", - n,blocks[n].fPtr,blocks[n].fSize,(char *)(blocks[n].fDataType.fID), - (char *)(blocks[n].fDataType.fOrigin,(char *)(AliHLTMUONConstants::TrackingDDLRawDataType().fID))); - + // Process an event + unsigned long totalSize = 0; // Amount of memory currently consumed in bytes. - if(strncmp((char *)(blocks[n].fDataType.fID),(char *)(AliHLTMUONConstants::TrackingDDLRawDataType().fID),kAliHLTComponentDataTypefIDsize)) continue; - - - if ( totalSize > size ) - break; - - int totalDDLSize = blocks[n].fSize/sizeof(int); - - if(!totalDDLSize) continue; - - int ddlRawDataSize = totalDDLSize - fHitRec->GetkDDLHeaderSize(); - int *buffer = (int *)blocks[n].fPtr; - - - for(int j=0;jGetkDDLHeaderSize()) ; - - AliHLTMUONRecHitStruct recHit[300]; - int nofHit = 300; - - if(! (fHitRec->Run(buffer,&ddlRawDataSize,recHit,&nofHit))){ - HLTError("ERROR In Processing of HitRec Algo "); - return EIO; - } - - unsigned long mySize = sizeof(AliHLTMUONRecHitStruct) * nofHit; - - HLTDebug("Event %d and block %d has nofHit %d\n",(int)evtData.fEventID,n,nofHit); - - // Check how much space we have left and adapt this output block's size accordingly. - if ( totalSize + mySize > size ) - mySize = size-totalSize; - - Logging( kHLTLogDebug, "HLT::MUONHitRec::DoEvent", "mySize set (2)", "mySize == %lu B - totalSize == %lu - size == %lu", - mySize, totalSize, size ); - - if ( mySize<=0 ) - continue; // No room left to write a further block. - - AliHLTMUONRecHitsBlockWriter block(outputPtr+totalSize, size-totalSize); - if (not block.InitCommonHeader()) + HLTDebug("Processing event %llu with %u input data blocks.", + evtData.fEventID, evtData.fBlockCnt + ); + + // Loop over all input blocks in the event + for ( unsigned long n = 0; n < evtData.fBlockCnt; n++ ) { - HLTError("There is not enough space in the output buffer for the new data block.", - " We require at least %u bytes, but have %u bytes left.", - sizeof(AliHLTMUONRecHitsBlockWriter::HeaderType), - block.BufferSize() +#ifdef __DEBUG + char id[kAliHLTComponentDataTypefIDsize+1]; + for (int i = 0; i < kAliHLTComponentDataTypefIDsize; i++) + id[i] = blocks[n].fDataType.fID[i]; + id[kAliHLTComponentDataTypefIDsize] = '\0'; + char origin[kAliHLTComponentDataTypefOriginSize+1]; + for (int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++) + origin[i] = blocks[n].fDataType.fOrigin[i]; + origin[kAliHLTComponentDataTypefOriginSize] = '\0'; +#endif // __DEBUG + HLTDebug("Handling block: %u, with fDataType.fID = '%s'," + " fDataType.fID = '%s', fPtr = %p and fSize = %u bytes.", + n, static_cast(id), static_cast(origin), + blocks[n].fPtr, blocks[n].fSize ); - break; + + if (blocks[n].fDataType != AliHLTMUONConstants::TrackingDDLRawDataType()) + { + // Log a message indicating that we got a data block that we + // do not know how to handle. + char id[kAliHLTComponentDataTypefIDsize+1]; + for (int i = 0; i < kAliHLTComponentDataTypefIDsize; i++) + id[i] = blocks[n].fDataType.fID[i]; + id[kAliHLTComponentDataTypefIDsize] = '\0'; + char origin[kAliHLTComponentDataTypefOriginSize+1]; + for (int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++) + origin[i] = blocks[n].fDataType.fOrigin[i]; + origin[kAliHLTComponentDataTypefOriginSize] = '\0'; + + if (fWarnForUnexpecedBlock) + HLTWarning("Received a data block of a type we can not handle: %s origin %s", + static_cast(id), static_cast(origin) + ); + else + HLTDebug("Received a data block of a type we can not handle: %s origin %s", + static_cast(id), static_cast(origin) + ); + + continue; + } + + // Create a new output data block and initialise the header. + AliHLTMUONRecHitsBlockWriter block(outputPtr+totalSize, size-totalSize); + if (not block.InitCommonHeader()) + { + HLTError("There is not enough space in the output buffer for the new data block.", + " We require at least %u bytes, but have %u bytes left.", + sizeof(AliHLTMUONRecHitsBlockWriter::HeaderType), + block.BufferSize() + ); + break; + } + + AliHLTUInt32_t totalDDLSize = blocks[n].fSize / sizeof(AliHLTUInt32_t); + AliHLTUInt32_t ddlRawDataSize = totalDDLSize - fHitRec->GetkDDLHeaderSize(); + AliHLTUInt32_t* buffer = reinterpret_cast(blocks[n].fPtr) + + fHitRec->GetkDDLHeaderSize(); + AliHLTUInt32_t nofHit = block.MaxNumberOfEntries(); + + HLTDebug("=========== Dumping DDL payload buffer =========="); + for (AliHLTUInt32_t j = 0; j < totalDDLSize; j++) + HLTDebug("buffer[%d] : %x",j,buffer[j]); + HLTDebug("================== End of dump ================="); + + if (not fHitRec->Run(buffer, ddlRawDataSize, block.GetArray(), nofHit)) + { + HLTError("Error while processing of hit reconstruction algorithm."); + size = totalSize; // Must tell the framework how much buffer space was used. + return EIO; + } + + // nofHit should now contain the number of reconstructed hits actually found + // and filled into the output data block, so we can set this number. + assert( nofHit <= block.MaxNumberOfEntries() ); + block.SetNumberOfEntries(nofHit); + + HLTDebug("Number of reconstructed hits found is %d", nofHit); + + // Fill a block data structure for our output block. + AliHLTComponentBlockData bd; + FillBlockData(bd); + bd.fPtr = outputPtr; + // This block's start (offset) is after all other blocks written so far. + bd.fOffset = totalSize; + bd.fSize = block.BytesUsed(); + bd.fDataType = AliHLTMUONConstants::RecHitsBlockDataType(); + bd.fSpecification = blocks[n].fSpecification; + outputBlocks.push_back(bd); + + // Increase the total amount of data written so far to our output memory + totalSize += block.BytesUsed(); } - - // Now copy the input block - unsigned long copied = 0; - // First copy all full multiples of the input block - - // And the copy the remaining fragment of the block - Logging( kHLTLogDebug, "1 : HLT::MUONHitRec::DoEvent", "Copying", "Copying %lu B - Copied: %lu B - totalSize: %lu B", - mySize-copied, copied, totalSize ); - memcpy( block.GetArray(), &recHit[0], mySize); - Logging( kHLTLogDebug, "HLT::MUONHitRec::DoEvent", "Copied", "Copied: %lu B - totalSize: %lu B", - copied, totalSize ); - - block.SetNumberOfEntries(nofHit); - - // Fill a block data structure for our output block. - AliHLTComponentBlockData bd; - FillBlockData(bd); - bd.fPtr = outputPtr; - // This block's start (offset) is after all other blocks written so far. - bd.fOffset = totalSize; - bd.fSize = block.BytesUsed(); - bd.fDataType = AliHLTMUONConstants::RecHitsBlockDataType(); - bd.fSpecification = blocks[n].fSpecification; - outputBlocks.push_back(bd); - - // Increase the total amount of data written so far to our output memory - totalSize += block.BytesUsed(); - } - // Finally we set the total size of output memory we consumed. - size = totalSize; - - return 0; + // Finally we set the total size of output memory we consumed. + size = totalSize; + + return 0; } diff --git a/HLT/MUON/OnlineAnalysis/AliHLTMUONHitReconstructorComponent.h b/HLT/MUON/OnlineAnalysis/AliHLTMUONHitReconstructorComponent.h index 22298eca989..8241f0b3cb3 100644 --- a/HLT/MUON/OnlineAnalysis/AliHLTMUONHitReconstructorComponent.h +++ b/HLT/MUON/OnlineAnalysis/AliHLTMUONHitReconstructorComponent.h @@ -74,6 +74,7 @@ class AliHLTMUONHitReconstructorComponent : public AliHLTProcessor TString fDDLDir; Int_t fDDL; bool fReaderType; + bool fWarnForUnexpecedBlock; // Flag indicating if we should log a warning if we got a block of an unexpected type. ClassDef(AliHLTMUONHitReconstructorComponent, 0) };