]>
Commit | Line | Data |
---|---|---|
1 | /************************************************************************** | |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
7 | * Permission to use, copy, modify and distribute this software and its * | |
8 | * documentation strictly for non-commercial purposes is hereby granted * | |
9 | * without fee, provided that the above copyright notice appears in all * | |
10 | * copies and that both the copyright notice and this permission notice * | |
11 | * appear in the supporting documentation. The authors make no claims * | |
12 | * about the suitability of this software for any purpose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | **************************************************************************/ | |
15 | ||
16 | // $Id$ | |
17 | ||
18 | //----------------------------------------------------------------------------- | |
19 | /// \class AliMUONDigitMaker | |
20 | /// MUON Digit maker from rawdata. | |
21 | /// | |
22 | /// Raw2Digits: | |
23 | /// Using real mapping for tracker | |
24 | /// Indranil Das (Adapted for runloader: Ch. Finck) july 05 | |
25 | /// | |
26 | /// Implemented non-constant buspatch numbers for tracking | |
27 | /// with correct DDL id. | |
28 | /// (Ch. Finck, dec 05) | |
29 | /// | |
30 | /// Add reader for scaler trigger events | |
31 | /// Use memcpy instead of assignment elt by elt | |
32 | /// (Ch. Finck, Jan 06) | |
33 | /// | |
34 | /// Using new interface with AliMUONRawStreamTracker(Trigger) | |
35 | /// (New interface of AliMUONRawReader class) | |
36 | /// (further details could be found in Alice-note) | |
37 | /// (Ch. Finck, March 06) | |
38 | /// | |
39 | /// Add (S)Digit maker tracker (for free) | |
40 | /// and for trigger. Create trigger inverse mapping. | |
41 | /// | |
42 | /// \author Ch. Finck, oct 06 | |
43 | //----------------------------------------------------------------------------- | |
44 | ||
45 | #include "AliMUONDigitMaker.h" | |
46 | ||
47 | #include "AliMUONDDLTrigger.h" | |
48 | #include "AliMUONDarcHeader.h" | |
49 | #include "AliMUONVDigit.h" | |
50 | #include "AliMUONVDigitStore.h" | |
51 | #include "AliMUONGlobalTrigger.h" | |
52 | #include "AliMUONLocalStruct.h" | |
53 | #include "AliMUONLocalTrigger.h" | |
54 | #include "AliMUONLogger.h" | |
55 | #include "AliMUONRawStreamTrackerHP.h" | |
56 | #include "AliMUONRawStreamTriggerHP.h" | |
57 | #include "AliMUONRegHeader.h" | |
58 | #include "AliMUONVTriggerStore.h" | |
59 | #include "AliMpCDB.h" | |
60 | #include "AliMpDetElement.h" | |
61 | #include "AliMpTriggerCrate.h" | |
62 | #include "AliMpLocalBoard.h" | |
63 | #include "AliMpCathodType.h" | |
64 | #include "AliMpDDLStore.h" | |
65 | #include "AliMpDEManager.h" | |
66 | #include "AliMpPad.h" | |
67 | #include "AliMpSegmentation.h" | |
68 | #include "AliMpVSegmentation.h" | |
69 | #include "AliCodeTimer.h" | |
70 | #include "AliLog.h" | |
71 | #include "AliRawReader.h" | |
72 | #include <TArrayS.h> | |
73 | ||
74 | using std::endl; | |
75 | using std::cout; | |
76 | /// \cond CLASSIMP | |
77 | ClassImp(AliMUONDigitMaker) // Class implementation in ROOT context | |
78 | /// \endcond | |
79 | ||
80 | //__________________________________________________________________________ | |
81 | AliMUONDigitMaker::AliMUONDigitMaker(Bool_t enableErrorLogger, Bool_t a, Bool_t b) : | |
82 | TObject(), | |
83 | fScalerEvent(kFALSE), | |
84 | fMakeTriggerDigits(kFALSE), | |
85 | fMakeTrackerDigits(kFALSE), | |
86 | fRawStreamTracker(new AliMUONRawStreamTrackerHP), | |
87 | fRawStreamTrigger(new AliMUONRawStreamTriggerHP), | |
88 | fDigitStore(0x0), | |
89 | fTriggerStore(0x0), | |
90 | fLogger(new AliMUONLogger(10000)){ | |
91 | /// ctor | |
92 | ||
93 | if ( !a || !b ) AliFatal("no longer supported"); | |
94 | ||
95 | AliDebug(1,""); | |
96 | ||
97 | // Standard Constructor | |
98 | if (enableErrorLogger) | |
99 | { | |
100 | fRawStreamTracker->EnabbleErrorLogger(); | |
101 | fRawStreamTrigger->EnabbleErrorLogger(); | |
102 | } | |
103 | else | |
104 | { | |
105 | fRawStreamTracker->DisableWarnings(); | |
106 | } | |
107 | ||
108 | SetMakeTriggerDigits(); | |
109 | SetMakeTrackerDigits(); | |
110 | ||
111 | // Load mapping | |
112 | if ( ! AliMpCDB::LoadDDLStore() ) { | |
113 | AliFatal("Could not access mapping from OCDB !"); | |
114 | } | |
115 | } | |
116 | ||
117 | //__________________________________________________________________________ | |
118 | AliMUONDigitMaker::AliMUONDigitMaker(Bool_t enableErrorLogger) : | |
119 | TObject(), | |
120 | fScalerEvent(kFALSE), | |
121 | fMakeTriggerDigits(kFALSE), | |
122 | fMakeTrackerDigits(kFALSE), | |
123 | fRawStreamTracker(new AliMUONRawStreamTrackerHP), | |
124 | fRawStreamTrigger(new AliMUONRawStreamTriggerHP), | |
125 | fDigitStore(0x0), | |
126 | fTriggerStore(0x0), | |
127 | fLogger(new AliMUONLogger(10000)) | |
128 | { | |
129 | /// ctor | |
130 | ||
131 | AliDebug(1,""); | |
132 | ||
133 | // Standard Constructor | |
134 | if (enableErrorLogger) | |
135 | { | |
136 | fRawStreamTracker->EnabbleErrorLogger(); | |
137 | fRawStreamTrigger->EnabbleErrorLogger(); | |
138 | } | |
139 | else | |
140 | { | |
141 | fRawStreamTracker->DisableWarnings(); | |
142 | } | |
143 | ||
144 | SetMakeTriggerDigits(); | |
145 | SetMakeTrackerDigits(); | |
146 | ||
147 | // Load mapping | |
148 | if ( ! AliMpCDB::LoadDDLStore() ) { | |
149 | AliFatal("Could not access mapping from OCDB !"); | |
150 | } | |
151 | } | |
152 | ||
153 | //__________________________________________________________________________ | |
154 | AliMUONDigitMaker::~AliMUONDigitMaker() | |
155 | { | |
156 | /// clean up | |
157 | /// and time processing measure | |
158 | ||
159 | delete fRawStreamTracker; | |
160 | delete fRawStreamTrigger; | |
161 | delete fLogger; | |
162 | } | |
163 | ||
164 | //____________________________________________________________________ | |
165 | void | |
166 | AliMUONDigitMaker::Print(Option_t*) const | |
167 | { | |
168 | /// Printout | |
169 | ||
170 | cout << "RawStreamerTracker class=" << fRawStreamTracker->ClassName() | |
171 | << " MakeTriggerDigits=" << fMakeTriggerDigits | |
172 | << " ScalerEvent=" << fScalerEvent | |
173 | << " DigitStore=" << fDigitStore | |
174 | << " TriggerStore=" << fTriggerStore << endl; | |
175 | ||
176 | if ( fLogger ) fLogger->Print(); | |
177 | } | |
178 | ||
179 | //____________________________________________________________________ | |
180 | Int_t | |
181 | AliMUONDigitMaker::Raw2Digits(AliRawReader* rawReader, | |
182 | AliMUONVDigitStore* digitStore, | |
183 | AliMUONVTriggerStore* triggerStore) | |
184 | { | |
185 | /// Main method to creates digit | |
186 | /// for tracker | |
187 | /// and trigger | |
188 | ||
189 | AliDebug(1,Form("rawReader=%p digitStore=%p triggerStore=%p", | |
190 | rawReader,digitStore,triggerStore)); | |
191 | ||
192 | fDigitStore = digitStore; | |
193 | fTriggerStore = triggerStore; | |
194 | ||
195 | if (!fDigitStore && !fTriggerStore) | |
196 | { | |
197 | fLogger->Log("No digit or trigger store given. Nothing to do..."); | |
198 | return kTriggerBAD & kTrackerBAD; | |
199 | } | |
200 | ||
201 | Int_t tracker(kOK); | |
202 | Int_t trigger(kOK); | |
203 | ||
204 | if ( fDigitStore ) fDigitStore->Clear(); // insure we start with an empty container | |
205 | ||
206 | if ( fMakeTrackerDigits ) { | |
207 | if ( fDigitStore ) tracker = ReadTrackerDDL(rawReader); | |
208 | else fLogger->Log("Asking for tracker digits but digitStore is null"); | |
209 | } | |
210 | ||
211 | if ( fTriggerStore || fMakeTriggerDigits ) | |
212 | { | |
213 | if ( fTriggerStore ) fTriggerStore->Clear(); | |
214 | if ( fMakeTriggerDigits && !fDigitStore ) | |
215 | { | |
216 | fLogger->Log("Asking for trigger digits but digitStore is null"); | |
217 | } | |
218 | else | |
219 | { | |
220 | trigger = ReadTriggerDDL(rawReader); | |
221 | } | |
222 | } | |
223 | ||
224 | return tracker | trigger; | |
225 | } | |
226 | ||
227 | //____________________________________________________________________ | |
228 | Int_t | |
229 | AliMUONDigitMaker::ReadTrackerDDL(AliRawReader* rawReader) | |
230 | { | |
231 | /// Reading tracker DDL | |
232 | /// filling the fDigitStore container, which must not be null | |
233 | ||
234 | AliDebug(1,""); | |
235 | ||
236 | AliCodeTimerAuto("",0); | |
237 | ||
238 | // elex info | |
239 | Int_t buspatchId; | |
240 | UChar_t channelId; | |
241 | UShort_t manuId; | |
242 | UShort_t charge; | |
243 | ||
244 | fRawStreamTracker->SetReader(rawReader); | |
245 | fRawStreamTracker->First(); | |
246 | ||
247 | while ( fRawStreamTracker->Next(buspatchId,manuId,channelId,charge,kTRUE) ) | |
248 | { | |
249 | // getting DE from buspatch | |
250 | Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(buspatchId); | |
251 | ||
252 | AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId); | |
253 | ||
254 | if (!de) | |
255 | { | |
256 | fLogger->Log(Form("DE %04d does not exist !", detElemId)); | |
257 | continue; | |
258 | } | |
259 | ||
260 | if (!de->IsConnectedChannel(manuId,channelId)) | |
261 | { | |
262 | // non connected pad, do nothing (this is not an error !) | |
263 | continue; | |
264 | } | |
265 | ||
266 | const AliMpVSegmentation* seg | |
267 | = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId, | |
268 | manuId); | |
269 | ||
270 | if (!seg) | |
271 | { | |
272 | fLogger->Log(Form("(DE,MANUID)=(%04d,%04d) is not valid",detElemId,manuId)); | |
273 | continue; | |
274 | } | |
275 | ||
276 | AliMp::CathodType cathodeType = de->GetCathodType(seg->PlaneType()); | |
277 | ||
278 | AliMpPad pad = seg->PadByLocation(manuId,channelId,kFALSE); | |
279 | ||
280 | if (!pad.IsValid()) | |
281 | { | |
282 | fLogger->Log(Form("No pad for detElemId: %d, manuId: %d, channelId: %d", | |
283 | detElemId, manuId, channelId)); | |
284 | continue; | |
285 | } | |
286 | ||
287 | AliMUONVDigit* digit = fDigitStore->Add(detElemId,manuId,channelId,cathodeType, | |
288 | AliMUONVDigitStore::kDeny); | |
289 | ||
290 | if (!digit) | |
291 | { | |
292 | fLogger->Log(Form("Digit DE %04d Manu %04d Channel %02d could not be added", | |
293 | detElemId, manuId, channelId)); | |
294 | continue; | |
295 | } | |
296 | ||
297 | digit->SetPadXY(pad.GetIx(),pad.GetIy()); | |
298 | ||
299 | digit->SetADC(charge); | |
300 | ||
301 | } | |
302 | ||
303 | if ( fRawStreamTracker->IsErrorMessage() ) | |
304 | { | |
305 | return kTrackerBAD; | |
306 | } | |
307 | ||
308 | return kOK; | |
309 | } | |
310 | ||
311 | //____________________________________________________________________ | |
312 | Int_t | |
313 | AliMUONDigitMaker::ReadTriggerDDL(AliRawReader* rawReader) | |
314 | { | |
315 | /// reading tracker DDL like ReadTriggerDDL but with fast decoder interface. | |
316 | /// filling the fTriggerStore container, which must not be null | |
317 | ||
318 | const AliMUONRawStreamTriggerHP::AliHeader* darcHeader = 0x0; | |
319 | const AliMUONRawStreamTriggerHP::AliRegionalHeader* regHeader = 0x0; | |
320 | const AliMUONRawStreamTriggerHP::AliLocalStruct* localStruct = 0x0; | |
321 | ||
322 | Int_t loCircuit; | |
323 | ||
324 | fRawStreamTrigger->SetReader(rawReader); | |
325 | ||
326 | while (fRawStreamTrigger->NextDDL()) | |
327 | { | |
328 | darcHeader = fRawStreamTrigger->GetHeaders(); | |
329 | ||
330 | // fill global trigger information | |
331 | if (fTriggerStore) | |
332 | { | |
333 | if (darcHeader->GetGlobalFlag()) | |
334 | { | |
335 | AliMUONGlobalTrigger globalTrigger; | |
336 | globalTrigger.SetFromGlobalResponse(darcHeader->GetGlobalOutput()); | |
337 | globalTrigger.SetFromGlobalInput(darcHeader->GetGlobalHeader()->fInput); | |
338 | fTriggerStore->SetGlobal(globalTrigger); | |
339 | } | |
340 | } | |
341 | ||
342 | Int_t nReg = fRawStreamTrigger->GetRegionalHeaderCount(); | |
343 | ||
344 | for(Int_t iReg = 0; iReg < nReg ;iReg++) | |
345 | { //reg loop | |
346 | ||
347 | ||
348 | // crate info | |
349 | AliMpTriggerCrate* crate = AliMpDDLStore::Instance()-> | |
350 | GetTriggerCrate(fRawStreamTrigger->GetDDL(), iReg); | |
351 | ||
352 | if (!crate) { | |
353 | fLogger->Log(Form("Missing crate number %d in DDL %d\n", iReg, fRawStreamTrigger->GetDDL())); | |
354 | continue; | |
355 | } | |
356 | ||
357 | regHeader = fRawStreamTrigger->GetRegionalHeader(iReg); | |
358 | ||
359 | Int_t nLocal = regHeader->GetLocalStructCount(); | |
360 | for(Int_t iLocal = 0; iLocal < nLocal; iLocal++) | |
361 | { | |
362 | ||
363 | localStruct = regHeader->GetLocalStruct(iLocal); | |
364 | ||
365 | // if card exist | |
366 | if (localStruct) { | |
367 | ||
368 | loCircuit = crate->GetLocalBoardId(localStruct->GetId()); | |
369 | ||
370 | if ( !loCircuit ) continue; // empty slot | |
371 | ||
372 | ||
373 | if (fTriggerStore) | |
374 | { | |
375 | // fill local trigger | |
376 | AliMUONLocalTrigger localTrigger; | |
377 | localTrigger.SetLocalStruct(loCircuit, *localStruct); | |
378 | fTriggerStore->Add(localTrigger); | |
379 | } | |
380 | ||
381 | if ( fMakeTriggerDigits ) | |
382 | { | |
383 | //FIXEME should find something better than a TArray | |
384 | TArrayS xyPattern[2]; | |
385 | ||
386 | localStruct->GetXPattern(xyPattern[0]); | |
387 | localStruct->GetYPattern(xyPattern[1]); | |
388 | ||
389 | TriggerDigits(loCircuit, xyPattern, *fDigitStore); | |
390 | } | |
391 | } // if triggerY | |
392 | } // iLocal | |
393 | } // iReg | |
394 | } // NextDDL | |
395 | ||
396 | return kOK; | |
397 | } | |
398 | ||
399 | //____________________________________________________________________ | |
400 | Int_t AliMUONDigitMaker::TriggerDigits(Int_t nBoard, | |
401 | const TArrayS* xyPattern, | |
402 | AliMUONVDigitStore& digitStore, Bool_t warn) const | |
403 | { | |
404 | /// make digits for trigger from pattern, and add them to digitStore | |
405 | ||
406 | AliCodeTimerAuto("",0); | |
407 | ||
408 | Int_t detElemId; | |
409 | ||
410 | AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(nBoard); | |
411 | ||
412 | if ( ! localBoard->IsNotified() ) { | |
413 | // Copy board | |
414 | // The mapping is not correct for copy boards | |
415 | // Use the one of corresponding phyiscal board | |
416 | nBoard = localBoard->GetInputXfrom(); | |
417 | } | |
418 | ||
419 | Int_t n,b; | |
420 | ||
421 | // loop over x1-4 and y1-4 | |
422 | for (Int_t iChamber = 0; iChamber < 4; ++iChamber) | |
423 | { | |
424 | for (Int_t iCath = 0; iCath < 2; ++iCath) | |
425 | { | |
426 | Int_t pattern = (Int_t)xyPattern[iCath].At(iChamber); | |
427 | if (!pattern) continue; | |
428 | ||
429 | // get detElemId | |
430 | detElemId = AliMpDDLStore::Instance()->GetDEfromLocalBoard(nBoard, iChamber); | |
431 | ||
432 | const AliMpVSegmentation* seg | |
433 | = AliMpSegmentation::Instance() | |
434 | ->GetMpSegmentation(detElemId, AliMp::GetCathodType(iCath)); | |
435 | ||
436 | // loop over the 16 bits of pattern | |
437 | for (Int_t ibitxy = 0; ibitxy < 16; ++ibitxy) | |
438 | { | |
439 | if ((pattern >> ibitxy) & 0x1) | |
440 | { | |
441 | // not quite sure about this | |
442 | Int_t offset = 0; | |
443 | if (iCath && localBoard->GetSwitch(AliMpLocalBoard::kZeroAllYLSB)) offset = -8; | |
444 | ||
445 | AliMpPad pad = seg->PadByLocation(nBoard,ibitxy+offset,warn); | |
446 | ||
447 | if (!pad.IsValid()) | |
448 | { | |
449 | fLogger->Log(Form("No pad for detElemId: %d, nboard %d, ibitxy: %d\n", | |
450 | detElemId, nBoard, ibitxy)); | |
451 | continue; | |
452 | } | |
453 | ||
454 | n = pad.GetLocalBoardId(0); // always take first location so that digits are not inserted several times | |
455 | b = pad.GetLocalBoardChannel(0); | |
456 | ||
457 | AliDebug(1,Form("Using localBoard %d ixy %d instead of %d,%d", | |
458 | n,b,nBoard,ibitxy)); | |
459 | ||
460 | AliMUONVDigit* digit = digitStore.Add(detElemId,n,b,iCath,AliMUONVDigitStore::kDeny); | |
461 | ||
462 | if (!digit) | |
463 | { | |
464 | AliDebug(1, Form("Digit DE %04d LocalBoard %03d ibitxy %02d cath %d already in store", | |
465 | detElemId,nBoard,ibitxy,iCath)); | |
466 | continue; | |
467 | } | |
468 | ||
469 | Int_t padX = pad.GetIx(); | |
470 | Int_t padY = pad.GetIy(); | |
471 | ||
472 | // fill digit | |
473 | digit->SetPadXY(padX,padY); | |
474 | digit->SetCharge(1.); | |
475 | }// xyPattern | |
476 | }// ibitxy | |
477 | }// cath | |
478 | } // ichamber | |
479 | ||
480 | return kTRUE; | |
481 | } | |
482 | ||
483 | //______________________________________________________________________________ | |
484 | Bool_t | |
485 | AliMUONDigitMaker::TriggerToDigitsStore(const AliMUONVTriggerStore& triggerStore, | |
486 | AliMUONVDigitStore& digitStore) const | |
487 | { | |
488 | // | |
489 | /// make (S)Digit for trigger | |
490 | // | |
491 | ||
492 | digitStore.Clear(); | |
493 | ||
494 | AliMUONLocalTrigger* locTrg; | |
495 | TIter next(triggerStore.CreateLocalIterator()); | |
496 | ||
497 | while ( ( locTrg = static_cast<AliMUONLocalTrigger*>(next()) ) ) | |
498 | { | |
499 | if (locTrg->IsNull()) continue; | |
500 | ||
501 | TArrayS xyPattern[2]; | |
502 | locTrg->GetXPattern(xyPattern[0]); | |
503 | locTrg->GetYPattern(xyPattern[1]); | |
504 | ||
505 | Int_t nBoard = locTrg->LoCircuit(); | |
506 | TriggerDigits(nBoard, xyPattern, digitStore); | |
507 | } | |
508 | return kTRUE; | |
509 | } | |
510 | ||
511 | //______________________________________________________________________________ | |
512 | void | |
513 | AliMUONDigitMaker::SetTryRecover(Bool_t flag) | |
514 | { | |
515 | /// Instruct the decoder to try to recover corrupted raw data. | |
516 | /// Only use for specific cases for which you know it will work... | |
517 | fRawStreamTracker->TryRecover(flag); | |
518 | } |