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