--- /dev/null
+/**************************************************************************
+ * 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. *
+ **************************************************************************/
+
+//-----------------------------------------------------------------
+// This is the class which is to be used during the writing of
+// simulated raw data (DDL files format).
+// It is using the root functionality in order to deal correctly
+// with little/big endian issue. By convention the detector raw
+// data payload is stored always with little endian (this corresponds
+// to the real life situation when the detector data is coming from
+// the hardware). The implementation of this class is based on Root
+// tobuf() method defined in Bytes.h
+//-------------------------------------------------------------------------
+
+#include <unistd.h>
+#include <Riostream.h>
+
+#include "AliFstream.h"
+#include "AliLog.h"
+
+ClassImp(AliFstream)
+
+//______________________________________________________________________________
+AliFstream::AliFstream():
+ fFile(0x0),
+ fBuffer(0x0),
+ fBufferSize(0),
+ fSwap(kFALSE)
+{
+ // 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)
+{
+ // Constructor
+ // Takes the input filename and
+ // opens the output stream
+
+#ifndef __DECCXX
+ fFile = new fstream(fileName, ios::binary|ios::out);
+#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;
+}
+
+//______________________________________________________________________________
+AliFstream::~AliFstream()
+{
+ // Destructor
+ //
+ if (fFile) {
+ fFile->close();
+ delete fFile;
+ }
+ if (fBuffer) delete [] fBuffer;
+}
+
+//______________________________________________________________________________
+void AliFstream::Seekg(UInt_t position)
+{
+ // Go to a given position
+ // inside the output stream
+ if (fFile) fFile->seekg(position);
+}
+
+//______________________________________________________________________________
+UInt_t AliFstream::Tellg()
+{
+ // Return the current
+ // position inside the
+ // output stream
+ if (fFile) return fFile->tellg();
+ else return 0;
+}
+
+//______________________________________________________________________________
+void AliFstream::WriteBuffer(const char *buffer, UInt_t size, Bool_t force)
+{
+ // Write the buffer to a file
+ // In case the user gives a 'force'
+ // flag then the buffer is written
+ // as it is. Otherwise, we check the
+ // endianess and swap the buffer data
+ // so that it is always stored using
+ // little endian format.
+ if (force) {
+ fFile->write(buffer,size);
+ }
+ else {
+ if (!fSwap) {
+ // Little endian - do nothing
+ fFile->write(buffer,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);
+ }
+ }
+}
--- /dev/null
+#ifndef ALIFSTREAM_H
+#define ALIFSTREAM_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice */
+
+//-------------------------------------------------------------------------
+// This is the class which is to be used during the writing of
+// simulated raw data (DDL files format).
+// It is using the root functionality in order to deal correctly
+// with little/big endian issue. By convention the detector raw
+// data payload is stored always with little endian (this corresponds
+// to the real life situation when the detector data is coming from
+// the hardware).
+//-------------------------------------------------------------------------
+
+#include <TObject.h>
+
+class AliFstream : public TObject {
+public:
+ AliFstream();
+ AliFstream(const char *fileName);
+ AliFstream(const AliFstream &source);
+ AliFstream& operator= (const AliFstream &source);
+ virtual ~AliFstream();
+
+ void Seekg(UInt_t position);
+ UInt_t Tellg();
+ void WriteBuffer(const char *buffer, UInt_t size, Bool_t force = kFALSE);
+
+private:
+
+ fstream *fFile; // Output file stream
+ UChar_t *fBuffer; // Pointer to the internal buffer
+ UInt_t fBufferSize; // Internal buffer size
+ Bool_t fSwap; // Big or little endian
+
+ ClassDef(AliFstream,0)
+};
+
+#endif