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"
60 #include "AliMpDetElement.h"
61 #include "AliMpTriggerCrate.h"
62 #include "AliMpLocalBoard.h"
63 #include "AliMpCathodType.h"
64 #include "AliMpDDLStore.h"
65 #include "AliMpDEManager.h"
67 #include "AliMpSegmentation.h"
68 #include "AliMpVSegmentation.h"
69 #include "AliCodeTimer.h"
71 #include "AliRawReader.h"
77 ClassImp(AliMUONDigitMaker) // Class implementation in ROOT context
80 //__________________________________________________________________________
81 AliMUONDigitMaker::AliMUONDigitMaker(Bool_t enableErrorLogger, Bool_t a, Bool_t b) :
84 fMakeTriggerDigits(kFALSE),
85 fRawStreamTracker(new AliMUONRawStreamTrackerHP),
86 fRawStreamTrigger(new AliMUONRawStreamTriggerHP),
89 fLogger(new AliMUONLogger(10000)){
92 if ( !a || !b ) AliFatal("no longer supported");
96 // Standard Constructor
97 if (enableErrorLogger)
99 fRawStreamTracker->EnabbleErrorLogger();
100 fRawStreamTrigger->EnabbleErrorLogger();
104 fRawStreamTracker->DisableWarnings();
107 SetMakeTriggerDigits();
110 if ( ! AliMpCDB::LoadDDLStore() ) {
111 AliFatal("Could not access mapping from OCDB !");
115 //__________________________________________________________________________
116 AliMUONDigitMaker::AliMUONDigitMaker(Bool_t enableErrorLogger) :
118 fScalerEvent(kFALSE),
119 fMakeTriggerDigits(kFALSE),
120 fRawStreamTracker(new AliMUONRawStreamTrackerHP),
121 fRawStreamTrigger(new AliMUONRawStreamTriggerHP),
124 fLogger(new AliMUONLogger(10000))
130 // Standard Constructor
131 if (enableErrorLogger)
133 fRawStreamTracker->EnabbleErrorLogger();
134 fRawStreamTrigger->EnabbleErrorLogger();
138 fRawStreamTracker->DisableWarnings();
141 SetMakeTriggerDigits();
144 if ( ! AliMpCDB::LoadDDLStore() ) {
145 AliFatal("Could not access mapping from OCDB !");
149 //__________________________________________________________________________
150 AliMUONDigitMaker::~AliMUONDigitMaker()
153 /// and time processing measure
155 delete fRawStreamTracker;
156 delete fRawStreamTrigger;
160 //____________________________________________________________________
162 AliMUONDigitMaker::Print(Option_t*) const
166 cout << "RawStreamerTracker class=" << fRawStreamTracker->ClassName()
167 << " MakeTriggerDigits=" << fMakeTriggerDigits
168 << " ScalerEvent=" << fScalerEvent
169 << " DigitStore=" << fDigitStore
170 << " TriggerStore=" << fTriggerStore << endl;
172 if ( fLogger ) fLogger->Print();
175 //____________________________________________________________________
177 AliMUONDigitMaker::Raw2Digits(AliRawReader* rawReader,
178 AliMUONVDigitStore* digitStore,
179 AliMUONVTriggerStore* triggerStore)
181 /// Main method to creates digit
185 AliDebug(1,Form("rawReader=%p digitStore=%p triggerStore=%p",
186 rawReader,digitStore,triggerStore));
188 fDigitStore = digitStore;
189 fTriggerStore = triggerStore;
191 if (!fDigitStore && !fTriggerStore)
193 fLogger->Log("No digit or trigger store given. Nothing to do...");
194 return kTriggerBAD & kTrackerBAD;
202 fDigitStore->Clear(); // insure we start with an empty container
203 tracker = ReadTrackerDDL(rawReader);
206 if ( fTriggerStore || fMakeTriggerDigits )
208 if ( fTriggerStore ) fTriggerStore->Clear();
209 if ( fMakeTriggerDigits && !fDigitStore )
211 fLogger->Log("Asking for trigger digits but digitStore is null");
215 trigger = ReadTriggerDDL(rawReader);
219 return tracker | trigger;
222 //____________________________________________________________________
224 AliMUONDigitMaker::ReadTrackerDDL(AliRawReader* rawReader)
226 /// Reading tracker DDL
227 /// filling the fDigitStore container, which must not be null
231 AliCodeTimerAuto("",0);
239 fRawStreamTracker->SetReader(rawReader);
240 fRawStreamTracker->First();
242 while ( fRawStreamTracker->Next(buspatchId,manuId,channelId,charge,kTRUE) )
244 // getting DE from buspatch
245 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(buspatchId);
247 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
251 fLogger->Log(Form("DE %04d does not exist !", detElemId));
255 if (!de->IsConnectedChannel(manuId,channelId))
257 // non connected pad, do nothing (this is not an error !)
261 const AliMpVSegmentation* seg
262 = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,
267 fLogger->Log(Form("(DE,MANUID)=(%04d,%04d) is not valid",detElemId,manuId));
271 AliMp::CathodType cathodeType = de->GetCathodType(seg->PlaneType());
273 AliMpPad pad = seg->PadByLocation(manuId,channelId,kFALSE);
277 fLogger->Log(Form("No pad for detElemId: %d, manuId: %d, channelId: %d",
278 detElemId, manuId, channelId));
282 AliMUONVDigit* digit = fDigitStore->Add(detElemId,manuId,channelId,cathodeType,
283 AliMUONVDigitStore::kDeny);
287 fLogger->Log(Form("Digit DE %04d Manu %04d Channel %02d could not be added",
288 detElemId, manuId, channelId));
292 digit->SetPadXY(pad.GetIx(),pad.GetIy());
294 digit->SetADC(charge);
298 if ( fRawStreamTracker->IsErrorMessage() )
306 //____________________________________________________________________
308 AliMUONDigitMaker::ReadTriggerDDL(AliRawReader* rawReader)
310 /// reading tracker DDL like ReadTriggerDDL but with fast decoder interface.
311 /// filling the fTriggerStore container, which must not be null
313 const AliMUONRawStreamTriggerHP::AliHeader* darcHeader = 0x0;
314 const AliMUONRawStreamTriggerHP::AliRegionalHeader* regHeader = 0x0;
315 const AliMUONRawStreamTriggerHP::AliLocalStruct* localStruct = 0x0;
319 fRawStreamTrigger->SetReader(rawReader);
321 while (fRawStreamTrigger->NextDDL())
323 darcHeader = fRawStreamTrigger->GetHeaders();
325 // fill global trigger information
328 if (darcHeader->GetGlobalFlag())
330 AliMUONGlobalTrigger globalTrigger;
331 globalTrigger.SetFromGlobalResponse(darcHeader->GetGlobalOutput());
332 globalTrigger.SetFromGlobalInput(darcHeader->GetGlobalHeader()->fInput);
333 fTriggerStore->SetGlobal(globalTrigger);
337 Int_t nReg = fRawStreamTrigger->GetRegionalHeaderCount();
339 for(Int_t iReg = 0; iReg < nReg ;iReg++)
344 AliMpTriggerCrate* crate = AliMpDDLStore::Instance()->
345 GetTriggerCrate(fRawStreamTrigger->GetDDL(), iReg);
348 fLogger->Log(Form("Missing crate number %d in DDL %d\n", iReg, fRawStreamTrigger->GetDDL()));
352 regHeader = fRawStreamTrigger->GetRegionalHeader(iReg);
354 Int_t nLocal = regHeader->GetLocalStructCount();
355 for(Int_t iLocal = 0; iLocal < nLocal; iLocal++)
358 localStruct = regHeader->GetLocalStruct(iLocal);
363 loCircuit = crate->GetLocalBoardId(localStruct->GetId());
365 if ( !loCircuit ) continue; // empty slot
370 // fill local trigger
371 AliMUONLocalTrigger localTrigger;
372 localTrigger.SetLocalStruct(loCircuit, *localStruct);
373 fTriggerStore->Add(localTrigger);
376 if ( fMakeTriggerDigits )
378 //FIXEME should find something better than a TArray
379 TArrayS xyPattern[2];
381 localStruct->GetXPattern(xyPattern[0]);
382 localStruct->GetYPattern(xyPattern[1]);
384 TriggerDigits(loCircuit, xyPattern, *fDigitStore);
394 //____________________________________________________________________
395 Int_t AliMUONDigitMaker::TriggerDigits(Int_t nBoard,
396 const TArrayS* xyPattern,
397 AliMUONVDigitStore& digitStore, Bool_t warn) const
399 /// make digits for trigger from pattern, and add them to digitStore
401 AliCodeTimerAuto("",0);
405 AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(nBoard);
407 if ( ! localBoard->IsNotified() ) {
409 // The mapping is not correct for copy boards
410 // Use the one of corresponding phyiscal board
411 nBoard = localBoard->GetInputXfrom();
416 // loop over x1-4 and y1-4
417 for (Int_t iChamber = 0; iChamber < 4; ++iChamber)
419 for (Int_t iCath = 0; iCath < 2; ++iCath)
421 Int_t pattern = (Int_t)xyPattern[iCath].At(iChamber);
422 if (!pattern) continue;
425 detElemId = AliMpDDLStore::Instance()->GetDEfromLocalBoard(nBoard, iChamber);
427 const AliMpVSegmentation* seg
428 = AliMpSegmentation::Instance()
429 ->GetMpSegmentation(detElemId, AliMp::GetCathodType(iCath));
431 // loop over the 16 bits of pattern
432 for (Int_t ibitxy = 0; ibitxy < 16; ++ibitxy)
434 if ((pattern >> ibitxy) & 0x1)
436 // not quite sure about this
438 if (iCath && localBoard->GetSwitch(AliMpLocalBoard::kZeroAllYLSB)) offset = -8;
440 AliMpPad pad = seg->PadByLocation(nBoard,ibitxy+offset,warn);
444 fLogger->Log(Form("No pad for detElemId: %d, nboard %d, ibitxy: %d\n",
445 detElemId, nBoard, ibitxy));
449 n = pad.GetLocalBoardId(0); // always take first location so that digits are not inserted several times
450 b = pad.GetLocalBoardChannel(0);
452 AliDebug(1,Form("Using localBoard %d ixy %d instead of %d,%d",
455 AliMUONVDigit* digit = digitStore.Add(detElemId,n,b,iCath,AliMUONVDigitStore::kDeny);
459 AliDebug(1, Form("Digit DE %04d LocalBoard %03d ibitxy %02d cath %d already in store",
460 detElemId,nBoard,ibitxy,iCath));
464 Int_t padX = pad.GetIx();
465 Int_t padY = pad.GetIy();
468 digit->SetPadXY(padX,padY);
469 digit->SetCharge(1.);
478 //______________________________________________________________________________
480 AliMUONDigitMaker::TriggerToDigitsStore(const AliMUONVTriggerStore& triggerStore,
481 AliMUONVDigitStore& digitStore) const
484 /// make (S)Digit for trigger
489 AliMUONLocalTrigger* locTrg;
490 TIter next(triggerStore.CreateLocalIterator());
492 while ( ( locTrg = static_cast<AliMUONLocalTrigger*>(next()) ) )
494 if (locTrg->IsNull()) continue;
496 TArrayS xyPattern[2];
497 locTrg->GetXPattern(xyPattern[0]);
498 locTrg->GetYPattern(xyPattern[1]);
500 Int_t nBoard = locTrg->LoCircuit();
501 TriggerDigits(nBoard, xyPattern, digitStore);
506 //______________________________________________________________________________
508 AliMUONDigitMaker::SetTryRecover(Bool_t flag)
510 /// Instruct the decoder to try to recover corrupted raw data.
511 /// Only use for specific cases for which you know it will work...
512 fRawStreamTracker->TryRecover(flag);