1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
16 //-----------------------------------------------------------------
17 // This is the class which is to be used during the writing of
18 // simulated raw data (DDL files format).
19 // It is using the root functionality in order to deal correctly
20 // with little/big endian issue. By convention the detector raw
21 // data payload is stored always with little endian (this corresponds
22 // to the real life situation when the detector data is coming from
23 // the hardware). The implementation of this class is based on Root
24 // tobuf() method defined in Bytes.h
25 //-------------------------------------------------------------------------
28 #include <Riostream.h>
30 #include "AliFstream.h"
35 //______________________________________________________________________________
36 AliFstream::AliFstream():
42 // Default constructor
44 for (Int_t i = 0; i < 8; i++) fBuffer[i] = 0;
47 //______________________________________________________________________________
48 AliFstream::AliFstream(const char *fileName):
55 // Takes the input filename and
56 // opens the output stream
59 fFile = new fstream(fileName, ios::binary|ios::out);
61 fFile = new fstream(fileName, ios::out);
66 UChar_t *ptemp = (UChar_t *)&temp;
67 if (!ptemp[0]) fSwap = kTRUE;
70 //______________________________________________________________________________
71 AliFstream::~AliFstream()
79 if (fBuffer) delete [] fBuffer;
82 //______________________________________________________________________________
83 void AliFstream::Seekp(UInt_t position)
85 // Go to a given position
86 // inside the output stream
87 if (fFile) fFile->seekp(position);
90 //______________________________________________________________________________
91 UInt_t AliFstream::Tellp()
94 // position inside the
96 if (fFile) return fFile->tellp();
100 //______________________________________________________________________________
101 void AliFstream::WriteBuffer(const char *buffer, UInt_t size, Bool_t force)
103 // Write the buffer to a file
104 // In case the user gives a 'force'
105 // flag then the buffer is written
106 // as it is. Otherwise, we check the
107 // endianess and swap the buffer data
108 // so that it is always stored using
109 // little endian format.
111 // The raw data payload size is always
114 AliFatal(Form("Size of the buffer is not multiple of 4 (size = %d) !",size));
117 fFile->write(buffer,size);
121 // Little endian - do nothing
122 fFile->write(buffer,size);
125 // Big endian - swap the buffer contents
126 if (size > fBufferSize) {
127 if (fBuffer) delete [] fBuffer;
128 fBuffer = new UChar_t[size];
131 swab(buffer,fBuffer,size);
132 fFile->write((const char *)fBuffer,size);