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 **************************************************************************/
20 #include "AliTPCMonitorDateFile.h"
22 ClassImp(AliTPCMonitorDateFile)
24 //____________________________________________________________________________
25 AliTPCMonitorDateFile::AliTPCMonitorDateFile()
29 fisBigMemAllocated = false;
30 freadPosOverflow = false;
38 //____________________________________________________________________________
39 AliTPCMonitorDateFile::~AliTPCMonitorDateFile()
43 if(fisBigMemAllocated == true){
48 //____________________________________________________________________________
49 void AliTPCMonitorDateFile::OpenDateFile(string name)
52 if( (ffilename != name) && (finitFile == true) ) {
56 fin->open(name.c_str());
62 //____________________________________________________________________________
63 Bool_t AliTPCMonitorDateFile::IsDateFileOpen()
65 // Check if DATE file is open
66 return fin->is_open();
69 //____________________________________________________________________________
70 void AliTPCMonitorDateFile::CloseDateFile()
74 freadPosOverflow = false;
79 //____________________________________________________________________________
80 void AliTPCMonitorDateFile::ResetFilePos()
82 // Reset file position
86 //____________________________________________________________________________
87 void AliTPCMonitorDateFile::SetFileSize()
89 // Set size of DATE file
90 fin->seekg (0, ios::end);
91 ffileSize = fin->tellg();
92 fin->seekg (0, ios::beg);
95 //____________________________________________________________________________
96 Int_t AliTPCMonitorDateFile::GetFileSize()
98 // Return size of DATE file
102 //____________________________________________________________________________
103 void AliTPCMonitorDateFile::ReadEvent()
105 // Read in event from file
108 Bool_t toSwapEndian = false;
109 //Fetch some bytes to get headers to know how much
110 fin->seekg(ffilePos);
111 //if( (getFilePosition() + sizeof(fmem)) <= (unsigned int)getFileSize()){
113 if( (GetFilePosition() + sfmem) <= (UInt_t)GetFileSize()){
116 fin->read((Char_t*)fmem,sfmem);
117 fin->seekg(ffilePos);
118 AliTPCMonitorDateFormat *DateForm;
119 DateForm = new AliTPCMonitorDateFormat((Char_t *)&fmem);
123 toSwapEndian = DateForm->IsEventWrongEndian();
124 if(toSwapEndian == true){
126 for(Int_t i = 0; i < 68; i++) {
127 swapcarry[0] = fmem[(i*4)+0];
128 swapcarry[1] = fmem[(i*4)+1];
129 swapcarry[2] = fmem[(i*4)+2];
130 swapcarry[3] = fmem[(i*4)+3];
131 fmem[(i*4)+0] = swapcarry[3];
132 fmem[(i*4)+1] = swapcarry[2];
133 fmem[(i*4)+2] = swapcarry[1];
134 fmem[(i*4)+3] = swapcarry[0];
136 DateForm = new AliTPCMonitorDateFormat((Char_t *)&fmem);
138 size = DateForm->GetEventSize();
139 if(size > GetAllocatedSizeofArray()) {
140 AllocateArray((Int_t)(size*1.1));
142 if( (GetFilePosition() + size) <= GetFileSize()){
143 fin->read((Char_t*)fbigMem,size);
144 if(toSwapEndian == true){
145 for(Int_t i = 0; i < (size/4); i++) {
146 swapcarry[0] = fbigMem[(i*4)+0];
147 swapcarry[1] = fbigMem[(i*4)+1];
148 swapcarry[2] = fbigMem[(i*4)+2];
149 swapcarry[3] = fbigMem[(i*4)+3];
150 fbigMem[(i*4)+0] = swapcarry[3];
151 fbigMem[(i*4)+1] = swapcarry[2];
152 fbigMem[(i*4)+2] = swapcarry[1];
153 fbigMem[(i*4)+3] = swapcarry[0];
158 freadPosOverflow = true;
162 freadPosOverflow = true;
166 //____________________________________________________________________________
167 Bool_t AliTPCMonitorDateFile::IsLastEvent()
169 // Check if event is last event in file
171 if( (ffilePos < ffileSize) && (freadPosOverflow == false) )
178 //____________________________________________________________________________
179 Bool_t AliTPCMonitorDateFile::IsEventValid()
181 // Check Over flow flag
183 if(freadPosOverflow == false)
190 //____________________________________________________________________________
191 Int_t AliTPCMonitorDateFile::GetFilePosition()
193 // Return current position in file
197 //____________________________________________________________________________
198 Int_t AliTPCMonitorDateFile::GetAllocatedSizeofArray()
200 // Return size of allocated data array
204 //____________________________________________________________________________
205 void AliTPCMonitorDateFile::AllocateArray(Int_t size)
207 // allocate data array
208 if(fisBigMemAllocated == false) {
209 fbigMem = new Char_t[size];
211 fisBigMemAllocated = true;
214 fbigMem = new Char_t[size];
216 fisBigMemAllocated = true;
220 //____________________________________________________________________________
221 Char_t *AliTPCMonitorDateFile::GetMemoryPointer()
223 // Return pointer to data array