]> git.uio.no Git - u/mrichter/AliRoot.git/blame - RAW/AliFstream.cxx
Spec file for production of RPM with static libraries needed by DATE mStreamRecorder
[u/mrichter/AliRoot.git] / RAW / AliFstream.cxx
CommitLineData
18de460b 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
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//-------------------------------------------------------------------------
26
27#include <unistd.h>
28#include <Riostream.h>
29
30#include "AliFstream.h"
31#include "AliLog.h"
32
33ClassImp(AliFstream)
34
35//______________________________________________________________________________
36AliFstream::AliFstream():
37 fFile(0x0),
38 fBuffer(0x0),
39 fBufferSize(0),
40 fSwap(kFALSE)
41{
42 // Default constructor
43
44 for (Int_t i = 0; i < 8; i++) fBuffer[i] = 0;
45}
46
47//______________________________________________________________________________
48AliFstream::AliFstream(const char *fileName):
49 fFile(0x0),
50 fBuffer(0x0),
51 fBufferSize(0),
52 fSwap(kFALSE)
53{
54 // Constructor
55 // Takes the input filename and
56 // opens the output stream
57
58#ifndef __DECCXX
59 fFile = new fstream(fileName, ios::binary|ios::out);
60#else
61 fFile = new fstream(fileName, ios::out);
62#endif
63
64 // Check endianess
65 UInt_t temp = 1;
66 UChar_t *ptemp = (UChar_t *)&temp;
67 if (!ptemp[0]) fSwap = kTRUE;
68}
69
70//______________________________________________________________________________
71AliFstream::AliFstream(const AliFstream &source):
72 TObject(source)
73{
74 // Copy constructor
75 //
76 AliFatal("Copy constructor not implemented !");
77}
78
79//______________________________________________________________________________
80AliFstream &AliFstream::operator =(const AliFstream& source)
81{
82 // assignment operator
83 //
84 if(this==&source) return *this;
85 ((TObject *)this)->operator=(source);
86
87 AliFatal("Assigment operator not implemented !");
88
89 return *this;
90}
91
92//______________________________________________________________________________
93AliFstream::~AliFstream()
94{
95 // Destructor
96 //
97 if (fFile) {
98 fFile->close();
99 delete fFile;
100 }
101 if (fBuffer) delete [] fBuffer;
102}
103
104//______________________________________________________________________________
41008432 105void AliFstream::Seekp(UInt_t position)
18de460b 106{
107 // Go to a given position
108 // inside the output stream
41008432 109 if (fFile) fFile->seekp(position);
18de460b 110}
111
112//______________________________________________________________________________
41008432 113UInt_t AliFstream::Tellp()
18de460b 114{
115 // Return the current
116 // position inside the
117 // output stream
41008432 118 if (fFile) return fFile->tellp();
18de460b 119 else return 0;
120}
121
122//______________________________________________________________________________
123void AliFstream::WriteBuffer(const char *buffer, UInt_t size, Bool_t force)
124{
125 // Write the buffer to a file
126 // In case the user gives a 'force'
127 // flag then the buffer is written
128 // as it is. Otherwise, we check the
129 // endianess and swap the buffer data
130 // so that it is always stored using
131 // little endian format.
41008432 132
133 // The raw data payload size is always
134 // 4 bytes aligned
135 if ((size % 4) != 0)
136 AliFatal(Form("Size of the buffer is not multiple of 4 (size = %d) !",size));
137
18de460b 138 if (force) {
139 fFile->write(buffer,size);
140 }
141 else {
142 if (!fSwap) {
143 // Little endian - do nothing
144 fFile->write(buffer,size);
145 }
146 else {
147 // Big endian - swap the buffer contents
148 if (size > fBufferSize) {
149 if (fBuffer) delete [] fBuffer;
150 fBuffer = new UChar_t[size];
151 fBufferSize = size;
152 }
153 swab(buffer,fBuffer,size);
154 fFile->write((const char *)fBuffer,size);
155 }
156 }
157}