]>
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 |
226 | idDDL = ich * 2 + 0x900; // official number for MUON | |
a19e2543 | 227 | sprintf(name, "MUON_%d.ddl",idDDL); |
228 | fFile[0] = fopen(name,"w"); | |
229 | ||
c7082611 | 230 | // idDDL = (ich * 2) + 1 + AliDAQ::DdlIDOffset("MUONTRK"); |
231 | idDDL = (ich * 2) + 1 + 0x900; | |
a19e2543 | 232 | sprintf(name, "MUON_%d.ddl",idDDL); |
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 | |
c7082611 | 245 | // idDDL = AliDAQ::DdlIDOffset("MUONTRG"); |
246 | idDDL = 0xA00;// official number for MUTR | |
a19e2543 | 247 | sprintf(name, "MUTR_%d.ddl",idDDL); |
248 | fFile[0] = fopen(name,"w"); | |
249 | ||
c7082611 | 250 | // idDDL = AliDAQ::DdlIDOffset("MUONTRG") + 1; |
251 | idDDL = 0xA00 + 1;// official number for MUTR | |
a19e2543 | 252 | sprintf(name, "MUTR_%d.ddl",idDDL); |
253 | fFile[1] = fopen(name,"w"); | |
254 | ||
255 | WriteTriggerDDL(); | |
256 | ||
257 | // reset and close | |
258 | fclose(fFile[0]); | |
259 | fclose(fFile[1]); | |
2cbb173f | 260 | |
261 | fMUONData->ResetDigits(); | |
262 | fMUONData->ResetTrigger(); | |
263 | fMUONData->GetLoader()->UnloadDigits(); | |
a19e2543 | 264 | |
265 | return kTRUE; | |
266 | } | |
2cbb173f | 267 | |
a19e2543 | 268 | //____________________________________________________________________ |
269 | Int_t AliMUONRawWriter::WriteTrackerDDL(Int_t iCh) | |
270 | { | |
271 | // writing DDL for tracker | |
272 | // used inverse mapping | |
2cf44ef3 | 273 | // |
2cbb173f | 274 | fTrackerTimer.Start(kFALSE); |
275 | ||
2cf44ef3 | 276 | |
84aac932 | 277 | static const Int_t kMAXADC = (1<<12)-1; // We code the charge on a 12 bits ADC. |
2cf44ef3 | 278 | |
a19e2543 | 279 | // resets |
280 | TClonesArray* muonDigits = 0; | |
2cf44ef3 | 281 | |
282 | fBusArray->Delete(); | |
283 | ||
a19e2543 | 284 | |
285 | // | |
2cf44ef3 | 286 | TArrayI nbInBus; |
287 | ||
288 | nbInBus.Set(5000); | |
289 | ||
a19e2543 | 290 | nbInBus.Reset(); |
291 | ||
292 | // DDL header | |
2cf44ef3 | 293 | Int_t headerSize = sizeof(fHeader)/4; |
294 | ||
295 | // DDL event one per half chamber | |
a19e2543 | 296 | |
2cf44ef3 | 297 | // raw data |
a19e2543 | 298 | Char_t parity = 0x4; |
299 | UShort_t manuId = 0; | |
300 | UChar_t channelId = 0; | |
301 | UShort_t charge = 0; | |
302 | Int_t busPatchId = 0; | |
a19e2543 | 303 | UInt_t word; |
2cf44ef3 | 304 | |
84ceeb06 | 305 | |
306 | // Dsp length | |
307 | Int_t totalDspLength; | |
308 | Int_t dspLength; | |
309 | ||
2cf44ef3 | 310 | // block length |
311 | Int_t totalBlkLength; | |
312 | Int_t blkLength; | |
313 | ||
314 | // total DDL length | |
315 | Int_t totalDDLLength; | |
316 | ||
317 | // indexes | |
a19e2543 | 318 | Int_t index; |
319 | Int_t indexDsp; | |
320 | Int_t indexBlk; | |
2cf44ef3 | 321 | |
322 | // digits | |
323 | Int_t nEntries = 0; | |
324 | Int_t* buffer = 0; | |
a19e2543 | 325 | Int_t padX; |
326 | Int_t padY; | |
327 | Int_t cathode = 0; | |
328 | Int_t detElemId; | |
329 | Int_t nDigits; | |
330 | ||
331 | const AliMUONDigit* digit; | |
332 | ||
333 | AliDebug(3, Form("WriteDDL chamber %d\n", iCh+1)); | |
334 | ||
a19e2543 | 335 | muonDigits = fMUONData->Digits(iCh); |
336 | ||
337 | nDigits = muonDigits->GetEntriesFast(); | |
338 | AliDebug(3,Form("ndigits = %d\n",nDigits)); | |
339 | ||
340 | // loop over digit | |
341 | for (Int_t idig = 0; idig < nDigits; idig++) { | |
342 | ||
343 | digit = (AliMUONDigit*) muonDigits->UncheckedAt(idig); | |
344 | ||
345 | padX = digit->PadX(); | |
346 | padY = digit->PadY(); | |
ce13d60d | 347 | charge = digit->ADC(); |
84aac932 | 348 | if ( charge > kMAXADC ) |
2cbb173f | 349 | { |
350 | // This is most probably an error in the digitizer (which should insure | |
84aac932 | 351 | // the adc is below kMAXADC), so make it a (non-fatal) error indeed. |
2cbb173f | 352 | AliError(Form("adc value %d above %x. Setting to %x", |
84aac932 | 353 | charge,kMAXADC,kMAXADC)); |
354 | charge = kMAXADC; | |
2cbb173f | 355 | } |
a19e2543 | 356 | cathode = digit->Cathode(); |
357 | detElemId = digit->DetElemId(); | |
358 | ||
359 | // inverse mapping | |
2cbb173f | 360 | busPatchId = GetBusPatch(*digit); |
361 | if (busPatchId<0) continue; | |
362 | ||
363 | if ( digit->ManuId() > 0x7FF || digit->ManuId() < 0 || | |
364 | digit->ManuChannel() > 0x3F || digit->ManuChannel() < 0 ) | |
365 | { | |
366 | StdoutToAliError(digit->Print();); | |
367 | AliFatal("ManuId,ManuChannel are invalid for the digit above."); | |
368 | } | |
369 | ||
370 | manuId = ( digit->ManuId() & 0x7FF ); // 11 bits | |
371 | channelId = ( digit->ManuChannel() & 0x3F ); // 6 bits | |
2cf44ef3 | 372 | |
373 | AliDebug(3,Form("input IdDE %d busPatchId %d PadX %d PadY %d iCath %d \n", | |
a19e2543 | 374 | detElemId, busPatchId, padX, padY, cathode)); |
2cf44ef3 | 375 | |
a19e2543 | 376 | AliDebug(3,Form("busPatchId %d, manuId %d channelId %d\n", busPatchId, manuId, channelId )); |
2cf44ef3 | 377 | |
a19e2543 | 378 | //packing word |
6dee95a7 | 379 | word = 0; |
a19e2543 | 380 | AliBitPacking::PackWord((UInt_t)manuId,word,18,28); |
381 | AliBitPacking::PackWord((UInt_t)channelId,word,12,17); | |
382 | AliBitPacking::PackWord((UInt_t)charge,word,0,11); | |
383 | ||
6dee95a7 | 384 | // parity word |
385 | parity = word & 0x1; | |
386 | for (Int_t i = 1; i <= 30; i++) | |
387 | parity ^= ((word >> i) & 0x1); | |
388 | AliBitPacking::PackWord((UInt_t)parity,word,31,31); | |
6dee95a7 | 389 | |
a19e2543 | 390 | // set sub Event |
2cf44ef3 | 391 | fBusStruct->SetLength(0); |
392 | fBusStruct->AddData(word); | |
393 | fBusStruct->SetBusPatchId(busPatchId); | |
a19e2543 | 394 | |
395 | // storing the number of identical buspatches | |
396 | nbInBus[busPatchId]++; | |
2cf44ef3 | 397 | AddData(*fBusStruct); |
398 | ||
a19e2543 | 399 | } |
400 | ||
401 | // sorting by buspatch | |
2cf44ef3 | 402 | fBusArray->Sort(); |
a19e2543 | 403 | |
404 | // gather datas from same bus patch | |
2cf44ef3 | 405 | nEntries = fBusArray->GetEntriesFast(); |
a19e2543 | 406 | |
2cf44ef3 | 407 | for (Int_t i = 0; i < nEntries; i++) { |
408 | AliMUONBusStruct* temp = (AliMUONBusStruct*)fBusArray->At(i); | |
a19e2543 | 409 | busPatchId = temp->GetBusPatchId(); |
410 | ||
411 | // add bus patch header, length and total length managed by subevent class | |
2cf44ef3 | 412 | for (Int_t j = 0; j < nbInBus[busPatchId]-1; j++) { |
413 | AliMUONBusStruct* temp1 = (AliMUONBusStruct*)fBusArray->At(++i); | |
a19e2543 | 414 | temp->AddData(temp1->GetData(0)); |
2cf44ef3 | 415 | fBusArray->RemoveAt(i) ; |
a19e2543 | 416 | } |
417 | } | |
2cf44ef3 | 418 | fBusArray->Compress(); |
a19e2543 | 419 | |
2cf44ef3 | 420 | if (AliLog::GetGlobalDebugLevel() == 3) { |
421 | nEntries = fBusArray->GetEntriesFast(); | |
422 | for (Int_t i = 0; i < nEntries; i++) { | |
423 | AliMUONBusStruct* temp = (AliMUONBusStruct*)fBusArray->At(i); | |
a19e2543 | 424 | printf("busPatchid back %d\n",temp->GetBusPatchId()); |
2cf44ef3 | 425 | for (Int_t j = 0; j < temp->GetLength(); j++) { |
426 | printf("manuId back %d, ",temp->GetManuId(j)); | |
427 | printf("channelId back %d, ",temp->GetChannelId(j)); | |
428 | printf("charge back %d\n",temp->GetCharge(j)); | |
a19e2543 | 429 | } |
430 | } | |
431 | printf("\n"); | |
432 | } | |
433 | ||
434 | // getting info for the number of buspatches | |
435 | Int_t iBusPatch; | |
436 | Int_t length; | |
437 | Int_t iBusPerDSP[5];//number of bus patches per DSP | |
438 | Int_t iDspMax; //number max of DSP per block | |
a19e2543 | 439 | Int_t iFile = 0; |
440 | fBusPatchManager->GetDspInfo(iCh, iDspMax, iBusPerDSP); | |
441 | ||
442 | TArrayI* vec = fBusPatchManager->GetBusfromDE((iCh+1)*100); | |
443 | ||
444 | Int_t iBus0AtCh = vec->At(0); //get first bus patch id for a given ich | |
c7082611 | 445 | |
a19e2543 | 446 | AliDebug(3,Form("iBus0AtCh %d", iBus0AtCh)); |
447 | ||
448 | iBusPatch = iBus0AtCh - 1; // starting point for each chamber | |
449 | ||
2cf44ef3 | 450 | // nEntries = fBusArray->GetEntriesFast(); |
84ceeb06 | 451 | |
452 | AliMUONBusStruct* busStructPtr = 0x0; | |
2cf44ef3 | 453 | |
a19e2543 | 454 | // open DDL file, on per 1/2 chamber |
2cf44ef3 | 455 | for (Int_t iDDL = 0; iDDL < 2; iDDL++) { |
456 | ||
457 | totalDDLLength = 0; | |
458 | ||
a19e2543 | 459 | // filling buffer |
84ceeb06 | 460 | buffer = new Int_t [(2048+24)*50]; // 24 words at most for one buspatch and 2048 manu info at most |
2cf44ef3 | 461 | |
a19e2543 | 462 | indexBlk = 0; |
463 | indexDsp = 0; | |
464 | index = 0; | |
2cf44ef3 | 465 | |
a19e2543 | 466 | // two blocks A and B per DDL |
2cf44ef3 | 467 | for (Int_t iBlock = 0; iBlock < 2; iBlock++) { |
468 | ||
a19e2543 | 469 | // block header |
2cf44ef3 | 470 | length = fBlockHeader->GetHeaderLength(); |
471 | memcpy(&buffer[index],fBlockHeader->GetHeader(),length*4); | |
a19e2543 | 472 | indexBlk = index; |
473 | index += length; | |
2cf44ef3 | 474 | |
a19e2543 | 475 | // 5 DSP's max per block |
2cf44ef3 | 476 | for (Int_t iDsp = 0; iDsp < iDspMax; iDsp++) { |
477 | ||
478 | // DSP header | |
479 | length = fDspHeader->GetHeaderLength(); | |
480 | memcpy(&buffer[index],fDspHeader->GetHeader(),length*4); | |
481 | indexDsp = index; | |
482 | index += length; | |
483 | ||
484 | //Â 5 buspatches max per DSP | |
485 | for (Int_t i = 0; i < iBusPerDSP[iDsp]; i++) { | |
486 | ||
487 | iBusPatch++; | |
488 | if ((fBusPatchManager->GetDDLfromBus(iBusPatch) % 2) == 0) // comparing to DDL file | |
489 | iFile = 1; | |
490 | else | |
491 | iFile = 0; | |
492 | ||
493 | AliDebug(3,Form("iCh %d iDDL %d iBlock %d iDsp %d busPatchId %d", iCh, iDDL, iBlock, iDsp, iBusPatch)); | |
494 | ||
495 | nEntries = fBusArray->GetEntriesFast(); | |
cd640dc7 | 496 | busPatchId = -1; |
84ceeb06 | 497 | |
2cf44ef3 | 498 | for (Int_t iEntries = 0; iEntries < nEntries; iEntries++) { // method "bourrique"... |
84ceeb06 | 499 | busStructPtr = (AliMUONBusStruct*)fBusArray->At(iEntries); |
500 | busPatchId = busStructPtr->GetBusPatchId(); | |
2cf44ef3 | 501 | if (busPatchId == iBusPatch) break; |
502 | busPatchId = -1; | |
84ceeb06 | 503 | AliDebug(3,Form("busPatchId %d", busStructPtr->GetBusPatchId())); |
2cf44ef3 | 504 | } |
505 | ||
506 | // check if buspatchid has digit | |
507 | if (busPatchId != -1) { | |
84ceeb06 | 508 | // add bus patch structure header |
509 | length = busStructPtr->GetHeaderLength(); | |
510 | memcpy(&buffer[index],busStructPtr->GetHeader(),length*4); | |
2cf44ef3 | 511 | index += length; |
84ceeb06 | 512 | |
513 | // add bus patch data | |
514 | for (Int_t j = 0; j < busStructPtr->GetLength(); j++) { | |
515 | buffer[index++] = busStructPtr->GetData(j); | |
516 | AliDebug(3,Form("busPatchId %d, manuId %d channelId %d\n", | |
517 | busStructPtr->GetBusPatchId(), | |
518 | busStructPtr->GetManuId(j), busStructPtr->GetChannelId(j) )); | |
2cf44ef3 | 519 | } |
520 | // fBusArray->RemoveAt(iEntries); | |
521 | // fBusArray->Compress(); | |
522 | } else { | |
523 | // writting anyhow buspatch structure (empty ones) | |
84ceeb06 | 524 | buffer[index++] = busStructPtr->GetDefaultDataKey(); // fill it also for empty data size |
525 | buffer[index++] = busStructPtr->GetHeaderLength(); // header length | |
2cf44ef3 | 526 | buffer[index++] = 0; // raw data length |
527 | buffer[index++] = iBusPatch; // bus patch | |
2cf44ef3 | 528 | } |
529 | } // bus patch | |
530 | ||
86400e61 | 531 | // check if totalLength even |
532 | // set padding word in case | |
533 | // Add one word 0xBEEFFACE at the end of DSP structure | |
534 | totalDspLength = index - indexDsp; | |
535 | if ((totalDspLength % 2) == 1) { | |
536 | buffer[indexDsp + fDspHeader->GetHeaderLength() - 2] = 1; | |
537 | buffer[index++] = fDspHeader->GetDefaultPaddingWord(); | |
538 | totalDspLength++; | |
539 | } | |
540 | ||
84ceeb06 | 541 | dspLength = totalDspLength - fDspHeader->GetHeaderLength(); |
542 | ||
543 | buffer[indexDsp+1] = totalDspLength; // dsp total length | |
544 | buffer[indexDsp+2] = dspLength; // data length | |
84ceeb06 | 545 | |
a19e2543 | 546 | } // dsp |
2cf44ef3 | 547 | |
548 | totalBlkLength = index - indexBlk; | |
549 | blkLength = totalBlkLength - fBlockHeader->GetHeaderLength(); | |
550 | totalDDLLength += totalBlkLength; | |
551 | ||
84ceeb06 | 552 | buffer[indexBlk+1] = totalBlkLength; // total block length |
553 | buffer[indexBlk+2] = blkLength; | |
2cf44ef3 | 554 | |
555 | } // block | |
a19e2543 | 556 | |
557 | //writting onto disk | |
558 | // write DDL 1 & 2 | |
2cf44ef3 | 559 | fHeader.fSize = (totalDDLLength + headerSize) * 4;// total length in bytes |
560 | fwrite((char*)(&fHeader),headerSize*4,1,fFile[iFile]); | |
a19e2543 | 561 | fwrite(buffer,sizeof(int),index,fFile[iFile]); |
2cf44ef3 | 562 | |
a19e2543 | 563 | delete[] buffer; |
564 | } | |
565 | ||
2cbb173f | 566 | fTrackerTimer.Stop(); |
a19e2543 | 567 | return kTRUE; |
568 | } | |
ced309a5 | 569 | |
570 | //____________________________________________________________________ | |
2cbb173f | 571 | Int_t AliMUONRawWriter::GetBusPatch(const AliMUONDigit& digit) |
ced309a5 | 572 | { |
2cf44ef3 | 573 | // |
2cbb173f | 574 | // Determine the BusPatch this digit belongs to. |
2cf44ef3 | 575 | // |
2cbb173f | 576 | fMappingTimer.Start(kFALSE); |
577 | ||
ced309a5 | 578 | Int_t* ptr = 0; |
579 | ||
580 | // information from digits | |
2cbb173f | 581 | Int_t detElemId = digit.DetElemId(); |
582 | ||
583 | AliMpVSegmentation* seg = | |
584 | fSegFactory->CreateMpSegmentationByElectronics(detElemId, digit.ManuId()); | |
585 | ||
586 | AliMpPlaneType plane = seg->PlaneType(); | |
ced309a5 | 587 | |
2cbb173f | 588 | AliMpStationType stationType = AliMpDEManager::GetStationType(detElemId); |
ced309a5 | 589 | |
2cbb173f | 590 | if ( stationType == kStation1 || stationType == kStation2 ) |
591 | { | |
592 | if (plane == kBendingPlane) | |
593 | { | |
594 | ptr = &fgManuPerBusSwp1B[0]; | |
595 | } | |
596 | else | |
597 | { | |
598 | ptr = &fgManuPerBusSwp1NB[0]; | |
ced309a5 | 599 | } |
600 | } | |
2cbb173f | 601 | else |
602 | { | |
603 | if (plane == kBendingPlane) | |
604 | { | |
605 | ptr = &fgManuPerBusSwp2B[0]; | |
606 | } | |
607 | else | |
608 | { | |
609 | ptr = &fgManuPerBusSwp2NB[0]; | |
610 | } | |
ced309a5 | 611 | } |
612 | ||
ced309a5 | 613 | // Getting buspatch id |
2cbb173f | 614 | TArrayI* vec = fBusPatchManager->GetBusfromDE(detElemId); |
ced309a5 | 615 | Int_t pos = 0; |
616 | ||
2cbb173f | 617 | Int_t m = ( digit.ManuId() & 0x3FF ); // remove bit 10 |
618 | //FIXME : how can we remove that condition | |
619 | // on the 10-th bit ? All the rest need not any knowledge about it, | |
620 | // can't we find a way to get manu<->buspatch transparent to this too ? | |
621 | ||
622 | if ( stationType == kStation1 || stationType == kStation2 ) | |
623 | { | |
ced309a5 | 624 | for (Int_t i = 0; i < 12; i++) |
2cbb173f | 625 | { |
626 | if (m >= *(ptr + pos++)) break; | |
627 | } | |
628 | } | |
629 | else | |
630 | { | |
ced309a5 | 631 | // offset of 100 in manuId for following bus patch |
2cbb173f | 632 | pos = m/100; |
ced309a5 | 633 | } |
634 | ||
635 | if (pos >(Int_t) vec->GetSize()) | |
2cbb173f | 636 | { |
637 | AliError(Form("pos greater %d than size %d manuId %d detElemId %d \n", | |
638 | pos, (Int_t)vec->GetSize(), digit.ManuId(), detElemId)); | |
639 | AliError(Form("Chamber %s Plane %s manuId %d m %d", | |
640 | StationTypeName(stationType).Data(), | |
641 | PlaneTypeName(plane).Data(), | |
642 | digit.ManuId(), | |
643 | m)); | |
644 | return -1; | |
645 | } | |
ced309a5 | 646 | |
2cbb173f | 647 | Int_t busPatchId = vec->At(pos); |
ced309a5 | 648 | |
2cbb173f | 649 | fMappingTimer.Stop(); |
650 | ||
651 | return busPatchId; | |
ced309a5 | 652 | } |
653 | ||
a19e2543 | 654 | //____________________________________________________________________ |
655 | Int_t AliMUONRawWriter::WriteTriggerDDL() | |
656 | { | |
2cf44ef3 | 657 | // |
658 | // Write trigger DDL | |
659 | // | |
2cbb173f | 660 | fTriggerTimer.Start(kFALSE); |
661 | ||
a19e2543 | 662 | // DDL event one per half chamber |
a19e2543 | 663 | |
a19e2543 | 664 | // stored local id number |
665 | TArrayI isFired(256); | |
666 | isFired.Reset(); | |
667 | ||
668 | ||
2cf44ef3 | 669 | // DDL header size |
670 | Int_t headerSize = sizeof(AliRawDataHeader)/4; | |
ced309a5 | 671 | |
a19e2543 | 672 | TClonesArray* localTrigger; |
673 | TClonesArray* globalTrigger; | |
674 | AliMUONGlobalTrigger* gloTrg; | |
675 | AliMUONLocalTrigger* locTrg = 0x0; | |
676 | ||
a19e2543 | 677 | // global trigger for trigger pattern |
678 | globalTrigger = fMUONData->GlobalTrigger(); | |
679 | gloTrg = (AliMUONGlobalTrigger*)globalTrigger->UncheckedAt(0); | |
2cf44ef3 | 680 | Int_t gloTrigPat = gloTrg->GetGlobalPattern(); |
a19e2543 | 681 | |
682 | // local trigger | |
683 | localTrigger = fMUONData->LocalTrigger(); | |
684 | ||
685 | UInt_t word; | |
686 | Int_t* buffer = 0; | |
687 | Int_t index; | |
688 | Int_t iEntries = 0; | |
689 | Int_t iLocCard, locCard; | |
690 | Char_t locDec, trigY, posY, posX,regOut; | |
691 | Int_t devX; | |
692 | Int_t version = 1; // software version | |
693 | Int_t eventType = 1; // trigger type: 1 for physics ? | |
694 | Int_t serialNb = 0xF; // serial nb of card: all bits on for the moment | |
695 | Int_t globalFlag = 1; // set to 2 if global info present in DDL else set to 1 | |
696 | ||
ced309a5 | 697 | if(fScalerEvent) |
698 | eventType = 2; //set to generate scaler events | |
699 | ||
a19e2543 | 700 | Int_t nEntries = (Int_t) (localTrigger->GetEntries());// 234 local cards |
701 | // stored the local card id that's fired | |
702 | for (Int_t i = 0; i < nEntries; i++) { | |
703 | locTrg = (AliMUONLocalTrigger*)localTrigger->At(i); | |
704 | isFired[locTrg->LoCircuit()] = 1; // storing local boards with informations | |
705 | } | |
706 | ||
707 | if (!nEntries) | |
62c04fc3 | 708 | AliInfo("No Trigger information available"); |
a19e2543 | 709 | |
ced309a5 | 710 | if(fScalerEvent) |
00f56161 | 711 | // [16(local)*51 words + 16 words]*8(reg) + 6 + 12 + 6 words scaler event 6672 words |
712 | buffer = new Int_t [6680]; | |
ced309a5 | 713 | else |
00f56161 | 714 | // [16(local)*6 words + 5 words]*8(reg) + 10 words = 818 |
715 | buffer = new Int_t [818]; | |
ced309a5 | 716 | |
a19e2543 | 717 | |
718 | // open DDL file, on per 1/2 chamber | |
719 | for (Int_t iDDL = 0; iDDL < 2; iDDL++) { | |
720 | ||
721 | index = 0; | |
722 | ||
a19e2543 | 723 | word = 0; |
00f56161 | 724 | // set darc status word |
a19e2543 | 725 | AliBitPacking::PackWord((UInt_t)iDDL+1,word,28,31); //see AliMUONDDLTrigger.h for details |
726 | AliBitPacking::PackWord((UInt_t)serialNb,word,24,27); | |
727 | AliBitPacking::PackWord((UInt_t)version,word,16,23); | |
728 | AliBitPacking::PackWord((UInt_t)eventType,word,12,15); | |
729 | ||
730 | if (iDDL == 0) // suppose global info in DDL one | |
731 | globalFlag = 2; | |
732 | else | |
733 | globalFlag = 1; | |
ced309a5 | 734 | |
a19e2543 | 735 | AliBitPacking::PackWord((UInt_t)globalFlag,word,8,11); |
2cf44ef3 | 736 | fDarcHeader->SetWord(word); |
18d3ded7 | 737 | |
738 | memcpy(&buffer[index], fDarcHeader->GetHeader(), (fDarcHeader->GetDarcHeaderLength())*4); | |
739 | index += fDarcHeader->GetDarcHeaderLength(); | |
a19e2543 | 740 | |
741 | if (iDDL == 0) | |
2cf44ef3 | 742 | fDarcHeader->SetGlobalOutput(gloTrigPat);// no global input for the moment.... |
a19e2543 | 743 | else |
2cf44ef3 | 744 | fDarcHeader->SetGlobalOutput(0); |
ced309a5 | 745 | |
746 | if (fScalerEvent) { | |
747 | // 6 DARC scaler words | |
2cf44ef3 | 748 | memcpy(&buffer[index], fDarcHeader->GetDarcScalers(),fDarcHeader->GetDarcScalerLength()*4); |
749 | index += fDarcHeader->GetDarcScalerLength(); | |
ced309a5 | 750 | } |
2cf44ef3 | 751 | // end of darc word |
752 | buffer[index++] = fDarcHeader->GetEndOfDarc(); | |
ced309a5 | 753 | |
754 | // 4 words of global board input + Global board output | |
18d3ded7 | 755 | memcpy(&buffer[index], fDarcHeader->GetGlobalInput(), (fDarcHeader->GetGlobalHeaderLength())*4); |
756 | index += fDarcHeader->GetGlobalHeaderLength(); | |
ced309a5 | 757 | |
758 | if (fScalerEvent) { | |
759 | // 10 Global scaler words | |
2cf44ef3 | 760 | memcpy(fDarcHeader->GetGlobalScalers(), &buffer[index], fDarcHeader->GetGlobalScalerLength()*4); |
761 | index += fDarcHeader->GetGlobalScalerLength(); | |
ced309a5 | 762 | } |
a19e2543 | 763 | |
2cf44ef3 | 764 | // end of global word |
765 | buffer[index++] = fDarcHeader->GetEndOfGlobal(); | |
766 | ||
a19e2543 | 767 | // 8 regional cards per DDL |
768 | for (Int_t iReg = 0; iReg < 8; iReg++) { | |
769 | ||
a19e2543 | 770 | // Regional card header |
771 | word = 0; | |
00f56161 | 772 | |
773 | // set darc status word | |
774 | fRegHeader->SetDarcWord(word); | |
775 | ||
a19e2543 | 776 | regOut = 0; |
2cf44ef3 | 777 | AliBitPacking::PackWord((UInt_t)serialNb,word,24,28); //see AliMUONLocalStruct.h for details |
a19e2543 | 778 | AliBitPacking::PackWord((UInt_t)version,word,16,23); |
779 | AliBitPacking::PackWord((UInt_t)iReg,word,12,15); | |
780 | AliBitPacking::PackWord((UInt_t)regOut,word,0,7); // whenever regional output will be implemented | |
781 | ||
2cf44ef3 | 782 | fRegHeader->SetWord(word); |
783 | memcpy(&buffer[index],fRegHeader->GetHeader(),fRegHeader->GetHeaderLength()*4); | |
784 | index += fRegHeader->GetHeaderLength(); | |
a19e2543 | 785 | |
ced309a5 | 786 | // 11 regional scaler word |
787 | if (fScalerEvent) { | |
2cf44ef3 | 788 | memcpy(&buffer[index], fRegHeader->GetScalers(), fRegHeader->GetScalerLength()*4); |
789 | index += fRegHeader->GetScalerLength(); | |
ced309a5 | 790 | } |
a19e2543 | 791 | |
2cf44ef3 | 792 | // end of regional word |
793 | buffer[index++] = fRegHeader->GetEndOfReg(); | |
794 | ||
a19e2543 | 795 | // 16 local card per regional board |
796 | for (Int_t iLoc = 0; iLoc < 16; iLoc++) { | |
797 | ||
798 | iLocCard = iLoc + iReg*16 + iDDL*128; | |
799 | ||
800 | if (isFired[iLocCard]) { | |
801 | locTrg = (AliMUONLocalTrigger*)localTrigger->At(iEntries); | |
802 | locCard = locTrg->LoCircuit(); | |
803 | locDec = locTrg->GetLoDecision(); | |
804 | trigY = 0; | |
805 | posY = locTrg->LoStripY(); | |
806 | posX = locTrg->LoStripX(); | |
807 | devX = locTrg->LoDev(); | |
808 | AliDebug(4,Form("loctrg %d, posX %d, posY %d, devX %d\n", | |
809 | locTrg->LoCircuit(),locTrg->LoStripX(),locTrg->LoStripY(),locTrg->LoDev())); | |
810 | } else { //no trigger (see PRR chpt 3.4) | |
2cf44ef3 | 811 | locCard = -1; // not possible on 4 bits |
a19e2543 | 812 | locDec = 0; |
813 | trigY = 1; | |
814 | posY = 15; | |
815 | posX = 0; | |
816 | devX = 0x8; | |
817 | } | |
818 | ||
819 | //packing word | |
820 | word = 0; | |
821 | AliBitPacking::PackWord((UInt_t)(iLocCard % 16),word,19,22); //card id number in crate | |
822 | AliBitPacking::PackWord((UInt_t)locDec,word,15,18); | |
823 | AliBitPacking::PackWord((UInt_t)trigY,word,14,14); | |
824 | AliBitPacking::PackWord((UInt_t)posY,word,10,13); | |
825 | AliBitPacking::PackWord((UInt_t)devX,word,5,9); | |
826 | AliBitPacking::PackWord((UInt_t)posX,word,0,4); | |
827 | ||
828 | if (locCard == iLocCard) { | |
829 | // add local cards structure | |
830 | buffer[index++] = (locTrg->GetX1Pattern() | (locTrg->GetX2Pattern() << 16)); | |
831 | buffer[index++] = (locTrg->GetX3Pattern() | (locTrg->GetX4Pattern() << 16)); | |
832 | buffer[index++] = (locTrg->GetY1Pattern() | (locTrg->GetY2Pattern() << 16)); | |
833 | buffer[index++] = (locTrg->GetY3Pattern() | (locTrg->GetY4Pattern() << 16)); | |
834 | buffer[index++] = (Int_t)word; // data word | |
835 | if (iEntries < nEntries-1) | |
836 | iEntries++; | |
837 | } else { | |
838 | buffer[index++] = 0; // 4 words for x1, x2, y1, y2 | |
839 | buffer[index++] = 0; | |
840 | buffer[index++] = 0; | |
841 | buffer[index++] = 0; | |
842 | buffer[index++] = (Int_t)word; // data word | |
843 | ||
844 | } | |
ced309a5 | 845 | // 45 regional scaler word |
846 | if (fScalerEvent) { | |
2cf44ef3 | 847 | memcpy(&buffer[index], fLocalStruct->GetScalers(), fLocalStruct->GetScalerLength()*4); |
848 | index += fLocalStruct->GetScalerLength(); | |
ced309a5 | 849 | } |
850 | ||
2cf44ef3 | 851 | // end of local structure words |
852 | buffer[index++] = fLocalStruct->GetEndOfLocal(); | |
a19e2543 | 853 | |
2cf44ef3 | 854 | } // local card |
a19e2543 | 855 | |
856 | } // Regional card | |
857 | ||
a19e2543 | 858 | |
859 | // writting onto disk | |
860 | // write DDL 1 | |
2cf44ef3 | 861 | fHeader.fSize = (index + headerSize) * 4;// total length in bytes |
862 | fwrite((char*)(&fHeader),headerSize*4,1,fFile[iDDL]); | |
a19e2543 | 863 | fwrite(buffer,sizeof(int),index,fFile[iDDL]); |
864 | ||
865 | } | |
866 | delete[] buffer; | |
867 | ||
2cbb173f | 868 | fTriggerTimer.Stop(); |
869 | ||
ced309a5 | 870 | return kTRUE; |
a19e2543 | 871 | } |
84ceeb06 | 872 | //____________________________________________________________________ |
873 | void AliMUONRawWriter::SetScalersNumbers() | |
874 | { | |
875 | // set numbers for scaler events for trigger headers | |
876 | // since this is provided by the experiment | |
877 | // put dummy numbers to check the monitoring | |
878 | ||
879 | fDarcHeader->SetScalersNumbers(); | |
880 | fRegHeader->SetScalersNumbers(); | |
881 | fLocalStruct->SetScalersNumbers(); | |
882 | ||
883 | fScalerEvent = kTRUE; | |
884 | } |