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 **************************************************************************/
18 Revision 1.2 2007/10/12 13:36:27 cvetan
19 Coding convention fixes from Stefan
21 Revision 1.1 2007/09/17 10:23:31 cvetan
22 New TPC monitoring package from Stefan Kniege. The monitoring package can be started by running TPCMonitor.C macro located in macros folder.
26 ////////////////////////////////////////////////////////////////////////
28 //// AliTPCMonitorAltro class
30 //// Class for decoding raw TPC data in the ALTRO format.
31 //// Data are transformed from 32 bit words to 10 bit or 40 bit respectively.
32 //// The whole payload is transformed at once and written to an array.
33 //// The single channels are decoded starting from the trailer word which is
34 //// decoded by DecodeTrailer(Int_t pos)
36 //// Authors: Roland Bramm,
37 //// Stefan Kniege, IKF, Frankfurt
39 /////////////////////////////////////////////////////////////////////////
42 #include "AliTPCMonitorAltro.h"
44 #include <Riostream.h>
46 ClassImp(AliTPCMonitorAltro)
48 //_____________________________________________________________________________________________
49 AliTPCMonitorAltro::AliTPCMonitorAltro(UInt_t* memory, Int_t size, Int_t fformat) :
56 fallocate40BitArray(false),
57 fallocate10BitArray(false),
66 ffilename(new Char_t[256])
68 // Constructor: Set different CDH offsets for ROOT (0) and date format
69 // Data offset can be changed via SetDataOffset(Int_t val)
71 if( fformat==0) foffset=7; // old CHD Format
72 else if(fformat==1) foffset=8; // memory pointer from DATE (start CDH)
73 else if(fformat==2) foffset=0; // memory pointer from ROOT (after CDH)
77 //_____________________________________________________________________________________________
78 AliTPCMonitorAltro::AliTPCMonitorAltro(const AliTPCMonitorAltro &altro) :
81 fmemory(altro.fmemory),
83 f40BitArray(altro.f40BitArray),
84 f10BitArray(altro.f10BitArray),
85 fdecoderPos(altro.fdecoderPos),
86 fallocate40BitArray(altro.fallocate40BitArray),
87 fallocate10BitArray(altro.fallocate10BitArray),
88 foffset(altro.foffset),
89 fwrite10bit(altro.fwrite10bit),
90 fTrailerNWords(altro.fTrailerNWords),
91 fTrailerHwAddress(altro.fTrailerHwAddress),
92 fTrailerDataPos(altro.fTrailerDataPos),
93 fTrailerBlockPos(altro.fTrailerBlockPos),
94 fTrailerPos(altro.fTrailerPos),
95 fNextPos(altro.fNextPos),
96 ffilename(new Char_t[strlen(altro.ffilename)+1])
99 strcpy(ffilename,altro.ffilename);
103 //_____________________________________________________________________________________________
104 AliTPCMonitorAltro &AliTPCMonitorAltro::operator =(const AliTPCMonitorAltro& altro)
106 // assignement operator
109 ((TNamed *)this)->operator=(altro);
111 fmemory=altro.fmemory;
113 f40BitArray=altro.f40BitArray;
114 f10BitArray=altro.f10BitArray;
115 fdecoderPos=altro.fdecoderPos;
116 fallocate40BitArray=altro.fallocate40BitArray;
117 fallocate10BitArray=altro.fallocate10BitArray;
118 foffset=altro.foffset;
119 fwrite10bit=altro.fwrite10bit;
120 fTrailerNWords=altro.fTrailerNWords;
121 fTrailerHwAddress=altro.fTrailerHwAddress;
122 fTrailerDataPos=altro.fTrailerDataPos;
123 fTrailerBlockPos=altro.fTrailerBlockPos;
124 fTrailerPos=altro.fTrailerPos;
125 fNextPos=altro.fNextPos;
126 ffilename = new Char_t[strlen(altro.ffilename)+1];
127 strcpy(ffilename,altro.ffilename);
133 //_____________________________________________________________________________________________
134 AliTPCMonitorAltro::~AliTPCMonitorAltro() {
136 if(fallocate40BitArray == true) delete[] f40BitArray;
137 if(fallocate10BitArray == true) delete[] f10BitArray;
141 //_____________________________________________________________________________________________
142 void AliTPCMonitorAltro::Allocate40BitArray()
144 // create array for 40 bit decoded data
145 fallocate40BitArray = true;
146 f40BitArray = new long long[Get40BitArraySize()];
149 //_____________________________________________________________________________________________
150 void AliTPCMonitorAltro::Allocate10BitArray()
152 // Create array for 10 bit decoded data
153 fallocate10BitArray = true;
154 f10BitArray = new Short_t[Get10BitArraySize()];
157 //_____________________________________________________________________________________________
158 long long *AliTPCMonitorAltro::Get40BitArray()
160 // Return pointer to array for 40 bit decoded data
164 //_____________________________________________________________________________________________
165 Short_t *AliTPCMonitorAltro::Get10BitArray()
167 // Return pointer to array for 10 bit decoded data
171 // //_____________________________________________________________________________________________
172 // Int_t AliTPCMonitorAltro::Get40BitArraySize()
174 // // Return number of 40 bit words in payload
175 // return fmemory[fsize-1];
178 // //_____________________________________________________________________________________________
179 // Int_t AliTPCMonitorAltro::Get10BitArraySize()
181 // // Return number of 10 bit words in payload
182 // return fmemory[fsize-1]*4;
185 //_____________________________________________________________________________________________
186 void AliTPCMonitorAltro::Decodeto40Bit()
188 // Decode 32 bit words in fmemory to 40 bit words
189 Long64_t blackbox = 0;
192 for(Int_t i = 0; i < Get40BitArraySize(); i++)
197 blackbox = (fmemory[foffset]) + (((Long64_t)(fmemory[foffset+1]&fgk08BitOn))<<32);
201 blackbox = (fmemory[foffset]>>8 ) + (((Long64_t)(fmemory[foffset+1]&fgk16BitOn))<<24);
205 blackbox = (fmemory[foffset]>>16) + (((Long64_t)(fmemory[foffset+1]&fgk24BitOn))<<16);
209 blackbox = (fmemory[foffset]>>24) + (((Long64_t)(fmemory[foffset+1] ))<< 8);
216 f40BitArray[i] = blackbox;
220 //_____________________________________________________________________________________________
221 void AliTPCMonitorAltro::Decodeto10Bit(Int_t equipment)
223 // Decode 32 bit words in fmemory to 10 bit words.
224 // Write words to file if fwrite10bit ("Write 10 bit" in Monitor.C Gui ) is set
226 Long64_t blackbox = 0;
232 Char_t nameout[256] ; sprintf(nameout,"%s_PayloadEquipmentId_%03i.txt",ffilename,equipment);
233 datout.open(nameout);
234 AliInfo(Form("AliTPCMonitorAltro::decodeto10Bit : Write Data to %s",nameout));
235 if(foffset==0) datout << "Payload without CDH in 10bit words " << endl;
236 else datout << "CDH in 32 bit hex words words (" << foffset << " lines ) followed by payload in 10 bit words " << endl;
237 for(Int_t ih = 0; ih< foffset ; ih++)
239 datout << hex << fmemory[ih] << endl;
243 for(Int_t ind = 0; ind < Get40BitArraySize(); ind++)
249 blackbox = (fmemory[foffset]) + (((Long64_t)(fmemory[foffset+1]&fgk08BitOn))<<32);
253 blackbox = (fmemory[foffset]>>8 ) + (((Long64_t)(fmemory[foffset+1]&fgk16BitOn))<<24);
257 blackbox = (fmemory[foffset]>>16) + (((Long64_t)(fmemory[foffset+1]&fgk24BitOn))<<16);
261 blackbox = (fmemory[foffset]>>24) + (((Long64_t)(fmemory[foffset+1] ))<< 8);
268 f10BitArray[ind*4+0] = (Short_t)( blackbox & fgkmask10 ) ;
269 f10BitArray[ind*4+1] = (Short_t)((blackbox & fgkmask20)>>10);
270 f10BitArray[ind*4+2] = (Short_t)((blackbox & fgkmask30)>>20);
271 f10BitArray[ind*4+3] = (Short_t)((blackbox & fgkmask40)>>30);
275 for(Int_t ind = 0; ind < Get40BitArraySize(); ind++)
277 datout << dec << f10BitArray[ind*4+0] << "\n";
278 datout << dec << f10BitArray[ind*4+1] << "\n";
279 datout << dec << f10BitArray[ind*4+2] << "\n";
280 datout << dec << f10BitArray[ind*4+3] << "\n";
284 if(fwrite10bit) datout.close();
287 //_____________________________________________________________________________________________
288 Int_t AliTPCMonitorAltro::DecodeTrailer(Int_t pos)
290 // Decode the trailer word starting at position pos in fmemory
291 // Check if information leads to proper next trailer position
292 if (GetAltroVersion()==0xaabb) return DecodeTrailerVbb(pos);
298 Long64_t trailer = 0;
302 for(Long64_t iter = 0 ; iter<4;iter++)
304 carry = f10BitArray[pos-iter] ;
305 carry = ( carry << (30- ((iter)*10)));
309 fTrailerHwAddress = (trailer & ((Long64_t )fgkTrailerMaskHardw) );
310 words = (Long64_t )( (trailer & ((Long64_t )fgkTrailerMaskNWords))>>16);
311 tail = (Long64_t )( (trailer & ((Long64_t )fgkTrailerMaskTail ))>>26 );
313 if(words%4!=0) rest = 4-(words%4);
314 fTrailerNWords = words+rest ;
315 fTrailerDataPos = pos -4 -rest ;
316 fTrailerBlockPos = pos -4 ;
317 fNextPos = (pos -fTrailerNWords -4);
319 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; }
320 else if( fNextPos==-1 ) { /* was last channel */ return 0; }
321 else if( fNextPos <0 ) { AliError("Next Trailer position < 0 "); return -1; }
322 else if((f10BitArray[fNextPos]!=682)) { AliError(Form("Could not find tail (2AA) at next supposed position %i",fNextPos)); return -1; }
323 else { return fNextPos;}
327 //_____________________________________________________________________________________________
328 Int_t AliTPCMonitorAltro::DecodeTrailerVbb(Int_t pos)
330 // Decode the trailer word starting at position pos in fmemory
331 // Check if information leads to proper next trailer position
333 if(pos>Get10BitArraySize()-4) return 0;
337 Long64_t trailer = 0;
341 for(Long64_t iter = 0 ; iter<4;iter++)
343 carry = f10BitArray[pos-iter] ;
344 carry = ( carry << (30- ((iter)*10)));
348 fTrailerHwAddress = (trailer & ((Long64_t )fgkTrailerMaskHardw) );
349 words = (Long64_t )( (trailer & ((Long64_t )fgkTrailerMaskNWords))>>16);
350 tail = (Long64_t )( (trailer & ((Long64_t )fgkTrailerMaskTail ))>>26 );
352 //Decide on read direction (sign) from the RCU trailer information
354 if (GetAltroVersion()==0xaabb) sign=1;
356 if(words%4!=0) rest = 4-(words%4);
357 fTrailerNWords = words+rest ;
358 fTrailerDataPos = pos +sign*(4+rest) ;
359 fTrailerBlockPos = pos +sign*4 ;
360 fNextPos = (pos +sign*(fTrailerNWords+4));
362 if( tail==fgkTrailerTailErr ) {
363 AliError(Form("Found Altro header with error marker (2AEE)[%0x]: %i. Supp.next Trailer line (2AA)[%0x]: %i ",
364 tail,pos,f10BitArray[fNextPos],fNextPos));
366 } else if ( tail!=fgkTrailerTail ) {
367 AliError(Form("Could not read Trailer. \"Write 10bit\" for this event. Last Trailer line (2AA)[%0x]: %i. Supp.next Trailer line (2AA)[%0x]: %i ",
368 tail,pos,f10BitArray[fNextPos],fNextPos)); return -1;
369 } else if( fNextPos==Get10BitArraySize()+3 ) { /* was last channel */
371 } else if( fNextPos >=Get10BitArraySize() ) {
372 AliError(Form("Next Trailer position < 0 %i", fNextPos));
374 } else if((f10BitArray[fNextPos]!=682)&&(f10BitArray[fNextPos]!=686)) {
375 AliError(Form("Could not find tail (2AA) at next supposed position %i",fNextPos));