Correcting EffC++ warnings
[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
16////////////////////////////////////
17///
18/// MUON Digit maker from rawdata in ALICE-MUON
19/// Using new interface with AliMUONRawStreamTracker(Trigger)
20/// (New interface of AliMUONRawReader class)
21/// Class version 1 (further details could be found in Alice-note)
22///
23/// Implemented non-constant buspatch numbers for tracking
24/// with correct DDL id (first guess)
25/// (Ch. Finck, dec 2005)
26///
27///
28/// Raw2Digits:
29/// Using real mapping for tracker
30/// Indranil Das (Adapted for runloader: Ch. Finck) july 05
31/// Add reader for scaler trigger events
32/// Use memcpy instead of assignment elt by elt
33/// (Ch. Finck, Jan 06)
34///
35////////////////////////////////////
36
37#include <fstream>
38#include <string>
39
40#include <TClonesArray.h>
41
42#include "AliRawReader.h"
43#include "AliRawDataHeader.h"
44#include "AliLog.h"
45#include "AliRun.h"
46
84ceeb06 47#include "AliMpBusPatch.h"
a3283a4c 48#include "AliMUON.h"
49#include "AliMUONDigitMaker.h"
50#include "AliMUONDigit.h"
51
52#include "AliMUONConstants.h"
53#include "AliMUONData.h"
54
55#include "AliMUONRawStreamTracker.h"
56#include "AliMUONDDLTracker.h"
57#include "AliMUONDspHeader.h"
58#include "AliMUONBlockHeader.h"
59#include "AliMUONBusStruct.h"
60
61#include "AliMUONRawStreamTrigger.h"
62#include "AliMUONDDLTrigger.h"
63#include "AliMUONDarcHeader.h"
64#include "AliMUONRegHeader.h"
65#include "AliMUONLocalStruct.h"
66
67#include "AliMUONLocalTrigger.h"
68#include "AliMUONGlobalTrigger.h"
69
70#include "AliMpSegFactory.h"
71#include "AliMpVSegmentation.h"
72#include "AliMpPad.h"
73#include "AliMpDEManager.h"
74
75ClassImp(AliMUONDigitMaker) // Class implementation in ROOT context
76//__________________________________________________________________________
77AliMUONDigitMaker::AliMUONDigitMaker(AliMUONData* data)
78 : TObject(),
9f5dcca3 79 fMUONData(data),
80 fSegFactory(new AliMpSegFactory()),
81 fBusPatchManager(new AliMpBusPatch()),
82 fScalerEvent(kFALSE),
83 fRawStreamTracker(new AliMUONRawStreamTracker()),
84 fRawStreamTrigger(new AliMUONRawStreamTrigger()),
85 fDigit(new AliMUONDigit()),
86 fLocalTrigger(new AliMUONLocalTrigger()),
87 fGlobalTrigger(new AliMUONGlobalTrigger()),
88 fTrackerTimer(),
89 fTriggerTimer(),
90 fMappingTimer()
a3283a4c 91{
92 //
93 // ctor with AliMUONData as argument
94 // for reconstruction
95 //
96
97 AliDebug(1,"");
98
99 // Standard Constructor
100
a3283a4c 101 // bus patch
a3283a4c 102 fBusPatchManager->ReadBusPatchFile();
103
a3283a4c 104
105 fTrackerTimer.Start(kTRUE); fTrackerTimer.Stop();
106 fTriggerTimer.Start(kTRUE); fTriggerTimer.Stop();
107 fMappingTimer.Start(kTRUE); fMappingTimer.Stop();
108
109}
110
111//__________________________________________________________________________
112AliMUONDigitMaker::AliMUONDigitMaker()
113 : TObject(),
114 fMUONData(0),
115 fSegFactory(0),
116 fBusPatchManager(0),
117 fScalerEvent(kFALSE),
118 fRawStreamTracker(0),
119 fRawStreamTrigger(0),
120 fDigit(0),
9f5dcca3 121 fLocalTrigger(0),
122 fGlobalTrigger(0),
123 fTrackerTimer(),
124 fTriggerTimer(),
125 fMappingTimer()
a3283a4c 126{
127 //
128 // Default Constructor
129 //
130 AliDebug(1,"");
131 fTrackerTimer.Start(kTRUE); fTrackerTimer.Stop();
132 fTriggerTimer.Start(kTRUE); fTriggerTimer.Stop();
133 fMappingTimer.Start(kTRUE); fMappingTimer.Stop();
134
135}
136
a3283a4c 137//__________________________________________________________________________
9f5dcca3 138AliMUONDigitMaker::~AliMUONDigitMaker()
a3283a4c 139{
140 //
141 // clean up
142 // and time processing measure
143 //
144 delete fSegFactory;
145
146 delete fRawStreamTracker;
147 delete fRawStreamTrigger;
148
149 delete fDigit;
150 delete fLocalTrigger;
151 delete fGlobalTrigger;
152
153 delete fBusPatchManager;
154
155 AliInfo(Form("Execution time for MUON tracker : R:%.2fs C:%.2fs",
156 fTrackerTimer.RealTime(),fTrackerTimer.CpuTime()));
157 AliInfo(Form(" Execution time for MUON tracker (mapping calls part) "
158 ": R:%.2fs C:%.2fs",
159 fMappingTimer.RealTime(),fMappingTimer.CpuTime()));
160 AliInfo(Form("Execution time for MUON trigger : R:%.2fs C:%.2fs",
161 fTriggerTimer.RealTime(),fTriggerTimer.CpuTime()));
162
163 return;
164}
165
166//____________________________________________________________________
167Int_t AliMUONDigitMaker::Raw2Digits(AliRawReader* rawReader)
168{
169 // Main method to creates digit
170 // for tracker
171 // and trigger
172
173 // generate digits
174 ReadTrackerDDL(rawReader);
175
176 // generate trigger
177 ReadTriggerDDL(rawReader);
178
179 return kTRUE;
180
181}
182
183//____________________________________________________________________
184Int_t AliMUONDigitMaker::ReadTrackerDDL(AliRawReader* rawReader)
185{
186
187 // reading tracker DDL
188 // filling the TClonesArray in MUONData
189 //
190 fTrackerTimer.Start(kFALSE);
191
192 // elex info
193 Int_t buspatchId;
194 UChar_t channelId;
195 UShort_t manuId;
196 Char_t parity;
197 UShort_t charge;
198 Int_t dataSize;
199
200 AliMUONDDLTracker* ddlTracker = 0x0;
201 AliMUONBlockHeader* blkHeader = 0x0;
202 AliMUONDspHeader* dspHeader = 0x0;
203 AliMUONBusStruct* busStruct = 0x0;
204
205
206 fRawStreamTracker->SetReader(rawReader);
207
208 while(fRawStreamTracker->NextDDL()) {
209
210 ddlTracker = fRawStreamTracker->GetDDLTracker();
211
212 Int_t nBlock = ddlTracker->GetBlkHeaderEntries();
213 for(Int_t iBlock = 0; iBlock < nBlock ;iBlock++){
214
215 blkHeader = ddlTracker->GetBlkHeaderEntry(iBlock);
216
217 Int_t nDsp = blkHeader->GetDspHeaderEntries();
218
219 for(Int_t iDsp = 0; iDsp < nDsp ;iDsp++){ //DSP loop
220
221 dspHeader = blkHeader->GetDspHeaderEntry(iDsp);
222
223 Int_t nBusPatch = dspHeader->GetBusPatchEntries();
224
225 for(Int_t iBusPatch = 0; iBusPatch < nBusPatch; iBusPatch++) {
226
227 busStruct = dspHeader->GetBusPatchEntry(iBusPatch);
228
229 dataSize = busStruct->GetLength();
230 buspatchId = busStruct->GetBusPatchId();
231
232 for (Int_t iData = 0; iData < dataSize; iData++) {
233
234 // digits info
235 parity = busStruct->GetParity(iData); // test later for parity
236 manuId = busStruct->GetManuId(iData);
237 channelId = busStruct->GetChannelId(iData);
238 charge = busStruct->GetCharge(iData);
239 // set charge
240 fDigit->SetSignal(charge);
241 fDigit->SetPhysicsSignal(charge);
242 fDigit->SetADC(charge);
243
244 // Get Back the hits at pads
245 Int_t error = GetMapping(buspatchId,manuId,channelId,fDigit);
84ceeb06 246 if (error) {
247 printf("Mapping Error\n");
248 continue;
249 }
a3283a4c 250 // debugging
251 if (AliLog::GetGlobalDebugLevel() == 3) {
252 Int_t padX = fDigit->PadX();
253 Int_t padY = fDigit->PadY();
254 Int_t iCath = fDigit->Cathode();
255 Int_t idDE = fDigit->DetElemId();
256
257 AliDebug(1,Form("output IdDE %d busPatchid %d PadX %d PadY %d iCath %d \n",
258 idDE, buspatchId, padX, padY, iCath));
259
260 AliDebug(3,Form("idDE %d Padx %d Pady %d, Cath %d, charge %d",
261 idDE, padX, padY, iCath, charge));
262 }
263
264 // fill digits
265 fMUONData->AddDigit(fRawStreamTracker->GetDDL()/2, *fDigit);
266
267 } // iData
268 } // iBusPatch
269 } // iDsp
270 } // iBlock
271 } // NextDDL
272
273 fTrackerTimer.Stop();
274
275 return kTRUE;
276}
277//____________________________________________________________________
278Int_t AliMUONDigitMaker::GetMapping(Int_t busPatchId, UShort_t manuId,
279 UChar_t channelId, AliMUONDigit* digit )
280{
281 //
282 // mapping for tracker
283 //
284 fMappingTimer.Start(kFALSE);
285
286 // getting DE from buspatch
287 Int_t detElemId = fBusPatchManager->GetDEfromBus(busPatchId);
288 AliDebug(3,Form("detElemId: %d busPatchId %d\n", detElemId, busPatchId));
289
290 AliMpVSegmentation* seg = fSegFactory->CreateMpSegmentationByElectronics(detElemId, manuId);
291 AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,channelId),kTRUE);
292
293 if (!pad.IsValid())
294 {
295 AliWarning(Form("No pad for detElemId: %d, busPatchId %d, manuId: %d, channelId: %d\n",
296 detElemId, busPatchId, manuId, channelId));
297 fMappingTimer.Stop();
298 return kTRUE;
299 } // return error
300
301 // Getting padX, padY and cathode number.
302 Int_t padX = pad.GetIndices().GetFirst();
303 Int_t padY = pad.GetIndices().GetSecond();
304 Int_t iCath = AliMpDEManager::GetCathod(detElemId,seg->PlaneType());
305
306 // storing into digits
307 digit->SetPadX(padX);
308 digit->SetPadY(padY);
309 digit->SetCathode(iCath);
310 digit->SetDetElemId(detElemId);
311 digit->SetElectronics(manuId,channelId);
312
313 AliDebug(3,Form("detElemId: %d, busPatchId %d, manuId: %d, channelId: %d, padx: %d pady %d\n",
314 detElemId, busPatchId, manuId, channelId, padX, padY));
315 StdoutToAliDebug(3,digit->Print(););
316
317 fMappingTimer.Stop();
318 return kFALSE;
319}
320
321//____________________________________________________________________
322Int_t AliMUONDigitMaker::ReadTriggerDDL(AliRawReader* rawReader)
323{
324 // reading tracker DDL
325 // filling the TClonesArray in MUONData
326 //
327
328 AliMUONDDLTrigger* ddlTrigger = 0x0;
329 AliMUONDarcHeader* darcHeader = 0x0;
330 AliMUONRegHeader* regHeader = 0x0;
331 AliMUONLocalStruct* localStruct = 0x0;
332
333 Int_t loCircuit;
334
335 fTriggerTimer.Start(kFALSE);
336
337 fRawStreamTrigger->SetReader(rawReader);
338
339 while(fRawStreamTrigger->NextDDL()) {
340
341 ddlTrigger = fRawStreamTrigger->GetDDLTrigger();
342 darcHeader = ddlTrigger->GetDarcHeader();
343
344 // fill global trigger information
af3c5ff4 345 if (darcHeader->GetGlobalFlag()) {
a3283a4c 346 fGlobalTrigger->SetGlobalPattern(darcHeader->GetGlobalOutput());
347 fMUONData->AddGlobalTrigger(*fGlobalTrigger);
348 }
349
350 Int_t nReg = darcHeader->GetRegHeaderEntries();
351
352 for(Int_t iReg = 0; iReg < nReg ;iReg++){ //reg loop
353
354 regHeader = darcHeader->GetRegHeaderEntry(iReg);
355
356 Int_t nLocal = regHeader->GetLocalEntries();
357
358 for(Int_t iLocal = 0; iLocal < nLocal; iLocal++) {
359
360 localStruct = regHeader->GetLocalEntry(iLocal);
361
362 if (localStruct->GetTriggerY() == 0) {
363 loCircuit = localStruct->GetId()+ 16*regHeader->GetId()
364 + 128*fRawStreamTrigger->GetDDL();
365
366 // fill local trigger
367 fLocalTrigger->SetLocalStruct(loCircuit, *localStruct);
368
369 fMUONData->AddLocalTrigger(*fLocalTrigger);
370 } // if triggerY
371 } // iLocal
372 } // iReg
373 } // NextDDL
374
375 fTriggerTimer.Stop();
376
377 return kTRUE;
378
379}
380