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),
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(altro.ffilename)
102 //_____________________________________________________________________________________________
103 AliTPCMonitorAltro &AliTPCMonitorAltro::operator =(const AliTPCMonitorAltro& altro)
105 // assignement operator
108 ((TNamed *)this)->operator=(altro);
110 fmemory=altro.fmemory;
112 f40BitArray=altro.f40BitArray;
113 f10BitArray=altro.f10BitArray;
114 fdecoderPos=altro.fdecoderPos;
115 fallocate40BitArray=altro.fallocate40BitArray;
116 fallocate10BitArray=altro.fallocate10BitArray;
117 foffset=altro.foffset;
118 fwrite10bit=altro.fwrite10bit;
119 fTrailerNWords=altro.fTrailerNWords;
120 fTrailerHwAddress=altro.fTrailerHwAddress;
121 fTrailerDataPos=altro.fTrailerDataPos;
122 fTrailerBlockPos=altro.fTrailerBlockPos;
123 fTrailerPos=altro.fTrailerPos;
124 fNextPos=altro.fNextPos;
125 ffilename = altro.ffilename;
131 //_____________________________________________________________________________________________
132 AliTPCMonitorAltro::~AliTPCMonitorAltro() {
134 if(fallocate40BitArray == true) delete[] f40BitArray;
135 if(fallocate10BitArray == true) delete[] f10BitArray;
138 //_____________________________________________________________________________________________
139 void AliTPCMonitorAltro::Allocate40BitArray()
141 // create array for 40 bit decoded data
142 fallocate40BitArray = true;
143 f40BitArray = new long long[Get40BitArraySize()];
146 //_____________________________________________________________________________________________
147 void AliTPCMonitorAltro::Allocate10BitArray()
149 // Create array for 10 bit decoded data
150 fallocate10BitArray = true;
151 f10BitArray = new Short_t[Get10BitArraySize()];
154 //_____________________________________________________________________________________________
155 long long *AliTPCMonitorAltro::Get40BitArray()
157 // Return pointer to array for 40 bit decoded data
161 //_____________________________________________________________________________________________
162 Short_t *AliTPCMonitorAltro::Get10BitArray()
164 // Return pointer to array for 10 bit decoded data
168 // //_____________________________________________________________________________________________
169 // Int_t AliTPCMonitorAltro::Get40BitArraySize()
171 // // Return number of 40 bit words in payload
172 // return fmemory[fsize-1];
175 // //_____________________________________________________________________________________________
176 // Int_t AliTPCMonitorAltro::Get10BitArraySize()
178 // // Return number of 10 bit words in payload
179 // return fmemory[fsize-1]*4;
182 //_____________________________________________________________________________________________
183 void AliTPCMonitorAltro::Decodeto40Bit()
185 // Decode 32 bit words in fmemory to 40 bit words
186 Long64_t blackbox = 0;
189 for(Int_t i = 0; i < Get40BitArraySize(); i++)
194 blackbox = (fmemory[foffset]) + (((Long64_t)(fmemory[foffset+1]&fgk08BitOn))<<32);
198 blackbox = (fmemory[foffset]>>8 ) + (((Long64_t)(fmemory[foffset+1]&fgk16BitOn))<<24);
202 blackbox = (fmemory[foffset]>>16) + (((Long64_t)(fmemory[foffset+1]&fgk24BitOn))<<16);
206 blackbox = (fmemory[foffset]>>24) + (((Long64_t)(fmemory[foffset+1] ))<< 8);
213 f40BitArray[i] = blackbox;
217 //_____________________________________________________________________________________________
218 void AliTPCMonitorAltro::Decodeto10Bit(Int_t equipment)
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
223 Long64_t blackbox = 0;
229 TString nameout=Form("%s_PayloadEquipmentId_%03i.txt",ffilename.Data(),equipment);
230 datout.open(nameout.Data());
231 AliInfo(Form("AliTPCMonitorAltro::decodeto10Bit : Write Data to %s",nameout.Data()));
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++)
236 datout << hex << fmemory[ih] << endl;
240 for(Int_t ind = 0; ind < Get40BitArraySize(); ind++)
246 blackbox = (fmemory[foffset]) + (((Long64_t)(fmemory[foffset+1]&fgk08BitOn))<<32);
250 blackbox = (fmemory[foffset]>>8 ) + (((Long64_t)(fmemory[foffset+1]&fgk16BitOn))<<24);
254 blackbox = (fmemory[foffset]>>16) + (((Long64_t)(fmemory[foffset+1]&fgk24BitOn))<<16);
258 blackbox = (fmemory[foffset]>>24) + (((Long64_t)(fmemory[foffset+1] ))<< 8);
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);
272 for(Int_t ind = 0; ind < Get40BitArraySize(); ind++)
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";
281 if(fwrite10bit) datout.close();
284 //_____________________________________________________________________________________________
285 Int_t AliTPCMonitorAltro::DecodeTrailer(Int_t pos)
287 // Decode the trailer word starting at position pos in fmemory
288 // Check if information leads to proper next trailer position
289 if (GetAltroVersion()==0xaabb) return DecodeTrailerVbb(pos);
295 Long64_t trailer = 0;
299 for(Long64_t iter = 0 ; iter<4;iter++)
301 carry = f10BitArray[pos-iter] ;
302 carry = ( carry << (30- ((iter)*10)));
306 fTrailerHwAddress = (trailer & ((Long64_t )fgkTrailerMaskHardw) );
307 words = (Long64_t )( (trailer & ((Long64_t )fgkTrailerMaskNWords))>>16);
308 tail = (Long64_t )( (trailer & ((Long64_t )fgkTrailerMaskTail ))>>26 );
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);
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; }
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;}
324 //_____________________________________________________________________________________________
325 Int_t AliTPCMonitorAltro::DecodeTrailerVbb(Int_t pos)
327 // Decode the trailer word starting at position pos in fmemory
328 // Check if information leads to proper next trailer position
330 if(pos>Get10BitArraySize()-4) return 0;
334 Long64_t trailer = 0;
338 for(Long64_t iter = 0 ; iter<4;iter++)
340 carry = f10BitArray[pos-iter] ;
341 carry = ( carry << (30- ((iter)*10)));
345 fTrailerHwAddress = (trailer & ((Long64_t )fgkTrailerMaskHardw) );
346 words = (Long64_t )( (trailer & ((Long64_t )fgkTrailerMaskNWords))>>16);
347 tail = (Long64_t )( (trailer & ((Long64_t )fgkTrailerMaskTail ))>>26 );
349 //Decide on read direction (sign) from the RCU trailer information
351 if (GetAltroVersion()==0xaabb) sign=1;
353 if(words%4!=0) rest = 4-(words%4);
354 fTrailerNWords = words+rest ;
355 fTrailerDataPos = pos +sign*(4+rest) ;
356 fTrailerBlockPos = pos +sign*4 ;
357 fNextPos = (pos +sign*(fTrailerNWords+4));
359 if( tail==fgkTrailerTailErr ) {
360 AliError(Form("Found Altro header with error marker (2AEE)[%0llx]: %i. Supp.next Trailer line (2AA)[%0x]: %i ",
361 tail,pos,f10BitArray[fNextPos],fNextPos));
363 } else if ( tail!=fgkTrailerTail ) {
364 AliError(Form("Could not read Trailer. \"Write 10bit\" for this event. Last Trailer line (2AA)[%0llx]: %i. Supp.next Trailer line (2AA)[%0x]: %i ",
365 tail,pos,f10BitArray[fNextPos],fNextPos)); return -1;
366 } else if( fNextPos==Get10BitArraySize()+3 ) { /* was last channel */
368 } else if( fNextPos >=Get10BitArraySize() ) {
369 AliError(Form("Next Trailer position < 0 %i", fNextPos));
371 } else if((f10BitArray[fNextPos]!=682)&&(f10BitArray[fNextPos]!=686)) {
372 AliError(Form("Could not find tail (2AA) at next supposed position %i",fNextPos));