1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 // TRD raw data conversion class //
22 ///////////////////////////////////////////////////////////////////////////////
28 #include "AliRawDataHeaderSim.h"
29 #include "AliRawReader.h"
31 #include "AliFstream.h"
33 #include "AliTRDrawData.h"
34 #include "AliTRDdigitsManager.h"
35 #include "AliTRDgeometry.h"
36 #include "AliTRDarrayDictionary.h"
37 #include "AliTRDarrayADC.h"
38 #include "AliTRDrawStreamBase.h"
39 #include "AliTRDrawOldStream.h"
40 #include "AliTRDRawStreamV2.h"
41 #include "AliTRDcalibDB.h"
42 #include "AliTRDSignalIndex.h"
43 #include "AliTRDfeeParam.h"
44 #include "AliTRDmcmSim.h"
46 ClassImp(AliTRDrawData)
48 Int_t AliTRDrawData::fgRawFormatVersion = AliTRDrawData::kRawOldFormat;
50 //_____________________________________________________________________________
51 AliTRDrawData::AliTRDrawData()
58 // Default constructor
61 fFee = AliTRDfeeParam::Instance();
62 fNumberOfDDLs = AliDAQ::NumberOfDdls("TRD");
66 //_____________________________________________________________________________
67 AliTRDrawData::AliTRDrawData(const AliTRDrawData &r)
77 fFee = AliTRDfeeParam::Instance();
78 fNumberOfDDLs = AliDAQ::NumberOfDdls("TRD");
82 //_____________________________________________________________________________
83 AliTRDrawData::~AliTRDrawData()
91 //_____________________________________________________________________________
92 Bool_t AliTRDrawData::Digits2Raw(TTree *digitsTree, TTree *tracks )
95 // Initialize necessary parameters and call one
96 // of the raw data simulator selected by SetRawVersion.
98 // Currently tracklet output is not spported yet and it
99 // will be supported in higher version simulator.
102 AliTRDdigitsManager* digitsManager = new AliTRDdigitsManager();
104 if (!digitsManager->ReadDigits(digitsTree)) {
105 delete digitsManager;
109 if (tracks != NULL) {
110 delete digitsManager;
111 AliError("Tracklet input is not supported yet.");
115 fGeo = new AliTRDgeometry();
117 if (!AliTRDcalibDB::Instance()) {
118 AliError("Could not get calibration object");
120 delete digitsManager;
124 Int_t retval = kTRUE;
125 Int_t rv = fFee->GetRAWversion();
127 // Call appropriate Raw Simulator
128 if ( rv > 0 && rv <= 3 ) retval = Digits2Raw(digitsManager);
131 AliWarning(Form("Unsupported raw version (%d).", rv));
136 delete digitsManager;
142 //_____________________________________________________________________________
143 Bool_t AliTRDrawData::Digits2Raw(AliTRDdigitsManager *digitsManager)
146 // Raw data simulator for all versions > 0. This is prepared for real data.
147 // This version simulate only raw data with ADC data and not with tracklet.
150 const Int_t kMaxHcWords = (fGeo->TBmax()/3)
156 // Buffer to temporary store half chamber data
157 UInt_t *hcBuffer = new UInt_t[kMaxHcWords];
159 Bool_t newEvent = kFALSE; // only for correct readout tree
161 // sect is same as iDDL, so I use only sect here.
162 for (Int_t sect = 0; sect < fGeo->Nsector(); sect++) {
165 sprintf(name,"TRD_%d.ddl",sect + AliTRDrawOldStream::kDDLOffset);
167 AliFstream* of = new AliFstream(name);
169 // Write a dummy data header
170 AliRawDataHeaderSim header; // the event header
171 UInt_t hpos = of->Tellp();
172 of->WriteBuffer((char *) (& header), sizeof(header));
174 // Reset payload byte size (payload does not include header).
175 Int_t npayloadbyte = 0;
178 if ( fgRawFormatVersion == 0 ){
179 // GTU common data header (5x4 bytes per super module, shows link mask)
180 for( Int_t stack = 0; stack < fGeo->Nstack(); stack++ ) {
181 UInt_t gtuCdh = (UInt_t)(0xe << 28);
182 for( Int_t layer = 0; layer < fGeo->Nlayer(); layer++) {
183 Int_t iDet = fGeo->GetDetector(layer, stack, sect);
185 // If chamber status is ok, we assume that the optical link is also OK.
186 // This is shown in the GTU link mask.
187 if ( AliTRDcalibDB::Instance()->GetChamberStatus(iDet) )
188 gtuCdh = gtuCdh | (3 << (2*layer));
190 of->WriteBuffer((char *) (& gtuCdh), sizeof(gtuCdh));
195 // Prepare chamber data
196 for( Int_t stack = 0; stack < fGeo->Nstack(); stack++) {
197 for( Int_t layer = 0; layer < fGeo->Nlayer(); layer++) {
199 Int_t iDet = fGeo->GetDetector(layer,stack,sect);
200 if (iDet == 0) newEvent = kTRUE; // it is expected that each event has at least one tracklet; this is only needed for correct readout tree
201 // Get the digits array
202 AliTRDarrayADC *digits = (AliTRDarrayADC *) digitsManager->GetDigits(iDet);
203 if (digits->HasData() ) { // second part is new!! and is for indicating a new event
208 Int_t rv = fFee->GetRAWversion();
211 if ( fgRawFormatVersion == 0 ){
212 // Process A side of the chamber
213 if ( rv >= 1 && rv <= 2 ) {
214 hcwords = ProduceHcDataV1andV2(digits,0,iDet,hcBuffer,kMaxHcWords);
218 hcwords = ProduceHcDataV3 (digits,0,iDet,hcBuffer,kMaxHcWords,newEvent);
219 //hcwords = ProduceHcDataV3 (digits,0,iDet,hcBuffer,kMaxHcWords);
220 if(newEvent == kTRUE) newEvent = kFALSE;
223 of->WriteBuffer((char *) hcBuffer, hcwords*4);
224 npayloadbyte += hcwords*4;
226 // Process B side of the chamber
227 if ( rv >= 1 && rv <= 2 ) {
228 hcwords = ProduceHcDataV1andV2(digits,1,iDet,hcBuffer,kMaxHcWords);
232 hcwords = ProduceHcDataV3 (digits,1,iDet,hcBuffer,kMaxHcWords,newEvent);
233 //hcwords = ProduceHcDataV3 (digits,1,iDet,hcBuffer,kMaxHcWords);
236 of->WriteBuffer((char *) hcBuffer, hcwords*4);
237 npayloadbyte += hcwords*4;
239 } else { // real data format
240 // Process A side of the chamber
241 hcwords = ProduceHcData(digits,0,iDet,hcBuffer,kMaxHcWords,newEvent);
242 if(newEvent == kTRUE) newEvent = kFALSE;
243 of->WriteBuffer((char *) hcBuffer, hcwords*4);
244 npayloadbyte += hcwords*4;
245 //for ( Int_t i=0; i<hcwords; i++ ) AliInfo(Form("Buf : %X",hcBuffer[i]));
247 // Process B side of the chamber
248 hcwords = ProduceHcData(digits,1,iDet,hcBuffer,kMaxHcWords,newEvent);
249 of->WriteBuffer((char *) hcBuffer, hcwords*4);
250 npayloadbyte += hcwords*4;
259 header.fSize = UInt_t(of->Tellp()) - hpos;
260 header.SetAttribute(0); // Valid data
261 of->Seekp(hpos); // Rewind to header position
262 of->WriteBuffer((char *) (& header), sizeof(header));
272 //_____________________________________________________________________________
273 void AliTRDrawData::ProduceSMIndexData(UInt_t *buf, Int_t& nw){
275 // This function generates
276 // 1) SM index words : ssssssss ssssssss vvvv rrrr r d t mmmmm
277 // - s : size of SM header (number of header, default = 0x0001)
278 // - v : SM header version (default = 0xa)
279 // - r : reserved for future use (default = 00000)
280 // - d : track data enabled bit (default = 0)
281 // - t : tracklet data enabled bit (default = 1)
282 // - m : stack mask (each bit corresponds a stack, default = 11111)
284 // 2) SM header : rrr c vvvv vvvvvvvv vvvv rrrr bbbbbbbb
285 // - r : reserved for future use (default = 000)
286 // - c : clean check out flag (default = 1)
287 // - v : hardware design revision (default = 0x0404)
288 // - r : reserved for future use (default = 0x0)
289 // - b : physical board ID (default = 0x71)
291 // 3) stack index words : ssssssss ssssssss vvvv mmmm mmmmmmmm
292 // - s : size of stack header (number of header, (default = 0x0007)
293 // - v : header version (default = 0xa)
294 // - m : link mask (default = 0xfff)
296 // 4) stack header : vvvvvvvv vvvvvvvv bbbbbbbb rrrr rrr c
297 // - v : hardware design revision (default = 0x0404)
298 // - b : physical board ID (default = 0x5b)
299 // - r : reserved for future use (default = 0000 000)
300 // - c : clean checkout flag (default = 1)
302 // and 6 dummy words(0x00000000)
305 buf[nw++] = 0x0001a03f; // SM index words
306 buf[nw++] = 0x10404071; // SM header
308 for (Int_t istack=0; istack<5; istack++){
309 buf[nw++] = 0x0007afff; // stack index words
310 buf[nw++] = 0x04045b01; // stack header
311 for (Int_t i=0;i<6;i++) buf[nw++] = 0x00000000; // 6 dummy words
312 } // loop over 5 stacks
316 //_____________________________________________________________________________
317 Int_t AliTRDrawData::ProduceHcData(AliTRDarrayADC *digits, Int_t side, Int_t det, UInt_t *buf, Int_t maxSize, Bool_t newEvent = kFALSE){
319 // This function can be used for both ZS and NZS data
322 Int_t nw = 0; // Number of written words
323 Int_t of = 0; // Number of overflowed words
324 Int_t layer = fGeo->GetLayer( det ); // Layer
325 Int_t stack = fGeo->GetStack( det ); // Stack
326 Int_t sect = fGeo->GetSector( det ); // Sector (=iDDL)
327 Int_t nRow = fGeo->GetRowMax( layer, stack, sect );
328 Int_t nCol = fGeo->GetColMax( layer );
329 const Int_t kNTBin = AliTRDcalibDB::Instance()->GetNumberOfTimeBins();
330 Int_t kCtype = 0; // Chamber type (0:C0, 1:C1)
332 Bool_t tracklet_on = fFee->GetTracklet(); // **new**
334 // Check the nCol and nRow.
335 if ((nCol == 144) && (nRow == 16 || nRow == 12)) {
336 kCtype = (nRow-12) / 4;
338 AliError(Form("This type of chamber is not supported (nRow=%d, nCol=%d).",nRow,nCol));
342 AliDebug(1,Form("Producing raw data for sect=%d layer=%d stack=%d side=%d",sect,layer,stack,side));
344 AliTRDmcmSim** mcm = new AliTRDmcmSim*[(kCtype + 3)*(fGeo->MCMmax())];
346 if (newEvent) ProduceSMIndexData(buf, nw); // SM index words , Stack index words
348 if (!tracklet_on) WriteIntermediateWordsV2(buf,nw,of,maxSize,det,side); // no tracklet or NZS
351 // scanning direction such, that tracklet-words are sorted in ascending z and then in ascending y order
352 // ROB numbering on chamber and MCM numbering on ROB increase with decreasing z and increasing y
353 for (Int_t iRobRow = (kCtype + 3)-1; iRobRow >= 0; iRobRow-- ) {
354 Int_t iRob = iRobRow * 2 + side;
356 for (Int_t iMcmRB = 0; iMcmRB < fGeo->MCMmax(); iMcmRB++ ) {
357 Int_t iMcm = 16 - 4*(iMcmRB/4 + 1) + (iMcmRB%4);
358 Int_t entry = iRobRow*(fGeo->MCMmax()) + iMcm;
360 mcm[entry] = new AliTRDmcmSim();
361 mcm[entry]->Init( det, iRob, iMcm , newEvent);
362 //mcm[entry]->Init( det, iRob, iMcm);
363 if (newEvent == kTRUE) newEvent = kFALSE; // only one mcm is concerned with new event
364 Int_t padrow = mcm[entry]->GetRow();
366 // Copy ADC data to MCM simulator
367 for (Int_t iAdc = 0; iAdc < 21; iAdc++ ) {
368 Int_t padcol = mcm[entry]->GetCol( iAdc );
369 if ((padcol >= 0) && (padcol < nCol)) {
370 for (Int_t iT = 0; iT < kNTBin; iT++) {
371 mcm[entry]->SetData( iAdc, iT, digits->GetData( padrow, padcol, iT) );
374 else { // this means it is out of chamber, and masked ADC
375 mcm[entry]->SetDataPedestal( iAdc );
379 // Simulate process in MCM
380 // mcm[entry]->Filter(); // Apply filter
381 // mcm[entry]->ZSMapping(); // Calculate zero suppression mapping
382 mcm[entry]->CopyArrays();
383 mcm[entry]->GeneratefZSM1Dim();
386 mcm[entry]->Tracklet();
387 Int_t tempNw = mcm[entry]->ProduceTrackletStream( &buf[nw], maxSize - nw );
392 AliError(Form("Buffer overflow detected. Please increase the buffer size and recompile."));
396 } else { // no tracklets: write raw-data already in this loop
397 // Write MCM data to buffer
398 Int_t tempNw = mcm[entry]->ProduceRawStreamV2( &buf[nw], maxSize - nw );
402 AliError(Form("Buffer overflow detected. Please increase the buffer size and recompile."));
410 //mcm->DumpData( "trdmcmdata.txt", "RFZS" ); // debugging purpose
414 // if tracklets are switched on, raw-data can be written only after all tracklets
416 WriteIntermediateWordsV2(buf,nw,of,maxSize,det,side);
418 // Scan for ROB and MCM
419 for (Int_t iRobRow = (kCtype + 3)-1; iRobRow >= 0; iRobRow-- ) {
420 //Int_t iRob = iRobRow * 2 + side;
422 for (Int_t iMcmRB = 0; iMcmRB < fGeo->MCMmax(); iMcmRB++ ) {
423 Int_t iMcm = 16 - 4*(iMcmRB/4 + 1) + (iMcmRB%4);
425 Int_t entry = iRobRow*(fGeo->MCMmax()) + iMcm;
427 // Write MCM data to buffer
428 Int_t tempNw = mcm[entry]->ProduceRawStreamV2( &buf[nw], maxSize - nw );
432 AliError(Form("Buffer overflow detected. Please increase the buffer size and recompile."));
445 // Write end of raw data marker
447 buf[nw++] = kEndofrawdatamarker;
453 AliError("Buffer overflow. Data is truncated. Please increase buffer size and recompile.");
460 //_____________________________________________________________________________
461 Int_t AliTRDrawData::ProduceHcDataV1andV2(AliTRDarrayADC *digits, Int_t side
462 , Int_t det, UInt_t *buf, Int_t maxSize)
465 // This function simulates: 1) SM-I commissiong data Oct. 06 (Raw Version == 1).
466 // 2) Full Raw Production Version (Raw Version == 2)
468 // Produce half chamber data (= an ORI data) for the given chamber (det) and side (side)
471 // side=0 means A side with ROB positions 0, 2, 4, 6.
472 // side=1 means B side with ROB positions 1, 3, 5, 7.
474 // Chamber type (C0 orC1) is determined by "det" automatically.
475 // Appropriate size of buffer (*buf) must be prepared prior to calling this function.
476 // Pointer to the buffer and its size must be given to "buf" and "maxSize".
477 // Return value is the number of valid data filled in the buffer in unit of 32 bits
479 // If buffer size if too small, the data is truncated with the buffer size however
480 // the function will finish without crash (this behaviour is similar to the MCM).
483 Int_t nw = 0; // Number of written words
484 Int_t of = 0; // Number of overflowed words
485 Int_t layer = fGeo->GetLayer( det ); // Layer
486 Int_t stack = fGeo->GetStack( det ); // Stack
487 Int_t sect = fGeo->GetSector( det ); // Sector (=iDDL)
488 Int_t nRow = fGeo->GetRowMax( layer, stack, sect );
489 Int_t nCol = fGeo->GetColMax( layer );
490 const Int_t kNTBin = AliTRDcalibDB::Instance()->GetNumberOfTimeBins();
491 Int_t kCtype = 0; // Chamber type (0:C0, 1:C1)
492 Int_t iEv = 0xA; // Event ID. Now fixed to 10, how do I get event id?
493 UInt_t x = 0; // General used number
494 Int_t rv = fFee->GetRAWversion();
496 // Check the nCol and nRow.
498 (nRow == 16 || nRow == 12)) {
499 kCtype = (nRow-12) / 4;
502 AliError(Form("This type of chamber is not supported (nRow=%d, nCol=%d)."
507 AliDebug(1,Form("Producing raw data for sect=%d layer=%d stack=%d side=%d"
508 ,sect,layer,stack,side));
510 // Tracklet should be processed here but not implemented yet
512 // Write end of tracklet marker
514 buf[nw++] = kEndoftrackletmarker;
520 // Half Chamber header
522 // Now it is the same version as used in SM-I commissioning.
523 Int_t dcs = det+100; // DCS Serial (in simulation, it is meaningless
524 x = (dcs<<20) | (sect<<15) | (layer<<12) | (stack<<9) | (side<<8) | 1;
532 else if ( rv == 2 ) {
533 // h[0] (there are 3 HC header)
534 Int_t minorv = 0; // The minor version number
535 Int_t add = 2; // The number of additional header words to follow
536 x = (1<<31) | (rv<<24) | (minorv<<17) | (add<<14) | (sect<<9) | (layer<<6) | (stack<<3) | (side<<2) | 1;
544 Int_t bcCtr = 99; // bunch crossing counter. Here it is set to 99 always for no reason
545 Int_t ptCtr = 15; // pretrigger counter. Here it is set to 15 always for no reason
546 Int_t ptPhase = 11; // pretrigger phase. Here it is set to 11 always for no reason
547 x = (bcCtr<<16) | (ptCtr<<12) | (ptPhase<<8) | ((kNTBin-1)<<2) | 1;
555 Int_t pedSetup = 1; // Pedestal filter setup (0:1). Here it is always 1 for no reason
556 Int_t gainSetup = 1; // Gain filter setup (0:1). Here it is always 1 for no reason
557 Int_t tailSetup = 1; // Tail filter setup (0:1). Here it is always 1 for no reason
558 Int_t xtSetup = 0; // Cross talk filter setup (0:1). Here it is always 0 for no reason
559 Int_t nonlinSetup = 0; // Nonlinearity filter setup (0:1). Here it is always 0 for no reason
560 Int_t bypassSetup = 0; // Filter bypass (for raw data) setup (0:1). Here it is always 0 for no reason
561 Int_t commonAdditive = 10; // Digital filter common additive (0:63). Here it is always 10 for no reason
562 x = (pedSetup<<31) | (gainSetup<<30) | (tailSetup<<29) | (xtSetup<<28) | (nonlinSetup<<27)
563 | (bypassSetup<<26) | (commonAdditive<<20) | 1;
572 // Scan for ROB and MCM
573 for (Int_t iRobRow = 0; iRobRow < (kCtype + 3); iRobRow++ ) {
574 Int_t iRob = iRobRow * 2 + side;
575 for (Int_t iMcm = 0; iMcm < fGeo->MCMmax(); iMcm++ ) {
576 Int_t padrow = iRobRow * 4 + iMcm / 4;
579 x = ((iRob * fGeo->MCMmax() + iMcm) << 24) | ((iEv % 0x100000) << 4) | 0xC;
588 for (Int_t iAdc = 0; iAdc < 21; iAdc++ ) {
589 Int_t padcol = fFee->GetPadColFromADC(iRob, iMcm, iAdc);
590 UInt_t aa = !(iAdc & 1) + 2;
591 UInt_t *a = new UInt_t[kNTBin+2];
592 // 3 timebins are packed into one 32 bits word
593 for (Int_t iT = 0; iT < kNTBin; iT+=3) {
594 if ((padcol >= 0) && (padcol < nCol)) {
595 a[iT ] = ((iT ) < kNTBin ) ? digits->GetData(padrow,padcol,iT ) : 0;
596 a[iT+1] = ((iT + 1) < kNTBin ) ? digits->GetData(padrow,padcol,iT + 1) : 0;
597 a[iT+2] = ((iT + 2) < kNTBin ) ? digits->GetData(padrow,padcol,iT + 2) : 0;
600 a[iT] = a[iT+1] = a[iT+2] = 0; // This happenes at the edge of chamber (should be pedestal! How?)
602 x = (a[iT+2] << 22) | (a[iT+1] << 12) | (a[iT] << 2) | aa;
613 for (Int_t iT = 0; iT < kNTBin; iT++) {
614 avg += (Float_t) (a[iT]);
616 avg /= (Float_t) kNTBin;
617 for (Int_t iT = 0; iT < kNTBin; iT++) {
618 rms += ((Float_t) (a[iT]) - avg) * ((Float_t) (a[iT]) - avg);
620 rms = TMath::Sqrt(rms / (Float_t) kNTBin);
622 AliDebug(2,Form("Large RMS (>1.7) (ROB,MCM,ADC)=(%02d,%02d,%02d), avg=%03.1f, rms=%03.1f"
623 ,iRob,iMcm,iAdc,avg,rms));
630 // Write end of raw data marker
632 buf[nw++] = kEndofrawdatamarker;
638 AliWarning("Buffer overflow. Data is truncated. Please increase buffer size and recompile.");
645 //_____________________________________________________________________________
647 //Int_t AliTRDrawData::ProduceHcDataV3(AliTRDarrayADC *digits, Int_t side , Int_t det, UInt_t *buf, Int_t maxSize)
648 Int_t AliTRDrawData::ProduceHcDataV3(AliTRDarrayADC *digits, Int_t side , Int_t det, UInt_t *buf, Int_t maxSize, Bool_t newEvent = kFALSE)
651 // This function simulates: Raw Version == 3 (Zero Suppression Prototype)
654 Int_t nw = 0; // Number of written words
655 Int_t of = 0; // Number of overflowed words
656 Int_t layer = fGeo->GetLayer( det ); // Layer
657 Int_t stack = fGeo->GetStack( det ); // Stack
658 Int_t sect = fGeo->GetSector( det ); // Sector (=iDDL)
659 Int_t nRow = fGeo->GetRowMax( layer, stack, sect );
660 Int_t nCol = fGeo->GetColMax( layer );
661 const Int_t kNTBin = AliTRDcalibDB::Instance()->GetNumberOfTimeBins();
662 Int_t kCtype = 0; // Chamber type (0:C0, 1:C1)
663 //Int_t iEv = 0xA; // Event ID. Now fixed to 10, how do I get event id?
667 Bool_t tracklet_on = fFee->GetTracklet(); // **new**
669 // Check the nCol and nRow.
671 (nRow == 16 || nRow == 12)) {
672 kCtype = (nRow-12) / 4;
675 AliError(Form("This type of chamber is not supported (nRow=%d, nCol=%d)."
680 AliDebug(1,Form("Producing raw data for sect=%d layer=%d stack=%d side=%d"
681 ,sect,layer,stack,side));
683 AliTRDmcmSim** mcm = new AliTRDmcmSim*[(kCtype + 3)*(fGeo->MCMmax())];
685 // in case no tracklet-words are processed: write the tracklet-endmarker as well as all additional words immediately and write
686 // raw-data in one go; if tracklet-processing is enabled, first all tracklet-words of a half-chamber have to be processed before the
687 // additional words (tracklet-endmarker,headers,...)are written. Raw-data is written in a second loop;
690 WriteIntermediateWords(buf,nw,of,maxSize,det,side);
693 // Scan for ROB and MCM
694 // scanning direction such, that tracklet-words are sorted in ascending z and then in ascending y order
695 // ROB numbering on chamber and MCM numbering on ROB increase with decreasing z and increasing y
696 for (Int_t iRobRow = (kCtype + 3)-1; iRobRow >= 0; iRobRow-- ) {
697 Int_t iRob = iRobRow * 2 + side;
699 for (Int_t iMcmRB = 0; iMcmRB < fGeo->MCMmax(); iMcmRB++ ) {
700 Int_t iMcm = 16 - 4*(iMcmRB/4 + 1) + (iMcmRB%4);
701 Int_t entry = iRobRow*(fGeo->MCMmax()) + iMcm;
703 mcm[entry] = new AliTRDmcmSim();
704 mcm[entry]->Init( det, iRob, iMcm , newEvent);
705 //mcm[entry]->Init( det, iRob, iMcm);
706 if (newEvent == kTRUE) newEvent = kFALSE; // only one mcm is concerned with new event
707 Int_t padrow = mcm[entry]->GetRow();
709 // Copy ADC data to MCM simulator
710 for (Int_t iAdc = 0; iAdc < 21; iAdc++ ) {
711 Int_t padcol = mcm[entry]->GetCol( iAdc );
712 if ((padcol >= 0) && (padcol < nCol)) {
713 for (Int_t iT = 0; iT < kNTBin; iT++) {
714 mcm[entry]->SetData( iAdc, iT, digits->GetData( padrow, padcol, iT) );
717 else { // this means it is out of chamber, and masked ADC
718 mcm[entry]->SetDataPedestal( iAdc );
722 // Simulate process in MCM
723 // mcm[entry]->Filter(); // Apply filter
724 // mcm[entry]->ZSMapping(); // Calculate zero suppression mapping
725 mcm[entry]->CopyArrays();
726 mcm[entry]->GeneratefZSM1Dim();
729 mcm[entry]->Tracklet();
730 Int_t tempNw = mcm[entry]->ProduceTrackletStream( &buf[nw], maxSize - nw );
735 AliError(Form("Buffer overflow detected. Please increase the buffer size and recompile."));
740 // no tracklets: write raw-data already in this loop
742 // Write MCM data to buffer
743 Int_t tempNw = mcm[entry]->ProduceRawStream( &buf[nw], maxSize - nw );
747 AliError(Form("Buffer overflow detected. Please increase the buffer size and recompile."));
758 //mcm->DumpData( "trdmcmdata.txt", "RFZS" ); // debugging purpose
762 // if tracklets are switched on, raw-data can be written only after all tracklets
764 WriteIntermediateWords(buf,nw,of,maxSize,det,side);
767 // Scan for ROB and MCM
768 for (Int_t iRobRow = (kCtype + 3)-1; iRobRow >= 0; iRobRow-- ) {
769 //Int_t iRob = iRobRow * 2 + side;
771 for (Int_t iMcmRB = 0; iMcmRB < fGeo->MCMmax(); iMcmRB++ ) {
772 Int_t iMcm = 16 - 4*(iMcmRB/4 + 1) + (iMcmRB%4);
774 Int_t entry = iRobRow*(fGeo->MCMmax()) + iMcm;
776 // Write MCM data to buffer
777 Int_t tempNw = mcm[entry]->ProduceRawStream( &buf[nw], maxSize - nw );
781 AliError(Form("Buffer overflow detected. Please increase the buffer size and recompile."));
794 // Write end of raw data marker
796 buf[nw++] = kEndofrawdatamarker;
802 AliError("Buffer overflow. Data is truncated. Please increase buffer size and recompile.");
810 //_____________________________________________________________________________
811 AliTRDdigitsManager *AliTRDrawData::Raw2Digits(AliRawReader *rawReader)
814 // Vx of the raw data reading
817 AliTRDarrayADC *digits = 0;
818 AliTRDarrayDictionary *track0 = 0;
819 AliTRDarrayDictionary *track1 = 0;
820 AliTRDarrayDictionary *track2 = 0;
822 //AliTRDSignalIndex *indexes = 0;
823 // Create the digits manager
824 AliTRDdigitsManager* digitsManager = new AliTRDdigitsManager();
825 digitsManager->CreateArrays();
827 //AliTRDrawOldStream input(rawReader);
828 // AliTRDRawStreamV2 input(rawReader);
829 // input.SetRawVersion( fFee->GetRAWversion() );
832 AliTRDrawStreamBase *pinput = AliTRDrawStreamBase::GetRawStream(rawReader);
833 AliTRDrawStreamBase &input = *pinput;
834 input.SetRawVersion( fFee->GetRAWversion() ); //<= ADDED by MinJung
836 AliInfo(Form("Stream version: %s", input.IsA()->GetName()));
838 // Loop through the digits
843 det = input.NextChamber(digitsManager);
847 digits = (AliTRDarrayADC *) digitsManager->GetDigits(det);
848 track0 = (AliTRDarrayDictionary *) digitsManager->GetDictionary(det,0);
849 track1 = (AliTRDarrayDictionary *) digitsManager->GetDictionary(det,1);
850 track2 = (AliTRDarrayDictionary *) digitsManager->GetDictionary(det,2);
852 if (digits) digits->Compress();
853 if (track0) track0->Compress();
854 if (track1) track1->Compress();
855 if (track2) track2->Compress();
862 return digitsManager;
866 //_____________________________________________________________________________
867 void AliTRDrawData::WriteIntermediateWords(UInt_t* buf, Int_t& nw, Int_t& of, const Int_t& maxSize, const Int_t& det, const Int_t& side) {
869 Int_t layer = fGeo->GetLayer( det ); // Layer
870 Int_t stack = fGeo->GetStack( det ); // Stack
871 Int_t sect = fGeo->GetSector( det ); // Sector (=iDDL)
872 Int_t rv = fFee->GetRAWversion();
873 const Int_t kNTBin = AliTRDcalibDB::Instance()->GetNumberOfTimeBins();
876 // Write end of tracklet marker
878 buf[nw++] = kEndoftrackletmarker;
884 // Half Chamber header
885 // h[0] (there are 3 HC header)
886 Int_t minorv = 0; // The minor version number
887 Int_t add = 2; // The number of additional header words to follow
888 x = (1<<31) | (rv<<24) | (minorv<<17) | (add<<14) | (sect<<9) | (layer<<6) | (stack<<3) | (side<<2) | 1;
896 Int_t bcCtr = 99; // bunch crossing counter. Here it is set to 99 always for no reason
897 Int_t ptCtr = 15; // pretrigger counter. Here it is set to 15 always for no reason
898 Int_t ptPhase = 11; // pretrigger phase. Here it is set to 11 always for no reason
899 x = (bcCtr<<16) | (ptCtr<<12) | (ptPhase<<8) | ((kNTBin-1)<<2) | 1;
907 Int_t pedSetup = 1; // Pedestal filter setup (0:1). Here it is always 1 for no reason
908 Int_t gainSetup = 1; // Gain filter setup (0:1). Here it is always 1 for no reason
909 Int_t tailSetup = 1; // Tail filter setup (0:1). Here it is always 1 for no reason
910 Int_t xtSetup = 0; // Cross talk filter setup (0:1). Here it is always 0 for no reason
911 Int_t nonlinSetup = 0; // Nonlinearity filter setup (0:1). Here it is always 0 for no reason
912 Int_t bypassSetup = 0; // Filter bypass (for raw data) setup (0:1). Here it is always 0 for no reason
913 Int_t commonAdditive = 10; // Digital filter common additive (0:63). Here it is always 10 for no reason
914 x = (pedSetup<<31) | (gainSetup<<30) | (tailSetup<<29) | (xtSetup<<28) | (nonlinSetup<<27)
915 | (bypassSetup<<26) | (commonAdditive<<20) | 1;
924 //_____________________________________________________________________________
925 void AliTRDrawData::WriteIntermediateWordsV2(UInt_t* buf, Int_t& nw, Int_t& of, const Int_t& maxSize, const Int_t& det, const Int_t& side) {
927 Int_t layer = fGeo->GetLayer( det ); // Layer
928 Int_t stack = fGeo->GetStack( det ); // Stack
929 Int_t sect = fGeo->GetSector( det ); // Sector (=iDDL)
930 Int_t rv = fFee->GetRAWversion();
931 const Int_t kNTBin = AliTRDcalibDB::Instance()->GetNumberOfTimeBins();
932 Bool_t tracklet_on = fFee->GetTracklet();
935 // Write end of tracklet marker
936 if (nw < maxSize) buf[nw++] = fgkEndOfTrackletMarker; else of++;
938 // Half Chamber header
939 // h[0] (there are 2 HC headers) xmmm mmmm nnnn nnnq qqss sssp ppcc ci01
940 // , where x : Raw version speacial number (=1)
941 // m : Raw version major number (test pattern, ZS, disable tracklet, 0, options)
942 // n : Raw version minor number
943 // q : number of addtional header words (default = 1)
944 // s : SM sector number (ALICE numbering)
945 // p : plane(layer) number
946 // c : chamber(stack) number
947 // i : side number (0:A, 1:B)
948 Int_t majorv = 0; // The major version number
949 Int_t minorv = 0; // The minor version number
950 Int_t add = 1; // The number of additional header words to follow : now 1, previous 2
951 Int_t TP = 0; // test pattern (default=0)
952 Int_t ZS = (rv==3) ? 1 : 0; // zero suppression
953 Int_t DT = (tracklet_on) ? 0 : 1; // disable tracklet
955 majorv = (TP<<6) | (ZS<<5) | (DT<<4) | 1; // major version
957 x = (1<<31) | (majorv<<24) | (minorv<<17) | (add<<14) | (sect<<9) | (layer<<6) | (stack<<3) | (side<<2) | 1;
958 if (nw < maxSize) buf[nw++] = x; else of++;
960 // h[1] tttt ttbb bbbb bbbb bbbb bbpp pphh hh01
961 // , where t : number of time bins
962 // b : bunch crossing number
963 // p : pretrigger counter
964 // h : pretrigger phase
965 Int_t bcCtr = 99; // bunch crossing counter. Here it is set to 99 always for no reason
966 Int_t ptCtr = 15; // pretrigger counter. Here it is set to 15 always for no reason
967 Int_t ptPhase = 11; // pretrigger phase. Here it is set to 11 always for no reason
968 //x = (bcCtr<<16) | (ptCtr<<12) | (ptPhase<<8) | ((kNTBin-1)<<2) | 1; // old format
969 x = ((kNTBin-1)<<26) | (bcCtr<<10) | (ptCtr<<6) | (ptPhase<<2) | 1;
970 if (nw < maxSize) buf[nw++] = x; else of++;
974 //_____________________________________________________________________________
975 AliTRDdigitsManager *AliTRDrawData::Raw2DigitsOLD(AliRawReader *rawReader)
978 // Vx of the raw data reading
981 AliTRDarrayADC *digits = 0;
982 AliTRDarrayDictionary *track0 = 0;
983 AliTRDarrayDictionary *track1 = 0;
984 AliTRDarrayDictionary *track2 = 0;
986 AliTRDSignalIndex *indexes = 0;
987 // Create the digits manager
988 AliTRDdigitsManager* digitsManager = new AliTRDdigitsManager();
989 digitsManager->CreateArrays();
991 //AliTRDrawOldStream input(rawReader);
992 AliTRDRawStreamV2 input(rawReader);
993 input.SetRawVersion( fFee->GetRAWversion() );
996 AliInfo(Form("Stream version: %s", input.IsA()->GetName()));
998 // Loop through the digits
1002 while (input.Next()) {
1004 det = input.GetDet();
1006 if (det != lastdet) { // If new detector found
1010 if (digits) digits->Compress();
1011 if (track0) track0->Compress();
1012 if (track1) track1->Compress();
1013 if (track2) track2->Compress();
1015 // Add a container for the digits of this detector
1016 digits = (AliTRDarrayADC *) digitsManager->GetDigits(det);
1017 track0 = (AliTRDarrayDictionary *) digitsManager->GetDictionary(det,0);
1018 track1 = (AliTRDarrayDictionary *) digitsManager->GetDictionary(det,1);
1019 track2 = (AliTRDarrayDictionary *) digitsManager->GetDictionary(det,2);
1021 // Allocate memory space for the digits buffer
1022 if (digits->GetNtime() == 0)
1024 digits->Allocate(input.GetMaxRow(),input.GetMaxCol(), input.GetNumberOfTimeBins());
1025 track0->Allocate(input.GetMaxRow(),input.GetMaxCol(), input.GetNumberOfTimeBins());
1026 track1->Allocate(input.GetMaxRow(),input.GetMaxCol(), input.GetNumberOfTimeBins());
1027 track2->Allocate(input.GetMaxRow(),input.GetMaxCol(), input.GetNumberOfTimeBins());
1030 indexes = digitsManager->GetIndexes(det);
1031 indexes->SetSM(input.GetSM());
1032 indexes->SetStack(input.GetStack());
1033 indexes->SetLayer(input.GetLayer());
1034 indexes->SetDetNumber(det);
1035 if (indexes->IsAllocated() == kFALSE)
1036 indexes->Allocate(input.GetMaxRow(), input.GetMaxCol(), input.GetNumberOfTimeBins());
1039 // 3 timebin data are stored per word
1040 for (it = 0; it < 3; it++)
1042 if ( input.GetTimeBin() + it < input.GetNumberOfTimeBins() )
1044 if (input.GetSignals()[it] > 0)
1046 digits->SetData(input.GetRow(), input.GetCol(),input.GetTimeBin() + it, input.GetSignals()[it]);
1048 indexes->AddIndexTBin(input.GetRow(), input.GetCol(),
1049 input.GetTimeBin() + it);
1050 track0->SetData(input.GetRow(), input.GetCol(), input.GetTimeBin() + it, 0);
1051 track1->SetData(input.GetRow(), input.GetCol(), input.GetTimeBin() + it, 0);
1052 track2->SetData(input.GetRow(), input.GetCol(), input.GetTimeBin() + it, 0);
1058 if (digits) digits->Compress();
1059 if (track0) track0->Compress();
1060 if (track1) track1->Compress();
1061 if (track2) track2->Compress();
1063 return digitsManager;