]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/TPCLib/AliHLTTPCDigitDumpComponent.cxx
The segmentations are made data member of the AliITSUGeomTGeo, will be loaded
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCDigitDumpComponent.cxx
index cc60e9164bde2f2651a6c901956cec945a850c02..c39ddec30ee20aed4a640f1e5d85945bff84fe07 100644 (file)
@@ -30,7 +30,9 @@
 #include <cassert>
 #include "AliHLTTPCDigitDumpComponent.h"
 #include "AliHLTTPCTransform.h"
-#include "AliHLTTPCDigitReaderRaw.h"
+#include "AliHLTTPCDigitReader.h"
+#include "AliHLTTPCDigitReaderUnpacked.h"
+#include "AliHLTTPCDigitReader32Bit.h"
 #include "AliHLTTPCDefinitions.h"
 
 /** ROOT macro for the implementation of ROOT specific class methods */
@@ -39,7 +41,12 @@ ClassImp(AliHLTTPCDigitDumpComponent)
 AliHLTTPCDigitDumpComponent::AliHLTTPCDigitDumpComponent()
   :
   AliHLTFileWriter(),
-  fRawreaderMode(0)
+  fDigitReaderType(kDigitReader32Bit),
+  fRcuTrailerSize(2),
+  fUnsorted(true),
+  fbBulkMode(true),
+  fpReader(NULL),
+  f32BitFormat(kFALSE)
 {
   // see header file for class documentation
   // or
@@ -75,7 +82,25 @@ AliHLTComponent* AliHLTTPCDigitDumpComponent::Spawn()
 int AliHLTTPCDigitDumpComponent::InitWriter()
 {
   // see header file for class documentation
-  return 0;
+  int iResult=0;
+  switch (fDigitReaderType) {
+  case kDigitReaderUnpacked:
+    HLTInfo("create DigitReaderUnpacked");
+    fpReader=new AliHLTTPCDigitReaderUnpacked; 
+    break;
+  case kDigitReader32Bit:
+    HLTInfo("create DigitReader32Bit");
+    fpReader=new AliHLTTPCDigitReader32Bit();
+    f32BitFormat = kTRUE;
+    break;
+  }
+  if (!fpReader) {
+    HLTError("can not create digit reader of type %d", fDigitReaderType);
+    iResult=-EFAULT;
+  } else {
+    fpReader->SetUnsorted(fUnsorted);
+  }
+  return iResult;
 }
 
 int AliHLTTPCDigitDumpComponent::ScanArgument(int argc, const char** argv)
@@ -85,28 +110,80 @@ int AliHLTTPCDigitDumpComponent::ScanArgument(int argc, const char** argv)
   TString argument="";
   bool bMissingParam=0;
   int i=0;
-  for (; i<argc && iResult>=0; i++) {
-    argument=argv[i];
-    if (argument.IsNull()) continue;
+  do {
+    if (i>=argc || (argument=argv[i]).IsNull()) continue;
 
     // -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;
+      HLTWarning("argument '-rawreadermode' deprecated");
+      break;
+    }
+
+    // -digitreader
+    if (argument.CompareTo("-digitreader")==0) {
+      if ((bMissingParam=(++i>=argc))) break;
+      TString param=argv[i];
+      if (param.CompareTo("unpacked", TString::kIgnoreCase)==0) {
+       fDigitReaderType=kDigitReaderUnpacked;
+      } else if (param.CompareTo("packed", TString::kIgnoreCase)==0) {
+       HLTWarning("argument 'packed' is deprecated, falling back to DigitReader32Bit");
+       fDigitReaderType=kDigitReader32Bit;
+      } else if (param.CompareTo("raw", TString::kIgnoreCase)==0) {
+       HLTWarning("argument 'raw' is deprecated, falling back to DigitReader32Bit");
+       fDigitReaderType=kDigitReader32Bit;
+      } else if (param.CompareTo("decoder", TString::kIgnoreCase)==0) {
+       HLTWarning("argument 'decoder' is deprecated, falling back to DigitReader32Bit");
+       fDigitReaderType=kDigitReader32Bit;
+      } else if (param.CompareTo("32bit", TString::kIgnoreCase)==0) {
+       fDigitReaderType=kDigitReader32Bit;
       } else {
-       fRawreaderMode=static_cast<unsigned>(mode);
+       HLTError("unknown digit reader type %s", param.Data());
+       iResult=-EINVAL;
+      }
+
+      break;
+    }
+
+    // -rcutrailersize
+    if (argument.CompareTo("-rcutrailersize")==0) {
+      if ((bMissingParam=(++i>=argc))) break;
+      char *endptr=NULL;
+      fRcuTrailerSize=strtoul(argv[i], &endptr, 0);
+      if (/*endptr ||*/ fRcuTrailerSize<1) {
+       HLTError("invalid parameter '%s', %s", argv[i], endptr==NULL?"number >= 1 expected":"can not convert string to number");
+       iResult=-EINVAL;
       }
       break;
     }
-  }
 
-  if (bMissingParam) {
-    iResult=-EPROTO;
-  }
-  if (iResult>=0) iResult=i+1;
+    // -unsorted
+    if (argument.CompareTo("-unsorted")==0) {
+      fUnsorted=true;
+      break;
+    }
+
+    // -sorted
+    if (argument.CompareTo("-sorted")==0) {
+      fUnsorted=false;
+      break;
+    }
+
+    // -bulk
+    if (argument.CompareTo("-bulk")==0) {
+      fbBulkMode=true;
+      break;
+    }
+
+    // -stream
+    if (argument.CompareTo("-stream")==0) {
+      fbBulkMode=false;
+      break;
+    }
+  } while (0); // just use the do/while here to have the option of breaking
+
+  if (bMissingParam) iResult=-EPROTO;
+  else if (iResult>=0) iResult=i;
 
   return iResult;
 }
