From e1440dab8e252dd893dfddd97414351fc9089508 Mon Sep 17 00:00:00 2001 From: richterm Date: Sat, 24 Nov 2007 15:50:22 +0000 Subject: [PATCH] implemented TPCDigitDump and AltroChannelSelector --- HLT/BASE/util/AliHLTFileWriter.h | 2 + .../AliHLTAltroChannelSelectorComponent.cxx | 149 ++++++++++++++++-- .../AliHLTAltroChannelSelectorComponent.h | 16 ++ HLT/TPCLib/AliHLTTPCAgent.cxx | 10 +- HLT/TPCLib/AliHLTTPCDigitDumpComponent.cxx | 101 +++++++++++- HLT/TPCLib/AliHLTTPCDigitDumpComponent.h | 3 + HLT/TPCLib/AliHLTTPCDigitReaderRaw.cxx | 12 ++ HLT/TPCLib/AliHLTTPCDigitReaderRaw.h | 9 ++ 8 files changed, 283 insertions(+), 19 deletions(-) diff --git a/HLT/BASE/util/AliHLTFileWriter.h b/HLT/BASE/util/AliHLTFileWriter.h index f7d5395a8b1..14a58a17dba 100644 --- a/HLT/BASE/util/AliHLTFileWriter.h +++ b/HLT/BASE/util/AliHLTFileWriter.h @@ -217,8 +217,10 @@ class AliHLTFileWriter : public AliHLTDataSink { TString fSpecFormat; // see above /** format string for block no (when added to file name) */ TString fBlcknoFormat; // see above + protected: /** enumeration format string */ TString fCurrentFileName; // see above + private: /** mode specifier, see @ref TWriterMode */ Short_t fMode; // see above diff --git a/HLT/TPCLib/AliHLTAltroChannelSelectorComponent.cxx b/HLT/TPCLib/AliHLTAltroChannelSelectorComponent.cxx index c2af3b2569f..452f4d1d156 100644 --- a/HLT/TPCLib/AliHLTAltroChannelSelectorComponent.cxx +++ b/HLT/TPCLib/AliHLTAltroChannelSelectorComponent.cxx @@ -27,14 +27,20 @@ // or // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt +#include #include "AliHLTAltroChannelSelectorComponent.h" +#include "AliHLTTPCTransform.h" +#include "AliHLTTPCDigitReaderRaw.h" +#include "AliHLTTPCDefinitions.h" +#include "AliHLTTPCPadArray.h" /** ROOT macro for the implementation of ROOT specific class methods */ ClassImp(AliHLTAltroChannelSelectorComponent) AliHLTAltroChannelSelectorComponent::AliHLTAltroChannelSelectorComponent() : - AliHLTProcessor() + AliHLTProcessor(), + fRawreaderMode(0) { // see header file for class documentation // or @@ -86,17 +92,31 @@ int AliHLTAltroChannelSelectorComponent::DoInit(int argc, const char** argv) // see header file for class documentation int iResult=0; TString argument=""; + bool bMissingParam=0; for (int i=0; i=0; i++) { argument=argv[i]; if (argument.IsNull()) continue; - // - if (argument.CompareTo("-whatsoever")==0) { + // -rawreadermode + if (argument.CompareTo("-rawreadermode")==0) { + if ((bMissingParam=(++i>=argc))) break; + int mode=AliHLTTPCDigitReaderRaw::DecodeMode(argv[i]); + if (mode<0) { + HLTError("invalid rawreadermode specifier '%s'", argv[i]); + iResult=-EINVAL; + } else { + fRawreaderMode=static_cast(mode); + } } else { iResult=-EINVAL; } } + if (bMissingParam) { + HLTError("missing parameter for argument %s", argument.Data()); + iResult=-EINVAL; + } + return iResult; } @@ -116,17 +136,124 @@ int AliHLTAltroChannelSelectorComponent::DoEvent(const AliHLTComponentEventData& // see header file for class documentation int iResult=0; - // search for the active pad information - for (int n=0; n<(int)evtData.fBlockCnt; n++ ) { -// if (blocks[n].fDataType == ...) { - -// } + // process the DLL input + int blockno=0; + for (; blockno<(int)evtData.fBlockCnt; blockno++ ) { + if (blocks[blockno].fDataType != (kAliHLTDataTypeDDLRaw|kAliHLTDataOriginTPC)) continue; + + // search for the active pad information + AliHLTTPCPadArray::AliHLTTPCActivePads* pActivePadsArray=NULL; + int iNofActivePads=0; + for (int i=0; i<(int)evtData.fBlockCnt; i++ ) { + if (blocks[i].fDataType == AliHLTTPCDefinitions::fgkActivePadsDataType && + blocks[i].fSpecification==blocks[blockno].fSpecification) { + pActivePadsArray=reinterpret_cast(blocks[i].fPtr); + iNofActivePads=blocks[i].fSize/sizeof(AliHLTTPCPadArray::AliHLTTPCActivePads); + } + } + if (pActivePadsArray==NULL) { + HLTWarning("no block of type %s for specification 0x%08x available, data block unchanged", + DataType2Text(AliHLTTPCDefinitions::fgkActivePadsDataType).c_str(), + blocks[blockno].fSpecification); + // forward the whole block + outputBlocks.push_back(blocks[blockno]); + continue; + } + + int part=AliHLTTPCDefinitions::GetMinPatchNr(blocks[blockno]); + assert(part==AliHLTTPCDefinitions::GetMaxPatchNr(blocks[blockno])); + int slice=AliHLTTPCDefinitions::GetMinSliceNr(blocks[blockno]); + assert(slice==AliHLTTPCDefinitions::GetMaxSliceNr(blocks[blockno])); + int firstRow=AliHLTTPCTransform::GetFirstRow(part); + int lastRow=AliHLTTPCTransform::GetLastRow(part); + AliHLTTPCDigitReaderRaw reader(fRawreaderMode); + reader.InitBlock(blocks[blockno].fPtr,blocks[blockno].fSize,firstRow,lastRow,part,slice); + AliHLTUInt32_t iOutputSize=0; + AliHLTUInt32_t iCapacity=size; + while (reader.NextAltroBlock()) { + int active=0; + for (; active=iNofActivePads) { + HLTDebug("ALTRO block Row %d, Pad %d discarded (inactive)", reader.GetRow(), reader.GetPad()); + continue; + } + + void* pChannel=NULL; + AliHLTUInt16_t hwAddress=~(AliHLTUInt16_t)0; + int channelSize=reader.GetAltroChannelRawData(pChannel, hwAddress); + HLTDebug("ALTRO block Row/Pad %d/%d selected (active)", reader.GetRow(), reader.GetPad()); + if (channelSize>0 && pChannel!=NULL) { + if (iOutputSize==0) { + // first add the RCU trailer + unsigned rcuTrailerLength=reader.GetRCUDataBlockLength(); + AliHLTUInt8_t* pSrc=reinterpret_cast(blocks[blockno].fPtr); + pSrc+=blocks[blockno].fSize; + if ((iResult=CopyBlockToEnd(outputPtr, iCapacity, iOutputSize, pSrc, rcuTrailerLength))>=0) { + assert(iResult==rcuTrailerLength); + iOutputSize+=rcuTrailerLength; + } else { + HLTError("failed to writer RCU trailer of length %d for block %d", rcuTrailerLength, blockno); + break; + } + } + } + if ((iResult=CopyBlockToEnd(outputPtr, iCapacity, iOutputSize, pChannel, channelSize))>=0) { + assert(iResult==channelSize); + iOutputSize+=channelSize; + } else { + HLTError("failed to writer ALTRO channel of length %d for block %d", channelSize, blockno); + break; + } + } + if (iResult>=0) { + // write the common data header + int cdhSize=reader.GetCommonDataHeaderSize(); + if ((iResult=CopyBlockToEnd(outputPtr, iCapacity, iOutputSize, blocks[blockno].fPtr, cdhSize))>=0) { + assert(iResult==cdhSize); + iOutputSize+=cdhSize; + + // set new length of the data block + AliHLTUInt32_t* pCdhSize=reinterpret_cast(outputPtr+iCapacity-iOutputSize+1); + *pCdhSize=iOutputSize; + + // insert block descriptor + AliHLTComponentBlockData bd; + FillBlockData(bd); + bd.fOffset=iCapacity-iOutputSize; + bd.fSize=iOutputSize; + bd.fDataType=blocks[blockno].fDataType; + bd.fSpecification=blocks[blockno].fSpecification; + outputBlocks.push_back(bd); + iCapacity-=iOutputSize; + } else { + HLTError("failed to write CDH of length %d for block %d", cdhSize, blockno); + break; + } + } } - // process the DLL input - for (int n=0; n<(int)evtData.fBlockCnt; n++ ) { - if (blocks[n].fDataType != (kAliHLTDataTypeDDLRaw|kAliHLTDataOriginTPC)) continue; + if (iResult<0) { + outputBlocks.clear(); } + // !!! do not change the size since the output buffer is filled from the end !!! + + return iResult; +} + +int AliHLTAltroChannelSelectorComponent::CopyBlockToEnd(AliHLTUInt8_t* pTgt, unsigned capacity, unsigned position, void* pSrc, unsigned size) +{ + int iResult=0; + if (pTgt==NULL || pSrc==NULL) return -EINVAL; + if (capacity-positionAddComponent(new AliHLTAltroChannelSelectorComponent); + pHandler->AddComponent(new AliHLTTPCDigitDumpComponent); return 0; } diff --git a/HLT/TPCLib/AliHLTTPCDigitDumpComponent.cxx b/HLT/TPCLib/AliHLTTPCDigitDumpComponent.cxx index 550531ab22f..7b9e35b755b 100644 --- a/HLT/TPCLib/AliHLTTPCDigitDumpComponent.cxx +++ b/HLT/TPCLib/AliHLTTPCDigitDumpComponent.cxx @@ -27,14 +27,19 @@ // or // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt +#include #include "AliHLTTPCDigitDumpComponent.h" +#include "AliHLTTPCTransform.h" +#include "AliHLTTPCDigitReaderRaw.h" +#include "AliHLTTPCDefinitions.h" /** ROOT macro for the implementation of ROOT specific class methods */ ClassImp(AliHLTTPCDigitDumpComponent) AliHLTTPCDigitDumpComponent::AliHLTTPCDigitDumpComponent() : - AliHLTFileWriter() + AliHLTFileWriter(), + fRawreaderMode(0) { // see header file for class documentation // or @@ -78,17 +83,31 @@ int AliHLTTPCDigitDumpComponent::ScanArgument(int argc, const char** argv) // see header file for class documentation int iResult=0; TString argument=""; - for (int i=0; i=0; i++) { + bool bMissingParam=0; + int i=0; + for (; i=0; i++) { argument=argv[i]; if (argument.IsNull()) continue; - // - if (argument.CompareTo("-whatsoever")==0) { - } else { - iResult=-EINVAL; + // -rawreadermode + if (argument.CompareTo("-rawreadermode")==0) { + if ((bMissingParam=(++i>=argc))) break; + int mode=AliHLTTPCDigitReaderRaw::DecodeMode(argv[i]); + if (mode<0) { + HLTError("invalid rawreadermode specifier '%s'", argv[i]); + iResult=-EINVAL; + } else { + fRawreaderMode=static_cast(mode); + } + break; } } + if (bMissingParam) { + iResult=-EPROTO; + } + if (iResult>=0) iResult=i+1; + return iResult; } @@ -100,9 +119,77 @@ int AliHLTTPCDigitDumpComponent::CloseWriter() int AliHLTTPCDigitDumpComponent::DumpEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, - AliHLTComponentTriggerData& trigData ) + AliHLTComponentTriggerData& /*trigData*/ ) { // see header file for class documentation int iResult=0; + int iPrintedSlice=-1; + int iPrintedPart=-1; + int blockno=0; + HLTDebug("%d blocks", evtData.fBlockCnt); + for (; blockno<(int)evtData.fBlockCnt; blockno++ ) { + //HLTDebug("event %d block %d: %s 0x%08x size %d", evtData.fEventID, blockno, DataType2Text(blocks[blockno].fDataType).c_str(), blocks[blockno].fSpecification, blocks[blockno].fSize); + if (blocks[blockno].fDataType != (kAliHLTDataTypeDDLRaw|kAliHLTDataOriginTPC)) continue; + + TString filename; + iResult=BuildFileName(evtData.fEventID, blockno, blocks[blockno].fDataType, blocks[blockno].fSpecification, filename); + ios::openmode filemode=(ios::openmode)0; + if (fCurrentFileName.CompareTo(filename)==0) { + // append to the file + filemode=ios::app; + } else { + // store the file for the next block + fCurrentFileName=filename; + } + if (iResult>=0) { + ofstream dump(filename.Data(), filemode); + if (dump.good()) { + int part=AliHLTTPCDefinitions::GetMinPatchNr(blocks[blockno]); + assert(part==AliHLTTPCDefinitions::GetMaxPatchNr(blocks[blockno])); + int slice=AliHLTTPCDefinitions::GetMinSliceNr(blocks[blockno]); + assert(slice==AliHLTTPCDefinitions::GetMaxSliceNr(blocks[blockno])); + int firstRow=AliHLTTPCTransform::GetFirstRow(part); + int lastRow=AliHLTTPCTransform::GetLastRow(part); + AliHLTTPCDigitReaderRaw reader(fRawreaderMode); + reader.InitBlock(blocks[blockno].fPtr,blocks[blockno].fSize,firstRow,lastRow,part,slice); + + int iPrintedRow=-1; + int iPrintedPad=-1; + int iLastTime=-1; + while (reader.Next()) { + if (iPrintedSlice!=slice || iPrintedPart!=part) { + iPrintedSlice=slice; + iPrintedPart=part; + dump << "====================================================================" << endl; + dump << " Slice: " << iPrintedSlice << " Pad: " << iPrintedPad << endl; + } + if (iPrintedRow!=reader.GetRow()) { + iPrintedRow=reader.GetRow(); + dump << "--------------------------------------------------------------------" << endl; + dump << "Row: " << iPrintedRow << endl; + } + if (iPrintedPad!=reader.GetPad()) { + iPrintedPad=reader.GetPad(); + dump << " Pad: " << iPrintedPad << endl; + } + if (iPrintedPad!=reader.GetPad()) { + iPrintedPad=reader.GetPad(); + dump << " Pad: " << iPrintedPad << endl; + } + if (iLastTime!=reader.GetTime()+1 && iLastTime!=reader.GetTime()-1 ) { + dump << endl; + dump << " Time: " << reader.GetTime(); + } + iLastTime=reader.GetTime(); + dump << " " << reader.GetSignal() << endl; + } + dump << endl << endl; + } else { + HLTError("can not open file %s for writing", filename.Data()); + iResult=-EBADF; + } + dump.close(); + } + } return iResult; } diff --git a/HLT/TPCLib/AliHLTTPCDigitDumpComponent.h b/HLT/TPCLib/AliHLTTPCDigitDumpComponent.h index ac6e965ec19..be9d2ce227b 100644 --- a/HLT/TPCLib/AliHLTTPCDigitDumpComponent.h +++ b/HLT/TPCLib/AliHLTTPCDigitDumpComponent.h @@ -65,6 +65,9 @@ class AliHLTTPCDigitDumpComponent : public AliHLTFileWriter { /** assignment operator prohibited */ AliHLTTPCDigitDumpComponent& operator=(const AliHLTTPCDigitDumpComponent&); + /** the mode for the DigitReaderRaw */ + unsigned fRawreaderMode; //!transient + ClassDef(AliHLTTPCDigitDumpComponent, 0); }; diff --git a/HLT/TPCLib/AliHLTTPCDigitReaderRaw.cxx b/HLT/TPCLib/AliHLTTPCDigitReaderRaw.cxx index fb2dea56fb0..16f0cd02766 100644 --- a/HLT/TPCLib/AliHLTTPCDigitReaderRaw.cxx +++ b/HLT/TPCLib/AliHLTTPCDigitReaderRaw.cxx @@ -307,6 +307,18 @@ int AliHLTTPCDigitReaderRaw::GetTime() return GetRealTime(); } +int AliHLTTPCDigitReaderRaw::GetAltroChannelRawData(void* &pTgt, AliHLTUInt16_t &hwAddress) +{ + int iResult; + if (fBuffer==NULL) return -ENODATA; + if (fAltroBlockPositionBytes-fAltroBlockLengthBytes>GetCommonDataHeaderSize()) { + pTgt=fBuffer+(fAltroBlockPositionBytes-fAltroBlockLengthBytes+1); + iResult=fAltroBlockLengthBytes; + hwAddress=fAltroBlockHWAddress; + } + return iResult; +} + bool AliHLTTPCDigitReaderRaw::RealNext() { // see header file for class documentation diff --git a/HLT/TPCLib/AliHLTTPCDigitReaderRaw.h b/HLT/TPCLib/AliHLTTPCDigitReaderRaw.h index c2013e84c03..db881be8aff 100644 --- a/HLT/TPCLib/AliHLTTPCDigitReaderRaw.h +++ b/HLT/TPCLib/AliHLTTPCDigitReaderRaw.h @@ -103,6 +103,15 @@ public: virtual int GetSignal(); virtual int GetTime(); + /** + * Get pointer and size of the data of the current ALTRO channel. + * @param pTgt target to receive the pointer to the buffer + * @param hwAddress target to receive the hardware address + * @return size of the buffer set to pTgt in bytes on success, + * neg error code if failed + */ + int GetAltroChannelRawData(void* &pTgt, AliHLTUInt16_t &hwAddress); + bool Verify( bool verify ) { bool old = fVerify; -- 2.43.0