]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONDigitMaker.cxx
Fixing previous change, empty argument macros not supported everywhere
[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
a3283a4c 47#include "AliMUONDDLTrigger.h"
48#include "AliMUONDarcHeader.h"
40e382ae 49#include "AliMUONVDigit.h"
50#include "AliMUONVDigitStore.h"
51#include "AliMUONGlobalTrigger.h"
a3283a4c 52#include "AliMUONLocalStruct.h"
a3283a4c 53#include "AliMUONLocalTrigger.h"
0145e89a 54#include "AliMUONLogger.h"
e3a2b9c9 55#include "AliMUONRawStreamTrackerHP.h"
481d8064 56#include "AliMUONRawStreamTriggerHP.h"
40e382ae 57#include "AliMUONRegHeader.h"
e1a10d41 58#include "AliMUONTriggerCircuit.h"
be63c782 59#include "AliMUONVTriggerStore.h"
60#include "AliMpDetElement.h"
d9b1ecb0 61#include "AliMpTriggerCrate.h"
62#include "AliMpLocalBoard.h"
40e382ae 63#include "AliMpCathodType.h"
64#include "AliMpDDLStore.h"
65#include "AliMpDEManager.h"
66#include "AliMpPad.h"
9265505b 67#include "AliMpSegmentation.h"
a3283a4c 68#include "AliMpVSegmentation.h"
be63c782 69#include "AliCodeTimer.h"
70#include "AliLog.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//__________________________________________________________________________
b6f591ae 79AliMUONDigitMaker::AliMUONDigitMaker(Bool_t enableErrorLogger, Bool_t a, Bool_t b) :
80TObject(),
81fScalerEvent(kFALSE),
82fMakeTriggerDigits(kFALSE),
83fRawStreamTracker(new AliMUONRawStreamTrackerHP),
84fRawStreamTrigger(new AliMUONRawStreamTriggerHP),
85fDigitStore(0x0),
86fTriggerStore(0x0),
87fLogger(new AliMUONLogger(10000))
88{
89 /// ctor
90
91 if ( !a || !b ) AliFatal("no longer supported");
92
93 AliDebug(1,"");
94
95 // Standard Constructor
96 if (enableErrorLogger)
97 {
98 fRawStreamTracker->EnabbleErrorLogger();
99 fRawStreamTrigger->EnabbleErrorLogger();
100 }
101 else
102 {
103 fRawStreamTracker->DisableWarnings();
104 }
105
106 SetMakeTriggerDigits();
107
108}
109
110//__________________________________________________________________________
111AliMUONDigitMaker::AliMUONDigitMaker(Bool_t enableErrorLogger) :
112TObject(),
9f5dcca3 113 fScalerEvent(kFALSE),
40e382ae 114 fMakeTriggerDigits(kFALSE),
b6f591ae 115 fRawStreamTracker(new AliMUONRawStreamTrackerHP),
116 fRawStreamTrigger(new AliMUONRawStreamTriggerHP),
40e382ae 117 fDigitStore(0x0),
0145e89a 118 fTriggerStore(0x0),
119 fLogger(new AliMUONLogger(10000))
a3283a4c 120{
40e382ae 121 /// ctor
a3283a4c 122
123 AliDebug(1,"");
e3a2b9c9 124
a3283a4c 125 // Standard Constructor
b6f591ae 126 if (enableErrorLogger)
127 {
3c7f5307 128 fRawStreamTracker->EnabbleErrorLogger();
129 fRawStreamTrigger->EnabbleErrorLogger();
130 }
b6f591ae 131 else
132 {
133 fRawStreamTracker->DisableWarnings();
134 }
a3283a4c 135
40e382ae 136 SetMakeTriggerDigits();
a3283a4c 137
138}
139
a3283a4c 140//__________________________________________________________________________
9f5dcca3 141AliMUONDigitMaker::~AliMUONDigitMaker()
a3283a4c 142{
9265505b 143 /// clean up
144 /// and time processing measure
145
a3283a4c 146 delete fRawStreamTracker;
147 delete fRawStreamTrigger;
0145e89a 148 delete fLogger;
a3283a4c 149}
150
151//____________________________________________________________________
be63c782 152void
153AliMUONDigitMaker::Print(Option_t*) const
154{
155 /// Printout
156
157 cout << "RawStreamerTracker class=" << fRawStreamTracker->ClassName()
158 << " MakeTriggerDigits=" << fMakeTriggerDigits
159 << " ScalerEvent=" << fScalerEvent
160 << " DigitStore=" << fDigitStore
161 << " TriggerStore=" << fTriggerStore << endl;
162
163 if ( fLogger ) fLogger->Print();
164}
165
166//____________________________________________________________________
167Int_t
168AliMUONDigitMaker::Raw2Digits(AliRawReader* rawReader,
169 AliMUONVDigitStore* digitStore,
170 AliMUONVTriggerStore* triggerStore)
a3283a4c 171{
9265505b 172 /// Main method to creates digit
173 /// for tracker
174 /// and trigger
a3283a4c 175
40e382ae 176 AliDebug(1,Form("rawReader=%p digitStore=%p triggerStore=%p",
177 rawReader,digitStore,triggerStore));
178
179 fDigitStore = digitStore;
180 fTriggerStore = triggerStore;
181
182 if (!fDigitStore && !fTriggerStore)
183 {
0145e89a 184 fLogger->Log("No digit or trigger store given. Nothing to do...");
be63c782 185 return kTriggerBAD & kTrackerBAD;
40e382ae 186 }
187
be63c782 188 Int_t tracker(kOK);
189 Int_t trigger(kOK);
190
40e382ae 191 if ( fDigitStore )
192 {
193 fDigitStore->Clear(); // insure we start with an empty container
be63c782 194 tracker = ReadTrackerDDL(rawReader);
40e382ae 195 }
196
197 if ( fTriggerStore || fMakeTriggerDigits )
198 {
199 if ( fTriggerStore ) fTriggerStore->Clear();
200 if ( fMakeTriggerDigits && !fDigitStore )
201 {
0145e89a 202 fLogger->Log("Asking for trigger digits but digitStore is null");
40e382ae 203 }
204 else
205 {
be63c782 206 trigger = ReadTriggerDDL(rawReader);
40e382ae 207 }
208 }
209
be63c782 210 return tracker | trigger;
a3283a4c 211}
212
213//____________________________________________________________________
be63c782 214Int_t
215AliMUONDigitMaker::ReadTrackerDDL(AliRawReader* rawReader)
a3283a4c 216{
40e382ae 217 /// Reading tracker DDL
218 /// filling the fDigitStore container, which must not be null
a3283a4c 219
40e382ae 220 AliDebug(1,"");
221
99c136e1 222 AliCodeTimerAuto("",0);
a3283a4c 223
224 // elex info
225 Int_t buspatchId;
226 UChar_t channelId;
227 UShort_t manuId;
a3283a4c 228 UShort_t charge;
a3283a4c 229
a3283a4c 230 fRawStreamTracker->SetReader(rawReader);
1bc885f3 231 fRawStreamTracker->First();
232
b6f591ae 233 while ( fRawStreamTracker->Next(buspatchId,manuId,channelId,charge,kTRUE) )
1bc885f3 234 {
40e382ae 235 // getting DE from buspatch
236 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(buspatchId);
a3283a4c 237
be63c782 238 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
239
240 if (!de)
241 {
242 fLogger->Log(Form("DE %04d does not exist !"));
243 continue;
244 }
245
246 if (!de->IsConnectedChannel(manuId,channelId))
247 {
248 // non connected pad, do nothing (this is not an error !)
249 continue;
250 }
251
40e382ae 252 const AliMpVSegmentation* seg
253 = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,
254 manuId);
a3283a4c 255
0145e89a 256 if (!seg)
257 {
258 fLogger->Log(Form("(DE,MANUID)=(%04d,%04d) is not valid",detElemId,manuId));
259 continue;
260 }
261
be63c782 262 AliMp::CathodType cathodeType = de->GetCathodType(seg->PlaneType());
1bc885f3 263
168e9c4d 264 AliMpPad pad = seg->PadByLocation(manuId,channelId,kFALSE);
be63c782 265
40e382ae 266 if (!pad.IsValid())
267 {
0145e89a 268 fLogger->Log(Form("No pad for detElemId: %d, manuId: %d, channelId: %d",
40e382ae 269 detElemId, manuId, channelId));
270 continue;
271 }
be63c782 272
40e382ae 273 AliMUONVDigit* digit = fDigitStore->Add(detElemId,manuId,channelId,cathodeType,
274 AliMUONVDigitStore::kDeny);
be63c782 275
40e382ae 276 if (!digit)
277 {
0145e89a 278 fLogger->Log(Form("Digit DE %04d Manu %04d Channel %02d could not be added",
40e382ae 279 detElemId, manuId, channelId));
280 continue;
281 }
282
168e9c4d 283 digit->SetPadXY(pad.GetIx(),pad.GetIy());
40e382ae 284
168e9c4d 285 digit->SetADC(charge);
9265505b 286
40e382ae 287 }
a3283a4c 288
be63c782 289 if ( fRawStreamTracker->IsErrorMessage() )
290 {
291 return kTrackerBAD;
292 }
293
294 return kOK;
a3283a4c 295}
296
297//____________________________________________________________________
be63c782 298Int_t
299AliMUONDigitMaker::ReadTriggerDDL(AliRawReader* rawReader)
481d8064 300{
301 /// reading tracker DDL like ReadTriggerDDL but with fast decoder interface.
302 /// filling the fTriggerStore container, which must not be null
303
304 const AliMUONRawStreamTriggerHP::AliHeader* darcHeader = 0x0;
305 const AliMUONRawStreamTriggerHP::AliRegionalHeader* regHeader = 0x0;
306 const AliMUONRawStreamTriggerHP::AliLocalStruct* localStruct = 0x0;
307
308 Int_t loCircuit;
309
310 fRawStreamTrigger->SetReader(rawReader);
481d8064 311
312 while (fRawStreamTrigger->NextDDL())
313 {
818aff28 314 darcHeader = fRawStreamTrigger->GetHeaders();
481d8064 315
316 // fill global trigger information
317 if (fTriggerStore)
318 {
319 if (darcHeader->GetGlobalFlag())
320 {
321 AliMUONGlobalTrigger globalTrigger;
322 globalTrigger.SetFromGlobalResponse(darcHeader->GetGlobalOutput());
a90f8830 323 globalTrigger.SetFromGlobalInput(darcHeader->GetGlobalHeader()->fInput);
481d8064 324 fTriggerStore->SetGlobal(globalTrigger);
325 }
326 }
327
818aff28 328 Int_t nReg = fRawStreamTrigger->GetRegionalHeaderCount();
481d8064 329
330 for(Int_t iReg = 0; iReg < nReg ;iReg++)
331 { //reg loop
332
333
334 // crate info
335 AliMpTriggerCrate* crate = AliMpDDLStore::Instance()->
336 GetTriggerCrate(fRawStreamTrigger->GetDDL(), iReg);
337
338 if (!crate)
339 fLogger->Log(Form("Missing crate number %d in DDL %d\n", iReg, fRawStreamTrigger->GetDDL()));
340
341
818aff28 342 regHeader = fRawStreamTrigger->GetRegionalHeader(iReg);
481d8064 343
344 Int_t nLocal = regHeader->GetLocalStructCount();
345 for(Int_t iLocal = 0; iLocal < nLocal; iLocal++)
346 {
347
348 localStruct = regHeader->GetLocalStruct(iLocal);
349
350 // if card exist
351 if (localStruct) {
352
353 loCircuit = crate->GetLocalBoardId(localStruct->GetId());
354
355 if ( !loCircuit ) continue; // empty slot
356
1ffbeb9d 357 AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(loCircuit, kTRUE);
481d8064 358
359 // skip copy cards
360 if( !localBoard->IsNotified())
361 continue;
362
363 if (fTriggerStore)
364 {
365 // fill local trigger
366 AliMUONLocalTrigger localTrigger;
367 localTrigger.SetLoCircuit(loCircuit);
368 localTrigger.SetLoStripX((Int_t)localStruct->GetXPos());
369 localTrigger.SetLoStripY((Int_t)localStruct->GetYPos());
370 localTrigger.SetLoDev((Int_t)localStruct->GetXDev());
371 localTrigger.SetLoSdev((Int_t)localStruct->GetSXDev());
372 localTrigger.SetLoTrigY((Int_t)localStruct->GetTrigY());
373 localTrigger.SetLoLpt(localStruct->GetLpt());
374 localTrigger.SetLoHpt(localStruct->GetHpt());
375 localTrigger.SetX1Pattern(localStruct->GetX1());
376 localTrigger.SetX2Pattern(localStruct->GetX2());
377 localTrigger.SetX3Pattern(localStruct->GetX3());
378 localTrigger.SetX4Pattern(localStruct->GetX4());
379 localTrigger.SetY1Pattern(localStruct->GetY1());
380 localTrigger.SetY2Pattern(localStruct->GetY2());
381 localTrigger.SetY3Pattern(localStruct->GetY3());
382 localTrigger.SetY4Pattern(localStruct->GetY4());
383 fTriggerStore->Add(localTrigger);
384 }
385
386 if ( fMakeTriggerDigits )
387 {
388 //FIXEME should find something better than a TArray
389 TArrayS xyPattern[2];
390
391 localStruct->GetXPattern(xyPattern[0]);
392 localStruct->GetYPattern(xyPattern[1]);
393
394 TriggerDigits(loCircuit, xyPattern, *fDigitStore);
395 }
396 } // if triggerY
397 } // iLocal
398 } // iReg
399 } // NextDDL
400
401 return kOK;
402}
403
d2d759cf 404//____________________________________________________________________
7771752e 405Int_t AliMUONDigitMaker::TriggerDigits(Int_t nBoard,
40e382ae 406 TArrayS* xyPattern,
407 AliMUONVDigitStore& digitStore) const
d2d759cf 408{
40e382ae 409 /// make digits for trigger from pattern, and add them to digitStore
d2d759cf 410
99c136e1 411 AliCodeTimerAuto("",0);
0145e89a 412
d9b1ecb0 413 Int_t detElemId;
414
415 AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(nBoard);
416
8c0b5e70 417 Int_t n,b;
418
d2d759cf 419 // loop over x1-4 and y1-4
40e382ae 420 for (Int_t iChamber = 0; iChamber < 4; ++iChamber)
421 {
422 for (Int_t iCath = 0; iCath < 2; ++iCath)
423 {
7771752e 424 Int_t pattern = (Int_t)xyPattern[iCath].At(iChamber);
425 if (!pattern) continue;
40e382ae 426
7771752e 427 // get detElemId
d9b1ecb0 428 detElemId = AliMpDDLStore::Instance()->GetDEfromLocalBoard(nBoard, iChamber);
40e382ae 429
430 const AliMpVSegmentation* seg
431 = AliMpSegmentation::Instance()
432 ->GetMpSegmentation(detElemId, AliMp::GetCathodType(iCath));
433
434 // loop over the 16 bits of pattern
435 for (Int_t ibitxy = 0; ibitxy < 16; ++ibitxy)
436 {
437 if ((pattern >> ibitxy) & 0x1)
438 {
439 // not quite sure about this
440 Int_t offset = 0;
441 if (iCath && localBoard->GetSwitch(6)) offset = -8;
442
168e9c4d 443 AliMpPad pad = seg->PadByLocation(nBoard,ibitxy+offset,kTRUE);
40e382ae 444
445 if (!pad.IsValid())
446 {
0145e89a 447 fLogger->Log(Form("No pad for detElemId: %d, nboard %d, ibitxy: %d\n",
40e382ae 448 detElemId, nBoard, ibitxy));
449 continue;
450 }
8c0b5e70 451
168e9c4d 452 n = pad.GetLocalBoardId(0); // always take first location so that digits are not inserted several times
453 b = pad.GetLocalBoardChannel(0);
8c0b5e70 454
455 AliDebug(1,Form("Using localBoard %d ixy %d instead of %d,%d",
456 n,b,nBoard,ibitxy));
457
458 AliMUONVDigit* digit = digitStore.Add(detElemId,n,b,iCath,AliMUONVDigitStore::kDeny);
40e382ae 459
460 if (!digit)
461 {
8c0b5e70 462 AliDebug(1, Form("Digit DE %04d LocalBoard %03d ibitxy %02d cath %d already in store",
463 detElemId,nBoard,ibitxy,iCath));
464 continue;
40e382ae 465 }
466
168e9c4d 467 Int_t padX = pad.GetIx();
468 Int_t padY = pad.GetIy();
40e382ae 469
470 // fill digit
471 digit->SetPadXY(padX,padY);
472 digit->SetCharge(1.);
473 }// xyPattern
474 }// ibitxy
7771752e 475 }// cath
476 } // ichamber
40e382ae 477
d2d759cf 478 return kTRUE;
481d8064 479}
d61f56df 480
54355f2c 481//______________________________________________________________________________
482Bool_t
483AliMUONDigitMaker::TriggerToDigitsStore(const AliMUONVTriggerStore& triggerStore,
484 AliMUONVDigitStore& digitStore) const
485{
486 //
487 /// make (S)Digit for trigger
488 //
489
490 digitStore.Clear();
491
492 AliMUONLocalTrigger* locTrg;
493 TIter next(triggerStore.CreateLocalIterator());
494
495 while ( ( locTrg = static_cast<AliMUONLocalTrigger*>(next()) ) )
496 {
497 if (locTrg->IsNull()) continue;
498
499 TArrayS xyPattern[2];
500 locTrg->GetXPattern(xyPattern[0]);
501 locTrg->GetYPattern(xyPattern[1]);
502
503 Int_t nBoard = locTrg->LoCircuit();
504 TriggerDigits(nBoard, xyPattern, digitStore);
505 }
506 return kTRUE;
507}