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