]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCMonitorDateFile.cxx
Fixed index (Adam)
[u/mrichter/AliRoot.git] / TPC / AliTPCMonitorDateFile.cxx
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 $Log$
18 */ 
19
20 #include "AliTPCMonitorDateFile.h"
21
22 ClassImp(AliTPCMonitorDateFile)
23
24 //____________________________________________________________________________
25 AliTPCMonitorDateFile::AliTPCMonitorDateFile() 
26 {
27   // Constructor
28   fin = new ifstream();
29   fisBigMemAllocated = false;
30   freadPosOverflow = false;
31   ffilePos = 0;
32   ffileSize = 0;
33   fbigMemsize = 0;
34   finitFile = false;
35   ffilename = "";
36 }
37
38 //____________________________________________________________________________
39 AliTPCMonitorDateFile::~AliTPCMonitorDateFile() 
40 {
41   // Destructor
42   delete fin;
43   if(fisBigMemAllocated == true){
44     delete[] fbigMem;
45   }
46 }
47
48 //____________________________________________________________________________
49 void AliTPCMonitorDateFile::OpenDateFile(string name) 
50 {
51   // Open DATE file 
52   if( (ffilename != name) && (finitFile == true) ) {
53     CloseDateFile();
54     ResetFilePos();
55   }
56   fin->open(name.c_str());
57   ffilename = name;
58   SetFileSize();
59   finitFile = true;
60 }
61
62 //____________________________________________________________________________
63 Bool_t AliTPCMonitorDateFile::IsDateFileOpen() 
64 {
65   // Check if DATE file is open
66   return fin->is_open();
67 }
68
69 //____________________________________________________________________________
70 void AliTPCMonitorDateFile::CloseDateFile() 
71 {
72   // Close DATE file
73   fin->close();
74   freadPosOverflow = false;
75   delete fin;
76   fin = new ifstream();
77 }
78
79 //____________________________________________________________________________
80 void AliTPCMonitorDateFile::ResetFilePos() 
81 {
82   // Reset file position 
83   ffilePos = 0;
84 }
85
86 //____________________________________________________________________________
87 void AliTPCMonitorDateFile::SetFileSize() 
88 {
89   // Set size of DATE file
90   fin->seekg (0, ios::end);
91   ffileSize = fin->tellg();
92   fin->seekg (0, ios::beg);
93 }
94
95 //____________________________________________________________________________
96 Int_t AliTPCMonitorDateFile::GetFileSize() 
97 {
98   // Return size of DATE file
99   return ffileSize;
100 }
101
102 //____________________________________________________________________________
103 void AliTPCMonitorDateFile::ReadEvent() 
104 {
105   // Read in event from file
106   Int_t size;
107   Char_t swapcarry[4];
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()){
112         UInt_t sfmem = 272;
113         if( (GetFilePosition() + sfmem) <= (UInt_t)GetFileSize()){
114
115           
116           fin->read((Char_t*)fmem,sfmem);
117                 fin->seekg(ffilePos);
118                 AliTPCMonitorDateFormat *DateForm;
119                 DateForm = new AliTPCMonitorDateFormat((Char_t *)&fmem);
120                 
121
122           
123                 toSwapEndian = DateForm->IsEventWrongEndian();
124                 if(toSwapEndian == true){
125                         delete DateForm;
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];
135                         }
136                         DateForm = new AliTPCMonitorDateFormat((Char_t *)&fmem);
137                 }
138                 size = DateForm->GetEventSize();
139                 if(size > GetAllocatedSizeofArray()) {
140                   AllocateArray((Int_t)(size*1.1));
141                 }
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];
154                                 }
155                         }
156                         ffilePos += size;
157                 }else{
158                   freadPosOverflow = true;
159                 }
160                 delete DateForm;
161         }else{
162           freadPosOverflow = true;
163         }
164 }
165
166 //____________________________________________________________________________
167 Bool_t AliTPCMonitorDateFile::IsLastEvent() 
168 {
169   // Check if event is last event in file
170   Bool_t retval;
171   if( (ffilePos < ffileSize) && (freadPosOverflow == false) )
172     retval = false;
173   else
174     retval = true;
175   return retval;
176 }
177
178 //____________________________________________________________________________
179 Bool_t AliTPCMonitorDateFile::IsEventValid()
180 {
181   // Check Over flow flag 
182   Bool_t retval;
183   if(freadPosOverflow == false)
184     retval = true;
185   else
186     retval = false;
187   return retval;
188 }
189
190 //____________________________________________________________________________
191 Int_t AliTPCMonitorDateFile::GetFilePosition() 
192 {
193   // Return current position in file
194   return ffilePos;
195 }
196
197 //____________________________________________________________________________
198 Int_t AliTPCMonitorDateFile::GetAllocatedSizeofArray() 
199 {
200   // Return size of allocated data array
201   return fbigMemsize;
202 }
203
204 //____________________________________________________________________________
205 void AliTPCMonitorDateFile::AllocateArray(Int_t size) 
206 {
207   // allocate data array
208   if(fisBigMemAllocated == false) {
209     fbigMem = new Char_t[size];
210     fbigMemsize = size;
211     fisBigMemAllocated = true;
212   } else {
213     delete fbigMem;
214     fbigMem = new Char_t[size];
215     fbigMemsize = size;
216     fisBigMemAllocated = true;
217   }
218 }
219
220 //____________________________________________________________________________
221 Char_t *AliTPCMonitorDateFile::GetMemoryPointer() 
222 {
223   // Return pointer to data array
224   return fbigMem;
225 }
226