]>
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" |
2745a409 | 33 | |
5990c064 | 34 | #include "AliTRDrawData.h" |
35 | #include "AliTRDdigitsManager.h" | |
bd0f8685 | 36 | #include "AliTRDgeometry.h" |
b65e5048 | 37 | #include "AliTRDarrayDictionary.h" |
38 | #include "AliTRDarrayADC.h" | |
dfbb4bb9 | 39 | #include "AliTRDrawStreamBase.h" |
3551db50 | 40 | #include "AliTRDcalibDB.h" |
ca21baaa | 41 | #include "AliTRDSignalIndex.h" |
dfd03fc3 | 42 | #include "AliTRDfeeParam.h" |
43 | #include "AliTRDmcmSim.h" | |
f2ab58d4 | 44 | #include "AliTRDtrackletWord.h" |
5896bc23 | 45 | #include "AliTRDdigitsParam.h" |
dfd03fc3 | 46 | |
5990c064 | 47 | ClassImp(AliTRDrawData) |
48 | ||
6a04e92b | 49 | Int_t AliTRDrawData::fgRawFormatVersion = AliTRDrawData::kRawNewFormat; |
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 | |
6a04e92b | 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)); | |
8c703901 | 199 | |
200 | // Reset payload byte size (payload does not include header). | |
201 | Int_t npayloadbyte = 0; | |
202 | ||
6a04e92b | 203 | |
037c5823 | 204 | if ( fgRawFormatVersion == 0 ){ |
7925de54 | 205 | // GTU common data header (5x4 bytes per super module, shows link mask) |
053767a4 | 206 | for( Int_t stack = 0; stack < fGeo->Nstack(); stack++ ) { |
037c5823 | 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); | |
6a04e92b | 210 | |
037c5823 | 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; | |
6a04e92b | 218 | } |
037c5823 | 219 | } |
6a04e92b | 220 | |
221 | ||
222 | // check the existance of the data | |
223 | // SM index word and Stack index word | |
224 | if ( fgRawFormatVersion == 1 ){ | |
037c5823 | 225 | UInt_t *iwbuffer = new UInt_t[109]; // index word buffer; max 109 = 2 SM headers + 67 dummy headers + 5*8 stack headers |
6a04e92b | 226 | Int_t nheader = 0; |
037c5823 | 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) | |
6a04e92b | 233 | iwbuffer[nheader++] = 0x10404071; // SM header |
037c5823 | 234 | for ( Int_t i=0; i<66; i++ ) iwbuffer[nheader++] = 0x00000000; // dummy words |
235 | iwbuffer[nheader++] = 0x10000000; // end of dummy words | |
6a04e92b | 236 | |
237 | for ( Int_t stack= 0; stack < fGeo->Nstack(); stack++) { | |
037c5823 | 238 | UInt_t linkMask = 0x0; |
6a04e92b | 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() ) { | |
037c5823 | 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; | |
6a04e92b | 247 | } // has data |
248 | } // loop over layer | |
249 | ||
037c5823 | 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 | |
6a04e92b | 253 | iwbuffer[nheader++] = 0x04045b01; // stack header |
254 | for (Int_t i=0;i<6;i++) iwbuffer[nheader++] = 0x00000000; // 6 dummy words | |
037c5823 | 255 | bStackHasData = kFALSE; |
6a04e92b | 256 | } |
257 | } // loop over stack | |
258 | ||
037c5823 | 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 | |
6a04e92b | 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 | // ------------------------------------------------------------------------------------------------- | |
8c703901 | 269 | |
270 | // Prepare chamber data | |
053767a4 | 271 | for( Int_t stack = 0; stack < fGeo->Nstack(); stack++) { |
272 | for( Int_t layer = 0; layer < fGeo->Nlayer(); layer++) { | |
8c703901 | 273 | |
053767a4 | 274 | Int_t iDet = fGeo->GetDetector(layer,stack,sect); |
6a04e92b | 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 | } | |
8c703901 | 281 | |
6a04e92b | 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 | |
8c703901 | 288 | |
6a04e92b | 289 | if (digits->HasData()) digits->Expand(); |
290 | ||
291 | Int_t hcwords = 0; | |
292 | Int_t rv = fFee->GetRAWversion(); | |
dfd03fc3 | 293 | |
987ba9a3 | 294 | |
295 | if ( fgRawFormatVersion == 0 ){ | |
296 | // Process A side of the chamber | |
5fc47291 | 297 | if ( rv >= 1 && rv <= 2 ) { |
298 | hcwords = ProduceHcDataV1andV2(digits,0,iDet,hcBuffer,kMaxHcWords); | |
299 | } | |
300 | if ( rv == 3 ) { | |
1d93b218 | 301 | |
96e6312d | 302 | hcwords = ProduceHcDataV3 (digits,0,iDet,hcBuffer,kMaxHcWords,newEvent); |
303 | //hcwords = ProduceHcDataV3 (digits,0,iDet,hcBuffer,kMaxHcWords); | |
1d93b218 | 304 | if(newEvent == kTRUE) newEvent = kFALSE; |
5fc47291 | 305 | } |
8c703901 | 306 | |
5fc47291 | 307 | of->WriteBuffer((char *) hcBuffer, hcwords*4); |
308 | npayloadbyte += hcwords*4; | |
309 | ||
987ba9a3 | 310 | // Process B side of the chamber |
5fc47291 | 311 | if ( rv >= 1 && rv <= 2 ) { |
312 | hcwords = ProduceHcDataV1andV2(digits,1,iDet,hcBuffer,kMaxHcWords); | |
313 | } | |
314 | if ( rv >= 3 ) { | |
1d93b218 | 315 | |
96e6312d | 316 | hcwords = ProduceHcDataV3 (digits,1,iDet,hcBuffer,kMaxHcWords,newEvent); |
317 | //hcwords = ProduceHcDataV3 (digits,1,iDet,hcBuffer,kMaxHcWords); | |
5fc47291 | 318 | } |
319 | ||
320 | of->WriteBuffer((char *) hcBuffer, hcwords*4); | |
321 | npayloadbyte += hcwords*4; | |
322 | ||
6a04e92b | 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) | |
987ba9a3 | 336 | of->WriteBuffer((char *) hcBuffer, hcwords*4); |
337 | npayloadbyte += hcwords*4; | |
6a04e92b | 338 | //for ( Int_t i=0; i<hcwords; i++ ) AliInfo(Form("Buf : %X",hcBuffer[i])); |
987ba9a3 | 339 | |
6a04e92b | 340 | // Process B side of the chamber |
341 | hcwords = ProduceHcData(digits,1,iDet,hcBuffer,kMaxHcWords,newEvent,newSM); | |
987ba9a3 | 342 | of->WriteBuffer((char *) hcBuffer, hcwords*4); |
343 | npayloadbyte += hcwords*4; | |
037c5823 | 344 | } else { // in case of no-suppression or NZS |
345 | /* | |
6a04e92b | 346 | hcBuffer[hcwords++] = fgkEndOfTrackletMarker; |
347 | hcBuffer[hcwords++] = fgkEndOfTrackletMarker; | |
348 | hcBuffer[hcwords++] = (1<<31) | (0<<24) | (0<<17) | (1<<14) | (sect<<9) | (layer<<6) | (stack<<3) | (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; | |
987ba9a3 | 355 | |
6a04e92b | 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; | |
037c5823 | 364 | */ |
365 | hcwords = ProduceHcDataNoSuppression(0,iDet,hcBuffer,kMaxHcWords); // side 0 | |
366 | of->WriteBuffer((char *) hcBuffer, hcwords*4); | |
6a04e92b | 367 | npayloadbyte += hcwords*4; |
dfd03fc3 | 368 | |
037c5823 | 369 | hcwords = ProduceHcDataNoSuppression(1,iDet,hcBuffer,kMaxHcWords); // side 1 |
6a04e92b | 370 | of->WriteBuffer((char *) hcBuffer, hcwords*4); |
037c5823 | 371 | npayloadbyte += hcwords*4; |
6a04e92b | 372 | } |
8c703901 | 373 | } |
374 | ||
6a04e92b | 375 | } // has data |
376 | ||
377 | } // loop over layer | |
378 | } // loop over stack | |
379 | ||
8c703901 | 380 | // Complete header |
08f92f14 | 381 | header.fSize = UInt_t(of->Tellp()) - hpos; |
8c703901 | 382 | header.SetAttribute(0); // Valid data |
08f92f14 | 383 | of->Seekp(hpos); // Rewind to header position |
384 | of->WriteBuffer((char *) (& header), sizeof(header)); | |
8c703901 | 385 | delete of; |
037c5823 | 386 | } // loop over sector(SM) |
8c703901 | 387 | |
0c349049 | 388 | delete [] hcBuffer; |
389 | ||
8c703901 | 390 | return kTRUE; |
391 | ||
392 | } | |
393 | ||
987ba9a3 | 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 | ||
6a04e92b | 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 | } | |
987ba9a3 | 441 | |
6a04e92b | 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 | //_____________________________________________________________________________ | |
543691ea | 451 | Int_t AliTRDrawData::AddStackIndexWords(UInt_t *buf, Int_t /*nStack*/, Int_t nMax){ |
6a04e92b | 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; | |
987ba9a3 | 480 | |
6a04e92b | 481 | return nAddedWords; |
987ba9a3 | 482 | } |
483 | ||
484 | //_____________________________________________________________________________ | |
6a04e92b | 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 | //_____________________________________________________________________________ | |
0aff7a99 | 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*/){ |
987ba9a3 | 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 | |
f793c83d | 516 | Int_t *tempnw = 0x0; // Number of written words for temp. buffer |
517 | Int_t *tempof = 0x0; // Number of overflowed words for temp. buffer | |
987ba9a3 | 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) | |
f793c83d | 521 | const Int_t kCtype = fGeo->GetStack(det) == 2 ? 0 : 1; // Chamber type (0:C0, 1:C1) |
987ba9a3 | 522 | |
037c5823 | 523 | Bool_t trackletOn = fFee->GetTracklet(); // tracklet simulation active? |
987ba9a3 | 524 | |
525 | AliDebug(1,Form("Producing raw data for sect=%d layer=%d stack=%d side=%d",sect,layer,stack,side)); | |
f793c83d | 526 | |
527 | AliTRDmcmSim* mcm = new AliTRDmcmSim(); | |
987ba9a3 | 528 | |
f793c83d | 529 | UInt_t *tempBuffer = buf; // tempBuffer used to write ADC data |
530 | // different in case of tracklet writing | |
531 | ||
037c5823 | 532 | if (trackletOn) { |
f793c83d | 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 | } | |
987ba9a3 | 541 | |
f793c83d | 542 | WriteIntermediateWordsV2(tempBuffer,*tempnw,*tempof,maxSize,det,side); //??? no tracklet or NZS |
987ba9a3 | 543 | |
987ba9a3 | 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 | |
6a04e92b | 546 | for (Int_t iRobRow = 0; iRobRow <= (kCtype + 3)-1; iRobRow++ ) { // ROB number should be increasing |
f793c83d | 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) | |
037c5823 | 554 | if (trackletOn) { |
f793c83d | 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 | } | |
987ba9a3 | 578 | |
f793c83d | 579 | delete mcm; |
987ba9a3 | 580 | |
987ba9a3 | 581 | |
f793c83d | 582 | // in case of tracklet writing copy temp data to final buffer |
037c5823 | 583 | if (trackletOn) { |
f793c83d | 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 | } | |
987ba9a3 | 591 | } |
592 | ||
987ba9a3 | 593 | // Write end of raw data marker |
6a04e92b | 594 | if (nw+3 < maxSize) { |
037c5823 | 595 | buf[nw++] = fgkEndOfDataMarker; // fFee->GetRawDataEndmarker(); |
596 | buf[nw++] = fgkEndOfDataMarker; // fFee->GetRawDataEndmarker(); | |
597 | //buf[nw++] = fgkEndOfDataMarker; // fFee->GetRawDataEndmarker(); | |
598 | //buf[nw++] = fgkEndOfDataMarker; // fFee->GetRawDataEndmarker(); | |
987ba9a3 | 599 | } else { |
f793c83d | 600 | of++; |
987ba9a3 | 601 | } |
602 | ||
037c5823 | 603 | if (trackletOn) { |
f793c83d | 604 | delete [] tempBuffer; |
605 | delete tempof; | |
606 | delete tempnw; | |
607 | } | |
608 | ||
987ba9a3 | 609 | if (of != 0) { |
f793c83d | 610 | AliError("Buffer overflow. Data is truncated. Please increase buffer size and recompile."); |
987ba9a3 | 611 | } |
612 | ||
613 | return nw; | |
614 | } | |
615 | ||
037c5823 | 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 | ||
8c703901 | 679 | //_____________________________________________________________________________ |
b65e5048 | 680 | Int_t AliTRDrawData::ProduceHcDataV1andV2(AliTRDarrayADC *digits, Int_t side |
7925de54 | 681 | , Int_t det, UInt_t *buf, Int_t maxSize) |
8c703901 | 682 | { |
7925de54 | 683 | // |
dfd03fc3 | 684 | // This function simulates: 1) SM-I commissiong data Oct. 06 (Raw Version == 1). |
685 | // 2) Full Raw Production Version (Raw Version == 2) | |
8c703901 | 686 | // |
687 | // Produce half chamber data (= an ORI data) for the given chamber (det) and side (side) | |
688 | // where | |
7925de54 | 689 | // |
8c703901 | 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 | ||
0c349049 | 702 | Int_t nw = 0; // Number of written words |
703 | Int_t of = 0; // Number of overflowed words | |
053767a4 | 704 | Int_t layer = fGeo->GetLayer( det ); // Layer |
705 | Int_t stack = fGeo->GetStack( det ); // Stack | |
0c349049 | 706 | Int_t sect = fGeo->GetSector( det ); // Sector (=iDDL) |
053767a4 | 707 | Int_t nRow = fGeo->GetRowMax( layer, stack, sect ); |
708 | Int_t nCol = fGeo->GetColMax( layer ); | |
a0446ff1 | 709 | const Int_t kNTBin = fDigitsParam->GetNTimeBins(det); |
710 | ||
0c349049 | 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(); | |
8c703901 | 715 | |
716 | // Check the nCol and nRow. | |
717 | if ((nCol == 144) && | |
718 | (nRow == 16 || nRow == 12)) { | |
719 | kCtype = (nRow-12) / 4; | |
720 | } | |
721 | else { | |
7925de54 | 722 | AliError(Form("This type of chamber is not supported (nRow=%d, nCol=%d)." |
8c703901 | 723 | ,nRow,nCol)); |
724 | return 0; | |
725 | } | |
726 | ||
053767a4 | 727 | AliDebug(1,Form("Producing raw data for sect=%d layer=%d stack=%d side=%d" |
728 | ,sect,layer,stack,side)); | |
8c703901 | 729 | |
730 | // Tracklet should be processed here but not implemented yet | |
731 | ||
732 | // Write end of tracklet marker | |
733 | if (nw < maxSize) { | |
bd63bf88 | 734 | buf[nw++] = kEndoftrackletmarker; |
8c703901 | 735 | } |
736 | else { | |
737 | of++; | |
738 | } | |
739 | ||
740 | // Half Chamber header | |
dfd03fc3 | 741 | if ( rv == 1 ) { |
7925de54 | 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 | |
053767a4 | 744 | x = (dcs<<20) | (sect<<15) | (layer<<12) | (stack<<9) | (side<<8) | 1; |
7925de54 | 745 | if (nw < maxSize) { |
746 | buf[nw++] = x; | |
747 | } | |
748 | else { | |
749 | of++; | |
750 | } | |
751 | } | |
dfd03fc3 | 752 | else if ( rv == 2 ) { |
bd63bf88 | 753 | // h[0] (there are 3 HC header) |
7925de54 | 754 | Int_t minorv = 0; // The minor version number |
ecf39416 | 755 | Int_t add = 2; // The number of additional header words to follow |
053767a4 | 756 | x = (1<<31) | (rv<<24) | (minorv<<17) | (add<<14) | (sect<<9) | (layer<<6) | (stack<<3) | (side<<2) | 1; |
7925de54 | 757 | if (nw < maxSize) { |
758 | buf[nw++] = x; | |
759 | } | |
760 | else { | |
761 | of++; | |
762 | } | |
763 | // h[1] | |
0c349049 | 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; | |
7925de54 | 768 | if (nw < maxSize) { |
769 | buf[nw++] = x; | |
770 | } | |
771 | else { | |
772 | of++; | |
773 | } | |
bd63bf88 | 774 | // h[2] |
0c349049 | 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; | |
bd63bf88 | 784 | if (nw < maxSize) { |
785 | buf[nw++] = x; | |
786 | } | |
787 | else { | |
788 | of++; | |
789 | } | |
8c703901 | 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; | |
7925de54 | 795 | for (Int_t iMcm = 0; iMcm < fGeo->MCMmax(); iMcm++ ) { |
8c703901 | 796 | Int_t padrow = iRobRow * 4 + iMcm / 4; |
797 | ||
798 | // MCM header | |
7925de54 | 799 | x = ((iRob * fGeo->MCMmax() + iMcm) << 24) | ((iEv % 0x100000) << 4) | 0xC; |
8c703901 | 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++ ) { | |
ecf39416 | 809 | Int_t padcol = fFee->GetPadColFromADC(iRob, iMcm, iAdc); |
6a04e92b | 810 | UInt_t aa = !(iAdc & 1) + 2; // 3 for the even ADC channel , 2 for the odd ADC channel |
0c349049 | 811 | UInt_t *a = new UInt_t[kNTBin+2]; |
8c703901 | 812 | // 3 timebins are packed into one 32 bits word |
0c349049 | 813 | for (Int_t iT = 0; iT < kNTBin; iT+=3) { |
7925de54 | 814 | if ((padcol >= 0) && (padcol < nCol)) { |
b65e5048 | 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; | |
7925de54 | 818 | } |
819 | else { | |
820 | a[iT] = a[iT+1] = a[iT+2] = 0; // This happenes at the edge of chamber (should be pedestal! How?) | |
8c703901 | 821 | } |
7925de54 | 822 | x = (a[iT+2] << 22) | (a[iT+1] << 12) | (a[iT] << 2) | aa; |
823 | if (nw < maxSize) { | |
824 | buf[nw++] = x; | |
8c703901 | 825 | } |
7925de54 | 826 | else { |
827 | of++; | |
8c703901 | 828 | } |
7925de54 | 829 | } |
8c703901 | 830 | // Diagnostics |
831 | Float_t avg = 0; | |
832 | Float_t rms = 0; | |
0c349049 | 833 | for (Int_t iT = 0; iT < kNTBin; iT++) { |
8c703901 | 834 | avg += (Float_t) (a[iT]); |
835 | } | |
0c349049 | 836 | avg /= (Float_t) kNTBin; |
837 | for (Int_t iT = 0; iT < kNTBin; iT++) { | |
8c703901 | 838 | rms += ((Float_t) (a[iT]) - avg) * ((Float_t) (a[iT]) - avg); |
839 | } | |
0c349049 | 840 | rms = TMath::Sqrt(rms / (Float_t) kNTBin); |
8c703901 | 841 | if (rms > 1.7) { |
7925de54 | 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)); | |
8c703901 | 844 | } |
e21c2d7d | 845 | delete [] a; |
8c703901 | 846 | } |
847 | } | |
848 | } | |
849 | ||
850 | // Write end of raw data marker | |
851 | if (nw < maxSize) { | |
bd63bf88 | 852 | buf[nw++] = kEndofrawdatamarker; |
8c703901 | 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; | |
5990c064 | 862 | |
863 | } | |
864 | ||
dfd03fc3 | 865 | //_____________________________________________________________________________ |
23200400 | 866 | |
b65e5048 | 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) | |
dfd03fc3 | 869 | { |
870 | // | |
871 | // This function simulates: Raw Version == 3 (Zero Suppression Prototype) | |
872 | // | |
873 | ||
0c349049 | 874 | Int_t nw = 0; // Number of written words |
875 | Int_t of = 0; // Number of overflowed words | |
053767a4 | 876 | Int_t layer = fGeo->GetLayer( det ); // Layer |
877 | Int_t stack = fGeo->GetStack( det ); // Stack | |
0c349049 | 878 | Int_t sect = fGeo->GetSector( det ); // Sector (=iDDL) |
053767a4 | 879 | Int_t nRow = fGeo->GetRowMax( layer, stack, sect ); |
880 | Int_t nCol = fGeo->GetColMax( layer ); | |
a0446ff1 | 881 | const Int_t kNTBin = fDigitsParam->GetNTimeBins(det); |
0c349049 | 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? | |
1d93b218 | 884 | |
885 | ||
886 | ||
037c5823 | 887 | Bool_t trackletOn = fFee->GetTracklet(); // **new** |
dfd03fc3 | 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 | ||
053767a4 | 900 | AliDebug(1,Form("Producing raw data for sect=%d layer=%d stack=%d side=%d" |
901 | ,sect,layer,stack,side)); | |
dfd03fc3 | 902 | |
1d93b218 | 903 | AliTRDmcmSim** mcm = new AliTRDmcmSim*[(kCtype + 3)*(fGeo->MCMmax())]; |
dfd03fc3 | 904 | |
1d93b218 | 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 | ||
037c5823 | 909 | if (!trackletOn) { |
1d93b218 | 910 | WriteIntermediateWords(buf,nw,of,maxSize,det,side); |
dfd03fc3 | 911 | } |
1d93b218 | 912 | |
dfd03fc3 | 913 | // Scan for ROB and MCM |
1d93b218 | 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-- ) { | |
dfd03fc3 | 917 | Int_t iRob = iRobRow * 2 + side; |
1d93b218 | 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(); | |
96e6312d | 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 | |
1d93b218 | 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++) { | |
b65e5048 | 934 | mcm[entry]->SetData( iAdc, iT, digits->GetData( padrow, padcol, iT) ); |
1d93b218 | 935 | } |
936 | } | |
937 | else { // this means it is out of chamber, and masked ADC | |
938 | mcm[entry]->SetDataPedestal( iAdc ); | |
939 | } | |
940 | } | |
dfd03fc3 | 941 | |
1d93b218 | 942 | // Simulate process in MCM |
b0a41e80 | 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(); | |
1d93b218 | 948 | |
037c5823 | 949 | if (trackletOn) { |
1d93b218 | 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 | } | |
dfd03fc3 | 960 | } |
1d93b218 | 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 | ||
709187ec | 977 | |
709187ec | 978 | |
1d93b218 | 979 | //mcm->DumpData( "trdmcmdata.txt", "RFZS" ); // debugging purpose |
dfd03fc3 | 980 | } |
981 | } | |
982 | ||
1d93b218 | 983 | // if tracklets are switched on, raw-data can be written only after all tracklets |
037c5823 | 984 | if (trackletOn) { |
1d93b218 | 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 | ||
dfd03fc3 | 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) { | |
ecf39416 | 1023 | AliError("Buffer overflow. Data is truncated. Please increase buffer size and recompile."); |
dfd03fc3 | 1024 | } |
1025 | ||
1d93b218 | 1026 | |
dfd03fc3 | 1027 | return nw; |
1028 | ||
1029 | } | |
1030 | ||
5990c064 | 1031 | //_____________________________________________________________________________ |
7925de54 | 1032 | AliTRDdigitsManager *AliTRDrawData::Raw2Digits(AliRawReader *rawReader) |
5990c064 | 1033 | { |
b864d801 | 1034 | // |
50378239 | 1035 | // Vx of the raw data reading |
b864d801 | 1036 | // |
5990c064 | 1037 | |
e2e85093 | 1038 | rawReader->Select("TRD"); //[mj] |
1039 | ||
b65e5048 | 1040 | AliTRDarrayADC *digits = 0; |
1041 | AliTRDarrayDictionary *track0 = 0; | |
1042 | AliTRDarrayDictionary *track1 = 0; | |
1043 | AliTRDarrayDictionary *track2 = 0; | |
5990c064 | 1044 | |
dfbb4bb9 | 1045 | //AliTRDSignalIndex *indexes = 0; |
1046 | // Create the digits manager | |
1047 | AliTRDdigitsManager* digitsManager = new AliTRDdigitsManager(); | |
1048 | digitsManager->CreateArrays(); | |
1049 | ||
92c7f341 | 1050 | if (!fTrackletContainer) { |
92c7f341 | 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]; | |
f2ab58d4 | 1055 | memset(fTrackletContainer[0], 0, kTrackletChmb*sizeof(UInt_t)); //jkl |
1056 | memset(fTrackletContainer[1], 0, kTrackletChmb*sizeof(UInt_t)); //jkl | |
92c7f341 | 1057 | } |
1058 | ||
dfbb4bb9 | 1059 | AliTRDrawStreamBase *pinput = AliTRDrawStreamBase::GetRawStream(rawReader); |
1060 | AliTRDrawStreamBase &input = *pinput; | |
12b70280 | 1061 | input.SetRawVersion( fFee->GetRAWversion() ); //<= ADDED by MinJung |
dfbb4bb9 | 1062 | |
1063 | AliInfo(Form("Stream version: %s", input.IsA()->GetName())); | |
1064 | ||
f2ab58d4 | 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 | ||
dfbb4bb9 | 1075 | // Loop through the digits |
1076 | Int_t det = 0; | |
1077 | ||
1078 | while (det >= 0) | |
1079 | { | |
92c7f341 | 1080 | det = input.NextChamber(digitsManager,fTrackletContainer); |
1081 | ||
f2ab58d4 | 1082 | if (*(fTrackletContainer[0]) > 0 || *(fTrackletContainer[1]) > 0) WriteTracklets(det); |
92c7f341 | 1083 | |
dfbb4bb9 | 1084 | if (det >= 0) |
1085 | { | |
1086 | // get... | |
b65e5048 | 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); | |
dfbb4bb9 | 1091 | // and compress |
b65e5048 | 1092 | if (digits) digits->Compress(); |
1093 | if (track0) track0->Compress(); | |
1094 | if (track1) track1->Compress(); | |
1095 | if (track2) track2->Compress(); | |
dfbb4bb9 | 1096 | } |
1097 | } | |
1098 | ||
67271412 | 1099 | if (trklLoader) { |
f2ab58d4 | 1100 | trklLoader->WriteData("OVERWRITE"); |
1101 | trklLoader->Unload(); | |
1102 | } | |
1103 | ||
92c7f341 | 1104 | if (fTrackletContainer){ |
1105 | delete [] fTrackletContainer[0]; | |
1106 | delete [] fTrackletContainer[1]; | |
1107 | delete [] fTrackletContainer; | |
1108 | fTrackletContainer = NULL; | |
1109 | } | |
1110 | ||
dfbb4bb9 | 1111 | delete pinput; |
1112 | pinput = NULL; | |
1113 | ||
1114 | return digitsManager; | |
1115 | } | |
1116 | ||
1d93b218 | 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) { | |
037c5823 | 1119 | // |
1120 | // write half-chamber headers | |
1121 | // | |
1d93b218 | 1122 | |
053767a4 | 1123 | Int_t layer = fGeo->GetLayer( det ); // Layer |
1124 | Int_t stack = fGeo->GetStack( det ); // Stack | |
1d93b218 | 1125 | Int_t sect = fGeo->GetSector( det ); // Sector (=iDDL) |
1126 | Int_t rv = fFee->GetRAWversion(); | |
a0446ff1 | 1127 | const Int_t kNTBin = fDigitsParam->GetNTimeBins(det); |
1d93b218 | 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 | |
053767a4 | 1142 | x = (1<<31) | (rv<<24) | (minorv<<17) | (add<<14) | (sect<<9) | (layer<<6) | (stack<<3) | (side<<2) | 1; |
1d93b218 | 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 | ||
987ba9a3 | 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) { | |
037c5823 | 1180 | // |
1181 | // write tracklet end marker(0x10001000) | |
1182 | // and half chamber headers(H[0] and H[1]) | |
1183 | // | |
987ba9a3 | 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(); | |
a0446ff1 | 1189 | const Int_t kNTBin = fDigitsParam->GetNTimeBins(det); |
5896bc23 | 1190 | Bool_t trackletOn = fFee->GetTracklet(); |
987ba9a3 | 1191 | UInt_t x = 0; |
1192 | ||
1193 | // Write end of tracklet marker | |
6a04e92b | 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 | ||
987ba9a3 | 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 | |
037c5823 | 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 | |
987ba9a3 | 1219 | |
037c5823 | 1220 | majorv = (tp<<6) | (zs<<5) | (dt<<4) | 1; // major version |
987ba9a3 | 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 | |
6a04e92b | 1234 | x = ((kNTBin)<<26) | (bcCtr<<10) | (ptCtr<<6) | (ptPhase<<2) | 1; |
987ba9a3 | 1235 | if (nw < maxSize) buf[nw++] = x; else of++; |
1236 | ||
1237 | } | |
1d93b218 | 1238 | |
92c7f341 | 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 | ||
f2ab58d4 | 1272 | // AliDataLoader *dl = fRunLoader->GetLoader("TRDLoader")->GetDataLoader("tracklets"); //jkl: wrong |
1273 | // dl->WriteData("OVERWRITE"); //jkl: wrong | |
92c7f341 | 1274 | //dl->Unload(); |
1275 | delete [] leaves; | |
1276 | ||
1277 | return kTRUE; | |
92c7f341 | 1278 | } |