]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONRawStreamTracker.cxx
Access to the file analyzed available now in analysis classes through the reader...
[u/mrichter/AliRoot.git] / MUON / AliMUONRawStreamTracker.cxx
index e33b921c027be37e4f1b36f4b7ad4566cdff042a..4f493c3c6196f250773f376828d3a906863bc9f7 100644 (file)
 /**************************************************************************
- * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
- *                                                                        *
- * Author: The ALICE Off-line Project.                                    *
- * Contributors are mentioned in the code where appropriate.              *
- *                                                                        *
- * Permission to use, copy, modify and distribute this software and its   *
- * documentation strictly for non-commercial purposes is hereby granted   *
- * without fee, provided that the above copyright notice appears in all   *
- * copies and that both the copyright notice and this permission notice   *
- * appear in the supporting documentation. The authors make no claims     *
- * about the suitability of this software for any purpose. It is          *
- * provided "as is" without express or implied warranty.                  *
- **************************************************************************/
-
-
-///////////////////////////////////////////////////////////////////////////////
-///
+* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+*                                                                        *
+* Author: The ALICE Off-line Project.                                    *
+* Contributors are mentioned in the code where appropriate.              *
+*                                                                        *
+* Permission to use, copy, modify and distribute this software and its   *
+* documentation strictly for non-commercial purposes is hereby granted   *
+* without fee, provided that the above copyright notice appears in all   *
+* copies and that both the copyright notice and this permission notice   *
+* appear in the supporting documentation. The authors make no claims     *
+* about the suitability of this software for any purpose. It is          *
+* provided "as is" without express or implied warranty.                  *
+**************************************************************************/
+
+/* $Id$ */
+
+
+//-----------------------------------------------------------------------------
+/// \class AliMUONRawStreamTracker
 /// This class provides access to MUON digits in raw data.
 ///
 /// It loops over all MUON digits in the raw data given by the AliRawReader.
 /// The Next method goes to the next digit. If there are no digits left
-/// it returns kFALSE (under develpment)
+/// it returns kFALSE
 /// It can loop also over DDL and store the decoded rawdata in TClonesArray
 /// in Payload class.
 /// 
-/// First version implement for Tracker
+/// Implement for Tracker
 ///
-///////////////////////////////////////////////////////////////////////////////
+/// \author Christian Finck & Laurent Aphecetche
+//-----------------------------------------------------------------------------
 
 #include "AliMUONRawStreamTracker.h"
 
+#include "AliMUONLogger.h"
 #include "AliRawReader.h"
 #include "AliRawDataHeader.h"
 #include "AliDAQ.h"
 #include "AliLog.h"
+#include "AliMUONPayloadTracker.h"
+#include "AliMUONBlockHeader.h"
+#include "AliMUONDspHeader.h"
+#include "AliMUONBusStruct.h"
+#include "AliMUONDDLTracker.h"
+#include "Riostream.h"
+#include <cassert>
+
+/// \cond CLASSIMP
+ClassImp(AliMUONRawStreamTracker)
+/// \endcond
 
-#include "AliMpBusPatch.h"
+const Int_t AliMUONRawStreamTracker::fgkMaxDDL = 20;
 
-ClassImp(AliMUONRawStreamTracker)
 
+//___________________________________________
 AliMUONRawStreamTracker::AliMUONRawStreamTracker()
-  : TObject(),
-    fRawReader(0x0),
-    fDDL(0),
-    fBusPatchId(0),
-    fDspId(0),
-    fBlkId(0),
-    fNextDDL(kTRUE),
-    fMaxDDL(20)
+ : AliMUONVRawStreamTracker(),
+   fPayload(new AliMUONPayloadTracker()),
+   fCurrentDDL(0),
+   fCurrentDDLIndex(fgkMaxDDL),
+   fCurrentBlockHeader(0),
+   fCurrentBlockHeaderIndex(0),
+   fCurrentDspHeader(0),
+   fCurrentDspHeaderIndex(0),
+   fCurrentBusStruct(0),
+   fCurrentBusStructIndex(0),
+   fCurrentDataIndex(0),
+   fDDL(0)
 {
-  //
-  // create an object to read MUON raw digits
-  // Default ctor for monitoring purposes
-  //
-
-  fPayload = new AliMUONPayloadTracker();
-
+  ///
+  /// create an object to read MUON raw digits
+  /// Default ctor for monitoring purposes
+  ///
+  
+  
 }
 
 //_________________________________________________________________
 AliMUONRawStreamTracker::AliMUONRawStreamTracker(AliRawReader* rawReader)