@@ -114,11 +191,13 @@ int AliHLTTPCDigitDumpComponent::ScanArgument(int argc, const char** argv)
 int AliHLTTPCDigitDumpComponent::CloseWriter()
 {
   // see header file for class documentation
+  if (fpReader) delete fpReader;
+  fpReader=NULL;
   return 0;
 }
 
 int AliHLTTPCDigitDumpComponent::DumpEvent( const AliHLTComponentEventData& evtData,
-                                           const AliHLTComponentBlockData* blocks
+                                           const AliHLTComponentBlockData* /*blocks*/
                                            AliHLTComponentTriggerData& /*trigData*/ )
 {
   // see header file for class documentation
@@ -126,15 +205,17 @@ int AliHLTTPCDigitDumpComponent::DumpEvent( const AliHLTComponentEventData& evtD
   int iPrintedSlice=-1;
   int iPrintedPart=-1;
   int blockno=0;
-  HLTDebug("%d blocks", evtData.fBlockCnt);
   const AliHLTComponentBlockData* pDesc=NULL;
 
-  for (pDesc=GetFirstInputBlock(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginTPC); pDesc!=NULL; pDesc=GetNextInputBlock(), blockno++) {
-    // TODO: Matthias 26.11.2007
-    // I have a very strange behavior with the processing of that log message leading to a crash in vsnprintf
-    // Maybe it's just trivial, but then it should not crash. Needs more investigation
-    //HLTDebug("event %d block %d: %s 0x%08x size %d", evtData.fEventID, blockno, DataType2Text(pDesc->fDataType).c_str(), pDesc->fSpecification, pDesc->fSize);
-    HLTDebug("dump digits for block %d specification 0x%08x", blockno, pDesc->fSpecification);
+  AliHLTTPCDigitReader* pReader=fpReader;
+  if (!pReader) return -ENODEV;
+
+  for (pDesc=GetFirstInputBlock(kAliHLTAnyDataType); pDesc!=NULL; pDesc=GetNextInputBlock(), blockno++) {
+    HLTDebug("event %Lu block %d: %s 0x%08x size %d", evtData.fEventID, blockno, DataType2Text(pDesc->fDataType).c_str(), pDesc->fSpecification, pDesc->fSize);
+
+    if (fDigitReaderType==kDigitReaderUnpacked && pDesc->fDataType!=AliHLTTPCDefinitions::fgkUnpackedRawDataType) continue;
+    else if (fDigitReaderType!=kDigitReaderUnpacked && pDesc->fDataType!=(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginTPC)) continue;
+
     TString filename;
     iResult=BuildFileName(evtData.fEventID, blockno, pDesc->fDataType, pDesc->fSpecification, filename);
     ios::openmode filemode=(ios::openmode)0;
@@ -154,45 +235,103 @@ int AliHLTTPCDigitDumpComponent::DumpEvent( const AliHLTComponentEventData& evtD
        assert(slice==AliHLTTPCDefinitions::GetMaxSliceNr(*pDesc));
        int firstRow=AliHLTTPCTransform::GetFirstRow(part);
        int lastRow=AliHLTTPCTransform::GetLastRow(part);
-       AliHLTTPCDigitReaderRaw reader(fRawreaderMode);
-       reader.InitBlock(pDesc->fPtr,pDesc->fSize,firstRow,lastRow,part,slice);
+
+       iResult=pReader->InitBlock(pDesc->fPtr,pDesc->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 << "====================================================================" << endl;
-           dump << "    Slice: " << iPrintedSlice << "   Pad: " << iPrintedPad;
+       if (fbBulkMode) {
+         while (pReader->NextChannel()) {
+           if (PrintHeaders(slice, iPrintedSlice, part, iPrintedPart, pReader, iPrintedRow, iPrintedPad, dump)) {
+             iLastTime=-1;
+           }
+           while (pReader->NextBunch()) {
+             int bunchLength=pReader->GetBunchSize();
+             
+             // Kenneth: 20-04-09. The following if have been added because of inconsistency in the 40 bit decoder and the 32 bit decoder.
+             // GetSignals() in the 40 bit decoder returns an array of UInt_t while the 32 bit one returns UShort_t
+             if(f32BitFormat == kTRUE){
+               const  UShort_t* bunchData=pReader->GetSignalsShort();
+               
+               // bunch data is printed in 'reverse' order in order to produce
+               // the same output as in stream reading mode
+               dump << "                     Time " << pReader->GetTime()+bunchLength-1 << ":  ";
+               for (int bin=bunchLength-1; bin>=0; bin--) {
+                 dump << "  " << bunchData[bin];
+               }
+               dump << "    -> Time: " << pReader->GetTime() << endl;
+             }
+             else{
+               const  UInt_t* bunchData=pReader->GetSignals();
+               dump << "                     Time " << pReader->GetTime()+bunchLength-1 << ":  ";
+               for (int bin=0; bin<bunchLength; bin++) {
+                 dump << "  " << bunchData[bin];
+               }
+               dump << "    -> Time: " << pReader->GetTime() << endl;
+             }
+           }
          }
-         if (iPrintedRow!=reader.GetRow()) {
-           iPrintedRow=reader.GetRow();
-           dump << endl;
-           dump << "--------------------------------------------------------------------" << endl;
-           dump << "Row: " << iPrintedRow << endl;
+         dump << endl;
+       } else {
+       while (pReader->Next()) {
+         if ((iPrintedSlice!=-1 && iLastTime!=-1 && iLastTime!=pReader->GetTime()+1 && iLastTime!=pReader->GetTime()-1)) {
+           dump << "    -> Time: " << iLastTime << endl;
+         } else if ((iPrintedPad!=-1 && iPrintedPad!=pReader->GetPad()) ||
+                    (iPrintedRow!=-1 && iPrintedRow!=pReader->GetRow())) {
+           dump << "    -> Time: " << iLastTime << endl;
+           //dump << endl;
          }
-         if (iPrintedPad!=reader.GetPad()) {
-           dump << endl;
-           iPrintedPad=reader.GetPad();
-           dump << "    Pad: " << iPrintedPad;
+
+         if (PrintHeaders(slice, iPrintedSlice, part, iPrintedPart, pReader, iPrintedRow, iPrintedPad, dump)) {
+           iLastTime=-1;
          }
-         if (iLastTime!=reader.GetTime()+1 && iLastTime!=reader.GetTime()-1 ) {
-           dump << endl;
-           dump << "        Time: " << reader.GetTime();
+         if (iLastTime==-1 || (iLastTime!=pReader->GetTime()+1 && iLastTime!=pReader->GetTime()-1)) {
+           dump << "                     Time " << pReader->GetTime() << ":  ";
          }
-         iLastTime=reader.GetTime();
-         dump << "  " << reader.GetSignal();
+         iLastTime=pReader->GetTime();
+         dump << "  " << pReader->GetSignal();
+       }
+       if (iLastTime>=0) dump << "    -> Time: " << iLastTime << endl << endl;
        }
-       dump << endl << endl;
       } else {
        HLTError("can not open file %s for writing", filename.Data());
        iResult=-EBADF;
       }
       dump.close();
     }
+    pReader->Reset();
+  }
+  return iResult;
+}
+
+int AliHLTTPCDigitDumpComponent::PrintHeaders(int slice, int &iPrintedSlice,
+                                             int part, int &iPrintedPart,
+                                             AliHLTTPCDigitReader* pReader,
+                                             int &iPrintedRow, int &iPrintedPad,
+                                             ofstream &dump) const
+{
+  // see header file for class documentation
+  int iResult=0;
+  assert(pReader);
+  if (iPrintedSlice!=slice || iPrintedPart!=part) {
+    iPrintedSlice=slice;
+    iPrintedPart=part;
+    dump << "====================================================================" << endl;
+    dump << "    Slice: " << iPrintedSlice << "   Partition: " << iPrintedPart << endl;
+    iPrintedRow=-1;
   }
+  if (iPrintedRow!=pReader->GetRow()) {
+    iPrintedRow=pReader->GetRow();
+    dump << "--------------------------------------------------------------------" << endl;
+    dump << "Row: " << iPrintedRow << endl;
+    iPrintedPad=-1;
+  }
+  if (iPrintedPad!=pReader->GetPad()) {
+    iPrintedPad=pReader->GetPad();
+    dump << "Row: " << iPrintedRow << "  Pad: " << iPrintedPad << "  HW address: " << pReader->GetAltroBlockHWaddr() << endl;
+    iResult=1;
+  }
+
   return iResult;
 }