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