]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDrawData.cxx
Additional protection in the destructor: when you have a chain of calls returning...
[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];
1d93b218 156
157 Bool_t newEvent = kFALSE; // only for correct readout tree
8c703901 158
159 // sect is same as iDDL, so I use only sect here.
053767a4 160 for (Int_t sect = 0; sect < fGeo->Nsector(); sect++) {
8c703901 161
162 char name[1024];
163 sprintf(name,"TRD_%d.ddl",sect + AliTRDRawStream::kDDLOffset);
164
08f92f14 165 AliFstream* of = new AliFstream(name);
8c703901 166
167 // Write a dummy data header
f7ee745b 168 AliRawDataHeaderSim header; // the event header
08f92f14 169 UInt_t hpos = of->Tellp();
170 of->WriteBuffer((char *) (& header), sizeof(header));
8c703901 171
172 // Reset payload byte size (payload does not include header).
173 Int_t npayloadbyte = 0;
174
1d93b218 175
176
7925de54 177 // GTU common data header (5x4 bytes per super module, shows link mask)
053767a4 178 for( Int_t stack = 0; stack < fGeo->Nstack(); stack++ ) {
0c349049 179 UInt_t gtuCdh = (UInt_t)(0xe << 28);
053767a4 180 for( Int_t layer = 0; layer < fGeo->Nlayer(); layer++) {
181 Int_t iDet = fGeo->GetDetector(layer, stack, sect);
1d93b218 182
7925de54 183 // If chamber status is ok, we assume that the optical link is also OK.
184 // This is shown in the GTU link mask.
f162af62 185 if ( AliTRDcalibDB::Instance()->GetChamberStatus(iDet) )
053767a4 186 gtuCdh = gtuCdh | (3 << (2*layer));
7925de54 187 }
0c349049 188 of->WriteBuffer((char *) (& gtuCdh), sizeof(gtuCdh));
8c703901 189 npayloadbyte += 4;
190 }
191
192 // Prepare chamber data
053767a4 193 for( Int_t stack = 0; stack < fGeo->Nstack(); stack++) {
194 for( Int_t layer = 0; layer < fGeo->Nlayer(); layer++) {
8c703901 195
053767a4 196 Int_t iDet = fGeo->GetDetector(layer,stack,sect);
1d93b218 197 if (iDet == 0) newEvent = kTRUE; // it is expected that each event has at least one tracklet; this is only needed for correct readout tree
198 // Get the digits array
625f5260 199 AliTRDdataArrayS *digits = (AliTRDdataArrayS *) digitsManager->GetDigits(iDet);
1d93b218 200 if (digits->HasData() ) { // second part is new!! and is for indicating a new event
8c703901 201
5fc47291 202 digits->Expand();
8c703901 203
5fc47291 204 Int_t hcwords = 0;
205 Int_t rv = fFee->GetRAWversion();
dfd03fc3 206
5fc47291 207 // Process A side of the chamber
208 if ( rv >= 1 && rv <= 2 ) {
209 hcwords = ProduceHcDataV1andV2(digits,0,iDet,hcBuffer,kMaxHcWords);
210 }
211 if ( rv == 3 ) {
1d93b218 212
23200400 213 //hcwords = ProduceHcDataV3 (digits,0,iDet,hcBuffer,kMaxHcWords,newEvent);
1d93b218 214 hcwords = ProduceHcDataV3 (digits,0,iDet,hcBuffer,kMaxHcWords);
215 if(newEvent == kTRUE) newEvent = kFALSE;
5fc47291 216 }
8c703901 217
5fc47291 218 of->WriteBuffer((char *) hcBuffer, hcwords*4);
219 npayloadbyte += hcwords*4;
220
221 // Process B side of the chamber
222 if ( rv >= 1 && rv <= 2 ) {
223 hcwords = ProduceHcDataV1andV2(digits,1,iDet,hcBuffer,kMaxHcWords);
224 }
225 if ( rv >= 3 ) {
1d93b218 226
227 //hcwords = ProduceHcDataV3 (digits,1,iDet,hcBuffer,kMaxHcWords,newEvent);
228 hcwords = ProduceHcDataV3 (digits,1,iDet,hcBuffer,kMaxHcWords);
5fc47291 229 }
230
231 of->WriteBuffer((char *) hcBuffer, hcwords*4);
232 npayloadbyte += hcwords*4;
233
234 }
dfd03fc3 235
8c703901 236 }
237 }
238
239 // Complete header
08f92f14 240 header.fSize = UInt_t(of->Tellp()) - hpos;
8c703901 241 header.SetAttribute(0); // Valid data
08f92f14 242 of->Seekp(hpos); // Rewind to header position
243 of->WriteBuffer((char *) (& header), sizeof(header));
8c703901 244 delete of;
8c703901 245 }
246
0c349049 247 delete [] hcBuffer;
248
8c703901 249 return kTRUE;
250
251}
252
253//_____________________________________________________________________________
625f5260 254Int_t AliTRDrawData::ProduceHcDataV1andV2(AliTRDdataArrayS *digits, Int_t side
7925de54 255 , Int_t det, UInt_t *buf, Int_t maxSize)
8c703901 256{
7925de54 257 //
dfd03fc3 258 // This function simulates: 1) SM-I commissiong data Oct. 06 (Raw Version == 1).
259 // 2) Full Raw Production Version (Raw Version == 2)
8c703901 260 //
261 // Produce half chamber data (= an ORI data) for the given chamber (det) and side (side)
262 // where
7925de54 263 //
8c703901 264 // side=0 means A side with ROB positions 0, 2, 4, 6.
265 // side=1 means B side with ROB positions 1, 3, 5, 7.
266 //
267 // Chamber type (C0 orC1) is determined by "det" automatically.
268 // Appropriate size of buffer (*buf) must be prepared prior to calling this function.
269 // Pointer to the buffer and its size must be given to "buf" and "maxSize".
270 // Return value is the number of valid data filled in the buffer in unit of 32 bits
271 // UInt_t words.
272 // If buffer size if too small, the data is truncated with the buffer size however
273 // the function will finish without crash (this behaviour is similar to the MCM).
274 //
275
0c349049 276 Int_t nw = 0; // Number of written words
277 Int_t of = 0; // Number of overflowed words
053767a4 278 Int_t layer = fGeo->GetLayer( det ); // Layer
279 Int_t stack = fGeo->GetStack( det ); // Stack
0c349049 280 Int_t sect = fGeo->GetSector( det ); // Sector (=iDDL)
053767a4 281 Int_t nRow = fGeo->GetRowMax( layer, stack, sect );
282 Int_t nCol = fGeo->GetColMax( layer );
0c349049 283 const Int_t kNTBin = AliTRDcalibDB::Instance()->GetNumberOfTimeBins();
284 Int_t kCtype = 0; // Chamber type (0:C0, 1:C1)
285 Int_t iEv = 0xA; // Event ID. Now fixed to 10, how do I get event id?
286 UInt_t x = 0; // General used number
287 Int_t rv = fFee->GetRAWversion();
8c703901 288
289 // Check the nCol and nRow.
290 if ((nCol == 144) &&
291 (nRow == 16 || nRow == 12)) {
292 kCtype = (nRow-12) / 4;
293 }
294 else {
7925de54 295 AliError(Form("This type of chamber is not supported (nRow=%d, nCol=%d)."
8c703901 296 ,nRow,nCol));
297 return 0;
298 }
299
053767a4 300 AliDebug(1,Form("Producing raw data for sect=%d layer=%d stack=%d side=%d"
301 ,sect,layer,stack,side));
8c703901 302
303 // Tracklet should be processed here but not implemented yet
304
305 // Write end of tracklet marker
306 if (nw < maxSize) {
bd63bf88 307 buf[nw++] = kEndoftrackletmarker;
8c703901 308 }
309 else {
310 of++;
311 }
312
313 // Half Chamber header
dfd03fc3 314 if ( rv == 1 ) {
7925de54 315 // Now it is the same version as used in SM-I commissioning.
316 Int_t dcs = det+100; // DCS Serial (in simulation, it is meaningless
053767a4 317 x = (dcs<<20) | (sect<<15) | (layer<<12) | (stack<<9) | (side<<8) | 1;
7925de54 318 if (nw < maxSize) {
319 buf[nw++] = x;
320 }
321 else {
322 of++;
323 }
324 }
dfd03fc3 325 else if ( rv == 2 ) {
bd63bf88 326 // h[0] (there are 3 HC header)
7925de54 327 Int_t minorv = 0; // The minor version number
ecf39416 328 Int_t add = 2; // The number of additional header words to follow
053767a4 329 x = (1<<31) | (rv<<24) | (minorv<<17) | (add<<14) | (sect<<9) | (layer<<6) | (stack<<3) | (side<<2) | 1;
7925de54 330 if (nw < maxSize) {
331 buf[nw++] = x;
332 }
333 else {
334 of++;
335 }
336 // h[1]
0c349049 337 Int_t bcCtr = 99; // bunch crossing counter. Here it is set to 99 always for no reason
338 Int_t ptCtr = 15; // pretrigger counter. Here it is set to 15 always for no reason
339 Int_t ptPhase = 11; // pretrigger phase. Here it is set to 11 always for no reason
340 x = (bcCtr<<16) | (ptCtr<<12) | (ptPhase<<8) | ((kNTBin-1)<<2) | 1;
7925de54 341 if (nw < maxSize) {
342 buf[nw++] = x;
343 }
344 else {
345 of++;
346 }
bd63bf88 347 // h[2]
0c349049 348 Int_t pedSetup = 1; // Pedestal filter setup (0:1). Here it is always 1 for no reason
349 Int_t gainSetup = 1; // Gain filter setup (0:1). Here it is always 1 for no reason
350 Int_t tailSetup = 1; // Tail filter setup (0:1). Here it is always 1 for no reason
351 Int_t xtSetup = 0; // Cross talk filter setup (0:1). Here it is always 0 for no reason
352 Int_t nonlinSetup = 0; // Nonlinearity filter setup (0:1). Here it is always 0 for no reason
353 Int_t bypassSetup = 0; // Filter bypass (for raw data) setup (0:1). Here it is always 0 for no reason
354 Int_t commonAdditive = 10; // Digital filter common additive (0:63). Here it is always 10 for no reason
355 x = (pedSetup<<31) | (gainSetup<<30) | (tailSetup<<29) | (xtSetup<<28) | (nonlinSetup<<27)
356 | (bypassSetup<<26) | (commonAdditive<<20) | 1;
bd63bf88 357 if (nw < maxSize) {
358 buf[nw++] = x;
359 }
360 else {
361 of++;
362 }
8c703901 363 }
364
365 // Scan for ROB and MCM
366 for (Int_t iRobRow = 0; iRobRow < (kCtype + 3); iRobRow++ ) {
367 Int_t iRob = iRobRow * 2 + side;
7925de54 368 for (Int_t iMcm = 0; iMcm < fGeo->MCMmax(); iMcm++ ) {
8c703901 369 Int_t padrow = iRobRow * 4 + iMcm / 4;
370
371 // MCM header
7925de54 372 x = ((iRob * fGeo->MCMmax() + iMcm) << 24) | ((iEv % 0x100000) << 4) | 0xC;
8c703901 373 if (nw < maxSize) {
374 buf[nw++] = x;
375 }
376 else {
377 of++;
378 }
379
380 // ADC data
381 for (Int_t iAdc = 0; iAdc < 21; iAdc++ ) {
ecf39416 382 Int_t padcol = fFee->GetPadColFromADC(iRob, iMcm, iAdc);
7925de54 383 UInt_t aa = !(iAdc & 1) + 2;
0c349049 384 UInt_t *a = new UInt_t[kNTBin+2];
8c703901 385 // 3 timebins are packed into one 32 bits word
0c349049 386 for (Int_t iT = 0; iT < kNTBin; iT+=3) {
7925de54 387 if ((padcol >= 0) && (padcol < nCol)) {
0c349049 388 a[iT ] = ((iT ) < kNTBin ) ? digits->GetDataUnchecked(padrow,padcol,iT ) : 0;
389 a[iT+1] = ((iT + 1) < kNTBin ) ? digits->GetDataUnchecked(padrow,padcol,iT + 1) : 0;
390 a[iT+2] = ((iT + 2) < kNTBin ) ? digits->GetDataUnchecked(padrow,padcol,iT + 2) : 0;
7925de54 391 }
392 else {
393 a[iT] = a[iT+1] = a[iT+2] = 0; // This happenes at the edge of chamber (should be pedestal! How?)
8c703901 394 }
7925de54 395 x = (a[iT+2] << 22) | (a[iT+1] << 12) | (a[iT] << 2) | aa;
396 if (nw < maxSize) {
397 buf[nw++] = x;
8c703901 398 }
7925de54 399 else {
400 of++;
8c703901 401 }
7925de54 402 }
8c703901 403 // Diagnostics
404 Float_t avg = 0;
405 Float_t rms = 0;
0c349049 406 for (Int_t iT = 0; iT < kNTBin; iT++) {
8c703901 407 avg += (Float_t) (a[iT]);
408 }
0c349049 409 avg /= (Float_t) kNTBin;
410 for (Int_t iT = 0; iT < kNTBin; iT++) {
8c703901 411 rms += ((Float_t) (a[iT]) - avg) * ((Float_t) (a[iT]) - avg);
412 }
0c349049 413 rms = TMath::Sqrt(rms / (Float_t) kNTBin);
8c703901 414 if (rms > 1.7) {
7925de54 415 AliDebug(2,Form("Large RMS (>1.7) (ROB,MCM,ADC)=(%02d,%02d,%02d), avg=%03.1f, rms=%03.1f"
416 ,iRob,iMcm,iAdc,avg,rms));
8c703901 417 }
e21c2d7d 418 delete [] a;
8c703901 419 }
420 }
421 }
422
423 // Write end of raw data marker
424 if (nw < maxSize) {
bd63bf88 425 buf[nw++] = kEndofrawdatamarker;
8c703901 426 }
427 else {
428 of++;
429 }
430 if (of != 0) {
431 AliWarning("Buffer overflow. Data is truncated. Please increase buffer size and recompile.");
432 }
433
434 return nw;
5990c064 435
436}
437
dfd03fc3 438//_____________________________________________________________________________
23200400 439
1d93b218 440Int_t AliTRDrawData::ProduceHcDataV3(AliTRDdataArrayS *digits, Int_t side , Int_t det, UInt_t *buf, Int_t maxSize)
23200400 441//Int_t AliTRDrawData::ProduceHcDataV3(AliTRDdataArrayS *digits, Int_t side , Int_t det, UInt_t *buf, Int_t maxSize, Bool_t newEvent)
dfd03fc3 442{
443 //
444 // This function simulates: Raw Version == 3 (Zero Suppression Prototype)
445 //
446
0c349049 447 Int_t nw = 0; // Number of written words
448 Int_t of = 0; // Number of overflowed words
053767a4 449 Int_t layer = fGeo->GetLayer( det ); // Layer
450 Int_t stack = fGeo->GetStack( det ); // Stack
0c349049 451 Int_t sect = fGeo->GetSector( det ); // Sector (=iDDL)
053767a4 452 Int_t nRow = fGeo->GetRowMax( layer, stack, sect );
453 Int_t nCol = fGeo->GetColMax( layer );
0c349049 454 const Int_t kNTBin = AliTRDcalibDB::Instance()->GetNumberOfTimeBins();
455 Int_t kCtype = 0; // Chamber type (0:C0, 1:C1)
456 //Int_t iEv = 0xA; // Event ID. Now fixed to 10, how do I get event id?
1d93b218 457
458
459
460 Bool_t tracklet_on = fFee->GetTracklet(); // **new**
dfd03fc3 461
462 // Check the nCol and nRow.
463 if ((nCol == 144) &&
464 (nRow == 16 || nRow == 12)) {
465 kCtype = (nRow-12) / 4;
466 }
467 else {
468 AliError(Form("This type of chamber is not supported (nRow=%d, nCol=%d)."
469 ,nRow,nCol));
470 return 0;
471 }
472
053767a4 473 AliDebug(1,Form("Producing raw data for sect=%d layer=%d stack=%d side=%d"
474 ,sect,layer,stack,side));
dfd03fc3 475
1d93b218 476 AliTRDmcmSim** mcm = new AliTRDmcmSim*[(kCtype + 3)*(fGeo->MCMmax())];
dfd03fc3 477
1d93b218 478 // in case no tracklet-words are processed: write the tracklet-endmarker as well as all additional words immediately and write
479 // raw-data in one go; if tracklet-processing is enabled, first all tracklet-words of a half-chamber have to be processed before the
480 // additional words (tracklet-endmarker,headers,...)are written. Raw-data is written in a second loop;
481
482 if (!tracklet_on) {
483 WriteIntermediateWords(buf,nw,of,maxSize,det,side);
dfd03fc3 484 }
1d93b218 485
dfd03fc3 486 // Scan for ROB and MCM
1d93b218 487 // scanning direction such, that tracklet-words are sorted in ascending z and then in ascending y order
488 // ROB numbering on chamber and MCM numbering on ROB increase with decreasing z and increasing y
489 for (Int_t iRobRow = (kCtype + 3)-1; iRobRow >= 0; iRobRow-- ) {
dfd03fc3 490 Int_t iRob = iRobRow * 2 + side;
1d93b218 491 // MCM on one ROB
492 for (Int_t iMcmRB = 0; iMcmRB < fGeo->MCMmax(); iMcmRB++ ) {
493 Int_t iMcm = 16 - 4*(iMcmRB/4 + 1) + (iMcmRB%4);
494 Int_t entry = iRobRow*(fGeo->MCMmax()) + iMcm;
495
496 mcm[entry] = new AliTRDmcmSim();
497 //mcm[entry]->Init( det, iRob, iMcm , newEvent);
498 mcm[entry]->Init( det, iRob, iMcm);
499 //if (newEvent == kTRUE) newEvent = kFALSE; // only one mcm is concerned with new event
500 Int_t padrow = mcm[entry]->GetRow();
501
502 // Copy ADC data to MCM simulator
503 for (Int_t iAdc = 0; iAdc < 21; iAdc++ ) {
504 Int_t padcol = mcm[entry]->GetCol( iAdc );
505 if ((padcol >= 0) && (padcol < nCol)) {
506 for (Int_t iT = 0; iT < kNTBin; iT++) {
507 mcm[entry]->SetData( iAdc, iT, digits->GetDataUnchecked( padrow, padcol, iT) );
508 }
509 }
510 else { // this means it is out of chamber, and masked ADC
511 mcm[entry]->SetDataPedestal( iAdc );
512 }
513 }
dfd03fc3 514
1d93b218 515 // Simulate process in MCM
516 mcm[entry]->Filter(); // Apply filter
517 mcm[entry]->ZSMapping(); // Calculate zero suppression mapping
518
519 if (tracklet_on) {
520 mcm[entry]->Tracklet();
521 Int_t tempNw = mcm[entry]->ProduceTrackletStream( &buf[nw], maxSize - nw );
522 //Int_t tempNw = 0;
523 if( tempNw < 0 ) {
524 of += tempNw;
525 nw += maxSize - nw;
526 AliError(Form("Buffer overflow detected. Please increase the buffer size and recompile."));
527 } else {
528 nw += tempNw;
529 }
dfd03fc3 530 }
1d93b218 531 // no tracklets: write raw-data already in this loop
532 else {
533 // Write MCM data to buffer
534 Int_t tempNw = mcm[entry]->ProduceRawStream( &buf[nw], maxSize - nw );
535 if( tempNw < 0 ) {
536 of += tempNw;
537 nw += maxSize - nw;
538 AliError(Form("Buffer overflow detected. Please increase the buffer size and recompile."));
539 } else {
540 nw += tempNw;
541 }
542
543 delete mcm[entry];
544 }
545
546
709187ec 547
709187ec 548
1d93b218 549 //mcm->DumpData( "trdmcmdata.txt", "RFZS" ); // debugging purpose
dfd03fc3 550 }
551 }
552
1d93b218 553 // if tracklets are switched on, raw-data can be written only after all tracklets
554 if (tracklet_on) {
555 WriteIntermediateWords(buf,nw,of,maxSize,det,side);
556
557
558 // Scan for ROB and MCM
559 for (Int_t iRobRow = (kCtype + 3)-1; iRobRow >= 0; iRobRow-- ) {
560 //Int_t iRob = iRobRow * 2 + side;
561 // MCM on one ROB
562 for (Int_t iMcmRB = 0; iMcmRB < fGeo->MCMmax(); iMcmRB++ ) {
563 Int_t iMcm = 16 - 4*(iMcmRB/4 + 1) + (iMcmRB%4);
564
565 Int_t entry = iRobRow*(fGeo->MCMmax()) + iMcm;
566
567 // Write MCM data to buffer
568 Int_t tempNw = mcm[entry]->ProduceRawStream( &buf[nw], maxSize - nw );
569 if( tempNw < 0 ) {
570 of += tempNw;
571 nw += maxSize - nw;
572 AliError(Form("Buffer overflow detected. Please increase the buffer size and recompile."));
573 } else {
574 nw += tempNw;
575 }
576
577 delete mcm[entry];
578
579 }
580 }
581 }
582
583 delete [] mcm;
584
dfd03fc3 585 // Write end of raw data marker
586 if (nw < maxSize) {
587 buf[nw++] = kEndofrawdatamarker;
588 }
589 else {
590 of++;
591 }
592 if (of != 0) {
ecf39416 593 AliError("Buffer overflow. Data is truncated. Please increase buffer size and recompile.");
dfd03fc3 594 }
595
1d93b218 596
dfd03fc3 597 return nw;
598
599}
600
5990c064 601//_____________________________________________________________________________
7925de54 602AliTRDdigitsManager *AliTRDrawData::Raw2Digits(AliRawReader *rawReader)
5990c064 603{
b864d801 604 //
50378239 605 // Vx of the raw data reading
b864d801 606 //
5990c064 607
625f5260 608 AliTRDdataArrayS *digits = 0;
2cb20be6 609 AliTRDdataArrayI *track0 = 0;
610 AliTRDdataArrayI *track1 = 0;
611 AliTRDdataArrayI *track2 = 0;
5990c064 612
dfbb4bb9 613 //AliTRDSignalIndex *indexes = 0;
614 // Create the digits manager
615 AliTRDdigitsManager* digitsManager = new AliTRDdigitsManager();
616 digitsManager->CreateArrays();
617
618 //AliTRDRawStream input(rawReader);
619 // AliTRDRawStreamV2 input(rawReader);
620 // input.SetRawVersion( fFee->GetRAWversion() );
621 // input.Init();
622
623 AliTRDrawStreamBase *pinput = AliTRDrawStreamBase::GetRawStream(rawReader);
624 AliTRDrawStreamBase &input = *pinput;
625
626 AliInfo(Form("Stream version: %s", input.IsA()->GetName()));
627
628 // Loop through the digits
629 Int_t det = 0;
630
631 while (det >= 0)
632 {
633 det = input.NextChamber(digitsManager);
634 if (det >= 0)
635 {
636 // get...
637 digits = (AliTRDdataArrayS *) digitsManager->GetDigits(det);
638 track0 = (AliTRDdataArrayI *) digitsManager->GetDictionary(det,0);
639 track1 = (AliTRDdataArrayI *) digitsManager->GetDictionary(det,1);
640 track2 = (AliTRDdataArrayI *) digitsManager->GetDictionary(det,2);
641 // and compress
642 if (digits) digits->Compress(1,0);
643 if (track0) track0->Compress(1,0);
644 if (track1) track1->Compress(1,0);
645 if (track2) track2->Compress(1,0);
646 }
647 }
648
649 delete pinput;
650 pinput = NULL;
651
652 return digitsManager;
653}
654
1d93b218 655
656//_____________________________________________________________________________
657void AliTRDrawData::WriteIntermediateWords(UInt_t* buf, Int_t& nw, Int_t& of, const Int_t& maxSize, const Int_t& det, const Int_t& side) {
658
053767a4 659 Int_t layer = fGeo->GetLayer( det ); // Layer
660 Int_t stack = fGeo->GetStack( det ); // Stack
1d93b218 661 Int_t sect = fGeo->GetSector( det ); // Sector (=iDDL)
662 Int_t rv = fFee->GetRAWversion();
663 const Int_t kNTBin = AliTRDcalibDB::Instance()->GetNumberOfTimeBins();
664 UInt_t x = 0;
665
666 // Write end of tracklet marker
667 if (nw < maxSize) {
668 buf[nw++] = kEndoftrackletmarker;
669 }
670 else {
671 of++;
672 }
673
674 // Half Chamber header
675 // h[0] (there are 3 HC header)
676 Int_t minorv = 0; // The minor version number
677 Int_t add = 2; // The number of additional header words to follow
053767a4 678 x = (1<<31) | (rv<<24) | (minorv<<17) | (add<<14) | (sect<<9) | (layer<<6) | (stack<<3) | (side<<2) | 1;
1d93b218 679 if (nw < maxSize) {
680 buf[nw++] = x;
681 }
682 else {
683 of++;
684 }
685 // h[1]
686 Int_t bcCtr = 99; // bunch crossing counter. Here it is set to 99 always for no reason
687 Int_t ptCtr = 15; // pretrigger counter. Here it is set to 15 always for no reason
688 Int_t ptPhase = 11; // pretrigger phase. Here it is set to 11 always for no reason
689 x = (bcCtr<<16) | (ptCtr<<12) | (ptPhase<<8) | ((kNTBin-1)<<2) | 1;
690 if (nw < maxSize) {
691 buf[nw++] = x;
692 }
693 else {
694 of++;
695 }
696 // h[2]
697 Int_t pedSetup = 1; // Pedestal filter setup (0:1). Here it is always 1 for no reason
698 Int_t gainSetup = 1; // Gain filter setup (0:1). Here it is always 1 for no reason
699 Int_t tailSetup = 1; // Tail filter setup (0:1). Here it is always 1 for no reason
700 Int_t xtSetup = 0; // Cross talk filter setup (0:1). Here it is always 0 for no reason
701 Int_t nonlinSetup = 0; // Nonlinearity filter setup (0:1). Here it is always 0 for no reason
702 Int_t bypassSetup = 0; // Filter bypass (for raw data) setup (0:1). Here it is always 0 for no reason
703 Int_t commonAdditive = 10; // Digital filter common additive (0:63). Here it is always 10 for no reason
704 x = (pedSetup<<31) | (gainSetup<<30) | (tailSetup<<29) | (xtSetup<<28) | (nonlinSetup<<27)
705 | (bypassSetup<<26) | (commonAdditive<<20) | 1;
706 if (nw < maxSize) {
707 buf[nw++] = x;
708 }
709 else {
710 of++;
711 }
712}
713
714
dfbb4bb9 715//_____________________________________________________________________________
716AliTRDdigitsManager *AliTRDrawData::Raw2DigitsOLD(AliRawReader *rawReader)
717{
718 //
719 // Vx of the raw data reading
720 //
721
722 AliTRDdataArrayS *digits = 0;
723 AliTRDdataArrayI *track0 = 0;
724 AliTRDdataArrayI *track1 = 0;
725 AliTRDdataArrayI *track2 = 0;
726
ca21baaa 727 AliTRDSignalIndex *indexes = 0;
5990c064 728 // Create the digits manager
b864d801 729 AliTRDdigitsManager* digitsManager = new AliTRDdigitsManager();
b864d801 730 digitsManager->CreateArrays();
5990c064 731
ecf39416 732 //AliTRDRawStream input(rawReader);
733 AliTRDRawStreamV2 input(rawReader);
dfd03fc3 734 input.SetRawVersion( fFee->GetRAWversion() );
50378239 735 input.Init();
5990c064 736
ecf39416 737 AliInfo(Form("Stream version: %s", input.IsA()->GetName()));
738
b864d801 739 // Loop through the digits
50378239 740 Int_t lastdet = -1;
741 Int_t det = 0;
742 Int_t it = 0;
ecf39416 743 while (input.Next()) {
50378239 744
745 det = input.GetDet();
746
ecf39416 747 if (det != lastdet) { // If new detector found
50378239 748
749 lastdet = det;
750
751 if (digits) digits->Compress(1,0);
752 if (track0) track0->Compress(1,0);
753 if (track1) track1->Compress(1,0);
754 if (track2) track2->Compress(1,0);
755
756 // Add a container for the digits of this detector
625f5260 757 digits = (AliTRDdataArrayS *) digitsManager->GetDigits(det);
758 track0 = (AliTRDdataArrayI *) digitsManager->GetDictionary(det,0);
759 track1 = (AliTRDdataArrayI *) digitsManager->GetDictionary(det,1);
760 track2 = (AliTRDdataArrayI *) digitsManager->GetDictionary(det,2);
50378239 761
762 // Allocate memory space for the digits buffer
763 if (digits->GetNtime() == 0)
764 {
765 digits->Allocate(input.GetMaxRow(),input.GetMaxCol(), input.GetNumberOfTimeBins());
766 track0->Allocate(input.GetMaxRow(),input.GetMaxCol(), input.GetNumberOfTimeBins());
767 track1->Allocate(input.GetMaxRow(),input.GetMaxCol(), input.GetNumberOfTimeBins());
768 track2->Allocate(input.GetMaxRow(),input.GetMaxCol(), input.GetNumberOfTimeBins());
769 }
ca21baaa 770
771 indexes = digitsManager->GetIndexes(det);
772 indexes->SetSM(input.GetSM());
773 indexes->SetStack(input.GetStack());
774 indexes->SetLayer(input.GetLayer());
775 indexes->SetDetNumber(det);
776 if (indexes->IsAllocated() == kFALSE)
777 indexes->Allocate(input.GetMaxRow(), input.GetMaxCol(), input.GetNumberOfTimeBins());
50378239 778 }
779
ecf39416 780 // 3 timebin data are stored per word
50378239 781 for (it = 0; it < 3; it++)
782 {
783 if ( input.GetTimeBin() + it < input.GetNumberOfTimeBins() )
784 {
ca21baaa 785 if (input.GetSignals()[it] > 0)
786 {
787 digits->SetDataUnchecked(input.GetRow(), input.GetCol(),
788 input.GetTimeBin() + it, input.GetSignals()[it]);
789
790 indexes->AddIndexTBin(input.GetRow(), input.GetCol(),
791 input.GetTimeBin() + it);
792 track0->SetDataUnchecked(input.GetRow(), input.GetCol(),
793 input.GetTimeBin() + it, 0);
794 track1->SetDataUnchecked(input.GetRow(), input.GetCol(),
795 input.GetTimeBin() + it, 0);
796 track2->SetDataUnchecked(input.GetRow(), input.GetCol(),
797 input.GetTimeBin() + it, 0);
798 }
50378239 799 }
800 }
5990c064 801 }
802
b864d801 803 if (digits) digits->Compress(1,0);
928e9fae 804 if (track0) track0->Compress(1,0);
805 if (track1) track1->Compress(1,0);
806 if (track2) track2->Compress(1,0);
b864d801 807
7925de54 808 return digitsManager;
809
810}
1d93b218 811
812
813
814