-  : TObject(),
-    fDDL(0),
-    fBusPatchId(0),
-    fDspId(0),
-    fBlkId(0),
-    fNextDDL(kTRUE),
-    fMaxDDL(20)
+: AliMUONVRawStreamTracker(rawReader),
+  fPayload(new AliMUONPayloadTracker()),
+  fCurrentDDL(0),
+  fCurrentDDLIndex(fgkMaxDDL),
+  fCurrentBlockHeader(0),
+  fCurrentBlockHeaderIndex(0),
+  fCurrentDspHeader(0),
+  fCurrentDspHeaderIndex(0),
+  fCurrentBusStruct(0),
+  fCurrentBusStructIndex(0),
+  fCurrentDataIndex(0),
+  fDDL(0)
 {
-  //
-  // ctor with AliRawReader as argument
-  // for reconstruction purpose
-  //
+  ///
+  /// ctor with AliRawReader as argument
+  /// for reconstruction purpose
+  ///
+  
+  
+}
 
-  fRawReader = rawReader;
-  fPayload   = new AliMUONPayloadTracker();
+//___________________________________
+AliMUONRawStreamTracker::~AliMUONRawStreamTracker()
+{
+  ///
+  /// clean up
+  ///
+  delete fPayload;
+}
+
+//_____________________________________________________________
+Bool_t 
+AliMUONRawStreamTracker::Next(Int_t& busPatchId,
+                              UShort_t& manuId, UChar_t& manuChannel,
+                              UShort_t& adc)
+{
+  ///
+  /// read the next raw digit (buspatch structure)
+  /// returns kFALSE if there is no digit left
+  /// Should call First() before this method to start the iteration.
+  ///
+  
+  if ( IsDone() ) return kFALSE;
+  
+  if ( fCurrentDataIndex >= fCurrentBusStruct->GetLength()-1 )
+  {
+    Bool_t ok = GetNextBusStruct();
+    if (!ok)
+    {
+      // this is the end
+      return kFALSE;
+    } 
+  }
 
+  ++fCurrentDataIndex;
+
+  busPatchId = fCurrentBusStruct->GetBusPatchId();
+  manuId = fCurrentBusStruct->GetManuId(fCurrentDataIndex);
+  manuChannel = fCurrentBusStruct->GetChannelId(fCurrentDataIndex);
+  adc = fCurrentBusStruct->GetCharge(fCurrentDataIndex);
+
+  return kTRUE;
 }
 
