Minors...Just ordering the libraries
[u/mrichter/AliRoot.git] / TPC / AliTPCMonitorAltro.cxx
CommitLineData
48265b32 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$
ca7b8371 18Revision 1.1 2007/09/17 10:23:31 cvetan
19New TPC monitoring package from Stefan Kniege. The monitoring package can be started by running TPCMonitor.C macro located in macros folder.
20
48265b32 21*/
22
ca7b8371 23////////////////////////////////////////////////////////////////////////
24////
25//// AliTPCMonitorAltro class
26////
27//// Class for decoding raw TPC data in the ALTRO format.
28//// Data are transformed from 32 bit words to 10 bit or 40 bit respectively.
29//// The whole payload is transformed at once and written to an array.
30//// The single channels are decoded starting from the trailer word which is
31//// decoded by DecodeTrailer(Int_t pos)
32////
33//// Authors: Roland Bramm,
34//// Stefan Kniege, IKF, Frankfurt
35////
36/////////////////////////////////////////////////////////////////////////
37
48265b32 38
39#include "AliTPCMonitorAltro.h"
ca7b8371 40#include "AliLog.h"
41#include <Riostream.h>
42
43ClassImp(AliTPCMonitorAltro)
48265b32 44
45//_____________________________________________________________________________________________
ca7b8371 46AliTPCMonitorAltro::AliTPCMonitorAltro(UInt_t* memory, Int_t size, Int_t fformat) :
47 fverb(0),
48 fmemory(memory),
49 fsize(size),
50 f40BitArray(0),
51 f10BitArray(0),
52 fdecoderPos(0),
53 fallocate40BitArray(false),
54 fallocate10BitArray(false),
55 foffset(0),
56 fwrite10bit(0),
57 fTrailerNWords(0),
58 fTrailerHwAddress(0),
59 fTrailerDataPos(0),
60 fTrailerBlockPos(0),
61 fTrailerPos(0),
62 fNextPos(0),
63 ffilename(new Char_t[256])
48265b32 64{
ca7b8371 65 // Constructor: Set different CDH offsets for ROOT (0) and date format
66 // Data offset can be changed via SetDataOffset(Int_t val)
67
48265b32 68 if( fformat==0) foffset=7; // old CHD Format
ca7b8371 69 else if(fformat==1) foffset=8; // memory pointer from DATE (start CDH)
70 else if(fformat==2) foffset=0; // memory pointer from ROOT (after CDH)
48265b32 71}
72
ca7b8371 73
74//_____________________________________________________________________________________________
75AliTPCMonitorAltro::AliTPCMonitorAltro(const AliTPCMonitorAltro &altro) :
76 TNamed(altro),
77 fverb(altro.fverb),
78 fmemory(altro.fmemory),
79 fsize(altro.fsize),
80 f40BitArray(altro.f40BitArray),
81 f10BitArray(altro.f10BitArray),
82 fdecoderPos(altro.fdecoderPos),
83 fallocate40BitArray(altro.fallocate40BitArray),
84 fallocate10BitArray(altro.fallocate10BitArray),
85 foffset(altro.foffset),
86 fwrite10bit(altro.fwrite10bit),
87 fTrailerNWords(altro.fTrailerNWords),
88 fTrailerHwAddress(altro.fTrailerHwAddress),
89 fTrailerDataPos(altro.fTrailerDataPos),
90 fTrailerBlockPos(altro.fTrailerBlockPos),
91 fTrailerPos(altro.fTrailerPos),
92 fNextPos(altro.fNextPos),
93 ffilename(new Char_t[strlen(altro.ffilename)+1])
94{
95 // copy constructor
96 strcpy(ffilename,altro.ffilename);
97
98}
99
100//_____________________________________________________________________________________________
101AliTPCMonitorAltro &AliTPCMonitorAltro::operator =(const AliTPCMonitorAltro& altro)
102{
103 // assignement operator
104
105 if(this!=&altro){
106 ((TNamed *)this)->operator=(altro);
107 fverb=altro.fverb;
108 fmemory=altro.fmemory;
109 fsize=altro.fsize;
110 f40BitArray=altro.f40BitArray;
111 f10BitArray=altro.f10BitArray;
112 fdecoderPos=altro.fdecoderPos;
113 fallocate40BitArray=altro.fallocate40BitArray;
114 fallocate10BitArray=altro.fallocate10BitArray;
115 foffset=altro.foffset;
116 fwrite10bit=altro.fwrite10bit;
117 fTrailerNWords=altro.fTrailerNWords;
118 fTrailerHwAddress=altro.fTrailerHwAddress;
119 fTrailerDataPos=altro.fTrailerDataPos;
120 fTrailerBlockPos=altro.fTrailerBlockPos;
121 fTrailerPos=altro.fTrailerPos;
122 fNextPos=altro.fNextPos;
123 ffilename = new Char_t[strlen(altro.ffilename)+1];
124 strcpy(ffilename,altro.ffilename);
125 }
126 return *this;
127}
128
129
48265b32 130//_____________________________________________________________________________________________
131AliTPCMonitorAltro::~AliTPCMonitorAltro() {
132 // Destructor
133 if(fallocate40BitArray == true) delete[] f40BitArray;
134 if(fallocate10BitArray == true) delete[] f10BitArray;
135 delete[] ffilename;
136 }
137
138//_____________________________________________________________________________________________
139void AliTPCMonitorAltro::Allocate40BitArray()
140{
141 // create array for 40 bit decoded data
142 fallocate40BitArray = true;
143 f40BitArray = new long long[Get40BitArraySize()];
144}
145
146//_____________________________________________________________________________________________
147void AliTPCMonitorAltro::Allocate10BitArray()
148{
149 // Create array for 10 bit decoded data
150 fallocate10BitArray = true;
151 f10BitArray = new Short_t[Get10BitArraySize()];
152}
153
154//_____________________________________________________________________________________________
155long long *AliTPCMonitorAltro::Get40BitArray()
156{
157 // Return pointer to array for 40 bit decoded data
158 return f40BitArray;
159}
160
161//_____________________________________________________________________________________________
162Short_t *AliTPCMonitorAltro::Get10BitArray()
163{
164 // Return pointer to array for 10 bit decoded data
165 return f10BitArray;
166}
167
168//_____________________________________________________________________________________________
169Int_t AliTPCMonitorAltro::Get40BitArraySize()
170{
171 // Return number of 40 bit words in payload
172 return fmemory[fsize-1];
173}
174
175//_____________________________________________________________________________________________
176Int_t AliTPCMonitorAltro::Get10BitArraySize()
177{
178 // Return number of 10 bit words in payload
179 return fmemory[fsize-1]*4;
180}
181
182//_____________________________________________________________________________________________
183void AliTPCMonitorAltro::Decodeto40Bit()
184{
185 // Decode 32 bit words in fmemory to 40 bit words
186 Long64_t blackbox = 0;
187 Int_t rest;
188
189 for(Int_t i = 0; i < Get40BitArraySize(); i++)
190 {
191 rest = i%4;
192 switch(rest) {
193 case 0:
ca7b8371 194 blackbox = (fmemory[foffset]) + (((Long64_t)(fmemory[foffset+1]&fgk08BitOn))<<32);
48265b32 195 foffset +=1;
196 break;
197 case 1:
ca7b8371 198 blackbox = (fmemory[foffset]>>8 ) + (((Long64_t)(fmemory[foffset+1]&fgk16BitOn))<<24);
48265b32 199 foffset +=1;
200 break;
201 case 2:
ca7b8371 202 blackbox = (fmemory[foffset]>>16) + (((Long64_t)(fmemory[foffset+1]&fgk24BitOn))<<16);
48265b32 203 foffset +=1;
204 break;
205 case 3:
206 blackbox = (fmemory[foffset]>>24) + (((Long64_t)(fmemory[foffset+1] ))<< 8);
207 foffset +=2;
208 break;
209 default:
210 blackbox = 0;
211 break;
212 }
213 f40BitArray[i] = blackbox;
214 }
215}
216
217//_____________________________________________________________________________________________
218void AliTPCMonitorAltro::Decodeto10Bit(Int_t equipment)
219{
220 // Decode 32 bit words in fmemory to 10 bit words.
221 // Write words to file if fwrite10bit ("Write 10 bit" in Monitor.C Gui ) is set
222
223 Long64_t blackbox = 0;
224 Int_t rest = 0;
225
226 ofstream datout;
227 if(fwrite10bit)
228 {
229 Char_t nameout[256] ; sprintf(nameout,"%s_PayloadEquipmentId_%03i.txt",ffilename,equipment);
230 datout.open(nameout);
231 AliInfo(Form("AliTPCMonitorAltro::decodeto10Bit : Write Data to %s",nameout));
232 if(foffset==0) datout << "Payload without CDH in 10bit words " << endl;
233 else datout << "CDH in 32 bit hex words words (" << foffset << " lines ) followed by payload in 10 bit words " << endl;
234 for(Int_t ih = 0; ih< foffset ; ih++)
235 {
236 datout << hex << fmemory[ih] << endl;
237 }
238 }
239
240 for(Int_t ind = 0; ind < Get40BitArraySize(); ind++)
241 {
242 rest = ind%4;
243 switch(rest)
244 {
245 case 0:
ca7b8371 246 blackbox = (fmemory[foffset]) + (((Long64_t)(fmemory[foffset+1]&fgk08BitOn))<<32);
48265b32 247 foffset +=1;
248 break;
249 case 1:
ca7b8371 250 blackbox = (fmemory[foffset]>>8 ) + (((Long64_t)(fmemory[foffset+1]&fgk16BitOn))<<24);
48265b32 251 foffset +=1;
252 break;
253 case 2:
ca7b8371 254 blackbox = (fmemory[foffset]>>16) + (((Long64_t)(fmemory[foffset+1]&fgk24BitOn))<<16);
48265b32 255 foffset +=1;
256 break;
257 case 3:
258 blackbox = (fmemory[foffset]>>24) + (((Long64_t)(fmemory[foffset+1] ))<< 8);
259 foffset +=2;
260 break;
261 default:
262 blackbox = 0;
263 break;
264 }
ca7b8371 265 f10BitArray[ind*4+0] = (Short_t)( blackbox & fgkmask10 ) ;
266 f10BitArray[ind*4+1] = (Short_t)((blackbox & fgkmask20)>>10);
267 f10BitArray[ind*4+2] = (Short_t)((blackbox & fgkmask30)>>20);
268 f10BitArray[ind*4+3] = (Short_t)((blackbox & fgkmask40)>>30);
48265b32 269 }
270 if(fwrite10bit)
271 {
272 for(Int_t ind = 0; ind < Get40BitArraySize(); ind++)
273 {
274 datout << dec << f10BitArray[ind*4+0] << "\n";
275 datout << dec << f10BitArray[ind*4+1] << "\n";
276 datout << dec << f10BitArray[ind*4+2] << "\n";
277 datout << dec << f10BitArray[ind*4+3] << "\n";
278 }
279 }
280
281 if(fwrite10bit) datout.close();
282}
283
284//_____________________________________________________________________________________________
285Int_t AliTPCMonitorAltro::DecodeTrailer(Int_t pos)
286{
287 // Decode the trailer word starting at position pos in fmemory
288 // Check if information leads to proper next trailer position
289
290 fTrailerPos = pos;
291 if(pos<=4) return 0;
292
293 Long64_t words = 0;
294 Long64_t tail = 0;
295 Long64_t trailer = 0;
296 Long64_t carry = 0;
297 Long64_t rest = 0 ;
298
299 for(Long64_t iter = 0 ; iter<4;iter++)
300 {
301 carry = f10BitArray[pos-iter] ;
302 carry = ( carry << (30- ((iter)*10)));
303 trailer += carry ;
304 }
305
ca7b8371 306 fTrailerHwAddress = (trailer & ((Long64_t )fgkTrailerMaskHardw) );
307 words = (Long64_t )( (trailer & ((Long64_t )fgkTrailerMaskNWords))>>16);
308 tail = (Long64_t )( (trailer & ((Long64_t )fgkTrailerMaskTail ))>>26 );
48265b32 309
310 if(words%4!=0) rest = 4-(words%4);
311 fTrailerNWords = words+rest ;
312 fTrailerDataPos = pos -4 -rest ;
313 fTrailerBlockPos = pos -4 ;
314 fNextPos = (pos -fTrailerNWords -4);
315
ca7b8371 316 if( tail!=fgkTrailerTail ) { AliError(Form("Could not read Trailer. \"Write 10bit\" for this event. Last Trailer line (2AA): %i. Supp.next Trailer line (2AA): %i ",pos,fNextPos)); return -1; }
48265b32 317 else if( fNextPos==-1 ) { /* was last channel */ return 0; }
318 else if( fNextPos <0 ) { AliError("Next Trailer position < 0 "); return -1; }
319 else if((f10BitArray[fNextPos]!=682)) { AliError(Form("Could not find tail (2AA) at next supposed position %i",fNextPos)); return -1; }
320 else { return fNextPos;}
321
322}
323
324
325