]>
Commit | Line | Data |
---|---|---|
a19e2543 | 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 | ||
da8d4b6d | 16 | /* $Id$ */ |
17 | ||
a19e2543 | 18 | //////////////////////////////////// |
19 | // | |
ced309a5 | 20 | // MUON Raw Data generaton in ALICE-MUON |
a19e2543 | 21 | // This class version 3 (further details could be found in Alice-note) |
22 | // | |
23 | // Implemented non-constant buspatch numbers for tracking | |
24 | // with correct DDL id (first guess) | |
25 | // (Ch. Finck, dec 2005) | |
26 | // | |
27 | // Digits2Raw: | |
28 | // Generates raw data for MUON tracker and finally for trigger | |
29 | // Using real mapping (inverse) for tracker | |
30 | // For trigger there is no mapping (mapping could be found in AliMUONTriggerCircuit) | |
2cf44ef3 | 31 | // Ch. Finck, July 04 |
ced309a5 | 32 | // Use memcpy instead of assignment elt by elt |
33 | // Introducing variable DSP numbers, real manu numbers per buspatch for st12 | |
34 | // Implemented scaler event for Trigger | |
2cf44ef3 | 35 | // Ch. Finck, Jan. 06 |
a19e2543 | 36 | // |
37 | //////////////////////////////////// | |
38 | ||
2cbb173f | 39 | #include "AliMUONRawWriter.h" |
a19e2543 | 40 | |
a19e2543 | 41 | #include "AliBitPacking.h" |
2cf44ef3 | 42 | #include "AliRawReader.h" |
9e378ff4 | 43 | #include "AliDAQ.h" |
a19e2543 | 44 | #include "AliLog.h" |
a19e2543 | 45 | #include "AliMUON.h" |
a19e2543 | 46 | #include "AliMUONConstants.h" |
2cf44ef3 | 47 | |
48 | #include "AliMUONDarcHeader.h" | |
49 | #include "AliMUONRegHeader.h" | |
50 | #include "AliMUONLocalStruct.h" | |
51 | #include "AliMUONDspHeader.h" | |
52 | #include "AliMUONBlockHeader.h" | |
53 | ||
2cbb173f | 54 | #include "AliMUONData.h" |
55 | #include "AliMUONDigit.h" | |
2cbb173f | 56 | #include "AliMUONGlobalTrigger.h" |
57 | #include "AliMUONLocalTrigger.h" | |
2cf44ef3 | 58 | |
2cbb173f | 59 | #include "AliMpBusPatch.h" |
60 | #include "AliMpDEManager.h" | |
61 | #include "AliMpPad.h" | |
a19e2543 | 62 | #include "AliMpPlaneType.h" |
2cbb173f | 63 | #include "AliMpSegFactory.h" |
64 | #include "AliMpStationType.h" | |
a19e2543 | 65 | #include "AliMpVSegmentation.h" |
2cf44ef3 | 66 | |
2cbb173f | 67 | #include "TClonesArray.h" |
2cf44ef3 | 68 | |
a19e2543 | 69 | ClassImp(AliMUONRawWriter) // Class implementation in ROOT context |
ced309a5 | 70 | |
71 | Int_t AliMUONRawWriter::fgManuPerBusSwp1B[12] = {1, 27, 53, 79, 105, 131, 157, 183, 201, 214, 224, 232}; | |
72 | Int_t AliMUONRawWriter::fgManuPerBusSwp1NB[12] = {1, 27, 53, 79, 105, 131, 157, 183, 201, 214, 225, 233}; | |
73 | ||
74 | Int_t AliMUONRawWriter::fgManuPerBusSwp2B[12] = {1, 27, 53, 79, 105, 131, 157, 183, 201, 214, 226, 246}; | |
75 | Int_t AliMUONRawWriter::fgManuPerBusSwp2NB[12] = {1, 27, 53, 79, 105, 131, 157, 183, 201, 214, 227, 245}; | |
76 | ||
77 | ||
a19e2543 | 78 | //__________________________________________________________________________ |
2cbb173f | 79 | AliMUONRawWriter::AliMUONRawWriter(AliMUONData* data) |
80 | : TObject(), | |
81 | fScalerEvent(kFALSE) | |
a19e2543 | 82 | { |
2cf44ef3 | 83 | // |
a19e2543 | 84 | // Standard Constructor |
2cf44ef3 | 85 | // |
2cbb173f | 86 | AliDebug(1,"Standard ctor"); |
87 | ||
a19e2543 | 88 | // initialize container |
a19e2543 | 89 | fMUONData = data; |
90 | ||
91 | // initialize array | |
2cf44ef3 | 92 | fBusArray = new TClonesArray("AliMUONBusStruct",1000); |
93 | fBusArray->SetOwner(kTRUE); | |
a19e2543 | 94 | |
84ceeb06 | 95 | // ddl tracker pointers |
2cf44ef3 | 96 | fBlockHeader = new AliMUONBlockHeader(); |
97 | fDspHeader = new AliMUONDspHeader(); | |
98 | fBusStruct = new AliMUONBusStruct(); | |
99 | ||
84ceeb06 | 100 | // setting data key to default value (only for writting) |
101 | fBlockHeader->SetDataKey(fBlockHeader->GetDefaultDataKey()); | |
102 | fDspHeader->SetDataKey(fDspHeader->GetDefaultDataKey()); | |
103 | fBusStruct->SetDataKey(fBusStruct->GetDefaultDataKey()); | |
104 | ||
84ceeb06 | 105 | // ddl trigger pointers |
2cf44ef3 | 106 | fDarcHeader = new AliMUONDarcHeader(); |
107 | fRegHeader = new AliMUONRegHeader(); | |
108 | fLocalStruct = new AliMUONLocalStruct(); | |
a19e2543 | 109 | |
84ceeb06 | 110 | // bus patch & Seg managers |
a19e2543 | 111 | fBusPatchManager = new AliMpBusPatch(); |
112 | fBusPatchManager->ReadBusPatchFile(); | |
2cbb173f | 113 | |
114 | fSegFactory = new AliMpSegFactory(); | |
115 | ||
84ceeb06 | 116 | // timers |
2cbb173f | 117 | fTrackerTimer.Start(kTRUE); fTrackerTimer.Stop(); |
118 | fTriggerTimer.Start(kTRUE); fTriggerTimer.Stop(); | |
119 | fMappingTimer.Start(kTRUE); fMappingTimer.Stop(); | |
120 | ||
a19e2543 | 121 | } |
122 | ||
123 | //__________________________________________________________________________ | |
124 | AliMUONRawWriter::AliMUONRawWriter() | |
125 | : TObject(), | |
126 | fMUONData(0), | |
2cf44ef3 | 127 | fBlockHeader(0), |
128 | fDspHeader(0), | |
129 | fBusStruct(0), | |
130 | fDarcHeader(0), | |
131 | fRegHeader(0), | |
132 | fLocalStruct(0), | |
ced309a5 | 133 | fBusPatchManager(0), |
2cbb173f | 134 | fScalerEvent(kFALSE), |
135 | fSegFactory(0x0) | |
a19e2543 | 136 | { |
2cf44ef3 | 137 | // |
a19e2543 | 138 | // Default Constructor |
2cf44ef3 | 139 | // |
2cbb173f | 140 | AliDebug(1,"Default ctor"); |
141 | fFile[0] = fFile[1] = 0x0; | |
142 | fTrackerTimer.Start(kTRUE); fTrackerTimer.Stop(); | |
143 | fTriggerTimer.Start(kTRUE); fTriggerTimer.Stop(); | |
144 | fMappingTimer.Start(kTRUE); fMappingTimer.Stop(); | |
a19e2543 | 145 | } |
146 | ||
147 | //_______________________________________________________________________ | |
148 | AliMUONRawWriter::AliMUONRawWriter (const AliMUONRawWriter& rhs) | |
149 | : TObject(rhs) | |
150 | { | |
2cf44ef3 | 151 | // |
152 | // Protected copy constructor | |
153 | // | |
a19e2543 | 154 | AliFatal("Not implemented."); |
155 | } | |
156 | ||
157 | //_______________________________________________________________________ | |
158 | AliMUONRawWriter & | |
159 | AliMUONRawWriter::operator=(const AliMUONRawWriter& rhs) | |
160 | { | |
2cf44ef3 | 161 | // |
162 | // Protected assignement operator | |
163 | // | |
a19e2543 | 164 | if (this == &rhs) return *this; |
165 | ||
166 | AliFatal("Not implemented."); | |
167 | ||
168 | return *this; | |
169 | } | |
170 | ||
171 | //__________________________________________________________________________ | |
172 | AliMUONRawWriter::~AliMUONRawWriter(void) | |
173 | { | |
2cf44ef3 | 174 | // |
175 | // Destructor | |
176 | // | |
2cbb173f | 177 | AliDebug(1,"dtor"); |
178 | ||
2cf44ef3 | 179 | delete fBusArray; |
2cbb173f | 180 | |
2cf44ef3 | 181 | delete fBlockHeader; |
182 | delete fDspHeader; | |
183 | delete fBusStruct; | |
184 | delete fDarcHeader; | |
185 | delete fRegHeader; | |
186 | delete fLocalStruct; | |
a19e2543 | 187 | |
2cbb173f | 188 | delete fBusPatchManager; |
189 | ||
190 | delete fSegFactory; | |
191 | ||
192 | AliInfo(Form("Execution time for MUON tracker : R:%.2fs C:%.2fs", | |
193 | fTrackerTimer.RealTime(),fTrackerTimer.CpuTime())); | |
194 | AliInfo(Form(" Execution time for MUON tracker (mapping calls part) " | |
195 | ": R:%.2fs C:%.2fs", | |
196 | fMappingTimer.RealTime(),fMappingTimer.CpuTime())); | |
197 | AliInfo(Form("Execution time for MUON trigger : R:%.2fs C:%.2fs", | |
198 | fTriggerTimer.RealTime(),fTriggerTimer.CpuTime())); | |
a19e2543 | 199 | } |
2cbb173f | 200 | |
a19e2543 | 201 | //____________________________________________________________________ |
202 | Int_t AliMUONRawWriter::Digits2Raw() | |
203 | { | |
2cf44ef3 | 204 | // |
205 | // convert digits of the current event to raw data | |
206 | // | |
a19e2543 | 207 | Int_t idDDL; |
208 | Char_t name[20]; | |
209 | ||
2cbb173f | 210 | fMUONData->GetLoader()->LoadDigits("READ"); |
a19e2543 | 211 | |
212 | fMUONData->SetTreeAddress("D,GLT"); | |
213 | ||
2cbb173f | 214 | fMUONData->ResetDigits(); |
215 | fMUONData->ResetTrigger(); | |
216 | ||
217 | // This will get both tracker and trigger digits. | |
218 | fMUONData->GetDigits(); | |
219 | ||
a19e2543 | 220 | // tracking chambers |
221 | ||
2cbb173f | 222 | for (Int_t ich = 0; ich < AliMUONConstants::NTrackingCh(); ich++) |
223 | { | |
a19e2543 | 224 | // open files |
c7082611 | 225 | // idDDL = ich * 2 + AliDAQ::DdlIDOffset("MUONTRK"); // waiting update in STEER |
362c9d61 | 226 | idDDL = ich * 2; |
227 | strcpy(name,AliDAQ::DdlFileName("MUONTRK",idDDL)); | |
a19e2543 | 228 | fFile[0] = fopen(name,"w"); |
229 | ||
c7082611 | 230 | // idDDL = (ich * 2) + 1 + AliDAQ::DdlIDOffset("MUONTRK"); |
362c9d61 | 231 | idDDL = (ich * 2) + 1; |
232 | strcpy(name,AliDAQ::DdlFileName("MUONTRK",idDDL)); | |
a19e2543 | 233 | fFile[1] = fopen(name,"w"); |
2cbb173f | 234 | |
a19e2543 | 235 | WriteTrackerDDL(ich); |
236 | ||
237 | // reset and close | |
238 | fclose(fFile[0]); | |
239 | fclose(fFile[1]); | |
a19e2543 | 240 | } |
241 | ||
242 | // trigger chambers | |
243 | ||
244 | // open files | |
362c9d61 | 245 | idDDL = 0;// MUTR |
246 | strcpy(name,AliDAQ::DdlFileName("MUONTRG",idDDL)); | |
a19e2543 | 247 | fFile[0] = fopen(name,"w"); |
248 | ||
362c9d61 | 249 | idDDL = 1;// MUTR |
250 | strcpy(name,AliDAQ::DdlFileName("MUONTRG",idDDL)); | |
a19e2543 | 251 | fFile[1] = fopen(name,"w"); |
252 | ||
253 | WriteTriggerDDL(); | |
254 | ||
255 | // reset and close | |
256 | fclose(fFile[0]); | |
257 | fclose(fFile[1]); | |
2cbb173f | 258 | |
259 | fMUONData->ResetDigits(); | |
260 | fMUONData->ResetTrigger(); | |
261 | fMUONData->GetLoader()->UnloadDigits(); | |
a19e2543 | 262 | |
263 | return kTRUE; | |
264 | } | |
2cbb173f | 265 | |
a19e2543 | 266 | //____________________________________________________________________ |
267 | Int_t AliMUONRawWriter::WriteTrackerDDL(Int_t iCh) | |
268 | { | |
269 | // writing DDL for tracker | |
270 | // used inverse mapping | |
2cf44ef3 | 271 | // |
2cbb173f | 272 | fTrackerTimer.Start(kFALSE); |
273 | ||
2cf44ef3 | 274 | |
84aac932 | 275 | static const Int_t kMAXADC = (1<<12)-1; // We code the charge on a 12 bits ADC. |
2cf44ef3 | 276 | |
a19e2543 | 277 | // resets |
278 | TClonesArray* muonDigits = 0; | |
2cf44ef3 | 279 | |
280 | fBusArray->Delete(); | |
281 | ||
a19e2543 | 282 | |
283 | // | |
2cf44ef3 | 284 | TArrayI nbInBus; |
285 | ||
286 | nbInBus.Set(5000); | |
287 | ||
a19e2543 | 288 | nbInBus.Reset(); |
289 | ||
290 | // DDL header | |
2cf44ef3 | 291 | Int_t headerSize = sizeof(fHeader)/4; |
292 | ||
293 | // DDL event one per half chamber | |
a19e2543 | 294 | |
2cf44ef3 | 295 | // raw data |
a19e2543 | 296 | Char_t parity = 0x4; |
297 | UShort_t manuId = 0; | |
298 | UChar_t channelId = 0; | |
299 | UShort_t charge = 0; | |
300 | Int_t busPatchId = 0; | |
a19e2543 | 301 | UInt_t word; |
2cf44ef3 | 302 | |
84ceeb06 | 303 | |
304 | // Dsp length | |
305 | Int_t totalDspLength; | |
306 | Int_t dspLength; | |
307 | ||
2cf44ef3 | 308 | // block length |
309 | Int_t totalBlkLength; | |
310 | Int_t blkLength; | |
311 | ||
312 | // total DDL length | |
313 | Int_t totalDDLLength; | |
314 | ||
315 | // indexes | |
a19e2543 | 316 | Int_t index; |
317 | Int_t indexDsp; | |
318 | Int_t indexBlk; | |
2cf44ef3 | 319 | |
320 | // digits | |
321 | Int_t nEntries = 0; | |
322 | Int_t* buffer = 0; | |
a19e2543 | 323 | Int_t padX; |
324 | Int_t padY; | |
325 | Int_t cathode = 0; | |
326 | Int_t detElemId; | |
327 | Int_t nDigits; | |
328 | ||
329 | const AliMUONDigit* digit; | |
330 | ||
331 | AliDebug(3, Form("WriteDDL chamber %d\n", iCh+1)); | |
332 | ||
a19e2543 | 333 | muonDigits = fMUONData->Digits(iCh); |
334 | ||
335 | nDigits = muonDigits->GetEntriesFast(); | |
336 | AliDebug(3,Form("ndigits = %d\n",nDigits)); | |
337 | ||
338 | // loop over digit | |
339 | for (Int_t idig = 0; idig < nDigits; idig++) { | |
340 | ||
341 | digit = (AliMUONDigit*) muonDigits->UncheckedAt(idig); | |
342 | ||
343 | padX = digit->PadX(); | |
344 | padY = digit->PadY(); | |
ce13d60d | 345 | charge = digit->ADC(); |
84aac932 | 346 | if ( charge > kMAXADC ) |
2cbb173f | 347 | { |
348 | // This is most probably an error in the digitizer (which should insure | |
84aac932 | 349 | // the adc is below kMAXADC), so make it a (non-fatal) error indeed. |
2cbb173f | 350 | AliError(Form("adc value %d above %x. Setting to %x", |
84aac932 | 351 | charge,kMAXADC,kMAXADC)); |
352 | charge = kMAXADC; | |
2cbb173f | 353 | } |
a19e2543 | 354 | cathode = digit->Cathode(); |
355 | detElemId = digit->DetElemId(); | |
356 | ||
357 | // inverse mapping | |
2cbb173f | 358 | busPatchId = GetBusPatch(*digit); |
359 | if (busPatchId<0) continue; | |
360 | ||
361 | if ( digit->ManuId() > 0x7FF || digit->ManuId() < 0 || | |
362 | digit->ManuChannel() > 0x3F || digit->ManuChannel() < 0 ) | |
363 | { | |
364 | StdoutToAliError(digit->Print();); | |
365 | AliFatal("ManuId,ManuChannel are invalid for the digit above."); | |
366 | } | |
367 | ||
368 | manuId = ( digit->ManuId() & 0x7FF ); // 11 bits | |
369 | channelId = ( digit->ManuChannel() & 0x3F ); // 6 bits | |
2cf44ef3 | 370 | |
371 | AliDebug(3,Form("input IdDE %d busPatchId %d PadX %d PadY %d iCath %d \n", | |
a19e2543 | 372 | detElemId, busPatchId, padX, padY, cathode)); |
2cf44ef3 | 373 | |
a19e2543 | 374 | AliDebug(3,Form("busPatchId %d, manuId %d channelId %d\n", busPatchId, manuId, channelId )); |
2cf44ef3 | 375 | |
a19e2543 | 376 | //packing word |
6dee95a7 | 377 | word = 0; |
a19e2543 | 378 | AliBitPacking::PackWord((UInt_t)manuId,word,18,28); |
379 | AliBitPacking::PackWord((UInt_t)channelId,word,12,17); | |
380 | AliBitPacking::PackWord((UInt_t)charge,word,0,11); | |
381 | ||
6dee95a7 | 382 | // parity word |
383 | parity = word & 0x1; | |
384 | for (Int_t i = 1; i <= 30; i++) | |
385 | parity ^= ((word >> i) & 0x1); | |
386 | AliBitPacking::PackWord((UInt_t)parity,word,31,31); | |
6dee95a7 | 387 | |
a19e2543 | 388 | // set sub Event |
2cf44ef3 | 389 | fBusStruct->SetLength(0); |
390 | fBusStruct->AddData(word); | |
391 | fBusStruct->SetBusPatchId(busPatchId); | |
a19e2543 | 392 | |
393 | // storing the number of identical buspatches | |
394 | nbInBus[busPatchId]++; | |
2cf44ef3 | 395 | AddData(*fBusStruct); |
396 | ||
a19e2543 | 397 | } |
398 | ||
399 | // sorting by buspatch | |
2cf44ef3 | 400 | fBusArray->Sort(); |
a19e2543 | 401 | |
402 | // gather datas from same bus patch | |
2cf44ef3 | 403 | nEntries = fBusArray->GetEntriesFast(); |
a19e2543 | 404 | |
2cf44ef3 | 405 | for (Int_t i = 0; i < nEntries; i++) { |
406 | AliMUONBusStruct* temp = (AliMUONBusStruct*)fBusArray->At(i); | |
a19e2543 | 407 | busPatchId = temp->GetBusPatchId(); |
408 | ||
409 | // add bus patch header, length and total length managed by subevent class | |
2cf44ef3 | 410 | for (Int_t j = 0; j < nbInBus[busPatchId]-1; j++) { |
411 | AliMUONBusStruct* temp1 = (AliMUONBusStruct*)fBusArray->At(++i); | |
a19e2543 | 412 | temp->AddData(temp1->GetData(0)); |
2cf44ef3 | 413 | fBusArray->RemoveAt(i) ; |
a19e2543 | 414 | } |
415 | } | |
2cf44ef3 | 416 | fBusArray->Compress(); |
a19e2543 | 417 | |
2cf44ef3 | 418 | if (AliLog::GetGlobalDebugLevel() == 3) { |
419 | nEntries = fBusArray->GetEntriesFast(); | |
420 | for (Int_t i = 0; i < nEntries; i++) { | |
421 | AliMUONBusStruct* temp = (AliMUONBusStruct*)fBusArray->At(i); | |
a19e2543 | 422 | printf("busPatchid back %d\n",temp->GetBusPatchId()); |
2cf44ef3 | 423 | for (Int_t j = 0; j < temp->GetLength(); j++) { |
424 | printf("manuId back %d, ",temp->GetManuId(j)); | |
425 | printf("channelId back %d, ",temp->GetChannelId(j)); | |
426 | printf("charge back %d\n",temp->GetCharge(j)); | |
a19e2543 | 427 | } |
428 | } | |
429 | printf("\n"); | |
430 | } | |
431 | ||
432 | // getting info for the number of buspatches | |
433 | Int_t iBusPatch; | |
434 | Int_t length; | |
435 | Int_t iBusPerDSP[5];//number of bus patches per DSP | |
436 | Int_t iDspMax; //number max of DSP per block | |
a19e2543 | 437 | Int_t iFile = 0; |
438 | fBusPatchManager->GetDspInfo(iCh, iDspMax, iBusPerDSP); | |
439 | ||
440 | TArrayI* vec = fBusPatchManager->GetBusfromDE((iCh+1)*100); | |
441 | ||
442 | Int_t iBus0AtCh = vec->At(0); //get first bus patch id for a given ich | |
c7082611 | 443 | |
a19e2543 | 444 | AliDebug(3,Form("iBus0AtCh %d", iBus0AtCh)); |
445 | ||
446 | iBusPatch = iBus0AtCh - 1; // starting point for each chamber | |
447 | ||
2cf44ef3 | 448 | // nEntries = fBusArray->GetEntriesFast(); |
84ceeb06 | 449 | |
450 | AliMUONBusStruct* busStructPtr = 0x0; | |
2cf44ef3 | 451 | |
a19e2543 | 452 | // open DDL file, on per 1/2 chamber |
2cf44ef3 | 453 | for (Int_t iDDL = 0; iDDL < 2; iDDL++) { |
454 | ||
455 | totalDDLLength = 0; | |
456 | ||
a19e2543 | 457 | // filling buffer |
84ceeb06 | 458 | buffer = new Int_t [(2048+24)*50]; // 24 words at most for one buspatch and 2048 manu info at most |
2cf44ef3 | 459 | |
a19e2543 | 460 | indexBlk = 0; |
461 | indexDsp = 0; | |
462 | index = 0; | |
2cf44ef3 | 463 | |
a19e2543 | 464 | // two blocks A and B per DDL |
2cf44ef3 | 465 | for (Int_t iBlock = 0; iBlock < 2; iBlock++) { |
466 | ||
a19e2543 | 467 | // block header |
2cf44ef3 | 468 | length = fBlockHeader->GetHeaderLength(); |
469 | memcpy(&buffer[index],fBlockHeader->GetHeader(),length*4); | |
a19e2543 | 470 | indexBlk = index; |
471 | index += length; | |
2cf44ef3 | 472 | |
a19e2543 | 473 | // 5 DSP's max per block |
2cf44ef3 | 474 | for (Int_t iDsp = 0; iDsp < iDspMax; iDsp++) { |
475 | ||
476 | // DSP header | |
477 | length = fDspHeader->GetHeaderLength(); | |
478 | memcpy(&buffer[index],fDspHeader->GetHeader(),length*4); | |
479 | indexDsp = index; | |
480 | index += length; | |
481 | ||
482 | //Â 5 buspatches max per DSP | |
483 | for (Int_t i = 0; i < iBusPerDSP[iDsp]; i++) { | |
484 | ||
485 | iBusPatch++; | |
486 | if ((fBusPatchManager->GetDDLfromBus(iBusPatch) % 2) == 0) // comparing to DDL file | |
487 | iFile = 1; | |
488 | else | |
489 | iFile = 0; | |
490 | ||
491 | AliDebug(3,Form("iCh %d iDDL %d iBlock %d iDsp %d busPatchId %d", iCh, iDDL, iBlock, iDsp, iBusPatch)); | |
492 | ||
493 | nEntries = fBusArray->GetEntriesFast(); | |
cd640dc7 | 494 | busPatchId = -1; |
84ceeb06 | 495 | |
2cf44ef3 | 496 | for (Int_t iEntries = 0; iEntries < nEntries; iEntries++) { // method "bourrique"... |
84ceeb06 | 497 | busStructPtr = (AliMUONBusStruct*)fBusArray->At(iEntries); |
498 | busPatchId = busStructPtr->GetBusPatchId(); | |
2cf44ef3 | 499 | if (busPatchId == iBusPatch) break; |
500 | busPatchId = -1; | |
84ceeb06 | 501 | AliDebug(3,Form("busPatchId %d", busStructPtr->GetBusPatchId())); |
2cf44ef3 | 502 | } |
503 | ||
504 | // check if buspatchid has digit | |
505 | if (busPatchId != -1) { | |
84ceeb06 | 506 | // add bus patch structure header |
507 | length = busStructPtr->GetHeaderLength(); | |
508 | memcpy(&buffer[index],busStructPtr->GetHeader(),length*4); | |
2cf44ef3 | 509 | index += length; |
84ceeb06 | 510 | |
511 | // add bus patch data | |
512 | for (Int_t j = 0; j < busStructPtr->GetLength(); j++) { | |
513 | buffer[index++] = busStructPtr->GetData(j); | |
514 | AliDebug(3,Form("busPatchId %d, manuId %d channelId %d\n", | |
515 | busStructPtr->GetBusPatchId(), | |
516 | busStructPtr->GetManuId(j), busStructPtr->GetChannelId(j) )); | |
2cf44ef3 | 517 | } |
518 | // fBusArray->RemoveAt(iEntries); | |
519 | // fBusArray->Compress(); | |
520 | } else { | |
521 | // writting anyhow buspatch structure (empty ones) | |
84ceeb06 | 522 | buffer[index++] = busStructPtr->GetDefaultDataKey(); // fill it also for empty data size |
523 | buffer[index++] = busStructPtr->GetHeaderLength(); // header length | |
2cf44ef3 | 524 | buffer[index++] = 0; // raw data length |
525 | buffer[index++] = iBusPatch; // bus patch | |
2cf44ef3 | 526 | } |
527 | } // bus patch | |
528 | ||
86400e61 | 529 | // check if totalLength even |
530 | // set padding word in case | |
531 | // Add one word 0xBEEFFACE at the end of DSP structure | |
532 | totalDspLength = index - indexDsp; | |
533 | if ((totalDspLength % 2) == 1) { | |
534 | buffer[indexDsp + fDspHeader->GetHeaderLength() - 2] = 1; | |
535 | buffer[index++] = fDspHeader->GetDefaultPaddingWord(); | |
536 | totalDspLength++; | |
537 | } | |
538 | ||
84ceeb06 | 539 | dspLength = totalDspLength - fDspHeader->GetHeaderLength(); |
540 | ||
541 | buffer[indexDsp+1] = totalDspLength; // dsp total length | |
542 | buffer[indexDsp+2] = dspLength; // data length | |
84ceeb06 | 543 | |
a19e2543 | 544 | } // dsp |
2cf44ef3 | 545 | |
546 | totalBlkLength = index - indexBlk; | |
547 | blkLength = totalBlkLength - fBlockHeader->GetHeaderLength(); | |
548 | totalDDLLength += totalBlkLength; | |
549 | ||
84ceeb06 | 550 | buffer[indexBlk+1] = totalBlkLength; // total block length |
551 | buffer[indexBlk+2] = blkLength; | |
2cf44ef3 | 552 | |
553 | } // block | |
a19e2543 | 554 | |
555 | //writting onto disk | |
556 | // write DDL 1 & 2 | |
2cf44ef3 | 557 | fHeader.fSize = (totalDDLLength + headerSize) * 4;// total length in bytes |
558 | fwrite((char*)(&fHeader),headerSize*4,1,fFile[iFile]); | |
a19e2543 | 559 | fwrite(buffer,sizeof(int),index,fFile[iFile]); |
2cf44ef3 | 560 | |
a19e2543 | 561 | delete[] buffer; |
562 | } | |
563 | ||
2cbb173f | 564 | fTrackerTimer.Stop(); |
a19e2543 | 565 | return kTRUE; |
566 | } | |
ced309a5 | 567 | |
568 | //____________________________________________________________________ | |
2cbb173f | 569 | Int_t AliMUONRawWriter::GetBusPatch(const AliMUONDigit& digit) |
ced309a5 | 570 | { |
2cf44ef3 | 571 | // |
2cbb173f | 572 | // Determine the BusPatch this digit belongs to. |
2cf44ef3 | 573 | // |
2cbb173f | 574 | fMappingTimer.Start(kFALSE); |
575 | ||
ced309a5 | 576 | Int_t* ptr = 0; |
577 | ||
578 | // information from digits | |
2cbb173f | 579 | Int_t detElemId = digit.DetElemId(); |
580 | ||
581 | AliMpVSegmentation* seg = | |
582 | fSegFactory->CreateMpSegmentationByElectronics(detElemId, digit.ManuId()); | |
583 | ||
584 | AliMpPlaneType plane = seg->PlaneType(); | |
ced309a5 | 585 | |
2cbb173f | 586 | AliMpStationType stationType = AliMpDEManager::GetStationType(detElemId); |
ced309a5 | 587 | |
2cbb173f | 588 | if ( stationType == kStation1 || stationType == kStation2 ) |
589 | { | |
590 | if (plane == kBendingPlane) | |
591 | { | |
592 | ptr = &fgManuPerBusSwp1B[0]; | |
593 | } | |
594 | else | |
595 | { | |
596 | ptr = &fgManuPerBusSwp1NB[0]; | |
ced309a5 | 597 | } |
598 | } | |
2cbb173f | 599 | else |
600 | { | |
601 | if (plane == kBendingPlane) | |
602 | { | |
603 | ptr = &fgManuPerBusSwp2B[0]; | |
604 | } | |
605 | else | |
606 | { | |
607 | ptr = &fgManuPerBusSwp2NB[0]; | |
608 | } | |
ced309a5 | 609 | } |
610 | ||
ced309a5 | 611 | // Getting buspatch id |
2cbb173f | 612 | TArrayI* vec = fBusPatchManager->GetBusfromDE(detElemId); |
ced309a5 | 613 | Int_t pos = 0; |
614 | ||
2cbb173f | 615 | Int_t m = ( digit.ManuId() & 0x3FF ); // remove bit 10 |
616 | //FIXME : how can we remove that condition | |
617 | // on the 10-th bit ? All the rest need not any knowledge about it, | |
618 | // can't we find a way to get manu<->buspatch transparent to this too ? | |
619 | ||
620 | if ( stationType == kStation1 || stationType == kStation2 ) | |
621 | { | |
ced309a5 | 622 | for (Int_t i = 0; i < 12; i++) |
2cbb173f | 623 | { |
624 | if (m >= *(ptr + pos++)) break; | |
625 | } | |
626 | } | |
627 | else | |
628 | { | |
ced309a5 | 629 | // offset of 100 in manuId for following bus patch |
2cbb173f | 630 | pos = m/100; |
ced309a5 | 631 | } |
632 | ||
633 | if (pos >(Int_t) vec->GetSize()) | |
2cbb173f | 634 | { |
635 | AliError(Form("pos greater %d than size %d manuId %d detElemId %d \n", | |
636 | pos, (Int_t)vec->GetSize(), digit.ManuId(), detElemId)); | |
637 | AliError(Form("Chamber %s Plane %s manuId %d m %d", | |
638 | StationTypeName(stationType).Data(), | |
639 | PlaneTypeName(plane).Data(), | |
640 | digit.ManuId(), | |
641 | m)); | |
642 | return -1; | |
643 | } | |
ced309a5 | 644 | |
2cbb173f | 645 | Int_t busPatchId = vec->At(pos); |
ced309a5 | 646 | |
2cbb173f | 647 | fMappingTimer.Stop(); |
648 | ||
649 | return busPatchId; | |
ced309a5 | 650 | } |
651 | ||
a19e2543 | 652 | //____________________________________________________________________ |
653 | Int_t AliMUONRawWriter::WriteTriggerDDL() | |
654 | { | |
2cf44ef3 | 655 | // |
656 | // Write trigger DDL | |
657 | // | |
2cbb173f | 658 | fTriggerTimer.Start(kFALSE); |
659 | ||
a19e2543 | 660 | // DDL event one per half chamber |
a19e2543 | 661 | |
a19e2543 | 662 | // stored local id number |
663 | TArrayI isFired(256); | |
664 | isFired.Reset(); | |
665 | ||
666 | ||
2cf44ef3 | 667 | // DDL header size |
668 | Int_t headerSize = sizeof(AliRawDataHeader)/4; | |
ced309a5 | 669 | |
a19e2543 | 670 | TClonesArray* localTrigger; |
671 | TClonesArray* globalTrigger; | |
672 | AliMUONGlobalTrigger* gloTrg; | |
673 | AliMUONLocalTrigger* locTrg = 0x0; | |
674 | ||
a19e2543 | 675 | // global trigger for trigger pattern |
676 | globalTrigger = fMUONData->GlobalTrigger(); | |
677 | gloTrg = (AliMUONGlobalTrigger*)globalTrigger->UncheckedAt(0); | |
2cf44ef3 | 678 | Int_t gloTrigPat = gloTrg->GetGlobalPattern(); |
a19e2543 | 679 | |
680 | // local trigger | |
681 | localTrigger = fMUONData->LocalTrigger(); | |
682 | ||
683 | UInt_t word; | |
684 | Int_t* buffer = 0; | |
685 | Int_t index; | |
686 | Int_t iEntries = 0; | |
687 | Int_t iLocCard, locCard; | |
688 | Char_t locDec, trigY, posY, posX,regOut; | |
689 | Int_t devX; | |
690 | Int_t version = 1; // software version | |
d622a0ec | 691 | Int_t eventPhys = 1; // trigger type: 1 for physics, 0 for software |
a19e2543 | 692 | Int_t serialNb = 0xF; // serial nb of card: all bits on for the moment |
d622a0ec | 693 | Int_t globalFlag = 0; // set to 1 if global info present in DDL else set to 0 |
694 | ||
695 | // size of headers | |
696 | static const Int_t kDarcHeaderLength = fDarcHeader->GetDarcHeaderLength(); | |
697 | static const Int_t kGlobalHeaderLength = fDarcHeader->GetGlobalHeaderLength(); | |
698 | static const Int_t kDarcScalerLength = fDarcHeader->GetDarcScalerLength(); | |
699 | static const Int_t kGlobalScalerLength = fDarcHeader->GetGlobalScalerLength(); | |
700 | static const Int_t kRegHeaderLength = fRegHeader->GetHeaderLength(); | |
701 | static const Int_t kRegScalerLength = fRegHeader->GetScalerLength(); | |
702 | static const Int_t kLocHeaderLength = fLocalStruct->GetLength(); | |
703 | static const Int_t kLocScalerLength = fLocalStruct->GetScalerLength(); | |
704 | ||
705 | // [16(local)*6 words + 6 words]*8(reg) + 8 words = 824 | |
706 | static const Int_t kBufferSize = (16 * (kLocHeaderLength+1) + (kRegHeaderLength+1))* 8 | |
707 | + kDarcHeaderLength + kGlobalHeaderLength + 2; | |
708 | ||
709 | // [16(local)*51 words + 16 words]*8(reg) + 8 + 10 + 8 words scaler event 6682 words | |
710 | static const Int_t kScalerBufferSize = (16 * (kLocHeaderLength + kLocScalerLength +1) + | |
711 | (kRegHeaderLength + kRegScalerLength +1))* 8 + | |
712 | (kDarcHeaderLength + kDarcScalerLength + | |
713 | kGlobalHeaderLength + kGlobalScalerLength + 2); | |
ced309a5 | 714 | if(fScalerEvent) |
d622a0ec | 715 | eventPhys = 0; //set to generate scaler events |
ced309a5 | 716 | |
a19e2543 | 717 | Int_t nEntries = (Int_t) (localTrigger->GetEntries());// 234 local cards |
718 | // stored the local card id that's fired | |
719 | for (Int_t i = 0; i < nEntries; i++) { | |
720 | locTrg = (AliMUONLocalTrigger*)localTrigger->At(i); | |
721 | isFired[locTrg->LoCircuit()] = 1; // storing local boards with informations | |
722 | } | |
723 | ||
724 | if (!nEntries) | |
62c04fc3 | 725 | AliInfo("No Trigger information available"); |
a19e2543 | 726 | |
ced309a5 | 727 | if(fScalerEvent) |
d622a0ec | 728 | buffer = new Int_t [kScalerBufferSize]; |
ced309a5 | 729 | else |
d622a0ec | 730 | buffer = new Int_t [kBufferSize]; |
ced309a5 | 731 | |
a19e2543 | 732 | |
733 | // open DDL file, on per 1/2 chamber | |
734 | for (Int_t iDDL = 0; iDDL < 2; iDDL++) { | |
735 | ||
736 | index = 0; | |
737 | ||
a19e2543 | 738 | if (iDDL == 0) // suppose global info in DDL one |
a19e2543 | 739 | globalFlag = 1; |
d622a0ec | 740 | else |
741 | globalFlag = 0; | |
ced309a5 | 742 | |
d622a0ec | 743 | word = 0; |
744 | // set darc status word | |
745 | // see AliMUONDarcHeader.h for details | |
746 | AliBitPacking::PackWord((UInt_t)eventPhys,word,30,30); | |
747 | AliBitPacking::PackWord((UInt_t)serialNb,word,20,23); | |
748 | AliBitPacking::PackWord((UInt_t)globalFlag,word,10,10); | |
749 | AliBitPacking::PackWord((UInt_t)version,word,12,19); | |
2cf44ef3 | 750 | fDarcHeader->SetWord(word); |
18d3ded7 | 751 | |
d622a0ec | 752 | memcpy(&buffer[index], fDarcHeader->GetHeader(), (kDarcHeaderLength)*4); |
18d3ded7 | 753 | index += fDarcHeader->GetDarcHeaderLength(); |
a19e2543 | 754 | |
755 | if (iDDL == 0) | |
2cf44ef3 | 756 | fDarcHeader->SetGlobalOutput(gloTrigPat);// no global input for the moment.... |
a19e2543 | 757 | else |
2cf44ef3 | 758 | fDarcHeader->SetGlobalOutput(0); |
ced309a5 | 759 | |
760 | if (fScalerEvent) { | |
761 | // 6 DARC scaler words | |
d622a0ec | 762 | memcpy(&buffer[index], fDarcHeader->GetDarcScalers(),kDarcScalerLength*4); |
2cf44ef3 | 763 | index += fDarcHeader->GetDarcScalerLength(); |
ced309a5 | 764 | } |
2cf44ef3 | 765 | // end of darc word |
766 | buffer[index++] = fDarcHeader->GetEndOfDarc(); | |
ced309a5 | 767 | |
768 | // 4 words of global board input + Global board output | |
d622a0ec | 769 | memcpy(&buffer[index], fDarcHeader->GetGlobalInput(), (kGlobalHeaderLength)*4); |
18d3ded7 | 770 | index += fDarcHeader->GetGlobalHeaderLength(); |
ced309a5 | 771 | |
772 | if (fScalerEvent) { | |
773 | // 10 Global scaler words | |
d622a0ec | 774 | memcpy(fDarcHeader->GetGlobalScalers(), &buffer[index], kGlobalScalerLength*4); |
2cf44ef3 | 775 | index += fDarcHeader->GetGlobalScalerLength(); |
ced309a5 | 776 | } |
a19e2543 | 777 | |
2cf44ef3 | 778 | // end of global word |
779 | buffer[index++] = fDarcHeader->GetEndOfGlobal(); | |
780 | ||
a19e2543 | 781 | // 8 regional cards per DDL |
782 | for (Int_t iReg = 0; iReg < 8; iReg++) { | |
783 | ||
a19e2543 | 784 | // Regional card header |
785 | word = 0; | |
00f56161 | 786 | |
787 | // set darc status word | |
788 | fRegHeader->SetDarcWord(word); | |
789 | ||
a19e2543 | 790 | regOut = 0; |
d622a0ec | 791 | // fill darc word, not darc status for the moment (empty) |
792 | //see AliMUONRegHeader.h for details | |
793 | AliBitPacking::PackWord((UInt_t)eventPhys,word,31,31); | |
794 | AliBitPacking::PackWord((UInt_t)serialNb,word,19,24); | |
a19e2543 | 795 | AliBitPacking::PackWord((UInt_t)version,word,16,23); |
d622a0ec | 796 | AliBitPacking::PackWord((UInt_t)iReg,word,15,18); |
a19e2543 | 797 | AliBitPacking::PackWord((UInt_t)regOut,word,0,7); // whenever regional output will be implemented |
2cf44ef3 | 798 | fRegHeader->SetWord(word); |
d622a0ec | 799 | |
2cf44ef3 | 800 | memcpy(&buffer[index],fRegHeader->GetHeader(),fRegHeader->GetHeaderLength()*4); |
801 | index += fRegHeader->GetHeaderLength(); | |
a19e2543 | 802 | |
ced309a5 | 803 | // 11 regional scaler word |
804 | if (fScalerEvent) { | |
2cf44ef3 | 805 | memcpy(&buffer[index], fRegHeader->GetScalers(), fRegHeader->GetScalerLength()*4); |
806 | index += fRegHeader->GetScalerLength(); | |
ced309a5 | 807 | } |
a19e2543 | 808 | |
2cf44ef3 | 809 | // end of regional word |
810 | buffer[index++] = fRegHeader->GetEndOfReg(); | |
811 | ||
a19e2543 | 812 | // 16 local card per regional board |
813 | for (Int_t iLoc = 0; iLoc < 16; iLoc++) { | |
814 | ||
815 | iLocCard = iLoc + iReg*16 + iDDL*128; | |
816 | ||
817 | if (isFired[iLocCard]) { | |
818 | locTrg = (AliMUONLocalTrigger*)localTrigger->At(iEntries); | |
819 | locCard = locTrg->LoCircuit(); | |
820 | locDec = locTrg->GetLoDecision(); | |
821 | trigY = 0; | |
822 | posY = locTrg->LoStripY(); | |
823 | posX = locTrg->LoStripX(); | |
824 | devX = locTrg->LoDev(); | |
825 | AliDebug(4,Form("loctrg %d, posX %d, posY %d, devX %d\n", | |
826 | locTrg->LoCircuit(),locTrg->LoStripX(),locTrg->LoStripY(),locTrg->LoDev())); | |
827 | } else { //no trigger (see PRR chpt 3.4) | |
2cf44ef3 | 828 | locCard = -1; // not possible on 4 bits |
a19e2543 | 829 | locDec = 0; |
830 | trigY = 1; | |
831 | posY = 15; | |
832 | posX = 0; | |
833 | devX = 0x8; | |
834 | } | |
835 | ||
836 | //packing word | |
837 | word = 0; | |
838 | AliBitPacking::PackWord((UInt_t)(iLocCard % 16),word,19,22); //card id number in crate | |
839 | AliBitPacking::PackWord((UInt_t)locDec,word,15,18); | |
840 | AliBitPacking::PackWord((UInt_t)trigY,word,14,14); | |
841 | AliBitPacking::PackWord((UInt_t)posY,word,10,13); | |
842 | AliBitPacking::PackWord((UInt_t)devX,word,5,9); | |
843 | AliBitPacking::PackWord((UInt_t)posX,word,0,4); | |
844 | ||
845 | if (locCard == iLocCard) { | |
846 | // add local cards structure | |
847 | buffer[index++] = (locTrg->GetX1Pattern() | (locTrg->GetX2Pattern() << 16)); | |
848 | buffer[index++] = (locTrg->GetX3Pattern() | (locTrg->GetX4Pattern() << 16)); | |
849 | buffer[index++] = (locTrg->GetY1Pattern() | (locTrg->GetY2Pattern() << 16)); | |
850 | buffer[index++] = (locTrg->GetY3Pattern() | (locTrg->GetY4Pattern() << 16)); | |
851 | buffer[index++] = (Int_t)word; // data word | |
852 | if (iEntries < nEntries-1) | |
853 | iEntries++; | |
854 | } else { | |
855 | buffer[index++] = 0; // 4 words for x1, x2, y1, y2 | |
856 | buffer[index++] = 0; | |
857 | buffer[index++] = 0; | |
858 | buffer[index++] = 0; | |
859 | buffer[index++] = (Int_t)word; // data word | |
860 | ||
861 | } | |
ced309a5 | 862 | // 45 regional scaler word |
863 | if (fScalerEvent) { | |
2cf44ef3 | 864 | memcpy(&buffer[index], fLocalStruct->GetScalers(), fLocalStruct->GetScalerLength()*4); |
865 | index += fLocalStruct->GetScalerLength(); | |
ced309a5 | 866 | } |
867 | ||
2cf44ef3 | 868 | // end of local structure words |
869 | buffer[index++] = fLocalStruct->GetEndOfLocal(); | |
a19e2543 | 870 | |
2cf44ef3 | 871 | } // local card |
a19e2543 | 872 | |
873 | } // Regional card | |
874 | ||
a19e2543 | 875 | |
876 | // writting onto disk | |
877 | // write DDL 1 | |
2cf44ef3 | 878 | fHeader.fSize = (index + headerSize) * 4;// total length in bytes |
879 | fwrite((char*)(&fHeader),headerSize*4,1,fFile[iDDL]); | |
a19e2543 | 880 | fwrite(buffer,sizeof(int),index,fFile[iDDL]); |
881 | ||
882 | } | |
883 | delete[] buffer; | |
884 | ||
2cbb173f | 885 | fTriggerTimer.Stop(); |
886 | ||
ced309a5 | 887 | return kTRUE; |
a19e2543 | 888 | } |
84ceeb06 | 889 | //____________________________________________________________________ |
890 | void AliMUONRawWriter::SetScalersNumbers() | |
891 | { | |
892 | // set numbers for scaler events for trigger headers | |
893 | // since this is provided by the experiment | |
894 | // put dummy numbers to check the monitoring | |
895 | ||
896 | fDarcHeader->SetScalersNumbers(); | |
897 | fRegHeader->SetScalersNumbers(); | |
898 | fLocalStruct->SetScalersNumbers(); | |
899 | ||
900 | fScalerEvent = kTRUE; | |
901 | } |