-//_________________________________________________________________
-AliMUONRawStreamTracker::AliMUONRawStreamTracker(const AliMUONRawStreamTracker& stream) :
-  TObject(stream)
-{ 
-  //
-  // copy ctor
-  //
-  AliFatal("copy constructor not implemented");
+//______________________________________________________
+Bool_t
+AliMUONRawStreamTracker::IsDone() const
+{
+  /// Whether the iteration is finished or not
+  return (fCurrentBusStruct==0);
 }
 
-//______________________________________________________________________
-AliMUONRawStreamTracker& AliMUONRawStreamTracker::operator = (const AliMUONRawStreamTracker& 
-                                             /* stream */)
+//______________________________________________________
+void
+AliMUONRawStreamTracker::First()
 {
-  // 
-  // assignment operator
-  //
-  AliFatal("assignment operator not implemented");
-  return *this;
+  /// Initialize the iteration process.
+  
+  fCurrentDDLIndex = -1;
+//  fCurrentDspHeaderIndex = -1; // Not necessary since this gets reset in the GetNextXXX methods.
+//  fCurrentBusStructIndex = -1;
+
+  // Must reset all the pointers because if we return before calling
+  // GetNextBusStruct() the user might call CurrentDDL(), CurrentBlockHeader(),
+  // CurrentDspHeader() or CurrentBusStruct() which should return reasonable
+  // results in that case.
+  fCurrentDDL = 0;
+  fCurrentBlockHeader = 0;
+  fCurrentDspHeader = 0;
+  fCurrentBusStruct = 0;
+  
+  // Find the first non-empty structure
+  if (not GetNextDDL()) return;
+  if (not GetNextBlockHeader()) return;
+  if (not GetNextDspHeader()) return;
+  GetNextBusStruct();
 }
 
+//______________________________________________________
+Bool_t
+AliMUONRawStreamTracker::GetNextDDL()
+{
+  /// Returns the next DDL present
+  
+  assert( GetReader() != 0 );
+  
+  Bool_t kFound(kFALSE);
+  
+  while ( fCurrentDDLIndex < fgkMaxDDL-1 && !kFound ) 
+  {
+    ++fCurrentDDLIndex;
+    GetReader()->Reset();
+    GetReader()->Select("MUONTRK",fCurrentDDLIndex,fCurrentDDLIndex);
+    if ( GetReader()->ReadHeader() ) 
+    {
+      kFound = kTRUE;
+    }
+  }
+  
+  if ( !kFound ) 
+  {
+    // fCurrentDDLIndex is set to fgkMaxDDL so that we exit the above loop immediately
+    // for a subsequent call to this method, unless NextEvent is called in between.
+    fCurrentDDLIndex = fgkMaxDDL;
+    // We have not actually been able to complete the loading of the new DDL so
+    // we are still on the old one. In this case we do not need to reset fCurrentDDL.
+    //fCurrentDDL = 0;
+    if (IsErrorLogger()) AddErrorMessage();
+    return kFALSE;
+  }
+  
+  Int_t totalDataWord  = GetReader()->GetDataSize(); // in bytes
+  
+  AliDebug(3, Form("DDL Number %d totalDataWord %d\n", fCurrentDDLIndex,
+                   totalDataWord));
 
-//___________________________________
-AliMUONRawStreamTracker::~AliMUONRawStreamTracker()
+  UInt_t *buffer = new UInt_t[totalDataWord/4];
+  
+  if ( !GetReader()->ReadNext((UChar_t*)buffer, totalDataWord) )
+  {
+    // We have not actually been able to complete the loading of the new DDL so
+    // we are still on the old one. In this case we do not need to reset fCurrentDDL.
+    //fCurrentDDL = 0;
+    delete [] buffer;
+    return kFALSE;
+  }
+  fPayload->ResetDDL();
+  
+#ifndef R__BYTESWAP  
+  Swap(buffer, totalDataWord / sizeof(UInt_t)); // swap needed for mac power pc
+#endif
+
+  Bool_t ok = fPayload->Decode(buffer, totalDataWord/4);
+  
+  delete[] buffer;
+  
+  fCurrentDDL = fPayload->GetDDLTracker();
+  
+  fCurrentBlockHeaderIndex = -1;
+  
+  return ok;
+}
+
+//______________________________________________________
+Bool_t
+AliMUONRawStreamTracker::GetNextBlockHeader()
 {
-  //
-  // clean up
-  //
-  delete fPayload;
+  /// Returns the next block Header present
+  
+  assert( fCurrentDDL != 0 );
+
+  fCurrentBlockHeader = 0;
+
+  Int_t i(fCurrentBlockHeaderIndex);
+  
+  while ( fCurrentBlockHeader == 0 && i < fCurrentDDL->GetBlkHeaderEntries()-1 ) 
+  {
+    ++i;
+    fCurrentBlockHeader = fCurrentDDL->GetBlkHeaderEntry(i);
+  }
+  
+  if ( !fCurrentBlockHeader ) 
+  {
+    Bool_t ok = GetNextDDL();
+    if (!ok) 
+    {
+      return kFALSE;
+    }
+    else
+    {
+      return GetNextBlockHeader();
+    }
+  }
+  
+  fCurrentBlockHeaderIndex = i;
+  
+  fCurrentDspHeaderIndex = -1;
+  
+  return kTRUE;
+}
 
+//______________________________________________________
+Bool_t
+AliMUONRawStreamTracker::GetNextDspHeader()
+{
+  /// Returns the next Dsp Header present
+
+  assert( fCurrentBlockHeader != 0 );
+  
+  fCurrentDspHeader = 0;
+  
+  Int_t i(fCurrentDspHeaderIndex);
+  
+  while ( fCurrentDspHeader == 0 && i < fCurrentBlockHeader->GetDspHeaderEntries()-1 )
+  {
+    ++i;
+    fCurrentDspHeader = fCurrentBlockHeader->GetDspHeaderEntry(i);
+  }
+  
+  if ( !fCurrentDspHeader ) 
+  {
+    Bool_t ok = GetNextBlockHeader();
+    if (!ok) 
+    {
+      return kFALSE;
+    }
+    else
+    {
+      return GetNextDspHeader();
+    }
+  }
+  
+  fCurrentDspHeaderIndex = i;
+  
+  fCurrentBusStructIndex = -1;
+  
+  return kTRUE;
 }
 
-//_____________________________________________________________
-Bool_t AliMUONRawStreamTracker::Next()
+//______________________________________________________
+Bool_t
+AliMUONRawStreamTracker::GetNextBusStruct()
 {
-  //
-  // read the next raw digit (buspatch structure)
-  // returns kFALSE if there is no digit left
-  // (under development)
-
-//      AliMUONDDLTracker*       ddlTracker = 0x0;
-//      AliMUONBlockHeader*      blkHeader  = 0x0;
-//      AliMUONDspHeader*        dspHeader  = 0x0;
-//      Int_t nBusPatch;
-//      Int_t nDsp;
-//      Int_t nBlock;
-
-//  next:  
-//      if (fNextDDL){
-//        printf("iDDL %d\n", fDDL+1);
-//        fBlkId = 0;
-//        fDspId = 0;
-//        fBusPatchId = 0;
-//        if(!NextDDL()) 
-//      return kFALSE;
-//      }
-//      fNextDDL = kFALSE;
-
-//      ddlTracker = GetDDLTracker();
-
-//      nBlock = ddlTracker->GetBlkHeaderEntries();
-//      if (fBlkId <  nBlock) {
-
-//        blkHeader = ddlTracker->GetBlkHeaderEntry(fBlkId);
-//        nDsp      = blkHeader->GetDspHeaderEntries();
-
-//        if( fDspId < nDsp) {
-//      dspHeader = blkHeader->GetDspHeaderEntry(fDspId);
-//      nBusPatch = dspHeader->GetBusPatchEntries();
-
-//      if (fBusPatchId < nBusPatch) {
-//        fBusStructPtr = dspHeader->GetBusPatchEntry(fBusPatchId++);
-//        return kTRUE;
-
-//      } else {// iBusPatch
-//        fDspId++;
-//        fBusPatchId = 0;
-//        goto next;
-//        //   Next();
-//      }
-
-//        } else {// iDsp
-//      fBlkId++;
-//      fDspId = 0;
-//      fBusPatchId = 0;
-//      goto next;
-//      //      Next();
-//        }
-
-//      } else {// iBlock
-//        fBlkId = 0;
-//        fDspId = 0;
-//        fBusPatchId = 0;
-//        fNextDDL = kTRUE;
-//        //return kTRUE;
-//        goto next; 
-//      }
-
-     return kFALSE;
+  /// Find the next non-empty busPatch structure
+  
+  assert( fCurrentDspHeader != 0 );
+  
+  fCurrentBusStruct = 0;
+
+  Int_t i(fCurrentBusStructIndex);
+  
+  while ( fCurrentBusStruct == 0 && i < fCurrentDspHeader->GetBusPatchEntries()-1 ) 
+  {
+    ++i;
+    fCurrentBusStruct = fCurrentDspHeader->GetBusPatchEntry(i);
+  }
+    
+  if ( !fCurrentBusStruct ) 
+  {
+    Bool_t ok = GetNextDspHeader();
+    if (!ok)
+    {
+      return kFALSE;
+    }
+    else
+    {
+      return GetNextBusStruct();
+    }
+  }
+  
+  fCurrentBusStructIndex = i;
+  
+  fCurrentDataIndex = -1;
+  
+  return kTRUE;
 }
 
 //______________________________________________________
 Bool_t AliMUONRawStreamTracker::NextDDL()
 {
-  // reading tracker DDL
-
+  /// reading tracker DDL
+  
+  assert( GetReader() != 0 );
+  
   fPayload->ResetDDL();
-
-
-  if (fDDL >= 20) {
+  
+  while ( fDDL < fgkMaxDDL ) 
+  {
+    GetReader()->Reset();
+    GetReader()->Select("MUONTRK", fDDL, fDDL);  //Select the DDL file to be read  
+    if (GetReader()->ReadHeader()) break;
+    AliDebug(3,Form("Skipping DDL %d which does not seem to be there",fDDL));
+    ++fDDL;
+  }
+  
+  if ( fDDL == fgkMaxDDL ) 
+  {
     fDDL = 0;
+    if ( IsErrorLogger()) AddErrorMessage();
     return kFALSE;
   }
+  
   AliDebug(3, Form("DDL Number %d\n", fDDL ));
-
-  fRawReader->Reset();
-  fRawReader->Select("MUONTRK", fDDL, fDDL);  //Select the DDL file to be read  
-
-  fRawReader->ReadHeader();
-
-  Int_t totalDataWord  = fRawReader->GetDataSize(); // in bytes
-
+  
+  Int_t totalDataWord  = GetReader()->GetDataSize(); // in bytes
+  
   UInt_t *buffer = new UInt_t[totalDataWord/4];
 
-  fRawReader->ReadNext((UChar_t*)buffer, totalDataWord); 
+  if(!GetReader()->ReadNext((UChar_t*)buffer, totalDataWord))
+  {
+    delete[] buffer;
+    return kFALSE;
+  }
 
-  fPayload->Decode(buffer, totalDataWord/4);
+#ifndef R__BYTESWAP  
+  Swap(buffer, totalDataWord / sizeof(UInt_t)); // swap needed for mac power pc
+#endif
+  
+  Bool_t ok = fPayload->Decode(buffer, totalDataWord/4);
 
   delete[] buffer;
-
+  
   fDDL++;
-
-  return kTRUE;
+  
+  return ok;
 }
 
 //______________________________________________________
-void AliMUONRawStreamTracker::SetMaxDDL(Int_t ddl
+void AliMUONRawStreamTracker::SetMaxBlock(Int_t blk
 {
-  // set DDL number
-  if (ddl > 20) ddl = 20;
-  fMaxDDL = ddl;
-
+  /// set regional card number
+  fPayload->SetMaxBlock(blk);
 }
 
 //______________________________________________________
-void AliMUONRawStreamTracker::SetMaxBlock(Int_t blk) 
+void AliMUONRawStreamTracker::AddErrorMessage()
 {
-  // set regional card number
-  fPayload->SetMaxBlock(blk);
+  /// add message into logger of AliRawReader per event
+
+    assert( GetReader() != 0 );
+    TString msg;
+    Int_t occurance = 0;
+    AliMUONLogger* log = fPayload->GetErrorLogger();
+    
+    log->ResetItr();
+    while(log->Next(msg, occurance))
+    { 
+      if (msg.Contains("Parity"))
+         GetReader()->AddMinorErrorLog(kParityErr, msg.Data());
+
+      if (msg.Contains("Glitch"))
+        GetReader()->AddMajorErrorLog(kGlitchErr, msg.Data());
+
+      if (msg.Contains("Padding"))
+        GetReader()->AddMinorErrorLog(kPaddingWordErr, msg.Data());
+    }
+    
+    log->Clear(); // clear logger after each event
 }
+
+//______________________________________________________
+Bool_t AliMUONRawStreamTracker::IsErrorMessage() const
+{
+  /// true if there is any error/warning 
+  if (GetPayLoad()->GetParityErrors() || 
+        GetPayLoad()->GetGlitchErrors() || 
+        GetPayLoad()->GetPaddingErrors())
+    return kTRUE;
+  
+  return kFALSE;
+}  
+    
+    
+    
+    
+