]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliFstream.cxx
Fix for copy/paste error
[u/mrichter/AliRoot.git] / STEER / AliFstream.cxx
index ba6398634360795d042aa4654f26d3514e45d205..ec4f670ab50e988f56fdd4bb8001b07ca766da49 100644 (file)
 
 #include <unistd.h>
 #include <Riostream.h>
-
+#include <stdio.h>
 #include "AliFstream.h"
 #include "AliLog.h"
 
+
 ClassImp(AliFstream)
 
 //______________________________________________________________________________
 AliFstream::AliFstream():
   fFile(0x0),
   fBuffer(0x0),
-  fBufferSize(0),
-  fSwap(kFALSE)
+  fBufferSize(0)
 {
   // Default constructor
-
-  for (Int_t i = 0; i < 8; i++) fBuffer[i] = 0;
 }
 
 //______________________________________________________________________________
 AliFstream::AliFstream(const char *fileName):
   fFile(0x0),
   fBuffer(0x0),
-  fBufferSize(0),
-  fSwap(kFALSE)
+  fBufferSize(0)
 {
   // Constructor
   // Takes the input filename and
@@ -60,33 +57,6 @@ AliFstream::AliFstream(const char *fileName):
 #else
   fFile = new fstream(fileName, ios::out);
 #endif
-
-  // Check endianess
-  UInt_t temp = 1;
-  UChar_t *ptemp = (UChar_t *)&temp;
-  if (!ptemp[0]) fSwap = kTRUE;
-}
-
-//______________________________________________________________________________
-AliFstream::AliFstream(const AliFstream &source):
-  TObject(source)
-{
-  // Copy constructor
-  //
-  AliFatal("Copy constructor not implemented !");
-}
-
-//______________________________________________________________________________
-AliFstream &AliFstream::operator =(const AliFstream& source)
-{
-  // assignment operator
-  //
-  if(this==&source) return *this;
-  ((TObject *)this)->operator=(source);
-
-  AliFatal("Assigment operator not implemented !");
-
-  return *this;
 }
 
 //______________________________________________________________________________
@@ -102,23 +72,32 @@ AliFstream::~AliFstream()
 }
 
 //______________________________________________________________________________
-void AliFstream::Seekg(UInt_t position)
+void AliFstream::Seekp(UInt_t position)
 {
   // Go to a given position
   // inside the output stream
-  if (fFile) fFile->seekg(position);
+  if (fFile) fFile->seekp(position);
 }
 
 //______________________________________________________________________________
-UInt_t AliFstream::Tellg()
+UInt_t AliFstream::Tellp()
 {
   // Return the current
   // position inside the
   // output stream
-  if (fFile) return fFile->tellg();
+  if (fFile) return fFile->tellp();
   else return 0;
 }
 
+//______________________________________________________________________________
+UInt_t AliFstream::Swap(UInt_t x)
+{
+   // Swap the endianess of the integer value 'x'
+
+   return (((x & 0x000000ffU) << 24) | ((x & 0x0000ff00U) <<  8) |
+           ((x & 0x00ff0000U) >>  8) | ((x & 0xff000000U) >> 24));
+}
+
 //______________________________________________________________________________
 void AliFstream::WriteBuffer(const char *buffer, UInt_t size, Bool_t force)
 {
@@ -129,23 +108,35 @@ void AliFstream::WriteBuffer(const char *buffer, UInt_t size, Bool_t force)
   // endianess and swap the buffer data
   // so that it is always stored using
   // little endian format.
+
+  // The raw data payload size is always
+  // 4 bytes aligned
+  
+  if ((size % sizeof(UInt_t)) != 0)
+    AliFatal(Form("Size of the buffer is not multiple of 4 (size = %d) !",size));
+  
   if (force) {
     fFile->write(buffer,size);
   }
   else {
-    if (!fSwap) {
-      // Little endian - do nothing
-      fFile->write(buffer,size);
+#ifdef R__BYTESWAP
+    fFile->write(buffer,size);
+#else
+    size /= sizeof(UInt_t);
+
+    if (size > fBufferSize) {
+      if (fBuffer) delete [] fBuffer;
+      fBuffer = new UInt_t[size];
+      fBufferSize = size;
     }
-    else {
-      // Big endian - swap the buffer contents
-      if (size > fBufferSize) {
-       if (fBuffer) delete [] fBuffer;
-       fBuffer = new UChar_t[size];
-       fBufferSize = size;
-      }
-      swab(buffer,fBuffer,size);
-      fFile->write((const char *)fBuffer,size);
+
+    UInt_t *buf = (UInt_t *)buffer;
+    for (UInt_t i = 0; i < size; i++, buf++) {
+      UInt_t value = Swap(*buf);
+      memcpy(fBuffer+i, &value, sizeof(UInt_t));
     }
+
+    fFile->write((const char *)fBuffer,size*sizeof(UInt_t));
+#endif
   }
 }