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 "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"
68 #include "AliMpSegmentation.h"
69 #include "AliMpVSegmentation.h"
70 #include "AliCodeTimer.h"
72 #include "AliRawReader.h"
76 ClassImp(AliMUONDigitMaker) // Class implementation in ROOT context
79 //__________________________________________________________________________
80 AliMUONDigitMaker::AliMUONDigitMaker(Bool_t enableErrorLogger, Bool_t useFastDecoder)
83 fMakeTriggerDigits(kFALSE),
84 fRawStreamTracker(NULL),
85 fRawStreamTrigger(new AliMUONRawStreamTrigger()),
88 fLogger(new AliMUONLogger(10000))
94 CreateRawStreamTracker(useFastDecoder);
96 // Standard Constructor
97 if (enableErrorLogger) {
98 fRawStreamTracker->EnabbleErrorLogger();
99 fRawStreamTrigger->EnabbleErrorLogger();
102 SetMakeTriggerDigits();
106 //__________________________________________________________________________
107 AliMUONDigitMaker::~AliMUONDigitMaker()
110 /// and time processing measure
112 delete fRawStreamTracker;
113 delete fRawStreamTrigger;
117 //__________________________________________________________________________
118 void AliMUONDigitMaker::CreateRawStreamTracker(Bool_t useFastDecoder)
120 /// Create raw stream tracker according to the passed option
124 AliInfo("Using fast decoder.");
125 fRawStreamTracker = new AliMUONRawStreamTrackerHP();
128 fRawStreamTracker = new AliMUONRawStreamTracker();
131 //____________________________________________________________________
133 AliMUONDigitMaker::Print(Option_t*) const
137 cout << "RawStreamerTracker class=" << fRawStreamTracker->ClassName()
138 << " MakeTriggerDigits=" << fMakeTriggerDigits
139 << " ScalerEvent=" << fScalerEvent
140 << " DigitStore=" << fDigitStore
141 << " TriggerStore=" << fTriggerStore << endl;
143 if ( fLogger ) fLogger->Print();
146 //____________________________________________________________________
148 AliMUONDigitMaker::Raw2Digits(AliRawReader* rawReader,
149 AliMUONVDigitStore* digitStore,
150 AliMUONVTriggerStore* triggerStore)
152 /// Main method to creates digit
156 AliDebug(1,Form("rawReader=%p digitStore=%p triggerStore=%p",
157 rawReader,digitStore,triggerStore));
159 fDigitStore = digitStore;
160 fTriggerStore = triggerStore;
162 if (!fDigitStore && !fTriggerStore)
164 fLogger->Log("No digit or trigger store given. Nothing to do...");
165 return kTriggerBAD & kTrackerBAD;
173 fDigitStore->Clear(); // insure we start with an empty container
174 tracker = ReadTrackerDDL(rawReader);
177 if ( fTriggerStore || fMakeTriggerDigits )
179 if ( fTriggerStore ) fTriggerStore->Clear();
180 if ( fMakeTriggerDigits && !fDigitStore )
182 fLogger->Log("Asking for trigger digits but digitStore is null");
186 trigger = ReadTriggerDDL(rawReader);
190 return tracker | trigger;
193 //____________________________________________________________________
195 AliMUONDigitMaker::ReadTrackerDDL(AliRawReader* rawReader)
197 /// Reading tracker DDL
198 /// filling the fDigitStore container, which must not be null
202 AliCodeTimerAuto("");
210 fRawStreamTracker->SetReader(rawReader);
211 fRawStreamTracker->First();
213 while ( fRawStreamTracker->Next(buspatchId,manuId,channelId,charge) )
215 // getting DE from buspatch
216 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(buspatchId);
218 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
222 fLogger->Log(Form("DE %04d does not exist !"));
226 if (!de->IsConnectedChannel(manuId,channelId))
228 // non connected pad, do nothing (this is not an error !)
232 const AliMpVSegmentation* seg
233 = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,
238 fLogger->Log(Form("(DE,MANUID)=(%04d,%04d) is not valid",detElemId,manuId));
242 AliMp::CathodType cathodeType = de->GetCathodType(seg->PlaneType());
244 AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,channelId),kFALSE);
248 fLogger->Log(Form("No pad for detElemId: %d, manuId: %d, channelId: %d",
249 detElemId, manuId, channelId));
253 AliMUONVDigit* digit = fDigitStore->Add(detElemId,manuId,channelId,cathodeType,
254 AliMUONVDigitStore::kDeny);
258 fLogger->Log(Form("Digit DE %04d Manu %04d Channel %02d could not be added",
259 detElemId, manuId, channelId));
263 digit->SetPadXY(pad.GetIndices().GetFirst(),
264 pad.GetIndices().GetSecond());
266 digit->SetADC(charge);
270 if ( fRawStreamTracker->IsErrorMessage() )
278 //____________________________________________________________________
280 AliMUONDigitMaker::ReadTriggerDDL(AliRawReader* rawReader)
282 /// reading tracker DDL
283 /// filling the fTriggerStore container, which must not be null
287 AliMUONDDLTrigger* ddlTrigger = 0x0;
288 AliMUONDarcHeader* darcHeader = 0x0;
289 AliMUONRegHeader* regHeader = 0x0;
290 AliMUONLocalStruct* localStruct = 0x0;
294 AliCodeTimerAuto("");
296 fRawStreamTrigger->SetReader(rawReader);
298 while (fRawStreamTrigger->NextDDL())
300 ddlTrigger = fRawStreamTrigger->GetDDLTrigger();
301 darcHeader = ddlTrigger->GetDarcHeader();
303 // fill global trigger information
306 if (darcHeader->GetGlobalFlag())
308 AliMUONGlobalTrigger globalTrigger;
309 globalTrigger.SetFromGlobalResponse(darcHeader->GetGlobalOutput());
310 fTriggerStore->SetGlobal(globalTrigger);
314 Int_t nReg = darcHeader->GetRegHeaderEntries();
316 for(Int_t iReg = 0; iReg < nReg ;iReg++)
321 AliMpTriggerCrate* crate = AliMpDDLStore::Instance()->
322 GetTriggerCrate(fRawStreamTrigger->GetDDL(), iReg);
325 fLogger->Log(Form("Missing crate number %d in DDL %d\n", iReg, fRawStreamTrigger->GetDDL()));
328 regHeader = darcHeader->GetRegHeaderEntry(iReg);
330 Int_t nLocal = regHeader->GetLocalEntries();
331 for(Int_t iLocal = 0; iLocal < nLocal; iLocal++)
334 localStruct = regHeader->GetLocalEntry(iLocal);
339 loCircuit = crate->GetLocalBoardId(localStruct->GetId());
341 if ( !loCircuit ) continue; // empty slot
343 AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(loCircuit, false);
346 if( !localBoard->IsNotified())
351 // fill local trigger
352 AliMUONLocalTrigger localTrigger;
353 localTrigger.SetLocalStruct(loCircuit, *localStruct);
354 fTriggerStore->Add(localTrigger);
357 if ( fMakeTriggerDigits )
359 //FIXEME should find something better than a TArray
360 TArrayS xyPattern[2];
362 localStruct->GetXPattern(xyPattern[0]);
363 localStruct->GetYPattern(xyPattern[1]);
365 TriggerDigits(loCircuit, xyPattern, *fDigitStore);
375 //____________________________________________________________________
376 Int_t AliMUONDigitMaker::TriggerDigits(Int_t nBoard,
378 AliMUONVDigitStore& digitStore) const
380 /// make digits for trigger from pattern, and add them to digitStore
382 AliCodeTimerAuto("");
386 AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(nBoard);
390 // loop over x1-4 and y1-4
391 for (Int_t iChamber = 0; iChamber < 4; ++iChamber)
393 for (Int_t iCath = 0; iCath < 2; ++iCath)
395 Int_t pattern = (Int_t)xyPattern[iCath].At(iChamber);
396 if (!pattern) continue;
399 detElemId = AliMpDDLStore::Instance()->GetDEfromLocalBoard(nBoard, iChamber);
401 const AliMpVSegmentation* seg
402 = AliMpSegmentation::Instance()
403 ->GetMpSegmentation(detElemId, AliMp::GetCathodType(iCath));
405 // loop over the 16 bits of pattern
406 for (Int_t ibitxy = 0; ibitxy < 16; ++ibitxy)
408 if ((pattern >> ibitxy) & 0x1)
410 // not quite sure about this
412 if (iCath && localBoard->GetSwitch(6)) offset = -8;
414 AliMpPad pad = seg->PadByLocation(AliMpIntPair(nBoard,ibitxy+offset),kTRUE);
418 fLogger->Log(Form("No pad for detElemId: %d, nboard %d, ibitxy: %d\n",
419 detElemId, nBoard, ibitxy));
423 n = pad.GetLocation(0).GetFirst(); // always take first location so that digits are not inserted several times
424 b = pad.GetLocation(0).GetSecond();
426 AliDebug(1,Form("Using localBoard %d ixy %d instead of %d,%d",
429 AliMUONVDigit* digit = digitStore.Add(detElemId,n,b,iCath,AliMUONVDigitStore::kDeny);
433 AliDebug(1, Form("Digit DE %04d LocalBoard %03d ibitxy %02d cath %d already in store",
434 detElemId,nBoard,ibitxy,iCath));
438 Int_t padX = pad.GetIndices().GetFirst();
439 Int_t padY = pad.GetIndices().GetSecond();
442 digit->SetPadXY(padX,padY);
443 digit->SetCharge(1.);
452 //____________________________________________________________________
453 void AliMUONDigitMaker::SetFastDecoder(Bool_t useFastDecoder)
455 /// Set fast raw data decoder
457 delete fRawStreamTracker;
458 CreateRawStreamTracker(useFastDecoder);