]>
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 "AliMUONRawStreamTracker.h" | |
56 | #include "AliMUONRawStreamTrackerHP.h" | |
57 | #include "AliMUONRawStreamTrigger.h" | |
58 | #include "AliMUONRegHeader.h" | |
59 | #include "AliMUONTriggerCircuit.h" | |
60 | #include "AliMUONVTriggerStore.h" | |
61 | #include "AliMpDetElement.h" | |
62 | #include "AliMpTriggerCrate.h" | |
63 | #include "AliMpLocalBoard.h" | |
64 | #include "AliMpCathodType.h" | |
65 | #include "AliMpDDLStore.h" | |
66 | #include "AliMpDEManager.h" | |
67 | #include "AliMpPad.h" | |
68 | #include "AliMpSegmentation.h" | |
69 | #include "AliMpVSegmentation.h" | |
70 | #include "AliCodeTimer.h" | |
71 | #include "AliLog.h" | |
72 | #include "AliRawReader.h" | |
73 | #include <TArrayS.h> | |
74 | ||
75 | /// \cond CLASSIMP | |
76 | ClassImp(AliMUONDigitMaker) // Class implementation in ROOT context | |
77 | /// \endcond | |
78 | ||
79 | //__________________________________________________________________________ | |
80 | AliMUONDigitMaker::AliMUONDigitMaker(Bool_t enableErrorLogger, Bool_t useFastDecoder) | |
81 | : TObject(), | |
82 | fScalerEvent(kFALSE), | |
83 | fMakeTriggerDigits(kFALSE), | |
84 | fRawStreamTracker(NULL), | |
85 | fRawStreamTrigger(new AliMUONRawStreamTrigger()), | |
86 | fDigitStore(0x0), | |
87 | fTriggerStore(0x0), | |
88 | fLogger(new AliMUONLogger(10000)) | |
89 | { | |
90 | /// ctor | |
91 | ||
92 | AliDebug(1,""); | |
93 | ||
94 | CreateRawStreamTracker(useFastDecoder); | |
95 | ||
96 | // Standard Constructor | |
97 | if (enableErrorLogger) { | |
98 | fRawStreamTracker->EnabbleErrorLogger(); | |
99 | fRawStreamTrigger->EnabbleErrorLogger(); | |
100 | } | |
101 | ||
102 | SetMakeTriggerDigits(); | |
103 | ||
104 | } | |
105 | ||
106 | //__________________________________________________________________________ | |
107 | AliMUONDigitMaker::~AliMUONDigitMaker() | |
108 | { | |
109 | /// clean up | |
110 | /// and time processing measure | |
111 | ||
112 | delete fRawStreamTracker; | |
113 | delete fRawStreamTrigger; | |
114 | delete fLogger; | |
115 | } | |
116 | ||
117 | //__________________________________________________________________________ | |
118 | void AliMUONDigitMaker::CreateRawStreamTracker(Bool_t useFastDecoder) | |
119 | { | |
120 | /// Create raw stream tracker according to the passed option | |
121 | ||
122 | if (useFastDecoder) | |
123 | { | |
124 | AliInfo("Using fast decoder."); | |
125 | fRawStreamTracker = new AliMUONRawStreamTrackerHP(); | |
126 | } | |
127 | else | |
128 | fRawStreamTracker = new AliMUONRawStreamTracker(); | |
129 | } | |
130 | ||
131 | //____________________________________________________________________ | |
132 | void | |
133 | AliMUONDigitMaker::Print(Option_t*) const | |
134 | { | |
135 | /// Printout | |
136 | ||
137 | cout << "RawStreamerTracker class=" << fRawStreamTracker->ClassName() | |
138 | << " MakeTriggerDigits=" << fMakeTriggerDigits | |
139 | << " ScalerEvent=" << fScalerEvent | |
140 | << " DigitStore=" << fDigitStore | |
141 | << " TriggerStore=" << fTriggerStore << endl; | |
142 | ||
143 | if ( fLogger ) fLogger->Print(); | |
144 | } | |
145 | ||
146 | //____________________________________________________________________ | |
147 | Int_t | |
148 | AliMUONDigitMaker::Raw2Digits(AliRawReader* rawReader, | |
149 | AliMUONVDigitStore* digitStore, | |
150 | AliMUONVTriggerStore* triggerStore) | |
151 | { | |
152 | /// Main method to creates digit | |
153 | /// for tracker | |
154 | /// and trigger | |
155 | ||
156 | AliDebug(1,Form("rawReader=%p digitStore=%p triggerStore=%p", | |
157 | rawReader,digitStore,triggerStore)); | |
158 | ||
159 | fDigitStore = digitStore; | |
160 | fTriggerStore = triggerStore; | |
161 | ||
162 | if (!fDigitStore && !fTriggerStore) | |
163 | { | |
164 | fLogger->Log("No digit or trigger store given. Nothing to do..."); | |
165 | return kTriggerBAD & kTrackerBAD; | |
166 | } | |
167 | ||
168 | Int_t tracker(kOK); | |
169 | Int_t trigger(kOK); | |
170 | ||
171 | if ( fDigitStore ) | |
172 | { | |
173 | fDigitStore->Clear(); // insure we start with an empty container | |
174 | tracker = ReadTrackerDDL(rawReader); | |
175 | } | |
176 | ||
177 | if ( fTriggerStore || fMakeTriggerDigits ) | |
178 | { | |
179 | if ( fTriggerStore ) fTriggerStore->Clear(); | |
180 | if ( fMakeTriggerDigits && !fDigitStore ) | |
181 | { | |
182 | fLogger->Log("Asking for trigger digits but digitStore is null"); | |
183 | } | |
184 | else | |
185 | { | |
186 | trigger = ReadTriggerDDL(rawReader); | |
187 | } | |
188 | } | |
189 | ||
190 | return tracker | trigger; | |
191 | } | |
192 | ||
193 | //____________________________________________________________________ | |
194 | Int_t | |
195 | AliMUONDigitMaker::ReadTrackerDDL(AliRawReader* rawReader) | |
196 | { | |
197 | /// Reading tracker DDL | |
198 | /// filling the fDigitStore container, which must not be null | |
199 | ||
200 | AliDebug(1,""); | |
201 | ||
202 | AliCodeTimerAuto(""); | |
203 | ||
204 | // elex info | |
205 | Int_t buspatchId; | |
206 | UChar_t channelId; | |
207 | UShort_t manuId; | |
208 | UShort_t charge; | |
209 | ||
210 | fRawStreamTracker->SetReader(rawReader); | |
211 | fRawStreamTracker->First(); | |
212 | ||
213 | while ( fRawStreamTracker->Next(buspatchId,manuId,channelId,charge) ) | |
214 | { | |
215 | // getting DE from buspatch | |
216 | Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(buspatchId); | |
217 | ||
218 | AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId); | |
219 | ||
220 | if (!de) | |
221 | { | |
222 | fLogger->Log(Form("DE %04d does not exist !")); | |
223 | continue; | |
224 | } | |
225 | ||
226 | if (!de->IsConnectedChannel(manuId,channelId)) | |
227 | { | |
228 | // non connected pad, do nothing (this is not an error !) | |
229 | continue; | |
230 | } | |
231 | ||
232 | const AliMpVSegmentation* seg | |
233 | = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId, | |
234 | manuId); | |
235 | ||
236 | if (!seg) | |
237 | { | |
238 | fLogger->Log(Form("(DE,MANUID)=(%04d,%04d) is not valid",detElemId,manuId)); | |
239 | continue; | |
240 | } | |
241 | ||
242 | AliMp::CathodType cathodeType = de->GetCathodType(seg->PlaneType()); | |
243 | ||
244 | AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,channelId),kFALSE); | |
245 | ||
246 | if (!pad.IsValid()) | |
247 | { | |
248 | fLogger->Log(Form("No pad for detElemId: %d, manuId: %d, channelId: %d", | |
249 | detElemId, manuId, channelId)); | |
250 | continue; | |
251 | } | |
252 | ||
253 | AliMUONVDigit* digit = fDigitStore->Add(detElemId,manuId,channelId,cathodeType, | |
254 | AliMUONVDigitStore::kDeny); | |
255 | ||
256 | if (!digit) | |
257 | { | |
258 | fLogger->Log(Form("Digit DE %04d Manu %04d Channel %02d could not be added", | |
259 | detElemId, manuId, channelId)); | |
260 | continue; | |
261 | } | |
262 | ||
263 | digit->SetPadXY(pad.GetIndices().GetFirst(), | |
264 | pad.GetIndices().GetSecond()); | |
265 | ||
266 | digit->SetADC(charge); | |
267 | ||
268 | } | |
269 | ||
270 | if ( fRawStreamTracker->IsErrorMessage() ) | |
271 | { | |
272 | return kTrackerBAD; | |
273 | } | |
274 | ||
275 | return kOK; | |
276 | } | |
277 | ||
278 | //____________________________________________________________________ | |
279 | Int_t | |
280 | AliMUONDigitMaker::ReadTriggerDDL(AliRawReader* rawReader) | |
281 | { | |
282 | /// reading tracker DDL | |
283 | /// filling the fTriggerStore container, which must not be null | |
284 | ||
285 | AliDebug(1,""); | |
286 | ||
287 | AliMUONDDLTrigger* ddlTrigger = 0x0; | |
288 | AliMUONDarcHeader* darcHeader = 0x0; | |
289 | AliMUONRegHeader* regHeader = 0x0; | |
290 | AliMUONLocalStruct* localStruct = 0x0; | |
291 | ||
292 | Int_t loCircuit; | |
293 | ||
294 | AliCodeTimerAuto(""); | |
295 | ||
296 | fRawStreamTrigger->SetReader(rawReader); | |
297 | ||
298 | while (fRawStreamTrigger->NextDDL()) | |
299 | { | |
300 | ddlTrigger = fRawStreamTrigger->GetDDLTrigger(); | |
301 | darcHeader = ddlTrigger->GetDarcHeader(); | |
302 | ||
303 | // fill global trigger information | |
304 | if (fTriggerStore) | |
305 | { | |
306 | if (darcHeader->GetGlobalFlag()) | |
307 | { | |
308 | AliMUONGlobalTrigger globalTrigger; | |
309 | globalTrigger.SetFromGlobalResponse(darcHeader->GetGlobalOutput()); | |
310 | fTriggerStore->SetGlobal(globalTrigger); | |
311 | } | |
312 | } | |
313 | ||
314 | Int_t nReg = darcHeader->GetRegHeaderEntries(); | |
315 | ||
316 | for(Int_t iReg = 0; iReg < nReg ;iReg++) | |
317 | { //reg loop | |
318 | ||
319 | ||
320 | // crate info | |
321 | AliMpTriggerCrate* crate = AliMpDDLStore::Instance()-> | |
322 | GetTriggerCrate(fRawStreamTrigger->GetDDL(), iReg); | |
323 | ||
324 | if (!crate) | |
325 | fLogger->Log(Form("Missing crate number %d in DDL %d\n", iReg, fRawStreamTrigger->GetDDL())); | |
326 | ||
327 | ||
328 | regHeader = darcHeader->GetRegHeaderEntry(iReg); | |
329 | ||
330 | Int_t nLocal = regHeader->GetLocalEntries(); | |
331 | for(Int_t iLocal = 0; iLocal < nLocal; iLocal++) | |
332 | { | |
333 | ||
334 | localStruct = regHeader->GetLocalEntry(iLocal); | |
335 | ||
336 | // if card exist | |
337 | if (localStruct) { | |
338 | ||
339 | loCircuit = crate->GetLocalBoardId(localStruct->GetId()); | |
340 | ||
341 | if ( !loCircuit ) continue; // empty slot | |
342 | ||
343 | AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(loCircuit, false); | |
344 | ||
345 | // skip copy cards | |
346 | if( !localBoard->IsNotified()) | |
347 | continue; | |
348 | ||
349 | if (fTriggerStore) | |
350 | { | |
351 | // fill local trigger | |
352 | AliMUONLocalTrigger localTrigger; | |
353 | localTrigger.SetLocalStruct(loCircuit, *localStruct); | |
354 | fTriggerStore->Add(localTrigger); | |
355 | } | |
356 | ||
357 | if ( fMakeTriggerDigits ) | |
358 | { | |
359 | //FIXEME should find something better than a TArray | |
360 | TArrayS xyPattern[2]; | |
361 | ||
362 | localStruct->GetXPattern(xyPattern[0]); | |
363 | localStruct->GetYPattern(xyPattern[1]); | |
364 | ||
365 | TriggerDigits(loCircuit, xyPattern, *fDigitStore); | |
366 | } | |
367 | } // if triggerY | |
368 | } // iLocal | |
369 | } // iReg | |
370 | } // NextDDL | |
371 | ||
372 | return kOK; | |
373 | } | |
374 | ||
375 | //____________________________________________________________________ | |
376 | Int_t AliMUONDigitMaker::TriggerDigits(Int_t nBoard, | |
377 | TArrayS* xyPattern, | |
378 | AliMUONVDigitStore& digitStore) const | |
379 | { | |
380 | /// make digits for trigger from pattern, and add them to digitStore | |
381 | ||
382 | AliCodeTimerAuto(""); | |
383 | ||
384 | Int_t detElemId; | |
385 | ||
386 | AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(nBoard); | |
387 | ||
388 | Int_t n,b; | |
389 | ||
390 | // loop over x1-4 and y1-4 | |
391 | for (Int_t iChamber = 0; iChamber < 4; ++iChamber) | |
392 | { | |
393 | for (Int_t iCath = 0; iCath < 2; ++iCath) | |
394 | { | |
395 | Int_t pattern = (Int_t)xyPattern[iCath].At(iChamber); | |
396 | if (!pattern) continue; | |
397 | ||
398 | // get detElemId | |
399 | detElemId = AliMpDDLStore::Instance()->GetDEfromLocalBoard(nBoard, iChamber); | |
400 | ||
401 | const AliMpVSegmentation* seg | |
402 | = AliMpSegmentation::Instance() | |
403 | ->GetMpSegmentation(detElemId, AliMp::GetCathodType(iCath)); | |
404 | ||
405 | // loop over the 16 bits of pattern | |
406 | for (Int_t ibitxy = 0; ibitxy < 16; ++ibitxy) | |
407 | { | |
408 | if ((pattern >> ibitxy) & 0x1) | |
409 | { | |
410 | // not quite sure about this | |
411 | Int_t offset = 0; | |
412 | if (iCath && localBoard->GetSwitch(6)) offset = -8; | |
413 | ||
414 | AliMpPad pad = seg->PadByLocation(AliMpIntPair(nBoard,ibitxy+offset),kTRUE); | |
415 | ||
416 | if (!pad.IsValid()) | |
417 | { | |
418 | fLogger->Log(Form("No pad for detElemId: %d, nboard %d, ibitxy: %d\n", | |
419 | detElemId, nBoard, ibitxy)); | |
420 | continue; | |
421 | } | |
422 | ||
423 | n = pad.GetLocation(0).GetFirst(); // always take first location so that digits are not inserted several times | |
424 | b = pad.GetLocation(0).GetSecond(); | |
425 | ||
426 | AliDebug(1,Form("Using localBoard %d ixy %d instead of %d,%d", | |
427 | n,b,nBoard,ibitxy)); | |
428 | ||
429 | AliMUONVDigit* digit = digitStore.Add(detElemId,n,b,iCath,AliMUONVDigitStore::kDeny); | |
430 | ||
431 | if (!digit) | |
432 | { | |
433 | AliDebug(1, Form("Digit DE %04d LocalBoard %03d ibitxy %02d cath %d already in store", | |
434 | detElemId,nBoard,ibitxy,iCath)); | |
435 | continue; | |
436 | } | |
437 | ||
438 | Int_t padX = pad.GetIndices().GetFirst(); | |
439 | Int_t padY = pad.GetIndices().GetSecond(); | |
440 | ||
441 | // fill digit | |
442 | digit->SetPadXY(padX,padY); | |
443 | digit->SetCharge(1.); | |
444 | }// xyPattern | |
445 | }// ibitxy | |
446 | }// cath | |
447 | } // ichamber | |
448 | ||
449 | return kTRUE; | |
450 | } | |
451 | ||
452 | //____________________________________________________________________ | |
453 | void AliMUONDigitMaker::SetFastDecoder(Bool_t useFastDecoder) | |
454 | { | |
455 | /// Set fast raw data decoder | |
456 | ||
457 | delete fRawStreamTracker; | |
458 | CreateRawStreamTracker(useFastDecoder); | |
459 | } | |
460 | ||
461 | ||
462 |