]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDrawData.cxx
Fixing warnings
[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
0aff7a99 24
090026bf 25#include <TMath.h>
ecf39416 26#include "TClass.h"
5990c064 27
2745a409 28#include "AliDAQ.h"
f7ee745b 29#include "AliRawDataHeaderSim.h"
2745a409 30#include "AliRawReader.h"
31#include "AliLog.h"
0c349049 32#include "AliFstream.h"
2745a409 33
5990c064 34#include "AliTRDrawData.h"
35#include "AliTRDdigitsManager.h"
bd0f8685 36#include "AliTRDgeometry.h"
b65e5048 37#include "AliTRDarrayDictionary.h"
38#include "AliTRDarrayADC.h"
dfbb4bb9 39#include "AliTRDrawStreamBase.h"
3551db50 40#include "AliTRDcalibDB.h"
ca21baaa 41#include "AliTRDSignalIndex.h"
dfd03fc3 42#include "AliTRDfeeParam.h"
43#include "AliTRDmcmSim.h"
5896bc23 44#include "AliTRDdigitsParam.h"
dfd03fc3 45
5990c064 46ClassImp(AliTRDrawData)
47
6a04e92b 48Int_t AliTRDrawData::fgRawFormatVersion = AliTRDrawData::kRawNewFormat;
037c5823 49Int_t AliTRDrawData::fgDataSuppressionLevel = 0;
987ba9a3 50
5990c064 51//_____________________________________________________________________________
2cb20be6 52AliTRDrawData::AliTRDrawData()
53 :TObject()
92c7f341 54 ,fRunLoader(NULL)
dfd03fc3 55 ,fGeo(NULL)
56 ,fFee(NULL)
8c703901 57 ,fNumberOfDDLs(0)
92c7f341 58 ,fTrackletTree(NULL)
59 ,fTrackletContainer(NULL)
6a04e92b 60 ,fSMindexPos(0)
61 ,fStackindexPos(0)
62 ,fEventCounter(0)
a0446ff1 63 ,fDigitsParam(NULL)
5990c064 64{
b864d801 65 //
66 // Default constructor
67 //
0c349049 68
dfd03fc3 69 fFee = AliTRDfeeParam::Instance();
70 fNumberOfDDLs = AliDAQ::NumberOfDdls("TRD");
0c349049 71
5990c064 72}
73
8c703901 74//_____________________________________________________________________________
75AliTRDrawData::AliTRDrawData(const AliTRDrawData &r)
76 :TObject(r)
92c7f341 77 ,fRunLoader(NULL)
dfd03fc3 78 ,fGeo(NULL)
79 ,fFee(NULL)
8c703901 80 ,fNumberOfDDLs(0)
92c7f341 81 ,fTrackletTree(NULL)
82 ,fTrackletContainer(NULL)
6a04e92b 83 ,fSMindexPos(0)
84 ,fStackindexPos(0)
85 ,fEventCounter(0)
a0446ff1 86 ,fDigitsParam(NULL)
8c703901 87{
88 //
89 // Copy constructor
90 //
0c349049 91
dfd03fc3 92 fFee = AliTRDfeeParam::Instance();
93 fNumberOfDDLs = AliDAQ::NumberOfDdls("TRD");
0c349049 94
8c703901 95}
96
5990c064 97//_____________________________________________________________________________
98AliTRDrawData::~AliTRDrawData()
99{
100 //
101 // Destructor
102 //
0c349049 103
92c7f341 104 if (fTrackletContainer){
105 delete fTrackletContainer;
106 fTrackletContainer = NULL;
107 }
108
8c703901 109}
110
111//_____________________________________________________________________________
037c5823 112Bool_t AliTRDrawData::Digits2Raw(TTree *digitsTree, const TTree *tracks )
8c703901 113{
114 //
115 // Initialize necessary parameters and call one
116 // of the raw data simulator selected by SetRawVersion.
117 //
118 // Currently tracklet output is not spported yet and it
119 // will be supported in higher version simulator.
120 //
121
037c5823 122 AliTRDdigitsManager* const digitsManager = new AliTRDdigitsManager();
8c703901 123
124 if (!digitsManager->ReadDigits(digitsTree)) {
125 delete digitsManager;
126 return kFALSE;
127 }
128
129 if (tracks != NULL) {
130 delete digitsManager;
7925de54 131 AliError("Tracklet input is not supported yet.");
8c703901 132 return kFALSE;
133 }
134
135 fGeo = new AliTRDgeometry();
136
f162af62 137 if (!AliTRDcalibDB::Instance()) {
7925de54 138 AliError("Could not get calibration object");
8c703901 139 delete fGeo;
140 delete digitsManager;
141 return kFALSE;
142 }
143
144 Int_t retval = kTRUE;
dfd03fc3 145 Int_t rv = fFee->GetRAWversion();
8c703901 146
147 // Call appropriate Raw Simulator
dfd03fc3 148 if ( rv > 0 && rv <= 3 ) retval = Digits2Raw(digitsManager);
7925de54 149 else {
150 retval = kFALSE;
dfd03fc3 151 AliWarning(Form("Unsupported raw version (%d).", rv));
8c703901 152 }
153
154 // Cleanup
155 delete fGeo;
156 delete digitsManager;
157
158 return retval;
159
160}
161
162//_____________________________________________________________________________
50378239 163Bool_t AliTRDrawData::Digits2Raw(AliTRDdigitsManager *digitsManager)
8c703901 164{
165 //
7925de54 166 // Raw data simulator for all versions > 0. This is prepared for real data.
8c703901 167 // This version simulate only raw data with ADC data and not with tracklet.
8c703901 168 //
169
0c349049 170 const Int_t kMaxHcWords = (fGeo->TBmax()/3)
171 * fGeo->ADCmax()
172 * fGeo->MCMmax()
173 * fGeo->ROBmaxC1()/2
174 + 100 + 20;
8c703901 175
176 // Buffer to temporary store half chamber data
0c349049 177 UInt_t *hcBuffer = new UInt_t[kMaxHcWords];
5896bc23 178
1d93b218 179 Bool_t newEvent = kFALSE; // only for correct readout tree
6a04e92b 180 Bool_t newSM = kFALSE; // new SM flag, for writing SM index words
181 Bool_t newStack = kFALSE; // new stack flag, for writing stack index words
8c703901 182
a0446ff1 183 // Get digits parameter
184 fDigitsParam = digitsManager->GetDigitsParam();
185
8c703901 186 // sect is same as iDDL, so I use only sect here.
053767a4 187 for (Int_t sect = 0; sect < fGeo->Nsector(); sect++) {
8c703901 188
189 char name[1024];
45e64f3b 190 sprintf(name,"TRD_%d.ddl",sect + AliTRDrawStreamBase::kDDLOffset);
8c703901 191
08f92f14 192 AliFstream* of = new AliFstream(name);
8c703901 193
6a04e92b 194 // Write a dummy data header
f7ee745b 195 AliRawDataHeaderSim header; // the event header
08f92f14 196 UInt_t hpos = of->Tellp();
197 of->WriteBuffer((char *) (& header), sizeof(header));
8c703901 198
199 // Reset payload byte size (payload does not include header).
200 Int_t npayloadbyte = 0;
201
6a04e92b 202
037c5823 203 if ( fgRawFormatVersion == 0 ){
7925de54 204 // GTU common data header (5x4 bytes per super module, shows link mask)
053767a4 205 for( Int_t stack = 0; stack < fGeo->Nstack(); stack++ ) {
037c5823 206 UInt_t gtuCdh = (UInt_t)(0xe << 28);
207 for( Int_t layer = 0; layer < fGeo->Nlayer(); layer++) {
208 Int_t iDet = fGeo->GetDetector(layer, stack, sect);
6a04e92b 209
037c5823 210 // If chamber status is ok, we assume that the optical link is also OK.
211 // This is shown in the GTU link mask.
212 if ( AliTRDcalibDB::Instance()->GetChamberStatus(iDet) )
213 gtuCdh = gtuCdh | (3 << (2*layer));
214 }
215 of->WriteBuffer((char *) (& gtuCdh), sizeof(gtuCdh));
216 npayloadbyte += 4;
6a04e92b 217 }
037c5823 218 }
6a04e92b 219
220
221 // check the existance of the data
222 // SM index word and Stack index word
223 if ( fgRawFormatVersion == 1 ){
037c5823 224 UInt_t *iwbuffer = new UInt_t[109]; // index word buffer; max 109 = 2 SM headers + 67 dummy headers + 5*8 stack headers
6a04e92b 225 Int_t nheader = 0;
037c5823 226 UInt_t bStackMask = 0x0;
227 Bool_t bStackHasData = kFALSE;
228 Bool_t bSMHasData = kFALSE;
229
230 //iwbuffer[nheader++] = 0x0001a020; // SM index words
231 iwbuffer[nheader++] = 0x0044a020; // SM index words | additional SM header:48 = 1 SM header + 47 dummy words(for future use)
6a04e92b 232 iwbuffer[nheader++] = 0x10404071; // SM header
037c5823 233 for ( Int_t i=0; i<66; i++ ) iwbuffer[nheader++] = 0x00000000; // dummy words
234 iwbuffer[nheader++] = 0x10000000; // end of dummy words
6a04e92b 235
236 for ( Int_t stack= 0; stack < fGeo->Nstack(); stack++) {
037c5823 237 UInt_t linkMask = 0x0;
6a04e92b 238 for( Int_t layer = 0; layer < fGeo->Nlayer(); layer++) {
239 Int_t iDet = fGeo->GetDetector(layer,stack,sect);
240 AliTRDarrayADC *digits = (AliTRDarrayADC *) digitsManager->GetDigits(iDet);
241 if ( digits->HasData() ) {
037c5823 242 bStackMask = bStackMask | ( 1 << stack ); // active stack mask for new stack
243 linkMask = linkMask | ( 3 << (2*layer) ); // 3 = 0011
244 bStackHasData = kTRUE;
245 bSMHasData = kTRUE;
6a04e92b 246 } // has data
247 } // loop over layer
248
037c5823 249 if ( fgDataSuppressionLevel==0 || bStackHasData ){
250 iwbuffer[nheader++] = 0x0007a000 | linkMask; // stack index word + link masks
251 if (fgDataSuppressionLevel==0) iwbuffer[nheader-1] = 0x0007afff; // no suppression
6a04e92b 252 iwbuffer[nheader++] = 0x04045b01; // stack header
253 for (Int_t i=0;i<6;i++) iwbuffer[nheader++] = 0x00000000; // 6 dummy words
037c5823 254 bStackHasData = kFALSE;
6a04e92b 255 }
256 } // loop over stack
257
037c5823 258 if ( fgDataSuppressionLevel==0 || bSMHasData ){
259 iwbuffer[0] = iwbuffer[0] | bStackMask; // add stack masks to SM index word
260 if (fgDataSuppressionLevel==0) iwbuffer[0] = 0x0044a03f; // no suppression : all stacks are active
6a04e92b 261 of->WriteBuffer((char *) iwbuffer, nheader*4);
262 AliDebug(11, Form("SM %d index word: %08x", iwbuffer[0]));
263 AliDebug(11, Form("SM %d header: %08x", iwbuffer[1]));
264 }
265 }
266 // end of SM & stack header ------------------------------------------------------------------------
267 // -------------------------------------------------------------------------------------------------
8c703901 268
269 // Prepare chamber data
053767a4 270 for( Int_t stack = 0; stack < fGeo->Nstack(); stack++) {
271 for( Int_t layer = 0; layer < fGeo->Nlayer(); layer++) {
8c703901 272
053767a4 273 Int_t iDet = fGeo->GetDetector(layer,stack,sect);
6a04e92b 274 if (iDet == 0){
275 newEvent = kTRUE; // it is expected that each event has at least one tracklet;
276 // this is only needed for correct readout tree
277 fEventCounter++;
278 AliDebug(11, Form("New event!! Event counter: %d",fEventCounter));
279 }
8c703901 280
6a04e92b 281 if ( stack==0 && layer==0 ) newSM = kTRUE; // new SM flag
282 if ( layer==0 ) newStack = kTRUE; // new stack flag
283 AliDebug(15, Form("stack : %d, layer : %d, iDec : %d\n",stack,layer,iDet));
284 // Get the digits array
285 AliTRDarrayADC *digits = (AliTRDarrayADC *) digitsManager->GetDigits(iDet);
286 if (fgDataSuppressionLevel==0 || digits->HasData() ) { // second part is new!! and is for indicating a new event
8c703901 287
6a04e92b 288 if (digits->HasData()) digits->Expand();
289
290 Int_t hcwords = 0;
291 Int_t rv = fFee->GetRAWversion();
dfd03fc3 292
987ba9a3 293
294 if ( fgRawFormatVersion == 0 ){
295 // Process A side of the chamber
5fc47291 296 if ( rv >= 1 && rv <= 2 ) {
297 hcwords = ProduceHcDataV1andV2(digits,0,iDet,hcBuffer,kMaxHcWords);
298 }
299 if ( rv == 3 ) {
1d93b218 300
96e6312d 301 hcwords = ProduceHcDataV3 (digits,0,iDet,hcBuffer,kMaxHcWords,newEvent);
302 //hcwords = ProduceHcDataV3 (digits,0,iDet,hcBuffer,kMaxHcWords);
1d93b218 303 if(newEvent == kTRUE) newEvent = kFALSE;
5fc47291 304 }
8c703901 305
5fc47291 306 of->WriteBuffer((char *) hcBuffer, hcwords*4);
307 npayloadbyte += hcwords*4;
308
987ba9a3 309 // Process B side of the chamber
5fc47291 310 if ( rv >= 1 && rv <= 2 ) {
311 hcwords = ProduceHcDataV1andV2(digits,1,iDet,hcBuffer,kMaxHcWords);
312 }
313 if ( rv >= 3 ) {
1d93b218 314
96e6312d 315 hcwords = ProduceHcDataV3 (digits,1,iDet,hcBuffer,kMaxHcWords,newEvent);
316 //hcwords = ProduceHcDataV3 (digits,1,iDet,hcBuffer,kMaxHcWords);
5fc47291 317 }
318
319 of->WriteBuffer((char *) hcBuffer, hcwords*4);
320 npayloadbyte += hcwords*4;
321
6a04e92b 322 } else { // real data format
323
324 if (digits->HasData()){
325 // Process A side of the chamber
326 hcwords = ProduceHcData(digits,0,iDet,hcBuffer,kMaxHcWords,newEvent,newSM);
327 //if ( newStack ){
328 // AssignStackMask(hcBuffer, stack); // active stack mask for this stack
329 // hcwords += AddStackIndexWords(hcBuffer, stack, hcwords);
330 // newStack = kFALSE;
331 //}
332 //if ( newSM ) newSM = kFALSE;
333 if ( newEvent ) newEvent = kFALSE;
334 //AssignLinkMask(hcBuffer, layer); // active link mask for this layer(2*HC)
987ba9a3 335 of->WriteBuffer((char *) hcBuffer, hcwords*4);
336 npayloadbyte += hcwords*4;
6a04e92b 337 //for ( Int_t i=0; i<hcwords; i++ ) AliInfo(Form("Buf : %X",hcBuffer[i]));
987ba9a3 338
6a04e92b 339 // Process B side of the chamber
340 hcwords = ProduceHcData(digits,1,iDet,hcBuffer,kMaxHcWords,newEvent,newSM);
987ba9a3 341 of->WriteBuffer((char *) hcBuffer, hcwords*4);
342 npayloadbyte += hcwords*4;
037c5823 343 } else { // in case of no-suppression or NZS
344/*
6a04e92b 345 hcBuffer[hcwords++] = fgkEndOfTrackletMarker;
346 hcBuffer[hcwords++] = fgkEndOfTrackletMarker;
347 hcBuffer[hcwords++] = (1<<31) | (0<<24) | (0<<17) | (1<<14) | (sect<<9) | (layer<<6) | (stack<<3) | (0<<2) | 1;
348 hcBuffer[hcwords++] = (24<<26) | (99<<10) | (15<<6) | (11<<2) | 1;
349 hcBuffer[hcwords++] = kEndofrawdatamarker;
350 hcBuffer[hcwords++] = kEndofrawdatamarker;
351 hcBuffer[hcwords++] = kEndofrawdatamarker;
352 hcBuffer[hcwords++] = kEndofrawdatamarker;
353 npayloadbyte += hcwords*4;
987ba9a3 354
6a04e92b 355 hcBuffer[hcwords++] = fgkEndOfTrackletMarker;
356 hcBuffer[hcwords++] = fgkEndOfTrackletMarker;
357 hcBuffer[hcwords++] = (1<<31) | (0<<24) | (0<<17) | (1<<14) | (sect<<9) | (layer<<6) | (stack<<3) | (1<<2) | 1;
358 hcBuffer[hcwords++] = (24<<26) | (99<<10) | (15<<6) | (11<<2) | 1;
359 hcBuffer[hcwords++] = kEndofrawdatamarker;
360 hcBuffer[hcwords++] = kEndofrawdatamarker;
361 hcBuffer[hcwords++] = kEndofrawdatamarker;
362 hcBuffer[hcwords++] = kEndofrawdatamarker;
037c5823 363*/
364 hcwords = ProduceHcDataNoSuppression(0,iDet,hcBuffer,kMaxHcWords); // side 0
365 of->WriteBuffer((char *) hcBuffer, hcwords*4);
6a04e92b 366 npayloadbyte += hcwords*4;
dfd03fc3 367
037c5823 368 hcwords = ProduceHcDataNoSuppression(1,iDet,hcBuffer,kMaxHcWords); // side 1
6a04e92b 369 of->WriteBuffer((char *) hcBuffer, hcwords*4);
037c5823 370 npayloadbyte += hcwords*4;
6a04e92b 371 }
8c703901 372 }
373
6a04e92b 374 } // has data
375
376 } // loop over layer
377 } // loop over stack
378
8c703901 379 // Complete header
08f92f14 380 header.fSize = UInt_t(of->Tellp()) - hpos;
8c703901 381 header.SetAttribute(0); // Valid data
08f92f14 382 of->Seekp(hpos); // Rewind to header position
383 of->WriteBuffer((char *) (& header), sizeof(header));
8c703901 384 delete of;
037c5823 385 } // loop over sector(SM)
8c703901 386
0c349049 387 delete [] hcBuffer;
388
8c703901 389 return kTRUE;
390
391}
392
987ba9a3 393//_____________________________________________________________________________
394void AliTRDrawData::ProduceSMIndexData(UInt_t *buf, Int_t& nw){
395 //
396 // This function generates
397 // 1) SM index words : ssssssss ssssssss vvvv rrrr r d t mmmmm
398 // - s : size of SM header (number of header, default = 0x0001)
399 // - v : SM header version (default = 0xa)
400 // - r : reserved for future use (default = 00000)
401 // - d : track data enabled bit (default = 0)
402 // - t : tracklet data enabled bit (default = 1)
403 // - m : stack mask (each bit corresponds a stack, default = 11111)
404 //
405 // 2) SM header : rrr c vvvv vvvvvvvv vvvv rrrr bbbbbbbb
406 // - r : reserved for future use (default = 000)
407 // - c : clean check out flag (default = 1)
408 // - v : hardware design revision (default = 0x0404)
409 // - r : reserved for future use (default = 0x0)
410 // - b : physical board ID (default = 0x71)
411 //
412 // 3) stack index words : ssssssss ssssssss vvvv mmmm mmmmmmmm
413 // - s : size of stack header (number of header, (default = 0x0007)
414 // - v : header version (default = 0xa)
415 // - m : link mask (default = 0xfff)
416 //
417 // 4) stack header : vvvvvvvv vvvvvvvv bbbbbbbb rrrr rrr c
418 // - v : hardware design revision (default = 0x0404)
419 // - b : physical board ID (default = 0x5b)
420 // - r : reserved for future use (default = 0000 000)
421 // - c : clean checkout flag (default = 1)
422 //
423 // and 6 dummy words(0x00000000)
424 //
425
6a04e92b 426 //buf[nw++] = 0x0001a03f; // SM index words
427 fSMindexPos = nw; // memorize position of the SM index word for re-allocating stack mask
428 buf[nw++] = 0x0001a020; // SM index words
429 buf[nw++] = 0x10404071; // SM header
430
431 fStackindexPos = nw; // memorize position of the stack index word for future adding
432 /*
433 for (Int_t istack=0; istack<5; istack++){
434 buf[nw++] = 0x0007afff; // stack index words
435 buf[nw++] = 0x04045b01; // stack header
436 for (Int_t i=0;i<6;i++) buf[nw++] = 0x00000000; // 6 dummy words
437 } // loop over 5 stacks
438 */
439}
987ba9a3 440
6a04e92b 441//_____________________________________________________________________________
442void AliTRDrawData::AssignStackMask(UInt_t *buf, Int_t nStack){
443 //
444 // This function re-assign stack mask active(from 0 to 1) in the SM index word
445 //
446 buf[fSMindexPos] = buf[fSMindexPos] | ( 1 << nStack );
447}
448
449//_____________________________________________________________________________
543691ea 450Int_t AliTRDrawData::AddStackIndexWords(UInt_t *buf, Int_t /*nStack*/, Int_t nMax){
6a04e92b 451 //
452 // This function add stack index words and stack header when there is data for the stack
453 //
454 // 1) stack index words : ssssssss ssssssss vvvv mmmm mmmmmmmm
455 // - s : size of stack header (number of header, (default = 0x0007)
456 // - v : header version (default = 0xa)
457 // - m : link mask (default = 0xfff)
458 // - m : link mask (starting value = 0x000)
459 //
460 // 2) stack header : vvvvvvvv vvvvvvvv bbbbbbbb rrrr rrr c
461 // - v : hardware design revision (default = 0x0404)
462 // - b : physical board ID (default = 0x5b)
463 // - r : reserved for future use (default = 0000 000)
464 // - c : clean checkout flag (default = 1)
465 //
466 // and 6 dummy words(0x00000000)
467 //
468
469 Int_t nAddedWords = 0; // Number of added words
470 if ( ShiftWords(buf, fStackindexPos, 8, nMax)== kFALSE ){
471 AliError("Adding stack header failed.");
472 return 0;
473 }
474
475 buf[fStackindexPos++] = 0x0007a000; // stack index words
476 buf[fStackindexPos++] = 0x04045b01; // stack header
477 for (Int_t i=0;i<6;i++) buf[fStackindexPos++] = 0x00000000; // 6 dummy words
478 nAddedWords += 8;
987ba9a3 479
6a04e92b 480 return nAddedWords;
987ba9a3 481}
482
483//_____________________________________________________________________________
6a04e92b 484void AliTRDrawData::AssignLinkMask(UInt_t *buf, Int_t nLayer){
485 //
486 // This function re-assign link mask active(from 0 to 1) in the stack index word
487 //
488 buf[fStackindexPos-8] = buf[fStackindexPos-8] | ( 3 << (2*nLayer) ); // 3 = 0011
489}
490
491//_____________________________________________________________________________
492Bool_t AliTRDrawData::ShiftWords(UInt_t *buf, Int_t nStart, Int_t nWords, Int_t nMax){
493 //
494 // This function shifts n words
495 //
496 //if ( nStart+nWords > sizeof(buf)/sizeof(UInt_t) ){
497 // AliError("Words shift failed. No more buffer space.");
498 // return kFALSE;
499 //}
500
501 for ( Int_t iw=nMax; iw>nStart-1; iw--){
502 buf[iw+nWords] = buf[iw];
503 }
504 return kTRUE;
505}
506
507//_____________________________________________________________________________
0aff7a99 508Int_t AliTRDrawData::ProduceHcData(AliTRDarrayADC *digits, Int_t side, Int_t det, UInt_t *buf, Int_t maxSize, Bool_t /*newEvent = kFALSE*/, Bool_t /*newSM = kFALSE*/){
987ba9a3 509 //
510 // This function can be used for both ZS and NZS data
511 //
512
513 Int_t nw = 0; // Number of written words
514 Int_t of = 0; // Number of overflowed words
f793c83d 515 Int_t *tempnw = 0x0; // Number of written words for temp. buffer
516 Int_t *tempof = 0x0; // Number of overflowed words for temp. buffer
987ba9a3 517 Int_t layer = fGeo->GetLayer( det ); // Layer
518 Int_t stack = fGeo->GetStack( det ); // Stack
519 Int_t sect = fGeo->GetSector( det ); // Sector (=iDDL)
f793c83d 520 const Int_t kCtype = fGeo->GetStack(det) == 2 ? 0 : 1; // Chamber type (0:C0, 1:C1)
987ba9a3 521
037c5823 522 Bool_t trackletOn = fFee->GetTracklet(); // tracklet simulation active?
987ba9a3 523
524 AliDebug(1,Form("Producing raw data for sect=%d layer=%d stack=%d side=%d",sect,layer,stack,side));
f793c83d 525
526 AliTRDmcmSim* mcm = new AliTRDmcmSim();
987ba9a3 527
f793c83d 528 UInt_t *tempBuffer = buf; // tempBuffer used to write ADC data
529 // different in case of tracklet writing
530
037c5823 531 if (trackletOn) {
f793c83d 532 tempBuffer = new UInt_t[maxSize];
533 tempnw = new Int_t(0);
534 tempof = new Int_t(0);
535 }
536 else {
537 tempnw = &nw;
538 tempof = &of;
539 }
987ba9a3 540
f793c83d 541 WriteIntermediateWordsV2(tempBuffer,*tempnw,*tempof,maxSize,det,side); //??? no tracklet or NZS
987ba9a3 542
987ba9a3 543 // scanning direction such, that tracklet-words are sorted in ascending z and then in ascending y order
544 // ROB numbering on chamber and MCM numbering on ROB increase with decreasing z and increasing y
6a04e92b 545 for (Int_t iRobRow = 0; iRobRow <= (kCtype + 3)-1; iRobRow++ ) { // ROB number should be increasing
f793c83d 546 Int_t iRob = iRobRow * 2 + side;
547 // MCM on one ROB
548 for (Int_t iMcmRB = 0; iMcmRB < fGeo->MCMmax(); iMcmRB++ ) {
549 Int_t iMcm = 16 - 4*(iMcmRB/4 + 1) + (iMcmRB%4);
550
551 mcm->Init(det, iRob, iMcm);
552 mcm->SetData(digits); // no filtering done here (already done in digitizer)
037c5823 553 if (trackletOn) {
f793c83d 554 mcm->Tracklet();
555 Int_t tempNw = mcm->ProduceTrackletStream(&buf[nw], maxSize - nw);
556 if( tempNw < 0 ) {
557 of += tempNw;
558 nw += maxSize - nw;
559 AliError(Form("Buffer overflow detected. Please increase the buffer size and recompile."));
560 } else {
561 nw += tempNw;
562 }
563 }
564 mcm->ZSMapping(); // Calculate zero suppression mapping
565 // at the moment it has to be rerun here
566 // Write MCM data to temp. buffer
567 Int_t tempNw = mcm->ProduceRawStream( &tempBuffer[*tempnw], maxSize - *tempnw, fEventCounter );
568 if ( tempNw < 0 ) {
569 *tempof += tempNw;
570 *tempnw += maxSize - nw;
571 AliError(Form("Buffer overflow detected. Please increase the buffer size and recompile."));
572 } else {
573 *tempnw += tempNw;
574 }
575 }
576 }
987ba9a3 577
f793c83d 578 delete mcm;
987ba9a3 579
987ba9a3 580
f793c83d 581 // in case of tracklet writing copy temp data to final buffer
037c5823 582 if (trackletOn) {
f793c83d 583 if (nw + *tempnw < maxSize) {
584 memcpy(&buf[nw], tempBuffer, *tempnw * sizeof(UInt_t));
585 nw += *tempnw;
586 }
587 else {
588 AliError("Buffer overflow detected");
589 }
987ba9a3 590 }
591
987ba9a3 592 // Write end of raw data marker
6a04e92b 593 if (nw+3 < maxSize) {
037c5823 594 buf[nw++] = fgkEndOfDataMarker; // fFee->GetRawDataEndmarker();
595 buf[nw++] = fgkEndOfDataMarker; // fFee->GetRawDataEndmarker();
596 //buf[nw++] = fgkEndOfDataMarker; // fFee->GetRawDataEndmarker();
597 //buf[nw++] = fgkEndOfDataMarker; // fFee->GetRawDataEndmarker();
987ba9a3 598 } else {
f793c83d 599 of++;
987ba9a3 600 }
601
037c5823 602 if (trackletOn) {
f793c83d 603 delete [] tempBuffer;
604 delete tempof;
605 delete tempnw;
606 }
607
987ba9a3 608 if (of != 0) {
f793c83d 609 AliError("Buffer overflow. Data is truncated. Please increase buffer size and recompile.");
987ba9a3 610 }
611
612 return nw;
613}
614
037c5823 615//_____________________________________________________________________________
616Int_t AliTRDrawData::ProduceHcDataNoSuppression(Int_t side, Int_t det, UInt_t *buf, Int_t maxSize){
617
618 // This function generates below words for no-suppression option(same as real data format)
619 // 1. end of tracklet marker
620 // 2. HC index word, HC header
621 // 3. MCM header, ADC mask
622 // 4. end of data marker
623 //
624
625 Int_t nw = 0; // number of written words
626 Int_t of = 0; // number of overflowed words
627 UInt_t x = 0; // word buffer
628 //UInt_t *tempBuffer = buf; // temp buffer
629 Int_t *tempnw = &nw; // temp number of written words
630 Int_t *tempof = &of; // temp number of overflowed words
631
632 const Int_t kCtype = fGeo->GetStack(det) == 2 ? 0 : 1; // Chamber type (0:C0, 1:C1)
633
634 WriteIntermediateWordsV2(buf, *tempnw, *tempof, maxSize, det, side); // end of tracklet marker and HC headers
635
636 for (Int_t iRobRow = 0; iRobRow <= (kCtype + 3)-1; iRobRow++ ) { // ROB number should be increasing
637 Int_t iRob = iRobRow * 2 + side; // ROB position
638
639 for (Int_t iMcmRB = 0; iMcmRB < fGeo->MCMmax(); iMcmRB++ ) { // MCM on ROB
640 Int_t iMcm = 16 - 4*(iMcmRB/4 + 1) + (iMcmRB%4); // MCM position
641
642 if ( nw+2 < maxSize ){
643 x = 0;
644 x = (1<<31) | (iRob << 28) | (iMcm << 24) | ((fEventCounter % 0x100000) << 4) | 0xC; // MCM header
645 buf[nw++] = x;
646
647 x = 0;
648 // Produce ADC mask : nncc cccm mmmm mmmm mmmm mmmm mmmm 1100
649 // n : unused , c : ADC count, m : selected ADCs , where ccccc are inverted
650 x = x | (1 << 30) | (31 << 25) | 0xC; // 11111 = 31
651 buf[nw++] = x;
652 } else {
653 of++;
654 }
655
656 } // loop over MCM
657 } // loop over ROB
658
659 // Write end of raw data marker
660 if (nw+1 < maxSize) {
661 buf[nw++] = fgkEndOfDataMarker; // fFee->GetRawDataEndmarker();
662 buf[nw++] = fgkEndOfDataMarker; // fFee->GetRawDataEndmarker();
663 //buf[nw++] = fgkEndOfDataMarker; // fFee->GetRawDataEndmarker();
664 //buf[nw++] = fgkEndOfDataMarker; // fFee->GetRawDataEndmarker();
665 } else {
666 of++;
667 }
668
669 if ( of != 0 ){ // if there is overflow
670 AliError("Buffer overflow. Data is truncated. Please increase buffer size and recompile.");
671 }
672
673 AliDebug(1, Form("Number of written words in this HC is %d",nw));
674
675 return nw;
676}
677
8c703901 678//_____________________________________________________________________________
b65e5048 679Int_t AliTRDrawData::ProduceHcDataV1andV2(AliTRDarrayADC *digits, Int_t side
7925de54 680 , Int_t det, UInt_t *buf, Int_t maxSize)
8c703901 681{
7925de54 682 //
dfd03fc3 683 // This function simulates: 1) SM-I commissiong data Oct. 06 (Raw Version == 1).
684 // 2) Full Raw Production Version (Raw Version == 2)
8c703901 685 //
686 // Produce half chamber data (= an ORI data) for the given chamber (det) and side (side)
687 // where
7925de54 688 //
8c703901 689 // side=0 means A side with ROB positions 0, 2, 4, 6.
690 // side=1 means B side with ROB positions 1, 3, 5, 7.
691 //
692 // Chamber type (C0 orC1) is determined by "det" automatically.
693 // Appropriate size of buffer (*buf) must be prepared prior to calling this function.
694 // Pointer to the buffer and its size must be given to "buf" and "maxSize".
695 // Return value is the number of valid data filled in the buffer in unit of 32 bits
696 // UInt_t words.
697 // If buffer size if too small, the data is truncated with the buffer size however
698 // the function will finish without crash (this behaviour is similar to the MCM).
699 //
700
0c349049 701 Int_t nw = 0; // Number of written words
702 Int_t of = 0; // Number of overflowed words
053767a4 703 Int_t layer = fGeo->GetLayer( det ); // Layer
704 Int_t stack = fGeo->GetStack( det ); // Stack
0c349049 705 Int_t sect = fGeo->GetSector( det ); // Sector (=iDDL)
053767a4 706 Int_t nRow = fGeo->GetRowMax( layer, stack, sect );
707 Int_t nCol = fGeo->GetColMax( layer );
a0446ff1 708 const Int_t kNTBin = fDigitsParam->GetNTimeBins(det);
709
0c349049 710 Int_t kCtype = 0; // Chamber type (0:C0, 1:C1)
711 Int_t iEv = 0xA; // Event ID. Now fixed to 10, how do I get event id?
712 UInt_t x = 0; // General used number
713 Int_t rv = fFee->GetRAWversion();
8c703901 714
715 // Check the nCol and nRow.
716 if ((nCol == 144) &&
717 (nRow == 16 || nRow == 12)) {
718 kCtype = (nRow-12) / 4;
719 }
720 else {
7925de54 721 AliError(Form("This type of chamber is not supported (nRow=%d, nCol=%d)."
8c703901 722 ,nRow,nCol));
723 return 0;
724 }
725
053767a4 726 AliDebug(1,Form("Producing raw data for sect=%d layer=%d stack=%d side=%d"
727 ,sect,layer,stack,side));
8c703901 728
729 // Tracklet should be processed here but not implemented yet
730
731 // Write end of tracklet marker
732 if (nw < maxSize) {
bd63bf88 733 buf[nw++] = kEndoftrackletmarker;
8c703901 734 }
735 else {
736 of++;
737 }
738
739 // Half Chamber header
dfd03fc3 740 if ( rv == 1 ) {
7925de54 741 // Now it is the same version as used in SM-I commissioning.
742 Int_t dcs = det+100; // DCS Serial (in simulation, it is meaningless
053767a4 743 x = (dcs<<20) | (sect<<15) | (layer<<12) | (stack<<9) | (side<<8) | 1;
7925de54 744 if (nw < maxSize) {
745 buf[nw++] = x;
746 }
747 else {
748 of++;
749 }
750 }
dfd03fc3 751 else if ( rv == 2 ) {
bd63bf88 752 // h[0] (there are 3 HC header)
7925de54 753 Int_t minorv = 0; // The minor version number
ecf39416 754 Int_t add = 2; // The number of additional header words to follow
053767a4 755 x = (1<<31) | (rv<<24) | (minorv<<17) | (add<<14) | (sect<<9) | (layer<<6) | (stack<<3) | (side<<2) | 1;
7925de54 756 if (nw < maxSize) {
757 buf[nw++] = x;
758 }
759 else {
760 of++;
761 }
762 // h[1]
0c349049 763 Int_t bcCtr = 99; // bunch crossing counter. Here it is set to 99 always for no reason
764 Int_t ptCtr = 15; // pretrigger counter. Here it is set to 15 always for no reason
765 Int_t ptPhase = 11; // pretrigger phase. Here it is set to 11 always for no reason
766 x = (bcCtr<<16) | (ptCtr<<12) | (ptPhase<<8) | ((kNTBin-1)<<2) | 1;
7925de54 767 if (nw < maxSize) {
768 buf[nw++] = x;
769 }
770 else {
771 of++;
772 }
bd63bf88 773 // h[2]
0c349049 774 Int_t pedSetup = 1; // Pedestal filter setup (0:1). Here it is always 1 for no reason
775 Int_t gainSetup = 1; // Gain filter setup (0:1). Here it is always 1 for no reason
776 Int_t tailSetup = 1; // Tail filter setup (0:1). Here it is always 1 for no reason
777 Int_t xtSetup = 0; // Cross talk filter setup (0:1). Here it is always 0 for no reason
778 Int_t nonlinSetup = 0; // Nonlinearity filter setup (0:1). Here it is always 0 for no reason
779 Int_t bypassSetup = 0; // Filter bypass (for raw data) setup (0:1). Here it is always 0 for no reason
780 Int_t commonAdditive = 10; // Digital filter common additive (0:63). Here it is always 10 for no reason
781 x = (pedSetup<<31) | (gainSetup<<30) | (tailSetup<<29) | (xtSetup<<28) | (nonlinSetup<<27)
782 | (bypassSetup<<26) | (commonAdditive<<20) | 1;
bd63bf88 783 if (nw < maxSize) {
784 buf[nw++] = x;
785 }
786 else {
787 of++;
788 }
8c703901 789 }
790
791 // Scan for ROB and MCM
792 for (Int_t iRobRow = 0; iRobRow < (kCtype + 3); iRobRow++ ) {
793 Int_t iRob = iRobRow * 2 + side;
7925de54 794 for (Int_t iMcm = 0; iMcm < fGeo->MCMmax(); iMcm++ ) {
8c703901 795 Int_t padrow = iRobRow * 4 + iMcm / 4;
796
797 // MCM header
7925de54 798 x = ((iRob * fGeo->MCMmax() + iMcm) << 24) | ((iEv % 0x100000) << 4) | 0xC;
8c703901 799 if (nw < maxSize) {
800 buf[nw++] = x;
801 }
802 else {
803 of++;
804 }
805
806 // ADC data
807 for (Int_t iAdc = 0; iAdc < 21; iAdc++ ) {
ecf39416 808 Int_t padcol = fFee->GetPadColFromADC(iRob, iMcm, iAdc);
6a04e92b 809 UInt_t aa = !(iAdc & 1) + 2; // 3 for the even ADC channel , 2 for the odd ADC channel
0c349049 810 UInt_t *a = new UInt_t[kNTBin+2];
8c703901 811 // 3 timebins are packed into one 32 bits word
0c349049 812 for (Int_t iT = 0; iT < kNTBin; iT+=3) {
7925de54 813 if ((padcol >= 0) && (padcol < nCol)) {
b65e5048 814 a[iT ] = ((iT ) < kNTBin ) ? digits->GetData(padrow,padcol,iT ) : 0;
815 a[iT+1] = ((iT + 1) < kNTBin ) ? digits->GetData(padrow,padcol,iT + 1) : 0;
816 a[iT+2] = ((iT + 2) < kNTBin ) ? digits->GetData(padrow,padcol,iT + 2) : 0;
7925de54 817 }
818 else {
819 a[iT] = a[iT+1] = a[iT+2] = 0; // This happenes at the edge of chamber (should be pedestal! How?)
8c703901 820 }
7925de54 821 x = (a[iT+2] << 22) | (a[iT+1] << 12) | (a[iT] << 2) | aa;
822 if (nw < maxSize) {
823 buf[nw++] = x;
8c703901 824 }
7925de54 825 else {
826 of++;
8c703901 827 }
7925de54 828 }
8c703901 829 // Diagnostics
830 Float_t avg = 0;
831 Float_t rms = 0;
0c349049 832 for (Int_t iT = 0; iT < kNTBin; iT++) {
8c703901 833 avg += (Float_t) (a[iT]);
834 }
0c349049 835 avg /= (Float_t) kNTBin;
836 for (Int_t iT = 0; iT < kNTBin; iT++) {
8c703901 837 rms += ((Float_t) (a[iT]) - avg) * ((Float_t) (a[iT]) - avg);
838 }
0c349049 839 rms = TMath::Sqrt(rms / (Float_t) kNTBin);
8c703901 840 if (rms > 1.7) {
7925de54 841 AliDebug(2,Form("Large RMS (>1.7) (ROB,MCM,ADC)=(%02d,%02d,%02d), avg=%03.1f, rms=%03.1f"
842 ,iRob,iMcm,iAdc,avg,rms));
8c703901 843 }
e21c2d7d 844 delete [] a;
8c703901 845 }
846 }
847 }
848
849 // Write end of raw data marker
850 if (nw < maxSize) {
bd63bf88 851 buf[nw++] = kEndofrawdatamarker;
8c703901 852 }
853 else {
854 of++;
855 }
856 if (of != 0) {
857 AliWarning("Buffer overflow. Data is truncated. Please increase buffer size and recompile.");
858 }
859
860 return nw;
5990c064 861
862}
863
dfd03fc3 864//_____________________________________________________________________________
23200400 865
b65e5048 866//Int_t AliTRDrawData::ProduceHcDataV3(AliTRDarrayADC *digits, Int_t side , Int_t det, UInt_t *buf, Int_t maxSize)
867Int_t AliTRDrawData::ProduceHcDataV3(AliTRDarrayADC *digits, Int_t side , Int_t det, UInt_t *buf, Int_t maxSize, Bool_t newEvent = kFALSE)
dfd03fc3 868{
869 //
870 // This function simulates: Raw Version == 3 (Zero Suppression Prototype)
871 //
872
0c349049 873 Int_t nw = 0; // Number of written words
874 Int_t of = 0; // Number of overflowed words
053767a4 875 Int_t layer = fGeo->GetLayer( det ); // Layer
876 Int_t stack = fGeo->GetStack( det ); // Stack
0c349049 877 Int_t sect = fGeo->GetSector( det ); // Sector (=iDDL)
053767a4 878 Int_t nRow = fGeo->GetRowMax( layer, stack, sect );
879 Int_t nCol = fGeo->GetColMax( layer );
a0446ff1 880 const Int_t kNTBin = fDigitsParam->GetNTimeBins(det);
0c349049 881 Int_t kCtype = 0; // Chamber type (0:C0, 1:C1)
882 //Int_t iEv = 0xA; // Event ID. Now fixed to 10, how do I get event id?
1d93b218 883
884
885
037c5823 886 Bool_t trackletOn = fFee->GetTracklet(); // **new**
dfd03fc3 887
888 // Check the nCol and nRow.
889 if ((nCol == 144) &&
890 (nRow == 16 || nRow == 12)) {
891 kCtype = (nRow-12) / 4;
892 }
893 else {
894 AliError(Form("This type of chamber is not supported (nRow=%d, nCol=%d)."
895 ,nRow,nCol));
896 return 0;
897 }
898
053767a4 899 AliDebug(1,Form("Producing raw data for sect=%d layer=%d stack=%d side=%d"
900 ,sect,layer,stack,side));
dfd03fc3 901
1d93b218 902 AliTRDmcmSim** mcm = new AliTRDmcmSim*[(kCtype + 3)*(fGeo->MCMmax())];
dfd03fc3 903
1d93b218 904 // in case no tracklet-words are processed: write the tracklet-endmarker as well as all additional words immediately and write
905 // raw-data in one go; if tracklet-processing is enabled, first all tracklet-words of a half-chamber have to be processed before the
906 // additional words (tracklet-endmarker,headers,...)are written. Raw-data is written in a second loop;
907
037c5823 908 if (!trackletOn) {
1d93b218 909 WriteIntermediateWords(buf,nw,of,maxSize,det,side);
dfd03fc3 910 }
1d93b218 911
dfd03fc3 912 // Scan for ROB and MCM
1d93b218 913 // scanning direction such, that tracklet-words are sorted in ascending z and then in ascending y order
914 // ROB numbering on chamber and MCM numbering on ROB increase with decreasing z and increasing y
915 for (Int_t iRobRow = (kCtype + 3)-1; iRobRow >= 0; iRobRow-- ) {
dfd03fc3 916 Int_t iRob = iRobRow * 2 + side;
1d93b218 917 // MCM on one ROB
918 for (Int_t iMcmRB = 0; iMcmRB < fGeo->MCMmax(); iMcmRB++ ) {
919 Int_t iMcm = 16 - 4*(iMcmRB/4 + 1) + (iMcmRB%4);
920 Int_t entry = iRobRow*(fGeo->MCMmax()) + iMcm;
921
922 mcm[entry] = new AliTRDmcmSim();
96e6312d 923 mcm[entry]->Init( det, iRob, iMcm , newEvent);
924 //mcm[entry]->Init( det, iRob, iMcm);
925 if (newEvent == kTRUE) newEvent = kFALSE; // only one mcm is concerned with new event
1d93b218 926 Int_t padrow = mcm[entry]->GetRow();
927
928 // Copy ADC data to MCM simulator
929 for (Int_t iAdc = 0; iAdc < 21; iAdc++ ) {
930 Int_t padcol = mcm[entry]->GetCol( iAdc );
931 if ((padcol >= 0) && (padcol < nCol)) {
932 for (Int_t iT = 0; iT < kNTBin; iT++) {
b65e5048 933 mcm[entry]->SetData( iAdc, iT, digits->GetData( padrow, padcol, iT) );
1d93b218 934 }
935 }
936 else { // this means it is out of chamber, and masked ADC
937 mcm[entry]->SetDataPedestal( iAdc );
938 }
939 }
dfd03fc3 940
1d93b218 941 // Simulate process in MCM
b0a41e80 942 mcm[entry]->Filter(); // Apply filter
943 mcm[entry]->ZSMapping(); // Calculate zero suppression mapping
944//jkl mcm[entry]->CopyArrays();
945//jkl mcm[entry]->GeneratefZSM1Dim();
946//jkl mcm[entry]->RestoreZeros();
1d93b218 947
037c5823 948 if (trackletOn) {
1d93b218 949 mcm[entry]->Tracklet();
950 Int_t tempNw = mcm[entry]->ProduceTrackletStream( &buf[nw], maxSize - nw );
951 //Int_t tempNw = 0;
952 if( tempNw < 0 ) {
953 of += tempNw;
954 nw += maxSize - nw;
955 AliError(Form("Buffer overflow detected. Please increase the buffer size and recompile."));
956 } else {
957 nw += tempNw;
958 }
dfd03fc3 959 }
1d93b218 960 // no tracklets: write raw-data already in this loop
961 else {
962 // Write MCM data to buffer
963 Int_t tempNw = mcm[entry]->ProduceRawStream( &buf[nw], maxSize - nw );
964 if( tempNw < 0 ) {
965 of += tempNw;
966 nw += maxSize - nw;
967 AliError(Form("Buffer overflow detected. Please increase the buffer size and recompile."));
968 } else {
969 nw += tempNw;
970 }
971
972 delete mcm[entry];
973 }
974
975
709187ec 976
709187ec 977
1d93b218 978 //mcm->DumpData( "trdmcmdata.txt", "RFZS" ); // debugging purpose
dfd03fc3 979 }
980 }
981
1d93b218 982 // if tracklets are switched on, raw-data can be written only after all tracklets
037c5823 983 if (trackletOn) {
1d93b218 984 WriteIntermediateWords(buf,nw,of,maxSize,det,side);
985
986
987 // Scan for ROB and MCM
988 for (Int_t iRobRow = (kCtype + 3)-1; iRobRow >= 0; iRobRow-- ) {
989 //Int_t iRob = iRobRow * 2 + side;
990 // MCM on one ROB
991 for (Int_t iMcmRB = 0; iMcmRB < fGeo->MCMmax(); iMcmRB++ ) {
992 Int_t iMcm = 16 - 4*(iMcmRB/4 + 1) + (iMcmRB%4);
993
994 Int_t entry = iRobRow*(fGeo->MCMmax()) + iMcm;
995
996 // Write MCM data to buffer
997 Int_t tempNw = mcm[entry]->ProduceRawStream( &buf[nw], maxSize - nw );
998 if( tempNw < 0 ) {
999 of += tempNw;
1000 nw += maxSize - nw;
1001 AliError(Form("Buffer overflow detected. Please increase the buffer size and recompile."));
1002 } else {
1003 nw += tempNw;
1004 }
1005
1006 delete mcm[entry];
1007
1008 }
1009 }
1010 }
1011
1012 delete [] mcm;
1013
dfd03fc3 1014 // Write end of raw data marker
1015 if (nw < maxSize) {
1016 buf[nw++] = kEndofrawdatamarker;
1017 }
1018 else {
1019 of++;
1020 }
1021 if (of != 0) {
ecf39416 1022 AliError("Buffer overflow. Data is truncated. Please increase buffer size and recompile.");
dfd03fc3 1023 }
1024
1d93b218 1025
dfd03fc3 1026 return nw;
1027
1028}
1029
5990c064 1030//_____________________________________________________________________________
7925de54 1031AliTRDdigitsManager *AliTRDrawData::Raw2Digits(AliRawReader *rawReader)
5990c064 1032{
b864d801 1033 //
50378239 1034 // Vx of the raw data reading
b864d801 1035 //
5990c064 1036
e2e85093 1037 rawReader->Select("TRD"); //[mj]
1038
b65e5048 1039 AliTRDarrayADC *digits = 0;
1040 AliTRDarrayDictionary *track0 = 0;
1041 AliTRDarrayDictionary *track1 = 0;
1042 AliTRDarrayDictionary *track2 = 0;
5990c064 1043
dfbb4bb9 1044 //AliTRDSignalIndex *indexes = 0;
1045 // Create the digits manager
1046 AliTRDdigitsManager* digitsManager = new AliTRDdigitsManager();
1047 digitsManager->CreateArrays();
1048
92c7f341 1049 if (!fTrackletContainer) {
1050 //if (!fTrackletContainer && ( fReconstructor->IsWritingTracklets() || fReconstructor->IsProcessingTracklets() )) {
1051 // maximum tracklets for one HC
1052 const Int_t kTrackletChmb=256;
1053 fTrackletContainer = new UInt_t *[2];
1054 fTrackletContainer[0] = new UInt_t[kTrackletChmb];
1055 fTrackletContainer[1] = new UInt_t[kTrackletChmb];
1056 }
1057
dfbb4bb9 1058 AliTRDrawStreamBase *pinput = AliTRDrawStreamBase::GetRawStream(rawReader);
1059 AliTRDrawStreamBase &input = *pinput;
12b70280 1060 input.SetRawVersion( fFee->GetRAWversion() ); //<= ADDED by MinJung
dfbb4bb9 1061
1062 AliInfo(Form("Stream version: %s", input.IsA()->GetName()));
1063
1064 // Loop through the digits
1065 Int_t det = 0;
1066
1067 while (det >= 0)
1068 {
92c7f341 1069 //det = input.NextChamber(digitsManager);
1070 det = input.NextChamber(digitsManager,fTrackletContainer);
1071
1072 //if (!fReconstructor->IsWritingTracklets()) continue;
1073 if (*(fTrackletContainer[0]) > 0 || *(fTrackletContainer[1]) > 0) WriteTracklets(det);
1074
dfbb4bb9 1075 if (det >= 0)
1076 {
1077 // get...
b65e5048 1078 digits = (AliTRDarrayADC *) digitsManager->GetDigits(det);
1079 track0 = (AliTRDarrayDictionary *) digitsManager->GetDictionary(det,0);
1080 track1 = (AliTRDarrayDictionary *) digitsManager->GetDictionary(det,1);
1081 track2 = (AliTRDarrayDictionary *) digitsManager->GetDictionary(det,2);
dfbb4bb9 1082 // and compress
b65e5048 1083 if (digits) digits->Compress();
1084 if (track0) track0->Compress();
1085 if (track1) track1->Compress();
1086 if (track2) track2->Compress();
dfbb4bb9 1087 }
1088 }
1089
92c7f341 1090 if (fTrackletContainer){
1091 delete [] fTrackletContainer[0];
1092 delete [] fTrackletContainer[1];
1093 delete [] fTrackletContainer;
1094 fTrackletContainer = NULL;
1095 }
1096
dfbb4bb9 1097 delete pinput;
1098 pinput = NULL;
1099
1100 return digitsManager;
1101}
1102
1d93b218 1103//_____________________________________________________________________________
1104void AliTRDrawData::WriteIntermediateWords(UInt_t* buf, Int_t& nw, Int_t& of, const Int_t& maxSize, const Int_t& det, const Int_t& side) {
037c5823 1105 //
1106 // write half-chamber headers
1107 //
1d93b218 1108
053767a4 1109 Int_t layer = fGeo->GetLayer( det ); // Layer
1110 Int_t stack = fGeo->GetStack( det ); // Stack
1d93b218 1111 Int_t sect = fGeo->GetSector( det ); // Sector (=iDDL)
1112 Int_t rv = fFee->GetRAWversion();
a0446ff1 1113 const Int_t kNTBin = fDigitsParam->GetNTimeBins(det);
1d93b218 1114 UInt_t x = 0;
1115
1116 // Write end of tracklet marker
1117 if (nw < maxSize) {
1118 buf[nw++] = kEndoftrackletmarker;
1119 }
1120 else {
1121 of++;
1122 }
1123
1124 // Half Chamber header
1125 // h[0] (there are 3 HC header)
1126 Int_t minorv = 0; // The minor version number
1127 Int_t add = 2; // The number of additional header words to follow
053767a4 1128 x = (1<<31) | (rv<<24) | (minorv<<17) | (add<<14) | (sect<<9) | (layer<<6) | (stack<<3) | (side<<2) | 1;
1d93b218 1129 if (nw < maxSize) {
1130 buf[nw++] = x;
1131 }
1132 else {
1133 of++;
1134 }
1135 // h[1]
1136 Int_t bcCtr = 99; // bunch crossing counter. Here it is set to 99 always for no reason
1137 Int_t ptCtr = 15; // pretrigger counter. Here it is set to 15 always for no reason
1138 Int_t ptPhase = 11; // pretrigger phase. Here it is set to 11 always for no reason
1139 x = (bcCtr<<16) | (ptCtr<<12) | (ptPhase<<8) | ((kNTBin-1)<<2) | 1;
1140 if (nw < maxSize) {
1141 buf[nw++] = x;
1142 }
1143 else {
1144 of++;
1145 }
1146 // h[2]
1147 Int_t pedSetup = 1; // Pedestal filter setup (0:1). Here it is always 1 for no reason
1148 Int_t gainSetup = 1; // Gain filter setup (0:1). Here it is always 1 for no reason
1149 Int_t tailSetup = 1; // Tail filter setup (0:1). Here it is always 1 for no reason
1150 Int_t xtSetup = 0; // Cross talk filter setup (0:1). Here it is always 0 for no reason
1151 Int_t nonlinSetup = 0; // Nonlinearity filter setup (0:1). Here it is always 0 for no reason
1152 Int_t bypassSetup = 0; // Filter bypass (for raw data) setup (0:1). Here it is always 0 for no reason
1153 Int_t commonAdditive = 10; // Digital filter common additive (0:63). Here it is always 10 for no reason
1154 x = (pedSetup<<31) | (gainSetup<<30) | (tailSetup<<29) | (xtSetup<<28) | (nonlinSetup<<27)
1155 | (bypassSetup<<26) | (commonAdditive<<20) | 1;
1156 if (nw < maxSize) {
1157 buf[nw++] = x;
1158 }
1159 else {
1160 of++;
1161 }
1162}
1163
987ba9a3 1164//_____________________________________________________________________________
1165void AliTRDrawData::WriteIntermediateWordsV2(UInt_t* buf, Int_t& nw, Int_t& of, const Int_t& maxSize, const Int_t& det, const Int_t& side) {
037c5823 1166 //
1167 // write tracklet end marker(0x10001000)
1168 // and half chamber headers(H[0] and H[1])
1169 //
987ba9a3 1170
1171 Int_t layer = fGeo->GetLayer( det ); // Layer
1172 Int_t stack = fGeo->GetStack( det ); // Stack
1173 Int_t sect = fGeo->GetSector( det ); // Sector (=iDDL)
1174 Int_t rv = fFee->GetRAWversion();
a0446ff1 1175 const Int_t kNTBin = fDigitsParam->GetNTimeBins(det);
5896bc23 1176 Bool_t trackletOn = fFee->GetTracklet();
987ba9a3 1177 UInt_t x = 0;
1178
1179 // Write end of tracklet marker
6a04e92b 1180 if (nw < maxSize){
1181 buf[nw++] = fgkEndOfTrackletMarker;
1182 buf[nw++] = fgkEndOfTrackletMarker; // the number of tracklet end marker should be more than 2
1183 }
1184 else {
1185 of++;
1186 }
1187
987ba9a3 1188
1189 // Half Chamber header
1190 // h[0] (there are 2 HC headers) xmmm mmmm nnnn nnnq qqss sssp ppcc ci01
1191 // , where x : Raw version speacial number (=1)
1192 // m : Raw version major number (test pattern, ZS, disable tracklet, 0, options)
1193 // n : Raw version minor number
1194 // q : number of addtional header words (default = 1)
1195 // s : SM sector number (ALICE numbering)
1196 // p : plane(layer) number
1197 // c : chamber(stack) number
1198 // i : side number (0:A, 1:B)
1199 Int_t majorv = 0; // The major version number
1200 Int_t minorv = 0; // The minor version number
1201 Int_t add = 1; // The number of additional header words to follow : now 1, previous 2
037c5823 1202 Int_t tp = 0; // test pattern (default=0)
1203 Int_t zs = (rv==3) ? 1 : 0; // zero suppression
1204 Int_t dt = (trackletOn) ? 0 : 1; // disable tracklet
987ba9a3 1205
037c5823 1206 majorv = (tp<<6) | (zs<<5) | (dt<<4) | 1; // major version
987ba9a3 1207
1208 x = (1<<31) | (majorv<<24) | (minorv<<17) | (add<<14) | (sect<<9) | (layer<<6) | (stack<<3) | (side<<2) | 1;
1209 if (nw < maxSize) buf[nw++] = x; else of++;
1210
1211 // h[1] tttt ttbb bbbb bbbb bbbb bbpp pphh hh01
1212 // , where t : number of time bins
1213 // b : bunch crossing number
1214 // p : pretrigger counter
1215 // h : pretrigger phase
1216 Int_t bcCtr = 99; // bunch crossing counter. Here it is set to 99 always for no reason
1217 Int_t ptCtr = 15; // pretrigger counter. Here it is set to 15 always for no reason
1218 Int_t ptPhase = 11; // pretrigger phase. Here it is set to 11 always for no reason
1219 //x = (bcCtr<<16) | (ptCtr<<12) | (ptPhase<<8) | ((kNTBin-1)<<2) | 1; // old format
6a04e92b 1220 x = ((kNTBin)<<26) | (bcCtr<<10) | (ptCtr<<6) | (ptPhase<<2) | 1;
987ba9a3 1221 if (nw < maxSize) buf[nw++] = x; else of++;
1222
1223}
1d93b218 1224
92c7f341 1225//_____________________________________________________________________________
1226Bool_t AliTRDrawData::WriteTracklets(Int_t det)
1227{
1228 //
1229 // Write the raw data tracklets into seperate file
1230 //
1231
1232 UInt_t **leaves = new UInt_t *[2];
1233 for (Int_t i=0; i<2 ;i++){
1234 leaves[i] = new UInt_t[258];
1235 leaves[i][0] = det; // det
1236 leaves[i][1] = i; // side
1237 memcpy(leaves[i]+2, fTrackletContainer[i], sizeof(UInt_t) * 256);
1238 }
1239
1240 if (!fTrackletTree){
1241 AliDataLoader *dl = fRunLoader->GetLoader("TRDLoader")->GetDataLoader("tracklets");
1242 dl->MakeTree();
1243 fTrackletTree = dl->Tree();
1244 }
1245
1246 TBranch *trkbranch = fTrackletTree->GetBranch("trkbranch");
1247 if (!trkbranch) {
1248 trkbranch = fTrackletTree->Branch("trkbranch",leaves[0],"det/i:side/i:tracklets[256]/i");
1249 }
1250
1251 for (Int_t i=0; i<2; i++){
1252 if (leaves[i][2]>0) {
1253 trkbranch->SetAddress(leaves[i]);
1254 fTrackletTree->Fill();
1255 }
1256 }
1257
1258 AliDataLoader *dl = fRunLoader->GetLoader("TRDLoader")->GetDataLoader("tracklets");
1259 dl->WriteData("OVERWRITE");
1260 //dl->Unload();
1261 delete [] leaves;
1262
1263 return kTRUE;
1264
1265}
1266
1267//_____________________________________________________________________________
1268Bool_t AliTRDrawData::OpenOutput()
1269{
1270 //
1271 // Connect the output tree
1272 //
1273
1274 // tracklet writing
1275 if (1){
1276 //if (fReconstructor->IsWritingTracklets()){
1277 TString evfoldname = AliConfig::GetDefaultEventFolderName();
1278 fRunLoader = AliRunLoader::GetRunLoader(evfoldname);
1279
1280 if (!fRunLoader) {
1281 fRunLoader = AliRunLoader::Open("galice.root");
1282 }
1283 if (!fRunLoader) {
1284 AliError(Form("Can not open session for file galice.root."));
1285 return kFALSE;
1286 }
1287
1288 UInt_t **leaves = new UInt_t *[2];
1289 AliDataLoader *dl = fRunLoader->GetLoader("TRDLoader")->GetDataLoader("tracklets");
1290 if (!dl) {
1291 AliError("Could not get the tracklets data loader!");
1292 dl = new AliDataLoader("TRD.Tracklets.root","tracklets", "tracklets");
1293 fRunLoader->GetLoader("TRDLoader")->AddDataLoader(dl);
1294 }
11d0be11 1295 fTrackletTree = dl->Tree();
1296 if (!fTrackletTree)
1297 {
1298 dl->MakeTree();
1299 fTrackletTree = dl->Tree();
1300 }
1301 TBranch *trkbranch = fTrackletTree->GetBranch("trkbranch");
1302 if (!trkbranch)
1303 fTrackletTree->Branch("trkbranch",leaves[0],"det/i:side/i:tracklets[256]/i");
92c7f341 1304 }
1305 return kTRUE;
1306
1307}
1308
1309
1310
f793c83d 1311