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