Update of HP decoders:
[u/mrichter/AliRoot.git] / MUON / AliMUONDigitMaker.cxx
CommitLineData
a3283a4c 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
3d1463c8 16// $Id$
17
18//-----------------------------------------------------------------------------
9265505b 19/// \class AliMUONDigitMaker
8c51a32f 20/// MUON Digit maker from rawdata.
a3283a4c 21///
22/// Raw2Digits:
23/// Using real mapping for tracker
24/// Indranil Das (Adapted for runloader: Ch. Finck) july 05
8c51a32f 25///
26/// Implemented non-constant buspatch numbers for tracking
27/// with correct DDL id.
28/// (Ch. Finck, dec 05)
29///
a3283a4c 30/// Add reader for scaler trigger events
31/// Use memcpy instead of assignment elt by elt
32/// (Ch. Finck, Jan 06)
8c51a32f 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.
78649106 41///
42/// \author Ch. Finck, oct 06
3d1463c8 43//-----------------------------------------------------------------------------
a3283a4c 44
a3283a4c 45#include "AliMUONDigitMaker.h"
a3283a4c 46
a3283a4c 47#include "AliMUONDDLTrigger.h"
48#include "AliMUONDarcHeader.h"
40e382ae 49#include "AliMUONVDigit.h"
50#include "AliMUONVDigitStore.h"
51#include "AliMUONGlobalTrigger.h"
a3283a4c 52#include "AliMUONLocalStruct.h"
a3283a4c 53#include "AliMUONLocalTrigger.h"
0145e89a 54#include "AliMUONLogger.h"
40e382ae 55#include "AliMUONRawStreamTracker.h"
e3a2b9c9 56#include "AliMUONRawStreamTrackerHP.h"
40e382ae 57#include "AliMUONRawStreamTrigger.h"
481d8064 58#include "AliMUONRawStreamTriggerHP.h"
40e382ae 59#include "AliMUONRegHeader.h"
e1a10d41 60#include "AliMUONTriggerCircuit.h"
be63c782 61#include "AliMUONVTriggerStore.h"
62#include "AliMpDetElement.h"
d9b1ecb0 63#include "AliMpTriggerCrate.h"
64#include "AliMpLocalBoard.h"
40e382ae 65#include "AliMpCathodType.h"
66#include "AliMpDDLStore.h"
67#include "AliMpDEManager.h"
68#include "AliMpPad.h"
9265505b 69#include "AliMpSegmentation.h"
a3283a4c 70#include "AliMpVSegmentation.h"
be63c782 71#include "AliCodeTimer.h"
72#include "AliLog.h"
9265505b 73#include "AliRawReader.h"
7771752e 74#include <TArrayS.h>
9265505b 75
9265505b 76/// \cond CLASSIMP
a3283a4c 77ClassImp(AliMUONDigitMaker) // Class implementation in ROOT context
9265505b 78/// \endcond
79
a3283a4c 80//__________________________________________________________________________
481d8064 81AliMUONDigitMaker::AliMUONDigitMaker(
82 Bool_t enableErrorLogger,
83 Bool_t useFastTrackerDecoder, Bool_t useFastTriggerDecoder
84 ) :
85 TObject(),
9f5dcca3 86 fScalerEvent(kFALSE),
40e382ae 87 fMakeTriggerDigits(kFALSE),
e3a2b9c9 88 fRawStreamTracker(NULL),
481d8064 89 fRawStreamTrigger(NULL),
40e382ae 90 fDigitStore(0x0),
0145e89a 91 fTriggerStore(0x0),
92 fLogger(new AliMUONLogger(10000))
a3283a4c 93{
40e382ae 94 /// ctor
a3283a4c 95
96 AliDebug(1,"");
e3a2b9c9 97
481d8064 98 CreateRawStreamTracker(useFastTrackerDecoder);
99 CreateRawStreamTrigger(useFastTriggerDecoder);
a3283a4c 100
101 // Standard Constructor
3c7f5307 102 if (enableErrorLogger) {
103 fRawStreamTracker->EnabbleErrorLogger();
104 fRawStreamTrigger->EnabbleErrorLogger();
105 }
a3283a4c 106
40e382ae 107 SetMakeTriggerDigits();
a3283a4c 108
109}
110
111//__________________________________________________________________________
9f5dcca3 112AliMUONDigitMaker::~AliMUONDigitMaker()
a3283a4c 113{
9265505b 114 /// clean up
115 /// and time processing measure
116
a3283a4c 117 delete fRawStreamTracker;
118 delete fRawStreamTrigger;
0145e89a 119 delete fLogger;
a3283a4c 120}
121
d61f56df 122//__________________________________________________________________________
123void AliMUONDigitMaker::CreateRawStreamTracker(Bool_t useFastDecoder)
124{
125/// Create raw stream tracker according to the passed option
126
127 if (useFastDecoder)
128 {
481d8064 129 AliInfo("Using fast tracker decoder.");
d61f56df 130 fRawStreamTracker = new AliMUONRawStreamTrackerHP();
131 }
132 else
133 fRawStreamTracker = new AliMUONRawStreamTracker();
481d8064 134}
135
136//__________________________________________________________________________
137void AliMUONDigitMaker::CreateRawStreamTrigger(Bool_t useFastDecoder)
138{
139/// Create raw stream trigger according to the passed option
140
141 if (useFastDecoder)
142 {
143 AliInfo("Using fast trigger decoder.");
144 fRawStreamTrigger = new AliMUONRawStreamTriggerHP();
145 }
146 else
147 fRawStreamTrigger = new AliMUONRawStreamTrigger();
148}
d61f56df 149
a3283a4c 150//____________________________________________________________________
be63c782 151void
152AliMUONDigitMaker::Print(Option_t*) const
153{
154 /// Printout
155
156 cout << "RawStreamerTracker class=" << fRawStreamTracker->ClassName()
157 << " MakeTriggerDigits=" << fMakeTriggerDigits
158 << " ScalerEvent=" << fScalerEvent
159 << " DigitStore=" << fDigitStore
160 << " TriggerStore=" << fTriggerStore << endl;
161
162 if ( fLogger ) fLogger->Print();
163}
164
165//____________________________________________________________________
166Int_t
167AliMUONDigitMaker::Raw2Digits(AliRawReader* rawReader,
168 AliMUONVDigitStore* digitStore,
169 AliMUONVTriggerStore* triggerStore)
a3283a4c 170{
9265505b 171 /// Main method to creates digit
172 /// for tracker
173 /// and trigger
a3283a4c 174
40e382ae 175 AliDebug(1,Form("rawReader=%p digitStore=%p triggerStore=%p",
176 rawReader,digitStore,triggerStore));
177
178 fDigitStore = digitStore;
179 fTriggerStore = triggerStore;
180
181 if (!fDigitStore && !fTriggerStore)
182 {
0145e89a 183 fLogger->Log("No digit or trigger store given. Nothing to do...");
be63c782 184 return kTriggerBAD & kTrackerBAD;
40e382ae 185 }
186
be63c782 187 Int_t tracker(kOK);
188 Int_t trigger(kOK);
189
40e382ae 190 if ( fDigitStore )
191 {
192 fDigitStore->Clear(); // insure we start with an empty container
be63c782 193 tracker = ReadTrackerDDL(rawReader);
40e382ae 194 }
195
196 if ( fTriggerStore || fMakeTriggerDigits )
197 {
198 if ( fTriggerStore ) fTriggerStore->Clear();
199 if ( fMakeTriggerDigits && !fDigitStore )
200 {
0145e89a 201 fLogger->Log("Asking for trigger digits but digitStore is null");
40e382ae 202 }
203 else
204 {
be63c782 205 trigger = ReadTriggerDDL(rawReader);
40e382ae 206 }
207 }
208
be63c782 209 return tracker | trigger;
a3283a4c 210}
211
212//____________________________________________________________________
be63c782 213Int_t
214AliMUONDigitMaker::ReadTrackerDDL(AliRawReader* rawReader)
a3283a4c 215{
40e382ae 216 /// Reading tracker DDL
217 /// filling the fDigitStore container, which must not be null
a3283a4c 218
40e382ae 219 AliDebug(1,"");
220
0145e89a 221 AliCodeTimerAuto("");
a3283a4c 222
223 // elex info
224 Int_t buspatchId;
225 UChar_t channelId;
226 UShort_t manuId;
a3283a4c 227 UShort_t charge;
a3283a4c 228
a3283a4c 229 fRawStreamTracker->SetReader(rawReader);
1bc885f3 230 fRawStreamTracker->First();
231
232 while ( fRawStreamTracker->Next(buspatchId,manuId,channelId,charge) )
233 {
40e382ae 234 // getting DE from buspatch
235 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(buspatchId);
a3283a4c 236
be63c782 237 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
238
239 if (!de)
240 {
241 fLogger->Log(Form("DE %04d does not exist !"));
242 continue;
243 }
244
245 if (!de->IsConnectedChannel(manuId,channelId))
246 {
247 // non connected pad, do nothing (this is not an error !)
248 continue;
249 }
250
40e382ae 251 const AliMpVSegmentation* seg
252 = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,
253 manuId);
a3283a4c 254
0145e89a 255 if (!seg)
256 {
257 fLogger->Log(Form("(DE,MANUID)=(%04d,%04d) is not valid",detElemId,manuId));
258 continue;
259 }
260
be63c782 261 AliMp::CathodType cathodeType = de->GetCathodType(seg->PlaneType());
1bc885f3 262
40e382ae 263 AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,channelId),kFALSE);
be63c782 264
40e382ae 265 if (!pad.IsValid())
266 {
0145e89a 267 fLogger->Log(Form("No pad for detElemId: %d, manuId: %d, channelId: %d",
40e382ae 268 detElemId, manuId, channelId));
269 continue;
270 }
be63c782 271
40e382ae 272 AliMUONVDigit* digit = fDigitStore->Add(detElemId,manuId,channelId,cathodeType,
273 AliMUONVDigitStore::kDeny);
be63c782 274
40e382ae 275 if (!digit)
276 {
0145e89a 277 fLogger->Log(Form("Digit DE %04d Manu %04d Channel %02d could not be added",
40e382ae 278 detElemId, manuId, channelId));
279 continue;
280 }
281
282 digit->SetPadXY(pad.GetIndices().GetFirst(),
283 pad.GetIndices().GetSecond());
284
285 digit->SetADC(charge);
9265505b 286
40e382ae 287 }
a3283a4c 288
be63c782 289 if ( fRawStreamTracker->IsErrorMessage() )
290 {
291 return kTrackerBAD;
292 }
293
294 return kOK;
a3283a4c 295}
296
297//____________________________________________________________________
be63c782 298Int_t
299AliMUONDigitMaker::ReadTriggerDDL(AliRawReader* rawReader)
a3283a4c 300{
9265505b 301 /// reading tracker DDL
40e382ae 302 /// filling the fTriggerStore container, which must not be null
a3283a4c 303
40e382ae 304 AliDebug(1,"");
305
a3283a4c 306 AliMUONDDLTrigger* ddlTrigger = 0x0;
307 AliMUONDarcHeader* darcHeader = 0x0;
308 AliMUONRegHeader* regHeader = 0x0;
309 AliMUONLocalStruct* localStruct = 0x0;
310
311 Int_t loCircuit;
d2d759cf 312
0145e89a 313 AliCodeTimerAuto("");
481d8064 314
315 if (UsingFastTriggerDecoder()) return ReadTriggerDDLFast(rawReader);
a3283a4c 316
317 fRawStreamTrigger->SetReader(rawReader);
318
40e382ae 319 while (fRawStreamTrigger->NextDDL())
320 {
a3283a4c 321 ddlTrigger = fRawStreamTrigger->GetDDLTrigger();
322 darcHeader = ddlTrigger->GetDarcHeader();
40e382ae 323
324 // fill global trigger information
325 if (fTriggerStore)
326 {
327 if (darcHeader->GetGlobalFlag())
328 {
329 AliMUONGlobalTrigger globalTrigger;
330 globalTrigger.SetFromGlobalResponse(darcHeader->GetGlobalOutput());
331 fTriggerStore->SetGlobal(globalTrigger);
d2d759cf 332 }
a3283a4c 333 }
40e382ae 334
a3283a4c 335 Int_t nReg = darcHeader->GetRegHeaderEntries();
40e382ae 336
337 for(Int_t iReg = 0; iReg < nReg ;iReg++)
338 { //reg loop
339
d9b1ecb0 340
341 // crate info
342 AliMpTriggerCrate* crate = AliMpDDLStore::Instance()->
343 GetTriggerCrate(fRawStreamTrigger->GetDDL(), iReg);
40e382ae 344
d53fb0de 345 if (!crate)
0145e89a 346 fLogger->Log(Form("Missing crate number %d in DDL %d\n", iReg, fRawStreamTrigger->GetDDL()));
d9b1ecb0 347
40e382ae 348
a3283a4c 349 regHeader = darcHeader->GetRegHeaderEntry(iReg);
40e382ae 350
a3283a4c 351 Int_t nLocal = regHeader->GetLocalEntries();
40e382ae 352 for(Int_t iLocal = 0; iLocal < nLocal; iLocal++)
353 {
354
355 localStruct = regHeader->GetLocalEntry(iLocal);
356
357 // if card exist
358 if (localStruct) {
359
d9b1ecb0 360 loCircuit = crate->GetLocalBoardId(localStruct->GetId());
361
362 if ( !loCircuit ) continue; // empty slot
363
364 AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(loCircuit, false);
365
366 // skip copy cards
367 if( !localBoard->IsNotified())
368 continue;
40e382ae 369
370 if (fTriggerStore)
371 {
372 // fill local trigger
373 AliMUONLocalTrigger localTrigger;
374 localTrigger.SetLocalStruct(loCircuit, *localStruct);
375 fTriggerStore->Add(localTrigger);
376 }
377
378 if ( fMakeTriggerDigits )
379 {
380 //FIXEME should find something better than a TArray
381 TArrayS xyPattern[2];
40e382ae 382
d9b1ecb0 383 localStruct->GetXPattern(xyPattern[0]);
384 localStruct->GetYPattern(xyPattern[1]);
40e382ae 385
386 TriggerDigits(loCircuit, xyPattern, *fDigitStore);
387 }
388 } // if triggerY
a3283a4c 389 } // iLocal
390 } // iReg
391 } // NextDDL
40e382ae 392
be63c782 393 return kOK;
a3283a4c 394}
7771752e 395
d2d759cf 396//____________________________________________________________________
481d8064 397Int_t
398AliMUONDigitMaker::ReadTriggerDDLFast(AliRawReader* rawReader)
399{
400 /// reading tracker DDL like ReadTriggerDDL but with fast decoder interface.
401 /// filling the fTriggerStore container, which must not be null
402
403 const AliMUONRawStreamTriggerHP::AliHeader* darcHeader = 0x0;
404 const AliMUONRawStreamTriggerHP::AliRegionalHeader* regHeader = 0x0;
405 const AliMUONRawStreamTriggerHP::AliLocalStruct* localStruct = 0x0;
406
407 Int_t loCircuit;
408
409 fRawStreamTrigger->SetReader(rawReader);
410 AliMUONRawStreamTriggerHP* rawStreamTrigger =
411 dynamic_cast<AliMUONRawStreamTriggerHP*>(fRawStreamTrigger);
412
413 while (fRawStreamTrigger->NextDDL())
414 {
415 darcHeader = rawStreamTrigger->GetHeaders();
416
417 // fill global trigger information
418 if (fTriggerStore)
419 {
420 if (darcHeader->GetGlobalFlag())
421 {
422 AliMUONGlobalTrigger globalTrigger;
423 globalTrigger.SetFromGlobalResponse(darcHeader->GetGlobalOutput());
424 fTriggerStore->SetGlobal(globalTrigger);
425 }
426 }
427
428 Int_t nReg = rawStreamTrigger->GetRegionalHeaderCount();
429
430 for(Int_t iReg = 0; iReg < nReg ;iReg++)
431 { //reg loop
432
433
434 // crate info
435 AliMpTriggerCrate* crate = AliMpDDLStore::Instance()->
436 GetTriggerCrate(fRawStreamTrigger->GetDDL(), iReg);
437
438 if (!crate)
439 fLogger->Log(Form("Missing crate number %d in DDL %d\n", iReg, fRawStreamTrigger->GetDDL()));
440
441
442 regHeader = rawStreamTrigger->GetRegionalHeader(iReg);
443
444 Int_t nLocal = regHeader->GetLocalStructCount();
445 for(Int_t iLocal = 0; iLocal < nLocal; iLocal++)
446 {
447
448 localStruct = regHeader->GetLocalStruct(iLocal);
449
450 // if card exist
451 if (localStruct) {
452
453 loCircuit = crate->GetLocalBoardId(localStruct->GetId());
454
455 if ( !loCircuit ) continue; // empty slot
456
457 AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(loCircuit, false);
458
459 // skip copy cards
460 if( !localBoard->IsNotified())
461 continue;
462
463 if (fTriggerStore)
464 {
465 // fill local trigger
466 AliMUONLocalTrigger localTrigger;
467 localTrigger.SetLoCircuit(loCircuit);
468 localTrigger.SetLoStripX((Int_t)localStruct->GetXPos());
469 localTrigger.SetLoStripY((Int_t)localStruct->GetYPos());
470 localTrigger.SetLoDev((Int_t)localStruct->GetXDev());
471 localTrigger.SetLoSdev((Int_t)localStruct->GetSXDev());
472 localTrigger.SetLoTrigY((Int_t)localStruct->GetTrigY());
473 localTrigger.SetLoLpt(localStruct->GetLpt());
474 localTrigger.SetLoHpt(localStruct->GetHpt());
475 localTrigger.SetX1Pattern(localStruct->GetX1());
476 localTrigger.SetX2Pattern(localStruct->GetX2());
477 localTrigger.SetX3Pattern(localStruct->GetX3());
478 localTrigger.SetX4Pattern(localStruct->GetX4());
479 localTrigger.SetY1Pattern(localStruct->GetY1());
480 localTrigger.SetY2Pattern(localStruct->GetY2());
481 localTrigger.SetY3Pattern(localStruct->GetY3());
482 localTrigger.SetY4Pattern(localStruct->GetY4());
483 fTriggerStore->Add(localTrigger);
484 }
485
486 if ( fMakeTriggerDigits )
487 {
488 //FIXEME should find something better than a TArray
489 TArrayS xyPattern[2];
490
491 localStruct->GetXPattern(xyPattern[0]);
492 localStruct->GetYPattern(xyPattern[1]);
493
494 TriggerDigits(loCircuit, xyPattern, *fDigitStore);
495 }
496 } // if triggerY
497 } // iLocal
498 } // iReg
499 } // NextDDL
500
501 return kOK;
502}
503
504//____________________________________________________________________
7771752e 505Int_t AliMUONDigitMaker::TriggerDigits(Int_t nBoard,
40e382ae 506 TArrayS* xyPattern,
507 AliMUONVDigitStore& digitStore) const
d2d759cf 508{
40e382ae 509 /// make digits for trigger from pattern, and add them to digitStore
d2d759cf 510
0145e89a 511 AliCodeTimerAuto("");
512
d9b1ecb0 513 Int_t detElemId;
514
515 AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(nBoard);
516
8c0b5e70 517 Int_t n,b;
518
d2d759cf 519 // loop over x1-4 and y1-4
40e382ae 520 for (Int_t iChamber = 0; iChamber < 4; ++iChamber)
521 {
522 for (Int_t iCath = 0; iCath < 2; ++iCath)
523 {
7771752e 524 Int_t pattern = (Int_t)xyPattern[iCath].At(iChamber);
525 if (!pattern) continue;
40e382ae 526
7771752e 527 // get detElemId
d9b1ecb0 528 detElemId = AliMpDDLStore::Instance()->GetDEfromLocalBoard(nBoard, iChamber);
40e382ae 529
530 const AliMpVSegmentation* seg
531 = AliMpSegmentation::Instance()
532 ->GetMpSegmentation(detElemId, AliMp::GetCathodType(iCath));
533
534 // loop over the 16 bits of pattern
535 for (Int_t ibitxy = 0; ibitxy < 16; ++ibitxy)
536 {
537 if ((pattern >> ibitxy) & 0x1)
538 {
539 // not quite sure about this
540 Int_t offset = 0;
541 if (iCath && localBoard->GetSwitch(6)) offset = -8;
542
543 AliMpPad pad = seg->PadByLocation(AliMpIntPair(nBoard,ibitxy+offset),kTRUE);
544
545 if (!pad.IsValid())
546 {
0145e89a 547 fLogger->Log(Form("No pad for detElemId: %d, nboard %d, ibitxy: %d\n",
40e382ae 548 detElemId, nBoard, ibitxy));
549 continue;
550 }
8c0b5e70 551
552 n = pad.GetLocation(0).GetFirst(); // always take first location so that digits are not inserted several times
553 b = pad.GetLocation(0).GetSecond();
554
555 AliDebug(1,Form("Using localBoard %d ixy %d instead of %d,%d",
556 n,b,nBoard,ibitxy));
557
558 AliMUONVDigit* digit = digitStore.Add(detElemId,n,b,iCath,AliMUONVDigitStore::kDeny);
40e382ae 559
560 if (!digit)
561 {
8c0b5e70 562 AliDebug(1, Form("Digit DE %04d LocalBoard %03d ibitxy %02d cath %d already in store",
563 detElemId,nBoard,ibitxy,iCath));
564 continue;
40e382ae 565 }
566
567 Int_t padX = pad.GetIndices().GetFirst();
568 Int_t padY = pad.GetIndices().GetSecond();
569
570 // fill digit
571 digit->SetPadXY(padX,padY);
572 digit->SetCharge(1.);
573 }// xyPattern
574 }// ibitxy
7771752e 575 }// cath
576 } // ichamber
40e382ae 577
d2d759cf 578 return kTRUE;
481d8064 579}
d61f56df 580
581//____________________________________________________________________
481d8064 582Bool_t AliMUONDigitMaker::UsingFastTrackerDecoder() const
583{
584/// Returns kTRUE if the digit maker is using the high performance decoder for
585/// tracker DDL stream decoding.
586
587 return (fRawStreamTracker->IsA() == AliMUONRawStreamTrackerHP::Class());
588}
589
590//____________________________________________________________________
591Bool_t AliMUONDigitMaker::UsingFastTriggerDecoder() const
592{
593/// Returns kTRUE if the digit maker is using the high performance decoder for
594/// trigger DDL stream decoding.
595
596 return (fRawStreamTrigger->IsA() == AliMUONRawStreamTriggerHP::Class());
597}
598
599//____________________________________________________________________
600void AliMUONDigitMaker::SetFastTrackerDecoder(Bool_t useFastDecoder)
d61f56df 601{
602/// Set fast raw data decoder
603
604 delete fRawStreamTracker;
605 CreateRawStreamTracker(useFastDecoder);
481d8064 606}
607
608//____________________________________________________________________
609void AliMUONDigitMaker::SetFastTriggerDecoder(Bool_t useFastDecoder)
610{
611/// Set fast raw data decoder
612
613 delete fRawStreamTrigger;
614 CreateRawStreamTrigger(useFastDecoder);
615}
d61f56df 616