]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDrawData.cxx
Centrality edges <0% and >90% checks are removed
[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"
c93255fe 33#include "AliLoader.h"
cc26f39c 34#include "AliTreeLoader.h"
2745a409 35
5990c064 36#include "AliTRDrawData.h"
37#include "AliTRDdigitsManager.h"
bd0f8685 38#include "AliTRDgeometry.h"
b65e5048 39#include "AliTRDarrayDictionary.h"
40#include "AliTRDarrayADC.h"
8df1f8f5 41#include "AliTRDrawStream.h"
3551db50 42#include "AliTRDcalibDB.h"
ca21baaa 43#include "AliTRDSignalIndex.h"
dfd03fc3 44#include "AliTRDfeeParam.h"
45#include "AliTRDmcmSim.h"
f2ab58d4 46#include "AliTRDtrackletWord.h"
5896bc23 47#include "AliTRDdigitsParam.h"
dfd03fc3 48
5990c064 49ClassImp(AliTRDrawData)
50
037c5823 51Int_t AliTRDrawData::fgDataSuppressionLevel = 0;
987ba9a3 52
5990c064 53//_____________________________________________________________________________
2cb20be6 54AliTRDrawData::AliTRDrawData()
55 :TObject()
92c7f341 56 ,fRunLoader(NULL)
dfd03fc3 57 ,fGeo(NULL)
58 ,fFee(NULL)
8c703901 59 ,fNumberOfDDLs(0)
92c7f341 60 ,fTrackletTree(NULL)
eba523a2 61 ,fTracklets(NULL)
62 ,fTracks(NULL)
6a04e92b 63 ,fSMindexPos(0)
64 ,fStackindexPos(0)
65 ,fEventCounter(0)
854b2b11 66 ,fTrgFlags()
50002f37 67 ,fMcmSim(new AliTRDmcmSim)
a0446ff1 68 ,fDigitsParam(NULL)
5990c064 69{
b864d801 70 //
71 // Default constructor
72 //
0c349049 73
dfd03fc3 74 fFee = AliTRDfeeParam::Instance();
75 fNumberOfDDLs = AliDAQ::NumberOfDdls("TRD");
0c349049 76
5990c064 77}
78
8c703901 79//_____________________________________________________________________________
80AliTRDrawData::AliTRDrawData(const AliTRDrawData &r)
81 :TObject(r)
92c7f341 82 ,fRunLoader(NULL)
dfd03fc3 83 ,fGeo(NULL)
84 ,fFee(NULL)
8c703901 85 ,fNumberOfDDLs(0)
92c7f341 86 ,fTrackletTree(NULL)
eba523a2 87 ,fTracklets(NULL)
88 ,fTracks(NULL)
6a04e92b 89 ,fSMindexPos(0)
90 ,fStackindexPos(0)
91 ,fEventCounter(0)
854b2b11 92 ,fTrgFlags()
50002f37 93 ,fMcmSim(new AliTRDmcmSim)
a0446ff1 94 ,fDigitsParam(NULL)
8c703901 95{
96 //
97 // Copy constructor
98 //
0c349049 99
dfd03fc3 100 fFee = AliTRDfeeParam::Instance();
101 fNumberOfDDLs = AliDAQ::NumberOfDdls("TRD");
0c349049 102
8c703901 103}
104
5990c064 105//_____________________________________________________________________________
106AliTRDrawData::~AliTRDrawData()
107{
108 //
109 // Destructor
110 //
0c349049 111
50002f37 112 delete fMcmSim;
113
8c703901 114}
115
116//_____________________________________________________________________________
037c5823 117Bool_t AliTRDrawData::Digits2Raw(TTree *digitsTree, const TTree *tracks )
8c703901 118{
119 //
120 // Initialize necessary parameters and call one
121 // of the raw data simulator selected by SetRawVersion.
122 //
123 // Currently tracklet output is not spported yet and it
124 // will be supported in higher version simulator.
125 //
126
037c5823 127 AliTRDdigitsManager* const digitsManager = new AliTRDdigitsManager();
8c703901 128
129 if (!digitsManager->ReadDigits(digitsTree)) {
130 delete digitsManager;
131 return kFALSE;
132 }
133
134 if (tracks != NULL) {
135 delete digitsManager;
7925de54 136 AliError("Tracklet input is not supported yet.");
8c703901 137 return kFALSE;
138 }
139
140 fGeo = new AliTRDgeometry();
141
f162af62 142 if (!AliTRDcalibDB::Instance()) {
7925de54 143 AliError("Could not get calibration object");
8c703901 144 delete fGeo;
145 delete digitsManager;
146 return kFALSE;
147 }
148
149 Int_t retval = kTRUE;
dfd03fc3 150 Int_t rv = fFee->GetRAWversion();
8c703901 151
152 // Call appropriate Raw Simulator
dfd03fc3 153 if ( rv > 0 && rv <= 3 ) retval = Digits2Raw(digitsManager);
7925de54 154 else {
155 retval = kFALSE;
dfd03fc3 156 AliWarning(Form("Unsupported raw version (%d).", rv));
8c703901 157 }
158
159 // Cleanup
160 delete fGeo;
161 delete digitsManager;
162
163 return retval;
164
165}
166
167//_____________________________________________________________________________
50378239 168Bool_t AliTRDrawData::Digits2Raw(AliTRDdigitsManager *digitsManager)
8c703901 169{
170 //
7925de54 171 // Raw data simulator for all versions > 0. This is prepared for real data.
8c703901 172 // This version simulate only raw data with ADC data and not with tracklet.
8c703901 173 //
174
0c349049 175 const Int_t kMaxHcWords = (fGeo->TBmax()/3)
176 * fGeo->ADCmax()
177 * fGeo->MCMmax()
178 * fGeo->ROBmaxC1()/2
179 + 100 + 20;
8c703901 180
181 // Buffer to temporary store half chamber data
0c349049 182 UInt_t *hcBuffer = new UInt_t[kMaxHcWords];
5896bc23 183
1d93b218 184 Bool_t newEvent = kFALSE; // only for correct readout tree
6a04e92b 185 Bool_t newSM = kFALSE; // new SM flag, for writing SM index words
186 Bool_t newStack = kFALSE; // new stack flag, for writing stack index words
8c703901 187
a0446ff1 188 // Get digits parameter
189 fDigitsParam = digitsManager->GetDigitsParam();
190
8c703901 191 // sect is same as iDDL, so I use only sect here.
053767a4 192 for (Int_t sect = 0; sect < fGeo->Nsector(); sect++) {
8c703901 193
194 char name[1024];
8df1f8f5 195 snprintf(name,1024,"TRD_%d.ddl",sect + AliTRDrawStream::kDDLOffset);
8c703901 196
08f92f14 197 AliFstream* of = new AliFstream(name);
8c703901 198
7d619a80 199 // Write a dummy data header
f7ee745b 200 AliRawDataHeaderSim header; // the event header
08f92f14 201 UInt_t hpos = of->Tellp();
202 of->WriteBuffer((char *) (& header), sizeof(header));
7d619a80 203
8c703901 204 // Reset payload byte size (payload does not include header).
205 Int_t npayloadbyte = 0;
206
6a04e92b 207 // check the existance of the data
208 // SM index word and Stack index word
037c5823 209 UInt_t *iwbuffer = new UInt_t[109]; // index word buffer; max 109 = 2 SM headers + 67 dummy headers + 5*8 stack headers
6a04e92b 210 Int_t nheader = 0;
037c5823 211 UInt_t bStackMask = 0x0;
212 Bool_t bStackHasData = kFALSE;
213 Bool_t bSMHasData = kFALSE;
7d619a80 214
037c5823 215 //iwbuffer[nheader++] = 0x0001a020; // SM index words
f88d630c 216 iwbuffer[nheader++] = 0x0044b020; // SM index words | additional SM header:48 = 1 SM header + 47 dummy words(for future use)
6a04e92b 217 iwbuffer[nheader++] = 0x10404071; // SM header
037c5823 218 for ( Int_t i=0; i<66; i++ ) iwbuffer[nheader++] = 0x00000000; // dummy words
219 iwbuffer[nheader++] = 0x10000000; // end of dummy words
7d619a80 220
6a04e92b 221 for ( Int_t stack= 0; stack < fGeo->Nstack(); stack++) {
7d619a80 222 UInt_t linkMask = 0x0;
223 for( Int_t layer = 0; layer < fGeo->Nlayer(); layer++) {
224 Int_t iDet = fGeo->GetDetector(layer,stack,sect);
225 AliTRDarrayADC *digits = (AliTRDarrayADC *) digitsManager->GetDigits(iDet);
226 if ( fgDataSuppressionLevel==0 || digits->HasData() ) {
227 bStackMask = bStackMask | ( 1 << stack ); // active stack mask for new stack
228 linkMask = linkMask | ( 3 << (2*layer) ); // 3 = 0011
229 bStackHasData = kTRUE;
230 bSMHasData = kTRUE;
231 } // has data
232 } // loop over layer
233
234 if ( fgDataSuppressionLevel==0 || bStackHasData ){
235 iwbuffer[nheader++] = 0x0007a000 | linkMask; // stack index word + link masks
236 if (fgDataSuppressionLevel==0) iwbuffer[nheader-1] = 0x0007afff; // no suppression
237 iwbuffer[nheader++] = 0x04045b01; // stack header
238 for (Int_t i=0;i<6;i++) iwbuffer[nheader++] = 0x00000000; // 6 dummy words
239 bStackHasData = kFALSE;
240 }
6a04e92b 241 } // loop over stack
7d619a80 242
037c5823 243 if ( fgDataSuppressionLevel==0 || bSMHasData ){
7d619a80 244 iwbuffer[0] = iwbuffer[0] | bStackMask; // add stack masks to SM index word
f88d630c 245 if (fgDataSuppressionLevel==0) iwbuffer[0] = 0x0044b03f; // no suppression : all stacks are active
7d619a80 246 of->WriteBuffer((char *) iwbuffer, nheader*4);
ff792017 247 AliDebug(11, Form("SM %d index word: %08x", sect, iwbuffer[0]));
248 AliDebug(11, Form("SM %d header: %08x", sect, iwbuffer[1]));
6a04e92b 249 }
6a04e92b 250 // end of SM & stack header ------------------------------------------------------------------------
251 // -------------------------------------------------------------------------------------------------
7d619a80 252
8c703901 253 // Prepare chamber data
053767a4 254 for( Int_t stack = 0; stack < fGeo->Nstack(); stack++) {
255 for( Int_t layer = 0; layer < fGeo->Nlayer(); layer++) {
7d619a80 256
257 Int_t iDet = fGeo->GetDetector(layer,stack,sect);
258 if (iDet == 0){
259 newEvent = kTRUE; // it is expected that each event has at least one tracklet;
260 // this is only needed for correct readout tree
261 fEventCounter++;
262 AliDebug(11, Form("New event!! Event counter: %d",fEventCounter));
263 }
264
265 if ( stack==0 && layer==0 ) newSM = kTRUE; // new SM flag
266 if ( layer==0 ) newStack = kTRUE; // new stack flag
267 AliDebug(15, Form("stack : %d, layer : %d, iDec : %d\n",stack,layer,iDet));
268 // Get the digits array
269 AliTRDarrayADC *digits = (AliTRDarrayADC *) digitsManager->GetDigits(iDet);
270 if (fgDataSuppressionLevel==0 || digits->HasData() ) { // second part is new!! and is for indicating a new event
271
272 if (digits->HasData()) digits->Expand();
273
274 Int_t hcwords = 0;
275
276 // Process A side of the chamber
277 hcwords = ProduceHcData(digits,0,iDet,hcBuffer,kMaxHcWords,newEvent,newSM);
278 if ( newEvent ) newEvent = kFALSE;
279 //AssignLinkMask(hcBuffer, layer); // active link mask for this layer(2*HC)
280 of->WriteBuffer((char *) hcBuffer, hcwords*4);
281 npayloadbyte += hcwords*4;
282
283 // Process B side of the chamber
284 hcwords = ProduceHcData(digits,1,iDet,hcBuffer,kMaxHcWords,newEvent,newSM);
285 of->WriteBuffer((char *) hcBuffer, hcwords*4);
286 npayloadbyte += hcwords*4;
287 } // has data
288
6a04e92b 289 } // loop over layer
290 } // loop over stack
7d619a80 291
8c703901 292 // Complete header
08f92f14 293 header.fSize = UInt_t(of->Tellp()) - hpos;
8c703901 294 header.SetAttribute(0); // Valid data
08f92f14 295 of->Seekp(hpos); // Rewind to header position
296 of->WriteBuffer((char *) (& header), sizeof(header));
8c703901 297 delete of;
8bd87c5e 298
299 delete [] iwbuffer;
300
037c5823 301 } // loop over sector(SM)
7d619a80 302
0c349049 303 delete [] hcBuffer;
7d619a80 304
8c703901 305 return kTRUE;
8c703901 306}
307
987ba9a3 308//_____________________________________________________________________________
309void AliTRDrawData::ProduceSMIndexData(UInt_t *buf, Int_t& nw){
310 //
311 // This function generates
312 // 1) SM index words : ssssssss ssssssss vvvv rrrr r d t mmmmm
313 // - s : size of SM header (number of header, default = 0x0001)
314 // - v : SM header version (default = 0xa)
315 // - r : reserved for future use (default = 00000)
316 // - d : track data enabled bit (default = 0)
317 // - t : tracklet data enabled bit (default = 1)
318 // - m : stack mask (each bit corresponds a stack, default = 11111)
319 //
320 // 2) SM header : rrr c vvvv vvvvvvvv vvvv rrrr bbbbbbbb
321 // - r : reserved for future use (default = 000)
322 // - c : clean check out flag (default = 1)
323 // - v : hardware design revision (default = 0x0404)
324 // - r : reserved for future use (default = 0x0)
325 // - b : physical board ID (default = 0x71)
326 //
327 // 3) stack index words : ssssssss ssssssss vvvv mmmm mmmmmmmm
328 // - s : size of stack header (number of header, (default = 0x0007)
329 // - v : header version (default = 0xa)
330 // - m : link mask (default = 0xfff)
331 //
332 // 4) stack header : vvvvvvvv vvvvvvvv bbbbbbbb rrrr rrr c
333 // - v : hardware design revision (default = 0x0404)
334 // - b : physical board ID (default = 0x5b)
335 // - r : reserved for future use (default = 0000 000)
336 // - c : clean checkout flag (default = 1)
337 //
338 // and 6 dummy words(0x00000000)
339 //
340
6a04e92b 341 //buf[nw++] = 0x0001a03f; // SM index words
342 fSMindexPos = nw; // memorize position of the SM index word for re-allocating stack mask
f88d630c 343 buf[nw++] = 0x0001b020; // SM index words
6a04e92b 344 buf[nw++] = 0x10404071; // SM header
345
346 fStackindexPos = nw; // memorize position of the stack index word for future adding
347 /*
348 for (Int_t istack=0; istack<5; istack++){
349 buf[nw++] = 0x0007afff; // stack index words
350 buf[nw++] = 0x04045b01; // stack header
351 for (Int_t i=0;i<6;i++) buf[nw++] = 0x00000000; // 6 dummy words
352 } // loop over 5 stacks
353 */
354}
987ba9a3 355
6a04e92b 356//_____________________________________________________________________________
357void AliTRDrawData::AssignStackMask(UInt_t *buf, Int_t nStack){
358 //
359 // This function re-assign stack mask active(from 0 to 1) in the SM index word
360 //
361 buf[fSMindexPos] = buf[fSMindexPos] | ( 1 << nStack );
362}
363
364//_____________________________________________________________________________
543691ea 365Int_t AliTRDrawData::AddStackIndexWords(UInt_t *buf, Int_t /*nStack*/, Int_t nMax){
6a04e92b 366 //
367 // This function add stack index words and stack header when there is data for the stack
368 //
369 // 1) stack index words : ssssssss ssssssss vvvv mmmm mmmmmmmm
370 // - s : size of stack header (number of header, (default = 0x0007)
371 // - v : header version (default = 0xa)
372 // - m : link mask (default = 0xfff)
373 // - m : link mask (starting value = 0x000)
374 //
375 // 2) stack header : vvvvvvvv vvvvvvvv bbbbbbbb rrrr rrr c
376 // - v : hardware design revision (default = 0x0404)
377 // - b : physical board ID (default = 0x5b)
378 // - r : reserved for future use (default = 0000 000)
379 // - c : clean checkout flag (default = 1)
380 //
381 // and 6 dummy words(0x00000000)
382 //
383
384 Int_t nAddedWords = 0; // Number of added words
385 if ( ShiftWords(buf, fStackindexPos, 8, nMax)== kFALSE ){
386 AliError("Adding stack header failed.");
387 return 0;
388 }
389
390 buf[fStackindexPos++] = 0x0007a000; // stack index words
391 buf[fStackindexPos++] = 0x04045b01; // stack header
392 for (Int_t i=0;i<6;i++) buf[fStackindexPos++] = 0x00000000; // 6 dummy words
393 nAddedWords += 8;
987ba9a3 394
6a04e92b 395 return nAddedWords;
987ba9a3 396}
397
398//_____________________________________________________________________________
6a04e92b 399void AliTRDrawData::AssignLinkMask(UInt_t *buf, Int_t nLayer){
400 //
401 // This function re-assign link mask active(from 0 to 1) in the stack index word
402 //
403 buf[fStackindexPos-8] = buf[fStackindexPos-8] | ( 3 << (2*nLayer) ); // 3 = 0011
404}
405
406//_____________________________________________________________________________
407Bool_t AliTRDrawData::ShiftWords(UInt_t *buf, Int_t nStart, Int_t nWords, Int_t nMax){
408 //
409 // This function shifts n words
410 //
411 //if ( nStart+nWords > sizeof(buf)/sizeof(UInt_t) ){
412 // AliError("Words shift failed. No more buffer space.");
413 // return kFALSE;
414 //}
415
416 for ( Int_t iw=nMax; iw>nStart-1; iw--){
417 buf[iw+nWords] = buf[iw];
418 }
419 return kTRUE;
420}
421
422//_____________________________________________________________________________
0aff7a99 423Int_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 424 //
7d619a80 425 // This function produces the raw data for one HC, i.e. tracklets, tracklet endmarkers,
426 // raw data, raw data endmarkers.
987ba9a3 427 // This function can be used for both ZS and NZS data
428 //
429
430 Int_t nw = 0; // Number of written words
431 Int_t of = 0; // Number of overflowed words
7d619a80 432 Int_t *tempnw = &nw; // Number of written words for temp. buffer
433 Int_t *tempof = &of; // Number of overflowed words for temp. buffer
987ba9a3 434 Int_t layer = fGeo->GetLayer( det ); // Layer
435 Int_t stack = fGeo->GetStack( det ); // Stack
436 Int_t sect = fGeo->GetSector( det ); // Sector (=iDDL)
f793c83d 437 const Int_t kCtype = fGeo->GetStack(det) == 2 ? 0 : 1; // Chamber type (0:C0, 1:C1)
987ba9a3 438
037c5823 439 Bool_t trackletOn = fFee->GetTracklet(); // tracklet simulation active?
987ba9a3 440
441 AliDebug(1,Form("Producing raw data for sect=%d layer=%d stack=%d side=%d",sect,layer,stack,side));
f793c83d 442
f793c83d 443 UInt_t *tempBuffer = buf; // tempBuffer used to write ADC data
444 // different in case of tracklet writing
445
037c5823 446 if (trackletOn) {
f793c83d 447 tempBuffer = new UInt_t[maxSize];
8bd87c5e 448 tempnw = new Int_t(0);
449 tempof = new Int_t(0);
7d619a80 450 }
451
452 WriteIntermediateWords(tempBuffer,*tempnw,*tempof,maxSize,det,side);
453
454 if (digits->HasData()) {
455 // scanning direction such, that tracklet-words are sorted in ascending z and then in ascending y order
456 // ROB numbering on chamber and MCM numbering on ROB increase with decreasing z and increasing y
457 for (Int_t iRobRow = 0; iRobRow <= (kCtype + 3)-1; iRobRow++ ) {
458 // ROB number should be increasing
459 Int_t iRob = iRobRow * 2 + side;
460 // MCM on one ROB
461 for (Int_t iMcmRB = 0; iMcmRB < fGeo->MCMmax(); iMcmRB++ ) {
462 Int_t iMcm = 16 - 4*(iMcmRB/4 + 1) + (iMcmRB%4);
463
50002f37 464 fMcmSim->Init(det, iRob, iMcm);
465 fMcmSim->SetData(digits); // no filtering done here (already done in digitizer)
7d619a80 466 if (trackletOn) {
50002f37 467 fMcmSim->Tracklet();
468 Int_t tempNw = fMcmSim->ProduceTrackletStream(&buf[nw], maxSize - nw);
7d619a80 469 if( tempNw < 0 ) {
470 of += tempNw;
471 nw += maxSize - nw;
472 AliError(Form("Buffer overflow detected. Please increase the buffer size and recompile."));
473 } else {
474 nw += tempNw;
475 }
476 }
50002f37 477 fMcmSim->ZSMapping(); // Calculate zero suppression mapping
7d619a80 478 // at the moment it has to be rerun here
479 // Write MCM data to temp. buffer
50002f37 480 Int_t tempNw = fMcmSim->ProduceRawStream( &tempBuffer[*tempnw], maxSize - *tempnw, fEventCounter );
7d619a80 481 if ( tempNw < 0 ) {
482 *tempof += tempNw;
483 *tempnw += maxSize - nw;
f793c83d 484 AliError(Form("Buffer overflow detected. Please increase the buffer size and recompile."));
485 } else {
7d619a80 486 *tempnw += tempNw;
f793c83d 487 }
488 }
f793c83d 489 }
7d619a80 490
7d619a80 491 // in case of tracklet writing copy temp data to final buffer
492 if (trackletOn) {
493 if (nw + *tempnw < maxSize) {
494 memcpy(&buf[nw], tempBuffer, *tempnw * sizeof(UInt_t));
495 nw += *tempnw;
496 }
497 else {
498 AliError("Buffer overflow detected");
499 }
f793c83d 500 }
987ba9a3 501 }
502
8bd87c5e 503 if (trackletOn) {
504 delete [] tempBuffer;
505 delete tempof;
506 delete tempnw;
507 }
508
987ba9a3 509 // Write end of raw data marker
6a04e92b 510 if (nw+3 < maxSize) {
7d619a80 511 buf[nw++] = fgkEndOfDataMarker;
512 buf[nw++] = fgkEndOfDataMarker;
513 buf[nw++] = fgkEndOfDataMarker;
514 buf[nw++] = fgkEndOfDataMarker;
987ba9a3 515 } else {
7d619a80 516 of += 4;
987ba9a3 517 }
518
519 if (of != 0) {
f793c83d 520 AliError("Buffer overflow. Data is truncated. Please increase buffer size and recompile.");
987ba9a3 521 }
522
523 return nw;
524}
525
5990c064 526//_____________________________________________________________________________
7925de54 527AliTRDdigitsManager *AliTRDrawData::Raw2Digits(AliRawReader *rawReader)
5990c064 528{
b864d801 529 //
50378239 530 // Vx of the raw data reading
b864d801 531 //
5990c064 532
e2e85093 533 rawReader->Select("TRD"); //[mj]
534
b65e5048 535 AliTRDarrayADC *digits = 0;
536 AliTRDarrayDictionary *track0 = 0;
537 AliTRDarrayDictionary *track1 = 0;
538 AliTRDarrayDictionary *track2 = 0;
5990c064 539
dfbb4bb9 540 //AliTRDSignalIndex *indexes = 0;
541 // Create the digits manager
542 AliTRDdigitsManager* digitsManager = new AliTRDdigitsManager();
543 digitsManager->CreateArrays();
544
eba523a2 545 AliTRDrawStream input(rawReader);
dfbb4bb9 546
f2ab58d4 547 // ----- preparing tracklet output -----
548 AliDataLoader *trklLoader = AliRunLoader::Instance()->GetLoader("TRDLoader")->GetDataLoader("tracklets");
549 if (!trklLoader) {
f2ab58d4 550 trklLoader = new AliDataLoader("TRD.Tracklets.root","tracklets", "tracklets");
551 AliRunLoader::Instance()->GetLoader("TRDLoader")->AddDataLoader(trklLoader);
552 }
8bd87c5e 553 if (!trklLoader) {
554 return 0x0;
555 }
cc26f39c 556 AliTreeLoader *trklTreeLoader = dynamic_cast<AliTreeLoader*> (trklLoader->GetBaseLoader("tracklets-raw"));
557 if (!trklTreeLoader) {
558 trklTreeLoader = new AliTreeLoader("tracklets-raw", trklLoader);
559 trklLoader->AddBaseLoader(trklTreeLoader);
560 }
8bd87c5e 561 if (!trklTreeLoader) {
562 return 0x0;
563 }
cc26f39c 564
565 if (!trklTreeLoader->Tree())
566 trklTreeLoader->MakeTree();
f2ab58d4 567
d2eba04b 568 input.SetTrackletArray(fTracklets);
569 input.SetTrackArray(fTracks);
eba523a2 570
dfbb4bb9 571 // Loop through the digits
572 Int_t det = 0;
573
574 while (det >= 0)
575 {
eba523a2 576 det = input.NextChamber(digitsManager);
50002f37 577
dfbb4bb9 578 if (det >= 0)
579 {
580 // get...
b65e5048 581 digits = (AliTRDarrayADC *) digitsManager->GetDigits(det);
582 track0 = (AliTRDarrayDictionary *) digitsManager->GetDictionary(det,0);
583 track1 = (AliTRDarrayDictionary *) digitsManager->GetDictionary(det,1);
584 track2 = (AliTRDarrayDictionary *) digitsManager->GetDictionary(det,2);
dfbb4bb9 585 // and compress
b65e5048 586 if (digits) digits->Compress();
587 if (track0) track0->Compress();
588 if (track1) track1->Compress();
589 if (track2) track2->Compress();
dfbb4bb9 590 }
591 }
592
8eab6a01 593 for (Int_t iSector = 0; iSector < fGeo->Nsector(); iSector++) {
594 fTrgFlags[iSector] = input.GetTriggerFlags(iSector);
595 }
596
8bd87c5e 597 trklTreeLoader->WriteData("OVERWRITE");
598 trklLoader->UnloadAll();
f2ab58d4 599
dfbb4bb9 600 return digitsManager;
601}
602
1d93b218 603//_____________________________________________________________________________
604void AliTRDrawData::WriteIntermediateWords(UInt_t* buf, Int_t& nw, Int_t& of, const Int_t& maxSize, const Int_t& det, const Int_t& side) {
037c5823 605 //
606 // write tracklet end marker(0x10001000)
607 // and half chamber headers(H[0] and H[1])
608 //
987ba9a3 609
610 Int_t layer = fGeo->GetLayer( det ); // Layer
611 Int_t stack = fGeo->GetStack( det ); // Stack
612 Int_t sect = fGeo->GetSector( det ); // Sector (=iDDL)
613 Int_t rv = fFee->GetRAWversion();
a0446ff1 614 const Int_t kNTBin = fDigitsParam->GetNTimeBins(det);
5896bc23 615 Bool_t trackletOn = fFee->GetTracklet();
987ba9a3 616 UInt_t x = 0;
617
618 // Write end of tracklet marker
7d619a80 619 if (nw < maxSize){
620 buf[nw++] = fgkEndOfTrackletMarker;
621 buf[nw++] = fgkEndOfTrackletMarker; // the number of tracklet end marker should be more than 2
6a04e92b 622 }
623 else {
7d619a80 624 of++;
6a04e92b 625 }
987ba9a3 626
7d619a80 627 // Half Chamber header
628 // h[0] (there are 2 HC headers) xmmm mmmm nnnn nnnq qqss sssp ppcc ci01
629 // , where x : Raw version speacial number (=1)
630 // m : Raw version major number (test pattern, ZS, disable tracklet, 0, options)
631 // n : Raw version minor number
632 // q : number of addtional header words (default = 1)
633 // s : SM sector number (ALICE numbering)
634 // p : plane(layer) number
635 // c : chamber(stack) number
636 // i : side number (0:A, 1:B)
637 Int_t majorv = 0; // The major version number
987ba9a3 638 Int_t minorv = 0; // The minor version number
639 Int_t add = 1; // The number of additional header words to follow : now 1, previous 2
7d619a80 640 Int_t tp = 0; // test pattern (default=0)
641 Int_t zs = (rv==3) ? 1 : 0; // zero suppression
642 Int_t dt = (trackletOn) ? 0 : 1; // disable tracklet
643
644 majorv = (tp<<6) | (zs<<5) | (dt<<4) | 1; // major version
645
987ba9a3 646 x = (1<<31) | (majorv<<24) | (minorv<<17) | (add<<14) | (sect<<9) | (layer<<6) | (stack<<3) | (side<<2) | 1;
647 if (nw < maxSize) buf[nw++] = x; else of++;
7d619a80 648
987ba9a3 649 // h[1] tttt ttbb bbbb bbbb bbbb bbpp pphh hh01
7d619a80 650 // , where t : number of time bins
651 // b : bunch crossing number
652 // p : pretrigger counter
653 // h : pretrigger phase
987ba9a3 654 Int_t bcCtr = 99; // bunch crossing counter. Here it is set to 99 always for no reason
655 Int_t ptCtr = 15; // pretrigger counter. Here it is set to 15 always for no reason
656 Int_t ptPhase = 11; // pretrigger phase. Here it is set to 11 always for no reason
657 //x = (bcCtr<<16) | (ptCtr<<12) | (ptPhase<<8) | ((kNTBin-1)<<2) | 1; // old format
6a04e92b 658 x = ((kNTBin)<<26) | (bcCtr<<10) | (ptCtr<<6) | (ptPhase<<2) | 1;
987ba9a3 659 if (nw < maxSize) buf[nw++] = x; else of++;
987ba9a3 660}