]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
implemented TPCDigitDump and AltroChannelSelector
authorrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Sat, 24 Nov 2007 15:50:22 +0000 (15:50 +0000)
committerrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Sat, 24 Nov 2007 15:50:22 +0000 (15:50 +0000)
HLT/BASE/util/AliHLTFileWriter.h
HLT/TPCLib/AliHLTAltroChannelSelectorComponent.cxx
HLT/TPCLib/AliHLTAltroChannelSelectorComponent.h
HLT/TPCLib/AliHLTTPCAgent.cxx
HLT/TPCLib/AliHLTTPCDigitDumpComponent.cxx
HLT/TPCLib/AliHLTTPCDigitDumpComponent.h
HLT/TPCLib/AliHLTTPCDigitReaderRaw.cxx
HLT/TPCLib/AliHLTTPCDigitReaderRaw.h

index f7d5395a8b166b65e528aa01ec320a6afebb72e7..14a58a17dba4f6b61e0a2b6491b1e5763ce52b9b 100644 (file)
@@ -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
index c2af3b2569f55e0e2ae5eb05dbe6a5be8aea705f..452f4d1d1562f34ff8545c624ead6a269ec68723 100644 (file)
 // or
 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
 
+#include <cassert>
 #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<argc && iResult>=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<unsigned>(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<AliHLTTPCPadArray::AliHLTTPCActivePads*>(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; active++) {
+       if (pActivePadsArray[active].fRow==reader.GetRow() &&
+           pActivePadsArray[active].fPad==reader.GetPad()) {
+         break;
+       }
+      }
+      if (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<AliHLTUInt8_t*>(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<AliHLTUInt32_t*>(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-position<size) return -ENOSPC;
+  
+  memcpy(pTgt+(capacity-position-size), pSrc, size);
+  iResult=size;
+  
   return iResult;
 }
index 35e8105645f9f3f66a08fb1e09e43b2fc6f4eba6..d1b8406425cdfb209a1912af1d042e7d036d3eba 100644 (file)
@@ -68,6 +68,22 @@ class AliHLTAltroChannelSelectorComponent : public AliHLTProcessor {
   /** assignment operator prohibited */
   AliHLTAltroChannelSelectorComponent& operator=(const AliHLTAltroChannelSelectorComponent&);
 
+  /**
+   * Copy a data block at the end of a buffer.
+   * The source buffer is inserted at given position relative to the buffer
+   * end.
+   * @param pTgt       target buffer
+   * @param capacity   capacity (size) of the buffer
+   * @param position   porition relative to the END of the buffer
+   * @param pSrc       source buffer to be copied
+   * @param size       size of the source buffer
+   * @return copied size, neg error code if failed
+   */
+  int CopyBlockToEnd(AliHLTUInt8_t* pTgt, unsigned capacity, unsigned position, void* pSrc, unsigned size);
+
+  /** the mode for the DigitReaderRaw */
+  unsigned fRawreaderMode; //!transient
+
   ClassDef(AliHLTAltroChannelSelectorComponent, 0);
 };
 
index 9320d94c5949896674a8ec02146736ab3448c500..7e4085a122136c956f33b85d19591819d99198cc 100644 (file)
 /** global instance for agent registration */
 AliHLTTPCAgent gAliHLTTPCAgent;
 
+// component headers
+#include "AliHLTAltroChannelSelectorComponent.h"
+#include "AliHLTTPCDigitDumpComponent.h"
+
 /** ROOT macro for the implementation of ROOT specific class methods */
 ClassImp(AliHLTTPCAgent)
 
@@ -110,7 +114,11 @@ const char* AliHLTTPCAgent::GetRequiredComponentLibraries() const
   return NULL;
 }
 
-int AliHLTTPCAgent::RegisterComponents(AliHLTComponentHandler* /*pHandler*/) const
+int AliHLTTPCAgent::RegisterComponents(AliHLTComponentHandler* pHandler) const
 {
+  // see header file for class documentation
+  if (!pHandler) return -EINVAL;
+  pHandler->AddComponent(new AliHLTAltroChannelSelectorComponent);
+  pHandler->AddComponent(new AliHLTTPCDigitDumpComponent);
   return 0;
 }
index 550531ab22f7a3d7618a970aca4216c22c301604..7b9e35b755b72bc7c770f6cb3614e7cae4cac716 100644 (file)
 // or
 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
 
+#include <cassert>
 #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<argc && iResult>=0; i++) {
+  bool bMissingParam=0;
+  int i=0;
+  for (; i<argc && iResult>=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<unsigned>(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;
 }
index ac6e965ec19f3fddac13d259b668055e937c1f58..be9d2ce227b34ca4b310630d245f1197fe2bd016 100644 (file)
@@ -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);
 };
 
index fb2dea56fb0b46887f31ca8fd80cdec2fa69b73a..16f0cd027668989c95a440383d0a133939202fcc 100644 (file)
@@ -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
index c2013e84c03274c12a3164f7274b073891f26736..db881be8aff2ef86179fd4835a2390c04cba0c39 100644 (file)
@@ -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;