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