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