]>
Commit | Line | Data |
---|---|---|
5990c064 | 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 | ||
88cb7938 | 16 | /* $Id$ */ |
5990c064 | 17 | |
18 | /////////////////////////////////////////////////////////////////////////////// | |
19 | // // | |
20 | // TRD raw data conversion class // | |
21 | // // | |
22 | /////////////////////////////////////////////////////////////////////////////// | |
23 | ||
090026bf | 24 | #include <TMath.h> |
ecf39416 | 25 | #include "TClass.h" |
5990c064 | 26 | |
2745a409 | 27 | #include "AliDAQ.h" |
f7ee745b | 28 | #include "AliRawDataHeaderSim.h" |
2745a409 | 29 | #include "AliRawReader.h" |
30 | #include "AliLog.h" | |
0c349049 | 31 | #include "AliFstream.h" |
2745a409 | 32 | |
5990c064 | 33 | #include "AliTRDrawData.h" |
34 | #include "AliTRDdigitsManager.h" | |
bd0f8685 | 35 | #include "AliTRDgeometry.h" |
5990c064 | 36 | #include "AliTRDdataArrayI.h" |
625f5260 | 37 | #include "AliTRDdataArrayS.h" |
b864d801 | 38 | #include "AliTRDRawStream.h" |
ecf39416 | 39 | #include "AliTRDRawStreamV2.h" |
3551db50 | 40 | #include "AliTRDcalibDB.h" |
ca21baaa | 41 | #include "AliTRDSignalIndex.h" |
dfd03fc3 | 42 | #include "AliTRDfeeParam.h" |
43 | #include "AliTRDmcmSim.h" | |
44 | ||
5990c064 | 45 | ClassImp(AliTRDrawData) |
46 | ||
47 | //_____________________________________________________________________________ | |
2cb20be6 | 48 | AliTRDrawData::AliTRDrawData() |
49 | :TObject() | |
dfd03fc3 | 50 | ,fGeo(NULL) |
51 | ,fFee(NULL) | |
8c703901 | 52 | ,fNumberOfDDLs(0) |
5990c064 | 53 | { |
b864d801 | 54 | // |
55 | // Default constructor | |
56 | // | |
0c349049 | 57 | |
dfd03fc3 | 58 | fFee = AliTRDfeeParam::Instance(); |
59 | fNumberOfDDLs = AliDAQ::NumberOfDdls("TRD"); | |
0c349049 | 60 | |
5990c064 | 61 | } |
62 | ||
8c703901 | 63 | //_____________________________________________________________________________ |
64 | AliTRDrawData::AliTRDrawData(const AliTRDrawData &r) | |
65 | :TObject(r) | |
dfd03fc3 | 66 | ,fGeo(NULL) |
67 | ,fFee(NULL) | |
8c703901 | 68 | ,fNumberOfDDLs(0) |
69 | { | |
70 | // | |
71 | // Copy constructor | |
72 | // | |
0c349049 | 73 | |
dfd03fc3 | 74 | fFee = AliTRDfeeParam::Instance(); |
75 | fNumberOfDDLs = AliDAQ::NumberOfDdls("TRD"); | |
0c349049 | 76 | |
8c703901 | 77 | } |
78 | ||
5990c064 | 79 | //_____________________________________________________________________________ |
80 | AliTRDrawData::~AliTRDrawData() | |
81 | { | |
82 | // | |
83 | // Destructor | |
84 | // | |
0c349049 | 85 | |
8c703901 | 86 | } |
87 | ||
88 | //_____________________________________________________________________________ | |
89 | Bool_t AliTRDrawData::Digits2Raw(TTree *digitsTree, TTree *tracks ) | |
90 | { | |
91 | // | |
92 | // Initialize necessary parameters and call one | |
93 | // of the raw data simulator selected by SetRawVersion. | |
94 | // | |
95 | // Currently tracklet output is not spported yet and it | |
96 | // will be supported in higher version simulator. | |
97 | // | |
98 | ||
8c703901 | 99 | AliTRDdigitsManager* digitsManager = new AliTRDdigitsManager(); |
100 | ||
101 | if (!digitsManager->ReadDigits(digitsTree)) { | |
102 | delete digitsManager; | |
103 | return kFALSE; | |
104 | } | |
105 | ||
106 | if (tracks != NULL) { | |
107 | delete digitsManager; | |
7925de54 | 108 | AliError("Tracklet input is not supported yet."); |
8c703901 | 109 | return kFALSE; |
110 | } | |
111 | ||
112 | fGeo = new AliTRDgeometry(); | |
113 | ||
f162af62 | 114 | if (!AliTRDcalibDB::Instance()) { |
7925de54 | 115 | AliError("Could not get calibration object"); |
8c703901 | 116 | delete fGeo; |
117 | delete digitsManager; | |
118 | return kFALSE; | |
119 | } | |
120 | ||
121 | Int_t retval = kTRUE; | |
dfd03fc3 | 122 | Int_t rv = fFee->GetRAWversion(); |
8c703901 | 123 | |
124 | // Call appropriate Raw Simulator | |
dfd03fc3 | 125 | if ( rv > 0 && rv <= 3 ) retval = Digits2Raw(digitsManager); |
7925de54 | 126 | else { |
127 | retval = kFALSE; | |
dfd03fc3 | 128 | AliWarning(Form("Unsupported raw version (%d).", rv)); |
8c703901 | 129 | } |
130 | ||
131 | // Cleanup | |
132 | delete fGeo; | |
133 | delete digitsManager; | |
134 | ||
135 | return retval; | |
136 | ||
137 | } | |
138 | ||
139 | //_____________________________________________________________________________ | |
50378239 | 140 | Bool_t AliTRDrawData::Digits2Raw(AliTRDdigitsManager *digitsManager) |
8c703901 | 141 | { |
142 | // | |
7925de54 | 143 | // Raw data simulator for all versions > 0. This is prepared for real data. |
8c703901 | 144 | // This version simulate only raw data with ADC data and not with tracklet. |
8c703901 | 145 | // |
146 | ||
0c349049 | 147 | const Int_t kMaxHcWords = (fGeo->TBmax()/3) |
148 | * fGeo->ADCmax() | |
149 | * fGeo->MCMmax() | |
150 | * fGeo->ROBmaxC1()/2 | |
151 | + 100 + 20; | |
8c703901 | 152 | |
153 | // Buffer to temporary store half chamber data | |
0c349049 | 154 | UInt_t *hcBuffer = new UInt_t[kMaxHcWords]; |
8c703901 | 155 | |
156 | // sect is same as iDDL, so I use only sect here. | |
157 | for (Int_t sect = 0; sect < fGeo->Nsect(); sect++) { | |
158 | ||
159 | char name[1024]; | |
160 | sprintf(name,"TRD_%d.ddl",sect + AliTRDRawStream::kDDLOffset); | |
161 | ||
08f92f14 | 162 | AliFstream* of = new AliFstream(name); |
8c703901 | 163 | |
164 | // Write a dummy data header | |
f7ee745b | 165 | AliRawDataHeaderSim header; // the event header |
08f92f14 | 166 | UInt_t hpos = of->Tellp(); |
167 | of->WriteBuffer((char *) (& header), sizeof(header)); | |
8c703901 | 168 | |
169 | // Reset payload byte size (payload does not include header). | |
170 | Int_t npayloadbyte = 0; | |
171 | ||
7925de54 | 172 | // GTU common data header (5x4 bytes per super module, shows link mask) |
8c703901 | 173 | for( Int_t cham = 0; cham < fGeo->Ncham(); cham++ ) { |
0c349049 | 174 | UInt_t gtuCdh = (UInt_t)(0xe << 28); |
7925de54 | 175 | for( Int_t plan = 0; plan < fGeo->Nplan(); plan++) { |
176 | Int_t iDet = fGeo->GetDetector(plan, cham, sect); | |
177 | // If chamber status is ok, we assume that the optical link is also OK. | |
178 | // This is shown in the GTU link mask. | |
f162af62 | 179 | if ( AliTRDcalibDB::Instance()->GetChamberStatus(iDet) ) |
0c349049 | 180 | gtuCdh = gtuCdh | (3 << (2*plan)); |
7925de54 | 181 | } |
0c349049 | 182 | of->WriteBuffer((char *) (& gtuCdh), sizeof(gtuCdh)); |
8c703901 | 183 | npayloadbyte += 4; |
184 | } | |
185 | ||
186 | // Prepare chamber data | |
187 | for( Int_t cham = 0; cham < fGeo->Ncham(); cham++) { | |
188 | for( Int_t plan = 0; plan < fGeo->Nplan(); plan++) { | |
189 | ||
190 | Int_t iDet = fGeo->GetDetector(plan,cham,sect); | |
191 | ||
192 | // Get the digits array | |
625f5260 | 193 | AliTRDdataArrayS *digits = (AliTRDdataArrayS *) digitsManager->GetDigits(iDet); |
8c703901 | 194 | digits->Expand(); |
195 | ||
7925de54 | 196 | Int_t hcwords = 0; |
dfd03fc3 | 197 | Int_t rv = fFee->GetRAWversion(); |
8c703901 | 198 | |
199 | // Process A side of the chamber | |
0c349049 | 200 | if ( rv >= 1 && rv <= 2 ) hcwords = ProduceHcDataV1andV2(digits,0,iDet,hcBuffer,kMaxHcWords); |
201 | if ( rv == 3 ) hcwords = ProduceHcDataV3 (digits,0,iDet,hcBuffer,kMaxHcWords); | |
dfd03fc3 | 202 | |
0c349049 | 203 | of->WriteBuffer((char *) hcBuffer, hcwords*4); |
8c703901 | 204 | npayloadbyte += hcwords*4; |
205 | ||
206 | // Process B side of the chamber | |
0c349049 | 207 | if ( rv >= 1 && rv <= 2 ) hcwords = ProduceHcDataV1andV2(digits,1,iDet,hcBuffer,kMaxHcWords); |
208 | if ( rv >= 3 ) hcwords = ProduceHcDataV3 (digits,1,iDet,hcBuffer,kMaxHcWords); | |
dfd03fc3 | 209 | |
0c349049 | 210 | of->WriteBuffer((char *) hcBuffer, hcwords*4); |
8c703901 | 211 | npayloadbyte += hcwords*4; |
8c703901 | 212 | } |
213 | } | |
214 | ||
215 | // Complete header | |
08f92f14 | 216 | header.fSize = UInt_t(of->Tellp()) - hpos; |
8c703901 | 217 | header.SetAttribute(0); // Valid data |
08f92f14 | 218 | of->Seekp(hpos); // Rewind to header position |
219 | of->WriteBuffer((char *) (& header), sizeof(header)); | |
8c703901 | 220 | delete of; |
8c703901 | 221 | } |
222 | ||
0c349049 | 223 | delete [] hcBuffer; |
224 | ||
8c703901 | 225 | return kTRUE; |
226 | ||
227 | } | |
228 | ||
229 | //_____________________________________________________________________________ | |
625f5260 | 230 | Int_t AliTRDrawData::ProduceHcDataV1andV2(AliTRDdataArrayS *digits, Int_t side |
7925de54 | 231 | , Int_t det, UInt_t *buf, Int_t maxSize) |
8c703901 | 232 | { |
7925de54 | 233 | // |
dfd03fc3 | 234 | // This function simulates: 1) SM-I commissiong data Oct. 06 (Raw Version == 1). |
235 | // 2) Full Raw Production Version (Raw Version == 2) | |
8c703901 | 236 | // |
237 | // Produce half chamber data (= an ORI data) for the given chamber (det) and side (side) | |
238 | // where | |
7925de54 | 239 | // |
8c703901 | 240 | // side=0 means A side with ROB positions 0, 2, 4, 6. |
241 | // side=1 means B side with ROB positions 1, 3, 5, 7. | |
242 | // | |
243 | // Chamber type (C0 orC1) is determined by "det" automatically. | |
244 | // Appropriate size of buffer (*buf) must be prepared prior to calling this function. | |
245 | // Pointer to the buffer and its size must be given to "buf" and "maxSize". | |
246 | // Return value is the number of valid data filled in the buffer in unit of 32 bits | |
247 | // UInt_t words. | |
248 | // If buffer size if too small, the data is truncated with the buffer size however | |
249 | // the function will finish without crash (this behaviour is similar to the MCM). | |
250 | // | |
251 | ||
0c349049 | 252 | Int_t nw = 0; // Number of written words |
253 | Int_t of = 0; // Number of overflowed words | |
254 | Int_t plan = fGeo->GetPlane( det ); // Plane | |
255 | Int_t cham = fGeo->GetChamber( det ); // Chamber | |
256 | Int_t sect = fGeo->GetSector( det ); // Sector (=iDDL) | |
257 | Int_t nRow = fGeo->GetRowMax( plan, cham, sect ); | |
258 | Int_t nCol = fGeo->GetColMax( plan ); | |
259 | const Int_t kNTBin = AliTRDcalibDB::Instance()->GetNumberOfTimeBins(); | |
260 | Int_t kCtype = 0; // Chamber type (0:C0, 1:C1) | |
261 | Int_t iEv = 0xA; // Event ID. Now fixed to 10, how do I get event id? | |
262 | UInt_t x = 0; // General used number | |
263 | Int_t rv = fFee->GetRAWversion(); | |
8c703901 | 264 | |
265 | // Check the nCol and nRow. | |
266 | if ((nCol == 144) && | |
267 | (nRow == 16 || nRow == 12)) { | |
268 | kCtype = (nRow-12) / 4; | |
269 | } | |
270 | else { | |
7925de54 | 271 | AliError(Form("This type of chamber is not supported (nRow=%d, nCol=%d)." |
8c703901 | 272 | ,nRow,nCol)); |
273 | return 0; | |
274 | } | |
275 | ||
276 | AliDebug(1,Form("Producing raw data for sect=%d plan=%d cham=%d side=%d" | |
277 | ,sect,plan,cham,side)); | |
278 | ||
279 | // Tracklet should be processed here but not implemented yet | |
280 | ||
281 | // Write end of tracklet marker | |
282 | if (nw < maxSize) { | |
bd63bf88 | 283 | buf[nw++] = kEndoftrackletmarker; |
8c703901 | 284 | } |
285 | else { | |
286 | of++; | |
287 | } | |
288 | ||
289 | // Half Chamber header | |
dfd03fc3 | 290 | if ( rv == 1 ) { |
7925de54 | 291 | // Now it is the same version as used in SM-I commissioning. |
292 | Int_t dcs = det+100; // DCS Serial (in simulation, it is meaningless | |
293 | x = (dcs<<20) | (sect<<15) | (plan<<12) | (cham<<9) | (side<<8) | 1; | |
294 | if (nw < maxSize) { | |
295 | buf[nw++] = x; | |
296 | } | |
297 | else { | |
298 | of++; | |
299 | } | |
300 | } | |
dfd03fc3 | 301 | else if ( rv == 2 ) { |
bd63bf88 | 302 | // h[0] (there are 3 HC header) |
7925de54 | 303 | Int_t minorv = 0; // The minor version number |
ecf39416 | 304 | Int_t add = 2; // The number of additional header words to follow |
dfd03fc3 | 305 | x = (1<<31) | (rv<<24) | (minorv<<17) | (add<<14) | (sect<<9) | (plan<<6) | (cham<<3) | (side<<2) | 1; |
7925de54 | 306 | if (nw < maxSize) { |
307 | buf[nw++] = x; | |
308 | } | |
309 | else { | |
310 | of++; | |
311 | } | |
312 | // h[1] | |
0c349049 | 313 | Int_t bcCtr = 99; // bunch crossing counter. Here it is set to 99 always for no reason |
314 | Int_t ptCtr = 15; // pretrigger counter. Here it is set to 15 always for no reason | |
315 | Int_t ptPhase = 11; // pretrigger phase. Here it is set to 11 always for no reason | |
316 | x = (bcCtr<<16) | (ptCtr<<12) | (ptPhase<<8) | ((kNTBin-1)<<2) | 1; | |
7925de54 | 317 | if (nw < maxSize) { |
318 | buf[nw++] = x; | |
319 | } | |
320 | else { | |
321 | of++; | |
322 | } | |
bd63bf88 | 323 | // h[2] |
0c349049 | 324 | Int_t pedSetup = 1; // Pedestal filter setup (0:1). Here it is always 1 for no reason |
325 | Int_t gainSetup = 1; // Gain filter setup (0:1). Here it is always 1 for no reason | |
326 | Int_t tailSetup = 1; // Tail filter setup (0:1). Here it is always 1 for no reason | |
327 | Int_t xtSetup = 0; // Cross talk filter setup (0:1). Here it is always 0 for no reason | |
328 | Int_t nonlinSetup = 0; // Nonlinearity filter setup (0:1). Here it is always 0 for no reason | |
329 | Int_t bypassSetup = 0; // Filter bypass (for raw data) setup (0:1). Here it is always 0 for no reason | |
330 | Int_t commonAdditive = 10; // Digital filter common additive (0:63). Here it is always 10 for no reason | |
331 | x = (pedSetup<<31) | (gainSetup<<30) | (tailSetup<<29) | (xtSetup<<28) | (nonlinSetup<<27) | |
332 | | (bypassSetup<<26) | (commonAdditive<<20) | 1; | |
bd63bf88 | 333 | if (nw < maxSize) { |
334 | buf[nw++] = x; | |
335 | } | |
336 | else { | |
337 | of++; | |
338 | } | |
8c703901 | 339 | } |
340 | ||
341 | // Scan for ROB and MCM | |
342 | for (Int_t iRobRow = 0; iRobRow < (kCtype + 3); iRobRow++ ) { | |
343 | Int_t iRob = iRobRow * 2 + side; | |
7925de54 | 344 | for (Int_t iMcm = 0; iMcm < fGeo->MCMmax(); iMcm++ ) { |
8c703901 | 345 | Int_t padrow = iRobRow * 4 + iMcm / 4; |
346 | ||
347 | // MCM header | |
7925de54 | 348 | x = ((iRob * fGeo->MCMmax() + iMcm) << 24) | ((iEv % 0x100000) << 4) | 0xC; |
8c703901 | 349 | if (nw < maxSize) { |
350 | buf[nw++] = x; | |
351 | } | |
352 | else { | |
353 | of++; | |
354 | } | |
355 | ||
356 | // ADC data | |
357 | for (Int_t iAdc = 0; iAdc < 21; iAdc++ ) { | |
ecf39416 | 358 | Int_t padcol = fFee->GetPadColFromADC(iRob, iMcm, iAdc); |
7925de54 | 359 | UInt_t aa = !(iAdc & 1) + 2; |
0c349049 | 360 | UInt_t *a = new UInt_t[kNTBin+2]; |
8c703901 | 361 | // 3 timebins are packed into one 32 bits word |
0c349049 | 362 | for (Int_t iT = 0; iT < kNTBin; iT+=3) { |
7925de54 | 363 | if ((padcol >= 0) && (padcol < nCol)) { |
0c349049 | 364 | a[iT ] = ((iT ) < kNTBin ) ? digits->GetDataUnchecked(padrow,padcol,iT ) : 0; |
365 | a[iT+1] = ((iT + 1) < kNTBin ) ? digits->GetDataUnchecked(padrow,padcol,iT + 1) : 0; | |
366 | a[iT+2] = ((iT + 2) < kNTBin ) ? digits->GetDataUnchecked(padrow,padcol,iT + 2) : 0; | |
7925de54 | 367 | } |
368 | else { | |
369 | a[iT] = a[iT+1] = a[iT+2] = 0; // This happenes at the edge of chamber (should be pedestal! How?) | |
8c703901 | 370 | } |
7925de54 | 371 | x = (a[iT+2] << 22) | (a[iT+1] << 12) | (a[iT] << 2) | aa; |
372 | if (nw < maxSize) { | |
373 | buf[nw++] = x; | |
8c703901 | 374 | } |
7925de54 | 375 | else { |
376 | of++; | |
8c703901 | 377 | } |
7925de54 | 378 | } |
8c703901 | 379 | // Diagnostics |
380 | Float_t avg = 0; | |
381 | Float_t rms = 0; | |
0c349049 | 382 | for (Int_t iT = 0; iT < kNTBin; iT++) { |
8c703901 | 383 | avg += (Float_t) (a[iT]); |
384 | } | |
0c349049 | 385 | avg /= (Float_t) kNTBin; |
386 | for (Int_t iT = 0; iT < kNTBin; iT++) { | |
8c703901 | 387 | rms += ((Float_t) (a[iT]) - avg) * ((Float_t) (a[iT]) - avg); |
388 | } | |
0c349049 | 389 | rms = TMath::Sqrt(rms / (Float_t) kNTBin); |
8c703901 | 390 | if (rms > 1.7) { |
7925de54 | 391 | AliDebug(2,Form("Large RMS (>1.7) (ROB,MCM,ADC)=(%02d,%02d,%02d), avg=%03.1f, rms=%03.1f" |
392 | ,iRob,iMcm,iAdc,avg,rms)); | |
8c703901 | 393 | } |
e21c2d7d | 394 | delete [] a; |
8c703901 | 395 | } |
396 | } | |
397 | } | |
398 | ||
399 | // Write end of raw data marker | |
400 | if (nw < maxSize) { | |
bd63bf88 | 401 | buf[nw++] = kEndofrawdatamarker; |
8c703901 | 402 | } |
403 | else { | |
404 | of++; | |
405 | } | |
406 | if (of != 0) { | |
407 | AliWarning("Buffer overflow. Data is truncated. Please increase buffer size and recompile."); | |
408 | } | |
409 | ||
410 | return nw; | |
5990c064 | 411 | |
412 | } | |
413 | ||
dfd03fc3 | 414 | //_____________________________________________________________________________ |
625f5260 | 415 | Int_t AliTRDrawData::ProduceHcDataV3(AliTRDdataArrayS *digits, Int_t side |
0c349049 | 416 | , Int_t det, UInt_t *buf, Int_t maxSize) |
dfd03fc3 | 417 | { |
418 | // | |
419 | // This function simulates: Raw Version == 3 (Zero Suppression Prototype) | |
420 | // | |
421 | ||
0c349049 | 422 | Int_t nw = 0; // Number of written words |
423 | Int_t of = 0; // Number of overflowed words | |
424 | Int_t plan = fGeo->GetPlane( det ); // Plane | |
425 | Int_t cham = fGeo->GetChamber( det ); // Chamber | |
426 | Int_t sect = fGeo->GetSector( det ); // Sector (=iDDL) | |
427 | Int_t nRow = fGeo->GetRowMax( plan, cham, sect ); | |
428 | Int_t nCol = fGeo->GetColMax( plan ); | |
429 | const Int_t kNTBin = AliTRDcalibDB::Instance()->GetNumberOfTimeBins(); | |
430 | Int_t kCtype = 0; // Chamber type (0:C0, 1:C1) | |
431 | //Int_t iEv = 0xA; // Event ID. Now fixed to 10, how do I get event id? | |
432 | UInt_t x = 0; // General used number | |
433 | Int_t rv = fFee->GetRAWversion(); | |
dfd03fc3 | 434 | |
435 | // Check the nCol and nRow. | |
436 | if ((nCol == 144) && | |
437 | (nRow == 16 || nRow == 12)) { | |
438 | kCtype = (nRow-12) / 4; | |
439 | } | |
440 | else { | |
441 | AliError(Form("This type of chamber is not supported (nRow=%d, nCol=%d)." | |
442 | ,nRow,nCol)); | |
443 | return 0; | |
444 | } | |
445 | ||
446 | AliDebug(1,Form("Producing raw data for sect=%d plan=%d cham=%d side=%d" | |
447 | ,sect,plan,cham,side)); | |
448 | ||
449 | // Tracklet should be processed here but not implemented yet | |
450 | ||
451 | // Write end of tracklet marker | |
452 | if (nw < maxSize) { | |
453 | buf[nw++] = kEndoftrackletmarker; | |
454 | } | |
455 | else { | |
456 | of++; | |
457 | } | |
458 | ||
459 | // Half Chamber header | |
460 | // h[0] (there are 3 HC header) | |
461 | Int_t minorv = 0; // The minor version number | |
ecf39416 | 462 | Int_t add = 2; // The number of additional header words to follow |
dfd03fc3 | 463 | x = (1<<31) | (rv<<24) | (minorv<<17) | (add<<14) | (sect<<9) | (plan<<6) | (cham<<3) | (side<<2) | 1; |
464 | if (nw < maxSize) { | |
465 | buf[nw++] = x; | |
466 | } | |
467 | else { | |
468 | of++; | |
469 | } | |
470 | // h[1] | |
0c349049 | 471 | Int_t bcCtr = 99; // bunch crossing counter. Here it is set to 99 always for no reason |
472 | Int_t ptCtr = 15; // pretrigger counter. Here it is set to 15 always for no reason | |
473 | Int_t ptPhase = 11; // pretrigger phase. Here it is set to 11 always for no reason | |
474 | x = (bcCtr<<16) | (ptCtr<<12) | (ptPhase<<8) | ((kNTBin-1)<<2) | 1; | |
dfd03fc3 | 475 | if (nw < maxSize) { |
476 | buf[nw++] = x; | |
477 | } | |
478 | else { | |
479 | of++; | |
480 | } | |
481 | // h[2] | |
0c349049 | 482 | Int_t pedSetup = 1; // Pedestal filter setup (0:1). Here it is always 1 for no reason |
483 | Int_t gainSetup = 1; // Gain filter setup (0:1). Here it is always 1 for no reason | |
484 | Int_t tailSetup = 1; // Tail filter setup (0:1). Here it is always 1 for no reason | |
485 | Int_t xtSetup = 0; // Cross talk filter setup (0:1). Here it is always 0 for no reason | |
486 | Int_t nonlinSetup = 0; // Nonlinearity filter setup (0:1). Here it is always 0 for no reason | |
487 | Int_t bypassSetup = 0; // Filter bypass (for raw data) setup (0:1). Here it is always 0 for no reason | |
488 | Int_t commonAdditive = 10; // Digital filter common additive (0:63). Here it is always 10 for no reason | |
489 | x = (pedSetup<<31) | (gainSetup<<30) | (tailSetup<<29) | (xtSetup<<28) | (nonlinSetup<<27) | |
490 | | (bypassSetup<<26) | (commonAdditive<<20) | 1; | |
dfd03fc3 | 491 | if (nw < maxSize) { |
492 | buf[nw++] = x; | |
493 | } | |
494 | else { | |
495 | of++; | |
496 | } | |
497 | ||
dfd03fc3 | 498 | // Scan for ROB and MCM |
499 | for (Int_t iRobRow = 0; iRobRow < (kCtype + 3); iRobRow++ ) { | |
500 | Int_t iRob = iRobRow * 2 + side; | |
501 | for (Int_t iMcm = 0; iMcm < fGeo->MCMmax(); iMcm++ ) { | |
502 | ||
709187ec | 503 | AliTRDmcmSim *mcm = new AliTRDmcmSim(); |
dfd03fc3 | 504 | mcm->Init( det, iRob, iMcm ); |
505 | Int_t padrow = mcm->GetRow(); | |
506 | ||
507 | // Copy ADC data to MCM simulator | |
508 | for (Int_t iAdc = 0; iAdc < 21; iAdc++ ) { | |
509 | Int_t padcol = mcm->GetCol( iAdc ); | |
510 | if ((padcol >= 0) && (padcol < nCol)) { | |
0c349049 | 511 | for (Int_t iT = 0; iT < kNTBin; iT++) { |
dfd03fc3 | 512 | mcm->SetData( iAdc, iT, digits->GetDataUnchecked( padrow, padcol, iT) ); |
513 | } | |
514 | } else { // this means it is out of chamber, and masked ADC | |
515 | mcm->SetDataPedestal( iAdc ); | |
516 | } | |
517 | } | |
518 | // Simulate process in MCM | |
519 | mcm->Filter(); // Apply filter | |
520 | mcm->ZSMapping(); // Calculate zero suppression mapping | |
ecf39416 | 521 | //mcm->DumpData( "trdmcmdata.txt", "RFZS" ); // debugging purpose |
dfd03fc3 | 522 | |
523 | // Write MCM data to buffer | |
0c349049 | 524 | Int_t tempNw = mcm->ProduceRawStream( &buf[nw], maxSize - nw ); |
525 | if( tempNw < 0 ) { | |
526 | of += tempNw; | |
dfd03fc3 | 527 | nw += maxSize - nw; |
528 | AliError(Form("Buffer overflow detected. Please increase the buffer size and recompile.")); | |
529 | } else { | |
0c349049 | 530 | nw += tempNw; |
dfd03fc3 | 531 | } |
709187ec | 532 | |
533 | delete mcm; | |
534 | ||
dfd03fc3 | 535 | } |
536 | } | |
537 | ||
538 | // Write end of raw data marker | |
539 | if (nw < maxSize) { | |
540 | buf[nw++] = kEndofrawdatamarker; | |
541 | } | |
542 | else { | |
543 | of++; | |
544 | } | |
545 | if (of != 0) { | |
ecf39416 | 546 | AliError("Buffer overflow. Data is truncated. Please increase buffer size and recompile."); |
dfd03fc3 | 547 | } |
548 | ||
549 | return nw; | |
550 | ||
551 | } | |
552 | ||
5990c064 | 553 | //_____________________________________________________________________________ |
7925de54 | 554 | AliTRDdigitsManager *AliTRDrawData::Raw2Digits(AliRawReader *rawReader) |
5990c064 | 555 | { |
b864d801 | 556 | // |
50378239 | 557 | // Vx of the raw data reading |
b864d801 | 558 | // |
5990c064 | 559 | |
625f5260 | 560 | AliTRDdataArrayS *digits = 0; |
2cb20be6 | 561 | AliTRDdataArrayI *track0 = 0; |
562 | AliTRDdataArrayI *track1 = 0; | |
563 | AliTRDdataArrayI *track2 = 0; | |
5990c064 | 564 | |
ca21baaa | 565 | AliTRDSignalIndex *indexes = 0; |
5990c064 | 566 | // Create the digits manager |
b864d801 | 567 | AliTRDdigitsManager* digitsManager = new AliTRDdigitsManager(); |
b864d801 | 568 | digitsManager->CreateArrays(); |
5990c064 | 569 | |
ecf39416 | 570 | //AliTRDRawStream input(rawReader); |
571 | AliTRDRawStreamV2 input(rawReader); | |
dfd03fc3 | 572 | input.SetRawVersion( fFee->GetRAWversion() ); |
50378239 | 573 | input.Init(); |
5990c064 | 574 | |
ecf39416 | 575 | AliInfo(Form("Stream version: %s", input.IsA()->GetName())); |
576 | ||
b864d801 | 577 | // Loop through the digits |
50378239 | 578 | Int_t lastdet = -1; |
579 | Int_t det = 0; | |
580 | Int_t it = 0; | |
ecf39416 | 581 | while (input.Next()) { |
50378239 | 582 | |
583 | det = input.GetDet(); | |
584 | ||
ecf39416 | 585 | if (det != lastdet) { // If new detector found |
50378239 | 586 | |
587 | lastdet = det; | |
588 | ||
589 | if (digits) digits->Compress(1,0); | |
590 | if (track0) track0->Compress(1,0); | |
591 | if (track1) track1->Compress(1,0); | |
592 | if (track2) track2->Compress(1,0); | |
593 | ||
594 | // Add a container for the digits of this detector | |
625f5260 | 595 | digits = (AliTRDdataArrayS *) digitsManager->GetDigits(det); |
596 | track0 = (AliTRDdataArrayI *) digitsManager->GetDictionary(det,0); | |
597 | track1 = (AliTRDdataArrayI *) digitsManager->GetDictionary(det,1); | |
598 | track2 = (AliTRDdataArrayI *) digitsManager->GetDictionary(det,2); | |
50378239 | 599 | |
600 | // Allocate memory space for the digits buffer | |
601 | if (digits->GetNtime() == 0) | |
602 | { | |
603 | digits->Allocate(input.GetMaxRow(),input.GetMaxCol(), input.GetNumberOfTimeBins()); | |
604 | track0->Allocate(input.GetMaxRow(),input.GetMaxCol(), input.GetNumberOfTimeBins()); | |
605 | track1->Allocate(input.GetMaxRow(),input.GetMaxCol(), input.GetNumberOfTimeBins()); | |
606 | track2->Allocate(input.GetMaxRow(),input.GetMaxCol(), input.GetNumberOfTimeBins()); | |
607 | } | |
ca21baaa | 608 | |
609 | indexes = digitsManager->GetIndexes(det); | |
610 | indexes->SetSM(input.GetSM()); | |
611 | indexes->SetStack(input.GetStack()); | |
612 | indexes->SetLayer(input.GetLayer()); | |
613 | indexes->SetDetNumber(det); | |
614 | if (indexes->IsAllocated() == kFALSE) | |
615 | indexes->Allocate(input.GetMaxRow(), input.GetMaxCol(), input.GetNumberOfTimeBins()); | |
50378239 | 616 | } |
617 | ||
ecf39416 | 618 | // 3 timebin data are stored per word |
50378239 | 619 | for (it = 0; it < 3; it++) |
620 | { | |
621 | if ( input.GetTimeBin() + it < input.GetNumberOfTimeBins() ) | |
622 | { | |
ca21baaa | 623 | if (input.GetSignals()[it] > 0) |
624 | { | |
625 | digits->SetDataUnchecked(input.GetRow(), input.GetCol(), | |
626 | input.GetTimeBin() + it, input.GetSignals()[it]); | |
627 | ||
628 | indexes->AddIndexTBin(input.GetRow(), input.GetCol(), | |
629 | input.GetTimeBin() + it); | |
630 | track0->SetDataUnchecked(input.GetRow(), input.GetCol(), | |
631 | input.GetTimeBin() + it, 0); | |
632 | track1->SetDataUnchecked(input.GetRow(), input.GetCol(), | |
633 | input.GetTimeBin() + it, 0); | |
634 | track2->SetDataUnchecked(input.GetRow(), input.GetCol(), | |
635 | input.GetTimeBin() + it, 0); | |
636 | } | |
50378239 | 637 | } |
638 | } | |
5990c064 | 639 | } |
640 | ||
b864d801 | 641 | if (digits) digits->Compress(1,0); |
928e9fae | 642 | if (track0) track0->Compress(1,0); |
643 | if (track1) track1->Compress(1,0); | |
644 | if (track2) track2->Compress(1,0); | |
b864d801 | 645 | |
7925de54 | 646 | return digitsManager; |
647 | ||
648 | } |