]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
New class for reading raw data from memory
authorcvetan <cvetan@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 12 Aug 2005 11:26:53 +0000 (11:26 +0000)
committercvetan <cvetan@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 12 Aug 2005 11:26:53 +0000 (11:26 +0000)
RAW/AliRawReaderMemory.cxx [new file with mode: 0644]
RAW/AliRawReaderMemory.h [new file with mode: 0644]
RAW/RAWLinkDef.h
RAW/libRAWData.pkg

diff --git a/RAW/AliRawReaderMemory.cxx b/RAW/AliRawReaderMemory.cxx
new file mode 100644 (file)
index 0000000..e80789a
--- /dev/null
@@ -0,0 +1,155 @@
+/**************************************************************************
+ * 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$ */
+
+///////////////////////////////////////////////////////////////////////////////
+/// 
+/// This is a class for reading raw data memory buffers.
+///
+///////////////////////////////////////////////////////////////////////////////
+
+#include "AliRawReaderMemory.h"
+#include <TSystem.h>
+
+
+ClassImp(AliRawReaderMemory)
+
+
+AliRawReaderMemory::AliRawReaderMemory() :
+  fBuffer(NULL),
+  fBufferSize(0),
+  fPosition(0)
+{
+// create an object to read digits from
+// the given memory location
+
+  fHeader = new AliRawDataHeader;
+}
+
+AliRawReaderMemory::AliRawReaderMemory(UChar_t* memory, UInt_t size) :
+  fBuffer(memory),
+  fBufferSize(size),
+  fPosition(0)
+{
+// create an object to read digits from the given memory
+
+  fHeader = new AliRawDataHeader;
+}
+
+AliRawReaderMemory::~AliRawReaderMemory()
+{
+// close the input memory
+
+  delete fHeader;
+}
+
+
+AliRawReaderMemory::AliRawReaderMemory(const AliRawReaderMemory& rawReader) :
+  AliRawReader(rawReader)
+{
+  Fatal("AliRawReaderMemory", "copy constructor not implemented");
+}
+
+AliRawReaderMemory& AliRawReaderMemory::operator = (const AliRawReaderMemory& 
+                                             /* rawReader */)
+{
+  Fatal("operator =", "assignment operator not implemented");
+  return *this;
+}
+
+Bool_t AliRawReaderMemory::ReadHeader()
+{
+// read a data header at the current buffer position
+// returns kFALSE if the mini header could not be read
+
+  if (!fBuffer) return kFALSE;
+  do {
+    if ( fPosition+fCount+sizeof(AliRawDataHeader) > fBufferSize ) return kFALSE;
+
+    memcpy( fHeader, fBuffer+fPosition+fCount, sizeof(AliRawDataHeader) );
+    fPosition += fCount+sizeof(AliRawDataHeader);
+
+    if (fHeader->fSize != 0xFFFFFFFF) {
+      // Check for fHeader->fSize < sizeof(AliRawDataHeader) ????
+      fCount = fHeader->fSize - sizeof(AliRawDataHeader);
+    } else {
+      fCount = fBufferSize-fPosition;
+    }
+  } while (!IsSelected());
+  return kTRUE;
+}
+
+Bool_t AliRawReaderMemory::ReadNextData(UChar_t*& data)
+{
+// reads the next payload at the current buffer position
+// returns kFALSE if the data could not be read
+
+  while (fCount == 0) {
+    if (!ReadHeader()) return kFALSE;
+  }
+  UInt_t currentPosition = fPosition;
+  fPosition += fCount;
+  fCount = 0;
+
+  data = fBuffer+currentPosition;
+  return kTRUE;
+}
+
+Bool_t AliRawReaderMemory::ReadNext(UChar_t* data, Int_t size)
+{
+// reads the next block of data at the current buffer position
+// returns kFALSE if the data could not be read
+
+  if ( fBufferSize-fPosition < (UInt_t)size ) return kFALSE;
+
+  memcpy( data, fBuffer+fPosition, size );
+  fCount -= size;
+  fPosition += size;
+  return kTRUE;
+}
+
+
+Bool_t AliRawReaderMemory::Reset()
+{
+// reset the current position in the buffer to the beginning of the curevent
+
+  fCount = 0;
+  fPosition = 0;
+  return kTRUE;
+}
+
+Bool_t AliRawReaderMemory::NextEvent()
+{
+// each memory buffer always contains only one event
+ return kFALSE; 
+}
+
+Bool_t AliRawReaderMemory::RewindEvents()
+{
+// reset the event counter
+
+  return Reset();
+}
+
+Bool_t AliRawReaderMemory::SetMemory( UChar_t* memory, ULong_t size )
+{
+  fBuffer = memory;
+  fBufferSize = size;
+  fCount = 0;
+  fPosition = 0;
+  return (fBuffer && fBufferSize>0) ? kTRUE : kFALSE;
+}
+
diff --git a/RAW/AliRawReaderMemory.h b/RAW/AliRawReaderMemory.h
new file mode 100644 (file)
index 0000000..fb1373d
--- /dev/null
@@ -0,0 +1,73 @@
+#ifndef ALIRAWREADERMEMORY_H
+#define ALIRAWREADERMEMORY_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $Id$ */
+
+///////////////////////////////////////////////////////////////////////////////
+///
+/// This is a class for reading raw data memory.
+///
+///////////////////////////////////////////////////////////////////////////////
+
+#include "AliRawReader.h"
+#ifdef __CINT__
+class fstream;
+#else
+#include <Riostream.h>
+#endif
+#include <TString.h>
+
+
+class AliRawReaderMemory: public AliRawReader {
+  public :
+    AliRawReaderMemory();
+    AliRawReaderMemory(UChar_t* memory, UInt_t size);
+/*     AliRawReaderMemory(const AliRawReaderMemory& rawReader); */
+/*     AliRawReaderMemory& operator = (const AliRawReaderMemory& rawReader); */
+    virtual ~AliRawReaderMemory();
+
+    virtual UInt_t   GetType() const {return 0;};
+    virtual UInt_t   GetRunNumber() const {return 0;};
+    virtual const UInt_t* GetEventId() const {return 0;};
+    virtual const UInt_t* GetTriggerPattern() const {return 0;};
+    virtual const UInt_t* GetDetectorPattern() const {return 0;};
+    virtual const UInt_t* GetAttributes() const {return 0;};
+    virtual const UInt_t* GetSubEventAttributes() const {return 0;};
+    virtual UInt_t   GetLDCId() const {return 0;};
+    virtual UInt_t   GetGDCId() const {return 0;};
+
+    virtual Int_t    GetEquipmentSize() const {return 0;};
+    virtual Int_t    GetEquipmentType() const {return 0;};
+    virtual Int_t    GetEquipmentId() const {return 0;};
+    virtual const UInt_t* GetEquipmentAttributes() const {return NULL;};
+    virtual Int_t    GetEquipmentElementSize() const {return 0;};
+
+    virtual Bool_t   ReadHeader();
+    virtual Bool_t   ReadNextData(UChar_t*& data);
+
+    virtual Bool_t   Reset();
+
+    virtual Bool_t   NextEvent();
+    virtual Bool_t   RewindEvents();
+
+    virtual Bool_t SetMemory( UChar_t* memory, ULong_t size );
+
+  protected :
+
+    UChar_t*         fBuffer;      // buffer for payload
+    UInt_t            fBufferSize;  // size of fBuffer in bytes
+    UInt_t          fPosition;    // Current position in memory
+
+    virtual Bool_t   ReadNext(UChar_t* data, Int_t size);
+
+    ClassDef(AliRawReaderMemory, 0) // class for reading raw digits from a memory block
+
+  private:
+
+    AliRawReaderMemory(const AliRawReaderMemory& rawReader);
+    AliRawReaderMemory& operator = (const AliRawReaderMemory& rawReader);
+};
+
+#endif
index 3770be4f06f659c1431b6ff4d3e6cda161239881..3cefda9ec3f76719250c41673052f9f4b6b1b699 100644 (file)
@@ -16,6 +16,7 @@
 #pragma link C++ class AliRawReaderRoot+;
 #pragma link C++ class AliRawReaderDate+;
 #pragma link C++ class AliRawReaderDateV3+;
+#pragma link C++ class AliRawReaderMemory+;
 #pragma link C++ class AliBitPacking+;
 #pragma link C++ class AliAltroBuffer+;
 #pragma link C++ class AliTPCCompression+;
index 766236cf1f84fb35472b786e74e06bd4d88427de..49208a983cc921815400ddd28faccef8dbd973cc 100644 (file)
@@ -12,6 +12,7 @@ SRCS:=  AliRawEventHeader.cxx AliRawEquipmentHeader.cxx \
        AliStats.cxx AliFilter.cxx \
        AliRawReader.cxx AliRawReaderFile.cxx AliRawReaderRoot.cxx \
        AliRawReaderDate.cxx AliRawReaderDateV3.cxx \
+       AliRawReaderMemory.cxx \
        AliBitPacking.cxx AliAltroBuffer.cxx \
        AliTPCCompression.cxx AliTPCHNode.cxx AliTPCHTable.cxx \
        AliAltroRawStream.cxx AliTPCRawStream.cxx \