]>
Commit | Line | Data |
---|---|---|
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$ | |
18 | */ | |
19 | ||
20 | ||
21 | #include "AliTPCMonitorAltro.h" | |
22 | #include "stdlib.h" | |
23 | #include <fstream> | |
24 | ClassImp(AliTPCMonitorAltro) | |
25 | ||
26 | //_____________________________________________________________________________________________ | |
27 | AliTPCMonitorAltro::AliTPCMonitorAltro(UInt_t* memory, Int_t size, Int_t fformat) | |
28 | { | |
29 | // Constructor: Set different CDH offsets for root(0) and date format | |
30 | fmemory = memory; | |
31 | fsize = size; | |
32 | fallocate40BitArray = false; | |
33 | fallocate10BitArray = false; | |
34 | fwrite10bit = 0; | |
35 | if( fformat==0) foffset=7; // old CHD Format | |
36 | else if(fformat==1) foffset=8; // memory pointer form DATE (start CDH) | |
37 | else if(fformat==2) foffset=0; // memory pointer form ROOT (after CDH) | |
38 | ||
39 | fverb =0; | |
40 | fTrailerNWords =0; | |
41 | fTrailerHwAddress =0; | |
42 | fTrailerDataPos =0; | |
43 | fTrailerBlockPos =0; | |
44 | fTrailerPos =0; | |
45 | fNextPos =0; | |
46 | ffilename = new Char_t[256]; | |
47 | } | |
48 | ||
49 | //_____________________________________________________________________________________________ | |
50 | AliTPCMonitorAltro::~AliTPCMonitorAltro() { | |
51 | // Destructor | |
52 | if(fallocate40BitArray == true) delete[] f40BitArray; | |
53 | if(fallocate10BitArray == true) delete[] f10BitArray; | |
54 | delete[] ffilename; | |
55 | } | |
56 | ||
57 | //_____________________________________________________________________________________________ | |
58 | void AliTPCMonitorAltro::Allocate40BitArray() | |
59 | { | |
60 | // create array for 40 bit decoded data | |
61 | fallocate40BitArray = true; | |
62 | f40BitArray = new long long[Get40BitArraySize()]; | |
63 | } | |
64 | ||
65 | //_____________________________________________________________________________________________ | |
66 | void AliTPCMonitorAltro::Allocate10BitArray() | |
67 | { | |
68 | // Create array for 10 bit decoded data | |
69 | fallocate10BitArray = true; | |
70 | f10BitArray = new Short_t[Get10BitArraySize()]; | |
71 | } | |
72 | ||
73 | //_____________________________________________________________________________________________ | |
74 | long long *AliTPCMonitorAltro::Get40BitArray() | |
75 | { | |
76 | // Return pointer to array for 40 bit decoded data | |
77 | return f40BitArray; | |
78 | } | |
79 | ||
80 | //_____________________________________________________________________________________________ | |
81 | Short_t *AliTPCMonitorAltro::Get10BitArray() | |
82 | { | |
83 | // Return pointer to array for 10 bit decoded data | |
84 | return f10BitArray; | |
85 | } | |
86 | ||
87 | //_____________________________________________________________________________________________ | |
88 | Int_t AliTPCMonitorAltro::Get40BitArraySize() | |
89 | { | |
90 | // Return number of 40 bit words in payload | |
91 | return fmemory[fsize-1]; | |
92 | } | |
93 | ||
94 | //_____________________________________________________________________________________________ | |
95 | Int_t AliTPCMonitorAltro::Get10BitArraySize() | |
96 | { | |
97 | // Return number of 10 bit words in payload | |
98 | return fmemory[fsize-1]*4; | |
99 | } | |
100 | ||
101 | //_____________________________________________________________________________________________ | |
102 | void AliTPCMonitorAltro::Decodeto40Bit() | |
103 | { | |
104 | // Decode 32 bit words in fmemory to 40 bit words | |
105 | Long64_t blackbox = 0; | |
106 | Int_t rest; | |
107 | ||
108 | for(Int_t i = 0; i < Get40BitArraySize(); i++) | |
109 | { | |
110 | rest = i%4; | |
111 | switch(rest) { | |
112 | case 0: | |
113 | blackbox = (fmemory[foffset]) + (((Long64_t)(fmemory[foffset+1]&k08BitOn))<<32); | |
114 | foffset +=1; | |
115 | break; | |
116 | case 1: | |
117 | blackbox = (fmemory[foffset]>>8 ) + (((Long64_t)(fmemory[foffset+1]&k16BitOn))<<24); | |
118 | foffset +=1; | |
119 | break; | |
120 | case 2: | |
121 | blackbox = (fmemory[foffset]>>16) + (((Long64_t)(fmemory[foffset+1]&k24BitOn))<<16); | |
122 | foffset +=1; | |
123 | break; | |
124 | case 3: | |
125 | blackbox = (fmemory[foffset]>>24) + (((Long64_t)(fmemory[foffset+1] ))<< 8); | |
126 | foffset +=2; | |
127 | break; | |
128 | default: | |
129 | blackbox = 0; | |
130 | break; | |
131 | } | |
132 | f40BitArray[i] = blackbox; | |
133 | } | |
134 | } | |
135 | ||
136 | //_____________________________________________________________________________________________ | |
137 | void AliTPCMonitorAltro::Decodeto10Bit(Int_t equipment) | |
138 | { | |
139 | // Decode 32 bit words in fmemory to 10 bit words. | |
140 | // Write words to file if fwrite10bit ("Write 10 bit" in Monitor.C Gui ) is set | |
141 | ||
142 | Long64_t blackbox = 0; | |
143 | Int_t rest = 0; | |
144 | ||
145 | ofstream datout; | |
146 | if(fwrite10bit) | |
147 | { | |
148 | Char_t nameout[256] ; sprintf(nameout,"%s_PayloadEquipmentId_%03i.txt",ffilename,equipment); | |
149 | datout.open(nameout); | |
150 | AliInfo(Form("AliTPCMonitorAltro::decodeto10Bit : Write Data to %s",nameout)); | |
151 | if(foffset==0) datout << "Payload without CDH in 10bit words " << endl; | |
152 | else datout << "CDH in 32 bit hex words words (" << foffset << " lines ) followed by payload in 10 bit words " << endl; | |
153 | for(Int_t ih = 0; ih< foffset ; ih++) | |
154 | { | |
155 | datout << hex << fmemory[ih] << endl; | |
156 | } | |
157 | } | |
158 | ||
159 | for(Int_t ind = 0; ind < Get40BitArraySize(); ind++) | |
160 | { | |
161 | rest = ind%4; | |
162 | switch(rest) | |
163 | { | |
164 | case 0: | |
165 | blackbox = (fmemory[foffset]) + (((Long64_t)(fmemory[foffset+1]&k08BitOn))<<32); | |
166 | foffset +=1; | |
167 | break; | |
168 | case 1: | |
169 | blackbox = (fmemory[foffset]>>8 ) + (((Long64_t)(fmemory[foffset+1]&k16BitOn))<<24); | |
170 | foffset +=1; | |
171 | break; | |
172 | case 2: | |
173 | blackbox = (fmemory[foffset]>>16) + (((Long64_t)(fmemory[foffset+1]&k24BitOn))<<16); | |
174 | foffset +=1; | |
175 | break; | |
176 | case 3: | |
177 | blackbox = (fmemory[foffset]>>24) + (((Long64_t)(fmemory[foffset+1] ))<< 8); | |
178 | foffset +=2; | |
179 | break; | |
180 | default: | |
181 | blackbox = 0; | |
182 | break; | |
183 | } | |
184 | f10BitArray[ind*4+0] = (Short_t)( blackbox & kmask10 ) ; | |
185 | f10BitArray[ind*4+1] = (Short_t)((blackbox & kmask20)>>10); | |
186 | f10BitArray[ind*4+2] = (Short_t)((blackbox & kmask30)>>20); | |
187 | f10BitArray[ind*4+3] = (Short_t)((blackbox & kmask40)>>30); | |
188 | } | |
189 | if(fwrite10bit) | |
190 | { | |
191 | for(Int_t ind = 0; ind < Get40BitArraySize(); ind++) | |
192 | { | |
193 | datout << dec << f10BitArray[ind*4+0] << "\n"; | |
194 | datout << dec << f10BitArray[ind*4+1] << "\n"; | |
195 | datout << dec << f10BitArray[ind*4+2] << "\n"; | |
196 | datout << dec << f10BitArray[ind*4+3] << "\n"; | |
197 | } | |
198 | } | |
199 | ||
200 | if(fwrite10bit) datout.close(); | |
201 | } | |
202 | ||
203 | //_____________________________________________________________________________________________ | |
204 | Int_t AliTPCMonitorAltro::DecodeTrailer(Int_t pos) | |
205 | { | |
206 | // Decode the trailer word starting at position pos in fmemory | |
207 | // Check if information leads to proper next trailer position | |
208 | ||
209 | fTrailerPos = pos; | |
210 | if(pos<=4) return 0; | |
211 | ||
212 | Long64_t words = 0; | |
213 | Long64_t tail = 0; | |
214 | Long64_t trailer = 0; | |
215 | Long64_t carry = 0; | |
216 | Long64_t rest = 0 ; | |
217 | ||
218 | for(Long64_t iter = 0 ; iter<4;iter++) | |
219 | { | |
220 | carry = f10BitArray[pos-iter] ; | |
221 | carry = ( carry << (30- ((iter)*10))); | |
222 | trailer += carry ; | |
223 | } | |
224 | ||
225 | fTrailerHwAddress = (trailer & ((Long64_t )kTrailerMaskHardw) ); | |
226 | words = (Long64_t )( (trailer & ((Long64_t )kTrailerMaskNWords))>>16); | |
227 | tail = (Long64_t )( (trailer & ((Long64_t )kTrailerMaskTail ))>>26 ); | |
228 | ||
229 | if(words%4!=0) rest = 4-(words%4); | |
230 | fTrailerNWords = words+rest ; | |
231 | fTrailerDataPos = pos -4 -rest ; | |
232 | fTrailerBlockPos = pos -4 ; | |
233 | fNextPos = (pos -fTrailerNWords -4); | |
234 | ||
235 | if( tail!=kTrailerTail ) { 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; } | |
236 | else if( fNextPos==-1 ) { /* was last channel */ return 0; } | |
237 | else if( fNextPos <0 ) { AliError("Next Trailer position < 0 "); return -1; } | |
238 | else if((f10BitArray[fNextPos]!=682)) { AliError(Form("Could not find tail (2AA) at next supposed position %i",fNextPos)); return -1; } | |
239 | else { return fNextPos;} | |
240 | ||
241 | } | |
242 | ||
243 | ||
244 |