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