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