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