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"
75 ClassImp(AliMUONDigitMaker) // Class implementation in ROOT context
78 //__________________________________________________________________________
79 AliMUONDigitMaker::AliMUONDigitMaker(Bool_t enableErrorLogger, Bool_t a, Bool_t b) :
82 fMakeTriggerDigits(kFALSE),
83 fRawStreamTracker(new AliMUONRawStreamTrackerHP),
84 fRawStreamTrigger(new AliMUONRawStreamTriggerHP),
87 fLogger(new AliMUONLogger(10000)){
90 if ( !a || !b ) AliFatal("no longer supported");
94 // Standard Constructor
95 if (enableErrorLogger)
97 fRawStreamTracker->EnabbleErrorLogger();
98 fRawStreamTrigger->EnabbleErrorLogger();
102 fRawStreamTracker->DisableWarnings();
105 SetMakeTriggerDigits();
108 if ( ! AliMpCDB::LoadDDLStore() ) {
109 AliFatal("Could not access mapping from OCDB !");
113 //__________________________________________________________________________
114 AliMUONDigitMaker::AliMUONDigitMaker(Bool_t enableErrorLogger) :
116 fScalerEvent(kFALSE),
117 fMakeTriggerDigits(kFALSE),
118 fRawStreamTracker(new AliMUONRawStreamTrackerHP),
119 fRawStreamTrigger(new AliMUONRawStreamTriggerHP),
122 fLogger(new AliMUONLogger(10000))
128 // Standard Constructor
129 if (enableErrorLogger)
131 fRawStreamTracker->EnabbleErrorLogger();
132 fRawStreamTrigger->EnabbleErrorLogger();
136 fRawStreamTracker->DisableWarnings();
139 SetMakeTriggerDigits();
142 if ( ! AliMpCDB::LoadDDLStore() ) {
143 AliFatal("Could not access mapping from OCDB !");
147 //__________________________________________________________________________
148 AliMUONDigitMaker::~AliMUONDigitMaker()
151 /// and time processing measure
153 delete fRawStreamTracker;
154 delete fRawStreamTrigger;
158 //____________________________________________________________________
160 AliMUONDigitMaker::Print(Option_t*) const
164 cout << "RawStreamerTracker class=" << fRawStreamTracker->ClassName()
165 << " MakeTriggerDigits=" << fMakeTriggerDigits
166 << " ScalerEvent=" << fScalerEvent
167 << " DigitStore=" << fDigitStore
168 << " TriggerStore=" << fTriggerStore << endl;
170 if ( fLogger ) fLogger->Print();
173 //____________________________________________________________________
175 AliMUONDigitMaker::Raw2Digits(AliRawReader* rawReader,
176 AliMUONVDigitStore* digitStore,
177 AliMUONVTriggerStore* triggerStore)
179 /// Main method to creates digit
183 AliDebug(1,Form("rawReader=%p digitStore=%p triggerStore=%p",
184 rawReader,digitStore,triggerStore));
186 fDigitStore = digitStore;
187 fTriggerStore = triggerStore;
189 if (!fDigitStore && !fTriggerStore)
191 fLogger->Log("No digit or trigger store given. Nothing to do...");
192 return kTriggerBAD & kTrackerBAD;
200 fDigitStore->Clear(); // insure we start with an empty container
201 tracker = ReadTrackerDDL(rawReader);
204 if ( fTriggerStore || fMakeTriggerDigits )
206 if ( fTriggerStore ) fTriggerStore->Clear();
207 if ( fMakeTriggerDigits && !fDigitStore )
209 fLogger->Log("Asking for trigger digits but digitStore is null");
213 trigger = ReadTriggerDDL(rawReader);
217 return tracker | trigger;
220 //____________________________________________________________________
222 AliMUONDigitMaker::ReadTrackerDDL(AliRawReader* rawReader)
224 /// Reading tracker DDL
225 /// filling the fDigitStore container, which must not be null
229 AliCodeTimerAuto("",0);
237 fRawStreamTracker->SetReader(rawReader);
238 fRawStreamTracker->First();
240 while ( fRawStreamTracker->Next(buspatchId,manuId,channelId,charge,kTRUE) )
242 // getting DE from buspatch
243 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(buspatchId);
245 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
249 fLogger->Log(Form("DE %04d does not exist !", detElemId));
253 if (!de->IsConnectedChannel(manuId,channelId))
255 // non connected pad, do nothing (this is not an error !)
259 const AliMpVSegmentation* seg
260 = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,
265 fLogger->Log(Form("(DE,MANUID)=(%04d,%04d) is not valid",detElemId,manuId));
269 AliMp::CathodType cathodeType = de->GetCathodType(seg->PlaneType());
271 AliMpPad pad = seg->PadByLocation(manuId,channelId,kFALSE);
275 fLogger->Log(Form("No pad for detElemId: %d, manuId: %d, channelId: %d",
276 detElemId, manuId, channelId));
280 AliMUONVDigit* digit = fDigitStore->Add(detElemId,manuId,channelId,cathodeType,
281 AliMUONVDigitStore::kDeny);
285 fLogger->Log(Form("Digit DE %04d Manu %04d Channel %02d could not be added",
286 detElemId, manuId, channelId));
290 digit->SetPadXY(pad.GetIx(),pad.GetIy());
292 digit->SetADC(charge);
296 if ( fRawStreamTracker->IsErrorMessage() )
304 //____________________________________________________________________
306 AliMUONDigitMaker::ReadTriggerDDL(AliRawReader* rawReader)
308 /// reading tracker DDL like ReadTriggerDDL but with fast decoder interface.
309 /// filling the fTriggerStore container, which must not be null
311 const AliMUONRawStreamTriggerHP::AliHeader* darcHeader = 0x0;
312 const AliMUONRawStreamTriggerHP::AliRegionalHeader* regHeader = 0x0;
313 const AliMUONRawStreamTriggerHP::AliLocalStruct* localStruct = 0x0;
317 fRawStreamTrigger->SetReader(rawReader);
319 while (fRawStreamTrigger->NextDDL())
321 darcHeader = fRawStreamTrigger->GetHeaders();
323 // fill global trigger information
326 if (darcHeader->GetGlobalFlag())
328 AliMUONGlobalTrigger globalTrigger;
329 globalTrigger.SetFromGlobalResponse(darcHeader->GetGlobalOutput());
330 globalTrigger.SetFromGlobalInput(darcHeader->GetGlobalHeader()->fInput);
331 fTriggerStore->SetGlobal(globalTrigger);
335 Int_t nReg = fRawStreamTrigger->GetRegionalHeaderCount();
337 for(Int_t iReg = 0; iReg < nReg ;iReg++)
342 AliMpTriggerCrate* crate = AliMpDDLStore::Instance()->
343 GetTriggerCrate(fRawStreamTrigger->GetDDL(), iReg);
346 fLogger->Log(Form("Missing crate number %d in DDL %d\n", iReg, fRawStreamTrigger->GetDDL()));
350 regHeader = fRawStreamTrigger->GetRegionalHeader(iReg);
352 Int_t nLocal = regHeader->GetLocalStructCount();
353 for(Int_t iLocal = 0; iLocal < nLocal; iLocal++)
356 localStruct = regHeader->GetLocalStruct(iLocal);
361 loCircuit = crate->GetLocalBoardId(localStruct->GetId());
363 if ( !loCircuit ) continue; // empty slot
365 AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(loCircuit, kTRUE);
368 if( !localBoard->IsNotified())
373 // fill local trigger
374 AliMUONLocalTrigger localTrigger;
375 localTrigger.SetLocalStruct(loCircuit, *localStruct);
376 fTriggerStore->Add(localTrigger);
379 if ( fMakeTriggerDigits )
381 //FIXEME should find something better than a TArray
382 TArrayS xyPattern[2];
384 localStruct->GetXPattern(xyPattern[0]);
385 localStruct->GetYPattern(xyPattern[1]);
387 TriggerDigits(loCircuit, xyPattern, *fDigitStore);
397 //____________________________________________________________________
398 Int_t AliMUONDigitMaker::TriggerDigits(Int_t nBoard,
399 const TArrayS* xyPattern,
400 AliMUONVDigitStore& digitStore) const
402 /// make digits for trigger from pattern, and add them to digitStore
404 AliCodeTimerAuto("",0);
408 AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(nBoard);
412 // loop over x1-4 and y1-4
413 for (Int_t iChamber = 0; iChamber < 4; ++iChamber)
415 for (Int_t iCath = 0; iCath < 2; ++iCath)
417 Int_t pattern = (Int_t)xyPattern[iCath].At(iChamber);
418 if (!pattern) continue;
421 detElemId = AliMpDDLStore::Instance()->GetDEfromLocalBoard(nBoard, iChamber);
423 const AliMpVSegmentation* seg
424 = AliMpSegmentation::Instance()
425 ->GetMpSegmentation(detElemId, AliMp::GetCathodType(iCath));
427 // loop over the 16 bits of pattern
428 for (Int_t ibitxy = 0; ibitxy < 16; ++ibitxy)
430 if ((pattern >> ibitxy) & 0x1)
432 // not quite sure about this
434 if (iCath && localBoard->GetSwitch(AliMpLocalBoard::kZeroAllYLSB)) offset = -8;
436 AliMpPad pad = seg->PadByLocation(nBoard,ibitxy+offset,kTRUE);
440 fLogger->Log(Form("No pad for detElemId: %d, nboard %d, ibitxy: %d\n",
441 detElemId, nBoard, ibitxy));
445 n = pad.GetLocalBoardId(0); // always take first location so that digits are not inserted several times
446 b = pad.GetLocalBoardChannel(0);
448 AliDebug(1,Form("Using localBoard %d ixy %d instead of %d,%d",
451 AliMUONVDigit* digit = digitStore.Add(detElemId,n,b,iCath,AliMUONVDigitStore::kDeny);
455 AliDebug(1, Form("Digit DE %04d LocalBoard %03d ibitxy %02d cath %d already in store",
456 detElemId,nBoard,ibitxy,iCath));
460 Int_t padX = pad.GetIx();
461 Int_t padY = pad.GetIy();
464 digit->SetPadXY(padX,padY);
465 digit->SetCharge(1.);
474 //______________________________________________________________________________
476 AliMUONDigitMaker::TriggerToDigitsStore(const AliMUONVTriggerStore& triggerStore,
477 AliMUONVDigitStore& digitStore) const
480 /// make (S)Digit for trigger
485 AliMUONLocalTrigger* locTrg;
486 TIter next(triggerStore.CreateLocalIterator());
488 while ( ( locTrg = static_cast<AliMUONLocalTrigger*>(next()) ) )
490 if (locTrg->IsNull()) continue;
492 TArrayS xyPattern[2];
493 locTrg->GetXPattern(xyPattern[0]);
494 locTrg->GetYPattern(xyPattern[1]);
496 Int_t nBoard = locTrg->LoCircuit();
497 TriggerDigits(nBoard, xyPattern, digitStore);
502 //______________________________________________________________________________
504 AliMUONDigitMaker::SetTryRecover(Bool_t flag)
506 /// Instruct the decoder to try to recover corrupted raw data.
507 /// Only use for specific cases for which you know it will work...
508 fRawStreamTracker->TryRecover(flag);