1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //-----------------------------------------------------------------------------
19 /// \class AliMUONDigitMaker
20 /// MUON Digit maker from rawdata.
23 /// Using real mapping for tracker
24 /// Indranil Das (Adapted for runloader: Ch. Finck) july 05
26 /// Implemented non-constant buspatch numbers for tracking
27 /// with correct DDL id.
28 /// (Ch. Finck, dec 05)
30 /// Add reader for scaler trigger events
31 /// Use memcpy instead of assignment elt by elt
32 /// (Ch. Finck, Jan 06)
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)
39 /// Add (S)Digit maker tracker (for free)
40 /// and for trigger. Create trigger inverse mapping.
42 /// \author Ch. Finck, oct 06
43 //-----------------------------------------------------------------------------
45 #include "AliMUONDigitMaker.h"
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 "AliMpDetElement.h"
60 #include "AliMpTriggerCrate.h"
61 #include "AliMpLocalBoard.h"
62 #include "AliMpCathodType.h"
63 #include "AliMpDDLStore.h"
64 #include "AliMpDEManager.h"
66 #include "AliMpSegmentation.h"
67 #include "AliMpVSegmentation.h"
68 #include "AliCodeTimer.h"
70 #include "AliRawReader.h"
74 ClassImp(AliMUONDigitMaker) // Class implementation in ROOT context
77 //__________________________________________________________________________
78 AliMUONDigitMaker::AliMUONDigitMaker(Bool_t enableErrorLogger, Bool_t a, Bool_t b) :
81 fMakeTriggerDigits(kFALSE),
82 fRawStreamTracker(new AliMUONRawStreamTrackerHP),
83 fRawStreamTrigger(new AliMUONRawStreamTriggerHP),
86 fLogger(new AliMUONLogger(10000)){
89 if ( !a || !b ) AliFatal("no longer supported");
93 // Standard Constructor
94 if (enableErrorLogger)
96 fRawStreamTracker->EnabbleErrorLogger();
97 fRawStreamTrigger->EnabbleErrorLogger();
101 fRawStreamTracker->DisableWarnings();
104 SetMakeTriggerDigits();
108 //__________________________________________________________________________
109 AliMUONDigitMaker::AliMUONDigitMaker(Bool_t enableErrorLogger) :
111 fScalerEvent(kFALSE),
112 fMakeTriggerDigits(kFALSE),
113 fRawStreamTracker(new AliMUONRawStreamTrackerHP),
114 fRawStreamTrigger(new AliMUONRawStreamTriggerHP),
117 fLogger(new AliMUONLogger(10000))
123 // Standard Constructor
124 if (enableErrorLogger)
126 fRawStreamTracker->EnabbleErrorLogger();
127 fRawStreamTrigger->EnabbleErrorLogger();
131 fRawStreamTracker->DisableWarnings();
134 SetMakeTriggerDigits();
138 //__________________________________________________________________________
139 AliMUONDigitMaker::~AliMUONDigitMaker()
142 /// and time processing measure
144 delete fRawStreamTracker;
145 delete fRawStreamTrigger;
149 //____________________________________________________________________
151 AliMUONDigitMaker::Print(Option_t*) const
155 cout << "RawStreamerTracker class=" << fRawStreamTracker->ClassName()
156 << " MakeTriggerDigits=" << fMakeTriggerDigits
157 << " ScalerEvent=" << fScalerEvent
158 << " DigitStore=" << fDigitStore
159 << " TriggerStore=" << fTriggerStore << endl;
161 if ( fLogger ) fLogger->Print();
164 //____________________________________________________________________
166 AliMUONDigitMaker::Raw2Digits(AliRawReader* rawReader,
167 AliMUONVDigitStore* digitStore,
168 AliMUONVTriggerStore* triggerStore)
170 /// Main method to creates digit
174 AliDebug(1,Form("rawReader=%p digitStore=%p triggerStore=%p",
175 rawReader,digitStore,triggerStore));
177 fDigitStore = digitStore;
178 fTriggerStore = triggerStore;
180 if (!fDigitStore && !fTriggerStore)
182 fLogger->Log("No digit or trigger store given. Nothing to do...");
183 return kTriggerBAD & kTrackerBAD;
191 fDigitStore->Clear(); // insure we start with an empty container
192 tracker = ReadTrackerDDL(rawReader);
195 if ( fTriggerStore || fMakeTriggerDigits )
197 if ( fTriggerStore ) fTriggerStore->Clear();
198 if ( fMakeTriggerDigits && !fDigitStore )
200 fLogger->Log("Asking for trigger digits but digitStore is null");
204 trigger = ReadTriggerDDL(rawReader);
208 return tracker | trigger;
211 //____________________________________________________________________
213 AliMUONDigitMaker::ReadTrackerDDL(AliRawReader* rawReader)
215 /// Reading tracker DDL
216 /// filling the fDigitStore container, which must not be null
220 AliCodeTimerAuto("",0);
228 fRawStreamTracker->SetReader(rawReader);
229 fRawStreamTracker->First();
231 while ( fRawStreamTracker->Next(buspatchId,manuId,channelId,charge,kTRUE) )
233 // getting DE from buspatch
234 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(buspatchId);
236 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
240 fLogger->Log(Form("DE %04d does not exist !", detElemId));
244 if (!de->IsConnectedChannel(manuId,channelId))
246 // non connected pad, do nothing (this is not an error !)
250 const AliMpVSegmentation* seg
251 = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,
256 fLogger->Log(Form("(DE,MANUID)=(%04d,%04d) is not valid",detElemId,manuId));
260 AliMp::CathodType cathodeType = de->GetCathodType(seg->PlaneType());
262 AliMpPad pad = seg->PadByLocation(manuId,channelId,kFALSE);
266 fLogger->Log(Form("No pad for detElemId: %d, manuId: %d, channelId: %d",
267 detElemId, manuId, channelId));
271 AliMUONVDigit* digit = fDigitStore->Add(detElemId,manuId,channelId,cathodeType,
272 AliMUONVDigitStore::kDeny);
276 fLogger->Log(Form("Digit DE %04d Manu %04d Channel %02d could not be added",
277 detElemId, manuId, channelId));
281 digit->SetPadXY(pad.GetIx(),pad.GetIy());
283 digit->SetADC(charge);
287 if ( fRawStreamTracker->IsErrorMessage() )
295 //____________________________________________________________________
297 AliMUONDigitMaker::ReadTriggerDDL(AliRawReader* rawReader)
299 /// reading tracker DDL like ReadTriggerDDL but with fast decoder interface.
300 /// filling the fTriggerStore container, which must not be null
302 const AliMUONRawStreamTriggerHP::AliHeader* darcHeader = 0x0;
303 const AliMUONRawStreamTriggerHP::AliRegionalHeader* regHeader = 0x0;
304 const AliMUONRawStreamTriggerHP::AliLocalStruct* localStruct = 0x0;
308 fRawStreamTrigger->SetReader(rawReader);
310 while (fRawStreamTrigger->NextDDL())
312 darcHeader = fRawStreamTrigger->GetHeaders();
314 // fill global trigger information
317 if (darcHeader->GetGlobalFlag())
319 AliMUONGlobalTrigger globalTrigger;
320 globalTrigger.SetFromGlobalResponse(darcHeader->GetGlobalOutput());
321 globalTrigger.SetFromGlobalInput(darcHeader->GetGlobalHeader()->fInput);
322 fTriggerStore->SetGlobal(globalTrigger);
326 Int_t nReg = fRawStreamTrigger->GetRegionalHeaderCount();
328 for(Int_t iReg = 0; iReg < nReg ;iReg++)
333 AliMpTriggerCrate* crate = AliMpDDLStore::Instance()->
334 GetTriggerCrate(fRawStreamTrigger->GetDDL(), iReg);
337 fLogger->Log(Form("Missing crate number %d in DDL %d\n", iReg, fRawStreamTrigger->GetDDL()));
340 regHeader = fRawStreamTrigger->GetRegionalHeader(iReg);
342 Int_t nLocal = regHeader->GetLocalStructCount();
343 for(Int_t iLocal = 0; iLocal < nLocal; iLocal++)
346 localStruct = regHeader->GetLocalStruct(iLocal);
351 loCircuit = crate->GetLocalBoardId(localStruct->GetId());
353 if ( !loCircuit ) continue; // empty slot
355 AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(loCircuit, kTRUE);
358 if( !localBoard->IsNotified())
363 // fill local trigger
364 AliMUONLocalTrigger localTrigger;
365 localTrigger.SetLocalStruct(loCircuit, *localStruct);
366 fTriggerStore->Add(localTrigger);
369 if ( fMakeTriggerDigits )
371 //FIXEME should find something better than a TArray
372 TArrayS xyPattern[2];
374 localStruct->GetXPattern(xyPattern[0]);
375 localStruct->GetYPattern(xyPattern[1]);
377 TriggerDigits(loCircuit, xyPattern, *fDigitStore);
387 //____________________________________________________________________
388 Int_t AliMUONDigitMaker::TriggerDigits(Int_t nBoard,
389 const TArrayS* xyPattern,
390 AliMUONVDigitStore& digitStore) const
392 /// make digits for trigger from pattern, and add them to digitStore
394 AliCodeTimerAuto("",0);
398 AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(nBoard);
402 // loop over x1-4 and y1-4
403 for (Int_t iChamber = 0; iChamber < 4; ++iChamber)
405 for (Int_t iCath = 0; iCath < 2; ++iCath)
407 Int_t pattern = (Int_t)xyPattern[iCath].At(iChamber);
408 if (!pattern) continue;
411 detElemId = AliMpDDLStore::Instance()->GetDEfromLocalBoard(nBoard, iChamber);
413 const AliMpVSegmentation* seg
414 = AliMpSegmentation::Instance()
415 ->GetMpSegmentation(detElemId, AliMp::GetCathodType(iCath));
417 // loop over the 16 bits of pattern
418 for (Int_t ibitxy = 0; ibitxy < 16; ++ibitxy)
420 if ((pattern >> ibitxy) & 0x1)
422 // not quite sure about this
424 if (iCath && localBoard->GetSwitch(AliMpLocalBoard::kZeroAllYLSB)) offset = -8;
426 AliMpPad pad = seg->PadByLocation(nBoard,ibitxy+offset,kTRUE);
430 fLogger->Log(Form("No pad for detElemId: %d, nboard %d, ibitxy: %d\n",
431 detElemId, nBoard, ibitxy));
435 n = pad.GetLocalBoardId(0); // always take first location so that digits are not inserted several times
436 b = pad.GetLocalBoardChannel(0);
438 AliDebug(1,Form("Using localBoard %d ixy %d instead of %d,%d",
441 AliMUONVDigit* digit = digitStore.Add(detElemId,n,b,iCath,AliMUONVDigitStore::kDeny);
445 AliDebug(1, Form("Digit DE %04d LocalBoard %03d ibitxy %02d cath %d already in store",
446 detElemId,nBoard,ibitxy,iCath));
450 Int_t padX = pad.GetIx();
451 Int_t padY = pad.GetIy();
454 digit->SetPadXY(padX,padY);
455 digit->SetCharge(1.);
464 //______________________________________________________________________________
466 AliMUONDigitMaker::TriggerToDigitsStore(const AliMUONVTriggerStore& triggerStore,
467 AliMUONVDigitStore& digitStore) const
470 /// make (S)Digit for trigger
475 AliMUONLocalTrigger* locTrg;
476 TIter next(triggerStore.CreateLocalIterator());
478 while ( ( locTrg = static_cast<AliMUONLocalTrigger*>(next()) ) )
480 if (locTrg->IsNull()) continue;
482 TArrayS xyPattern[2];
483 locTrg->GetXPattern(xyPattern[0]);
484 locTrg->GetYPattern(xyPattern[1]);
486 Int_t nBoard = locTrg->LoCircuit();
487 TriggerDigits(nBoard, xyPattern, digitStore);
492 //______________________________________________________________________________
494 AliMUONDigitMaker::SetTryRecover(Bool_t flag)
496 /// Instruct the decoder to try to recover corrupted raw data.
497 /// Only use for specific cases for which you know it will work...
498 fRawStreamTracker->TryRecover(flag);