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