]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONDigitMaker.cxx
Adding comment line only
[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
0145e89a 47#include "AliCodeTimer.h"
40e382ae 48#include "AliLog.h"
a3283a4c 49#include "AliMUONDDLTrigger.h"
50#include "AliMUONDarcHeader.h"
40e382ae 51#include "AliMUONVDigit.h"
52#include "AliMUONVDigitStore.h"
53#include "AliMUONGlobalTrigger.h"
a3283a4c 54#include "AliMUONLocalStruct.h"
a3283a4c 55#include "AliMUONLocalTrigger.h"
0145e89a 56#include "AliMUONLogger.h"
40e382ae 57#include "AliMUONRawStreamTracker.h"
e3a2b9c9 58#include "AliMUONRawStreamTrackerHP.h"
40e382ae 59#include "AliMUONRawStreamTrigger.h"
60#include "AliMUONRegHeader.h"
e1a10d41 61#include "AliMUONTriggerCircuit.h"
d9b1ecb0 62#include "AliMpTriggerCrate.h"
63#include "AliMpLocalBoard.h"
40e382ae 64#include "AliMUONVTriggerStore.h"
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"
9265505b 71#include "AliRawReader.h"
7771752e 72#include <TArrayS.h>
9265505b 73
9265505b 74/// \cond CLASSIMP
a3283a4c 75ClassImp(AliMUONDigitMaker) // Class implementation in ROOT context
9265505b 76/// \endcond
77
a3283a4c 78//__________________________________________________________________________
e3a2b9c9 79AliMUONDigitMaker::AliMUONDigitMaker(Bool_t enableErrorLogger, Bool_t useFastDecoder)
a3283a4c 80 : TObject(),
9f5dcca3 81 fScalerEvent(kFALSE),
40e382ae 82 fMakeTriggerDigits(kFALSE),
e3a2b9c9 83 fRawStreamTracker(NULL),
9f5dcca3 84 fRawStreamTrigger(new AliMUONRawStreamTrigger()),
40e382ae 85 fDigitStore(0x0),
0145e89a 86 fTriggerStore(0x0),
87 fLogger(new AliMUONLogger(10000))
a3283a4c 88{
40e382ae 89 /// ctor
a3283a4c 90
91 AliDebug(1,"");
e3a2b9c9 92
d61f56df 93 CreateRawStreamTracker(useFastDecoder);
a3283a4c 94
95 // Standard Constructor
3c7f5307 96 if (enableErrorLogger) {
97 fRawStreamTracker->EnabbleErrorLogger();
98 fRawStreamTrigger->EnabbleErrorLogger();
99 }
a3283a4c 100
40e382ae 101 SetMakeTriggerDigits();
a3283a4c 102
103}
104
a3283a4c 105//__________________________________________________________________________
9f5dcca3 106AliMUONDigitMaker::~AliMUONDigitMaker()
a3283a4c 107{
9265505b 108 /// clean up
109 /// and time processing measure
110
a3283a4c 111 delete fRawStreamTracker;
112 delete fRawStreamTrigger;
113
0145e89a 114 delete fLogger;
a3283a4c 115}
116
d61f56df 117//__________________________________________________________________________
118void AliMUONDigitMaker::CreateRawStreamTracker(Bool_t useFastDecoder)
119{
120/// Create raw stream tracker according to the passed option
121
122 if (useFastDecoder)
123 {
124 AliInfo("Using fast decoder.");
125 fRawStreamTracker = new AliMUONRawStreamTrackerHP();
126 }
127 else
128 fRawStreamTracker = new AliMUONRawStreamTracker();
129}
130
a3283a4c 131//____________________________________________________________________
40e382ae 132Int_t AliMUONDigitMaker::Raw2Digits(AliRawReader* rawReader,
133 AliMUONVDigitStore* digitStore,
134 AliMUONVTriggerStore* triggerStore)
a3283a4c 135{
9265505b 136 /// Main method to creates digit
137 /// for tracker
138 /// and trigger
a3283a4c 139
40e382ae 140 AliDebug(1,Form("rawReader=%p digitStore=%p triggerStore=%p",
141 rawReader,digitStore,triggerStore));
142
143 fDigitStore = digitStore;
144 fTriggerStore = triggerStore;
145
146 if (!fDigitStore && !fTriggerStore)
147 {
0145e89a 148 fLogger->Log("No digit or trigger store given. Nothing to do...");
40e382ae 149 return kFALSE;
150 }
151
152 if ( fDigitStore )
153 {
154 fDigitStore->Clear(); // insure we start with an empty container
155 ReadTrackerDDL(rawReader);
156 }
157
158 if ( fTriggerStore || fMakeTriggerDigits )
159 {
160 if ( fTriggerStore ) fTriggerStore->Clear();
161 if ( fMakeTriggerDigits && !fDigitStore )
162 {
0145e89a 163 fLogger->Log("Asking for trigger digits but digitStore is null");
40e382ae 164 }
165 else
166 {
e604ac4c 167 ReadTriggerDDL(rawReader);
40e382ae 168 }
169 }
170
a3283a4c 171 return kTRUE;
a3283a4c 172}
173
174//____________________________________________________________________
175Int_t AliMUONDigitMaker::ReadTrackerDDL(AliRawReader* rawReader)
176{
40e382ae 177 /// Reading tracker DDL
178 /// filling the fDigitStore container, which must not be null
a3283a4c 179
40e382ae 180 AliDebug(1,"");
181
0145e89a 182 AliCodeTimerAuto("");
a3283a4c 183
184 // elex info
185 Int_t buspatchId;
186 UChar_t channelId;
187 UShort_t manuId;
a3283a4c 188 UShort_t charge;
a3283a4c 189
a3283a4c 190 fRawStreamTracker->SetReader(rawReader);
1bc885f3 191 fRawStreamTracker->First();
192
193 while ( fRawStreamTracker->Next(buspatchId,manuId,channelId,charge) )
194 {
40e382ae 195 // getting DE from buspatch
196 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(buspatchId);
a3283a4c 197
40e382ae 198 const AliMpVSegmentation* seg
199 = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,
200 manuId);
a3283a4c 201
0145e89a 202 if (!seg)
203 {
204 fLogger->Log(Form("(DE,MANUID)=(%04d,%04d) is not valid",detElemId,manuId));
205 continue;
206 }
207
40e382ae 208 AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId,
209 seg->PlaneType());
1bc885f3 210
40e382ae 211 AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,channelId),kFALSE);
212
213 if (!pad.IsValid())
214 {
0145e89a 215 fLogger->Log(Form("No pad for detElemId: %d, manuId: %d, channelId: %d",
40e382ae 216 detElemId, manuId, channelId));
217 continue;
218 }
219
220 AliMUONVDigit* digit = fDigitStore->Add(detElemId,manuId,channelId,cathodeType,
221 AliMUONVDigitStore::kDeny);
222 if (!digit)
223 {
0145e89a 224 fLogger->Log(Form("Digit DE %04d Manu %04d Channel %02d could not be added",
40e382ae 225 detElemId, manuId, channelId));
226 continue;
227 }
228
229 digit->SetPadXY(pad.GetIndices().GetFirst(),
230 pad.GetIndices().GetSecond());
231
232 digit->SetADC(charge);
9265505b 233
40e382ae 234 }
a3283a4c 235
40e382ae 236 return kTRUE;
a3283a4c 237}
238
239//____________________________________________________________________
240Int_t AliMUONDigitMaker::ReadTriggerDDL(AliRawReader* rawReader)
241{
9265505b 242 /// reading tracker DDL
40e382ae 243 /// filling the fTriggerStore container, which must not be null
a3283a4c 244
40e382ae 245 AliDebug(1,"");
246
a3283a4c 247 AliMUONDDLTrigger* ddlTrigger = 0x0;
248 AliMUONDarcHeader* darcHeader = 0x0;
249 AliMUONRegHeader* regHeader = 0x0;
250 AliMUONLocalStruct* localStruct = 0x0;
251
252 Int_t loCircuit;
d2d759cf 253
0145e89a 254 AliCodeTimerAuto("");
a3283a4c 255
256 fRawStreamTrigger->SetReader(rawReader);
257
40e382ae 258 while (fRawStreamTrigger->NextDDL())
259 {
a3283a4c 260 ddlTrigger = fRawStreamTrigger->GetDDLTrigger();
261 darcHeader = ddlTrigger->GetDarcHeader();
40e382ae 262
263 // fill global trigger information
264 if (fTriggerStore)
265 {
266 if (darcHeader->GetGlobalFlag())
267 {
268 AliMUONGlobalTrigger globalTrigger;
269 globalTrigger.SetFromGlobalResponse(darcHeader->GetGlobalOutput());
270 fTriggerStore->SetGlobal(globalTrigger);
d2d759cf 271 }
a3283a4c 272 }
40e382ae 273
a3283a4c 274 Int_t nReg = darcHeader->GetRegHeaderEntries();
40e382ae 275
276 for(Int_t iReg = 0; iReg < nReg ;iReg++)
277 { //reg loop
278
d9b1ecb0 279
280 // crate info
281 AliMpTriggerCrate* crate = AliMpDDLStore::Instance()->
282 GetTriggerCrate(fRawStreamTrigger->GetDDL(), iReg);
40e382ae 283
d53fb0de 284 if (!crate)
0145e89a 285 fLogger->Log(Form("Missing crate number %d in DDL %d\n", iReg, fRawStreamTrigger->GetDDL()));
d9b1ecb0 286
40e382ae 287
a3283a4c 288 regHeader = darcHeader->GetRegHeaderEntry(iReg);
40e382ae 289
a3283a4c 290 Int_t nLocal = regHeader->GetLocalEntries();
40e382ae 291 for(Int_t iLocal = 0; iLocal < nLocal; iLocal++)
292 {
293
294 localStruct = regHeader->GetLocalEntry(iLocal);
295
296 // if card exist
297 if (localStruct) {
298
d9b1ecb0 299 loCircuit = crate->GetLocalBoardId(localStruct->GetId());
300
301 if ( !loCircuit ) continue; // empty slot
302
303 AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(loCircuit, false);
304
305 // skip copy cards
306 if( !localBoard->IsNotified())
307 continue;
40e382ae 308
309 if (fTriggerStore)
310 {
311 // fill local trigger
312 AliMUONLocalTrigger localTrigger;
313 localTrigger.SetLocalStruct(loCircuit, *localStruct);
314 fTriggerStore->Add(localTrigger);
315 }
316
317 if ( fMakeTriggerDigits )
318 {
319 //FIXEME should find something better than a TArray
320 TArrayS xyPattern[2];
40e382ae 321
d9b1ecb0 322 localStruct->GetXPattern(xyPattern[0]);
323 localStruct->GetYPattern(xyPattern[1]);
40e382ae 324
325 TriggerDigits(loCircuit, xyPattern, *fDigitStore);
326 }
327 } // if triggerY
a3283a4c 328 } // iLocal
329 } // iReg
330 } // NextDDL
40e382ae 331
a3283a4c 332 return kTRUE;
333
334}
7771752e 335
d2d759cf 336//____________________________________________________________________
7771752e 337Int_t AliMUONDigitMaker::TriggerDigits(Int_t nBoard,
40e382ae 338 TArrayS* xyPattern,
339 AliMUONVDigitStore& digitStore) const
d2d759cf 340{
40e382ae 341 /// make digits for trigger from pattern, and add them to digitStore
d2d759cf 342
0145e89a 343 AliCodeTimerAuto("");
344
d9b1ecb0 345 Int_t detElemId;
346
347 AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(nBoard);
348
8c0b5e70 349 Int_t n,b;
350
d2d759cf 351 // loop over x1-4 and y1-4
40e382ae 352 for (Int_t iChamber = 0; iChamber < 4; ++iChamber)
353 {
354 for (Int_t iCath = 0; iCath < 2; ++iCath)
355 {
7771752e 356 Int_t pattern = (Int_t)xyPattern[iCath].At(iChamber);
357 if (!pattern) continue;
40e382ae 358
7771752e 359 // get detElemId
d9b1ecb0 360 detElemId = AliMpDDLStore::Instance()->GetDEfromLocalBoard(nBoard, iChamber);
40e382ae 361
362 const AliMpVSegmentation* seg
363 = AliMpSegmentation::Instance()
364 ->GetMpSegmentation(detElemId, AliMp::GetCathodType(iCath));
365
366 // loop over the 16 bits of pattern
367 for (Int_t ibitxy = 0; ibitxy < 16; ++ibitxy)
368 {
369 if ((pattern >> ibitxy) & 0x1)
370 {
371 // not quite sure about this
372 Int_t offset = 0;
373 if (iCath && localBoard->GetSwitch(6)) offset = -8;
374
375 AliMpPad pad = seg->PadByLocation(AliMpIntPair(nBoard,ibitxy+offset),kTRUE);
376
377 if (!pad.IsValid())
378 {
0145e89a 379 fLogger->Log(Form("No pad for detElemId: %d, nboard %d, ibitxy: %d\n",
40e382ae 380 detElemId, nBoard, ibitxy));
381 continue;
382 }
8c0b5e70 383
384 n = pad.GetLocation(0).GetFirst(); // always take first location so that digits are not inserted several times
385 b = pad.GetLocation(0).GetSecond();
386
387 AliDebug(1,Form("Using localBoard %d ixy %d instead of %d,%d",
388 n,b,nBoard,ibitxy));
389
390 AliMUONVDigit* digit = digitStore.Add(detElemId,n,b,iCath,AliMUONVDigitStore::kDeny);
40e382ae 391
392 if (!digit)
393 {
8c0b5e70 394 AliDebug(1, Form("Digit DE %04d LocalBoard %03d ibitxy %02d cath %d already in store",
395 detElemId,nBoard,ibitxy,iCath));
396 continue;
40e382ae 397 }
398
399 Int_t padX = pad.GetIndices().GetFirst();
400 Int_t padY = pad.GetIndices().GetSecond();
401
402 // fill digit
403 digit->SetPadXY(padX,padY);
404 digit->SetCharge(1.);
405 }// xyPattern
406 }// ibitxy
7771752e 407 }// cath
408 } // ichamber
40e382ae 409
d2d759cf 410 return kTRUE;
411}
d61f56df 412
413//____________________________________________________________________
414void AliMUONDigitMaker::SetFastDecoder(Bool_t useFastDecoder)
415{
416/// Set fast raw data decoder
417
418 delete fRawStreamTracker;
419 CreateRawStreamTracker(useFastDecoder);
420}
421
422
423