]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONDigitMaker.cxx
Optimized rawdata reconstruction & removing effc++ warnings (Christian)
[u/mrichter/AliRoot.git] / MUON / AliMUONDigitMaker.cxx
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
47 #include "AliMpBusPatch.h"
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 "AliMUONTriggerCrateStore.h"
68 #include "AliMUONTriggerCrate.h"
69 #include "AliMUONLocalTriggerBoard.h"
70 #include "AliMUONLocalTrigger.h"
71 #include "AliMUONGlobalTrigger.h"
72
73 #include "AliMpSegFactory.h"
74 #include "AliMpVSegmentation.h"
75 #include "AliMpPad.h"
76 #include "AliMpDEManager.h"
77
78 ClassImp(AliMUONDigitMaker) // Class implementation in ROOT context
79 //__________________________________________________________________________
80 AliMUONDigitMaker::AliMUONDigitMaker()
81   : TObject(),
82     fMUONData(0x0),
83     fSegFactory(new AliMpSegFactory()),
84     fBusPatchManager(new AliMpBusPatch()),
85     fScalerEvent(kFALSE),
86     fRawStreamTracker(new AliMUONRawStreamTracker()),    
87     fRawStreamTrigger(new AliMUONRawStreamTrigger()),    
88     fDigit(new AliMUONDigit()),
89     fLocalTrigger(new AliMUONLocalTrigger()),
90     fGlobalTrigger(new AliMUONGlobalTrigger()),
91     fCrateManager(new AliMUONTriggerCrateStore()),
92     fTrackerTimer(),
93     fTriggerTimer(),
94     fMappingTimer()
95 {
96   //
97   // ctor with AliMUONData as argument
98   // for reconstruction
99   //
100
101   AliDebug(1,"");
102
103   // Standard Constructor
104
105   // bus patch 
106   fBusPatchManager->ReadBusPatchFile();
107
108   // Crate manager
109   fCrateManager->ReadFromFile();
110
111   fTrackerTimer.Start(kTRUE); fTrackerTimer.Stop();
112   fTriggerTimer.Start(kTRUE); fTriggerTimer.Stop();
113   fMappingTimer.Start(kTRUE); fMappingTimer.Stop();
114
115 }
116
117 //__________________________________________________________________________
118 AliMUONDigitMaker::~AliMUONDigitMaker()
119 {
120   //
121   // clean up
122   // and time processing measure
123   //
124   delete fSegFactory;  
125
126   delete fRawStreamTracker;
127   delete fRawStreamTrigger;
128
129   delete fDigit;
130   delete fLocalTrigger;
131   delete fGlobalTrigger;
132
133   delete fCrateManager;
134
135   delete fBusPatchManager;
136
137   AliInfo(Form("Execution time for MUON tracker : R:%.2fs C:%.2fs",
138                fTrackerTimer.RealTime(),fTrackerTimer.CpuTime()));
139   AliInfo(Form("   Execution time for MUON tracker (mapping calls part) "
140                ": R:%.2fs C:%.2fs",
141                fMappingTimer.RealTime(),fMappingTimer.CpuTime()));
142   AliInfo(Form("Execution time for MUON trigger : R:%.2fs C:%.2fs",
143                fTriggerTimer.RealTime(),fTriggerTimer.CpuTime()));
144
145   return;
146 }
147
148 //____________________________________________________________________
149 Int_t AliMUONDigitMaker::Raw2Digits(AliRawReader* rawReader)
150 {
151   // Main method to creates digit
152   // for tracker 
153   // and trigger
154
155   // generate digits
156   ReadTrackerDDL(rawReader);
157
158   // generate trigger
159   ReadTriggerDDL(rawReader);
160
161   return kTRUE;
162
163 }
164
165 //____________________________________________________________________
166 Int_t AliMUONDigitMaker::ReadTrackerDDL(AliRawReader* rawReader)
167 {
168
169   // reading tracker DDL
170   // filling the TClonesArray in MUONData
171   //
172   fTrackerTimer.Start(kFALSE);
173
174   // elex info
175   Int_t    buspatchId;
176   UChar_t  channelId;
177   UShort_t manuId;
178   Char_t   parity;
179   UShort_t charge; 
180   Int_t    dataSize;
181
182   Int_t iChamber;
183
184   AliMUONDDLTracker*   ddlTracker = 0x0;
185   AliMUONBlockHeader*  blkHeader  = 0x0;
186   AliMUONDspHeader*    dspHeader  = 0x0;
187   AliMUONBusStruct*    busStruct  = 0x0;
188
189
190   fRawStreamTracker->SetReader(rawReader);
191
192   while(fRawStreamTracker->NextDDL()) {
193
194     ddlTracker =  fRawStreamTracker->GetDDLTracker();
195
196     Int_t nBlock = ddlTracker->GetBlkHeaderEntries();
197     for(Int_t iBlock = 0; iBlock < nBlock ;iBlock++){
198
199       blkHeader = ddlTracker->GetBlkHeaderEntry(iBlock);
200  
201       Int_t nDsp = blkHeader->GetDspHeaderEntries();
202
203       for(Int_t iDsp = 0; iDsp < nDsp ;iDsp++){   //DSP loop
204
205         dspHeader =  blkHeader->GetDspHeaderEntry(iDsp);
206
207         Int_t nBusPatch = dspHeader->GetBusPatchEntries();
208
209         for(Int_t iBusPatch = 0; iBusPatch < nBusPatch; iBusPatch++) {  
210
211           busStruct = dspHeader->GetBusPatchEntry(iBusPatch);
212
213           dataSize   = busStruct->GetLength();
214           buspatchId = busStruct->GetBusPatchId();
215
216           for (Int_t iData = 0; iData < dataSize; iData++) {
217
218             // digits info
219             parity    = busStruct->GetParity(iData); // test later for parity
220             manuId    = busStruct->GetManuId(iData);
221             channelId = busStruct->GetChannelId(iData);
222             charge    = busStruct->GetCharge(iData);
223             // set charge
224             fDigit->SetSignal(charge);
225             fDigit->SetPhysicsSignal(charge);
226             fDigit->SetADC(charge);
227
228             // Get Back the hits at pads
229             Int_t error = GetMapping(buspatchId,manuId,channelId,fDigit); 
230             if (error) {
231               AliWarning("Mapping Error\n");
232               continue;
233             }
234             // debugging 
235             if (AliLog::GetGlobalDebugLevel() == 3) {
236               Int_t padX  = fDigit->PadX();
237               Int_t padY  = fDigit->PadY();
238               Int_t iCath = fDigit->Cathode();  
239               Int_t idDE  = fDigit->DetElemId();
240
241               AliDebug(1,Form("output  IdDE %d busPatchid %d PadX %d PadY %d iCath %d \n", 
242                               idDE, buspatchId, padX, padY, iCath));
243                 
244               AliDebug(3,Form("idDE %d Padx %d Pady %d, Cath %d, charge %d",
245                               idDE, padX, padY, iCath, charge));
246             }
247
248             // fill digits
249             iChamber = fDigit->DetElemId()/100 - 1;
250             fMUONData->AddDigit(iChamber, *fDigit);
251
252           } // iData
253         } // iBusPatch
254       } // iDsp
255     } // iBlock
256   } // NextDDL
257
258   fTrackerTimer.Stop();
259
260   return kTRUE;
261 }
262 //____________________________________________________________________
263 Int_t AliMUONDigitMaker::GetMapping(Int_t busPatchId, UShort_t manuId, 
264                                          UChar_t channelId, AliMUONDigit* digit )
265 {
266   //
267   // mapping  for tracker
268   //
269   fMappingTimer.Start(kFALSE);
270   
271   // getting DE from buspatch
272   Int_t detElemId = fBusPatchManager->GetDEfromBus(busPatchId);
273   AliDebug(3,Form("detElemId: %d busPatchId %d\n", detElemId, busPatchId));
274
275   AliMpVSegmentation* seg = fSegFactory->CreateMpSegmentationByElectronics(detElemId, manuId);  
276   AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,channelId),kTRUE);
277
278   if (!pad.IsValid())
279   {
280     AliWarning(Form("No pad for detElemId: %d, busPatchId %d, manuId: %d, channelId: %d\n",
281                   detElemId, busPatchId, manuId, channelId));
282     fMappingTimer.Stop();
283     return kTRUE;
284   } // return error
285
286   // Getting padX, padY and cathode number.
287   Int_t padX = pad.GetIndices().GetFirst();
288   Int_t padY = pad.GetIndices().GetSecond();
289   Int_t iCath = AliMpDEManager::GetCathod(detElemId,seg->PlaneType());
290
291   // storing into digits
292   digit->SetPadX(padX);
293   digit->SetPadY(padY);
294   digit->SetCathode(iCath);
295   digit->SetDetElemId(detElemId);
296   digit->SetElectronics(manuId,channelId);
297   
298   AliDebug(3,Form("detElemId: %d, busPatchId %d, manuId: %d, channelId: %d, padx: %d pady %d\n",
299                   detElemId, busPatchId, manuId, channelId, padX, padY));
300   StdoutToAliDebug(3,digit->Print(););
301   
302   fMappingTimer.Stop();
303   return kFALSE;
304 }
305
306 //____________________________________________________________________
307 Int_t AliMUONDigitMaker::ReadTriggerDDL(AliRawReader* rawReader)
308 {
309   // reading tracker DDL
310   // filling the TClonesArray in MUONData
311   //
312
313   AliMUONDDLTrigger*       ddlTrigger      = 0x0;
314   AliMUONDarcHeader*       darcHeader      = 0x0;
315   AliMUONRegHeader*        regHeader       = 0x0;
316   AliMUONLocalStruct*      localStruct     = 0x0;
317
318   Int_t loCircuit;
319
320   fTriggerTimer.Start(kFALSE);
321
322   fRawStreamTrigger->SetReader(rawReader);
323
324   while(fRawStreamTrigger->NextDDL()) {
325
326     ddlTrigger = fRawStreamTrigger->GetDDLTrigger();
327     darcHeader = ddlTrigger->GetDarcHeader();
328
329     // fill global trigger information
330     if (darcHeader->GetGlobalFlag()) {
331       fGlobalTrigger->SetGlobalPattern(darcHeader->GetGlobalOutput());
332       fMUONData->AddGlobalTrigger(*fGlobalTrigger);
333     }
334
335     Int_t nReg = darcHeader->GetRegHeaderEntries();
336
337     for(Int_t iReg = 0; iReg < nReg ;iReg++){   //reg loop
338
339      // crate info
340       AliMUONTriggerCrate* crate = fCrateManager->Crate(fRawStreamTrigger->GetDDL(), iReg);
341   
342       if (!crate) 
343         AliWarning(Form("Missing crate number %d in DDL %d\n", iReg, fRawStreamTrigger->GetDDL()));
344
345       TObjArray *boards  = crate->Boards();
346
347
348       regHeader =  darcHeader->GetRegHeaderEntry(iReg);
349
350       Int_t nLocal = regHeader->GetLocalEntries();
351
352       for(Int_t iLocal = 0; iLocal < nLocal; iLocal++) {  
353
354         localStruct = regHeader->GetLocalEntry(iLocal);
355
356         // if card has triggered
357         if (localStruct->GetTriggerY() == 0) {
358
359           AliMUONLocalTriggerBoard* localBoard = 
360             (AliMUONLocalTriggerBoard*)boards->At(localStruct->GetId()+1);
361
362           loCircuit = localBoard->GetNumber();
363             
364           // fill local trigger
365           fLocalTrigger->SetLocalStruct(loCircuit, *localStruct);
366
367           fMUONData->AddLocalTrigger(*fLocalTrigger);
368         } // if triggerY
369       } // iLocal
370     } // iReg
371   } // NextDDL
372
373   fTriggerTimer.Stop();
374
375   return kTRUE;
376
377 }
378
379 //____________________________________________________________________
380 void  AliMUONDigitMaker::GetCrateName(Char_t* name, Int_t iDDL, Int_t iReg)
381 {
382   // set crate name from DDL & reg number
383   // method same as in RawWriter, not so nice
384   // should be put in AliMUONTriggerCrateStore
385
386       switch(iReg) {
387       case 0:
388       case 1:
389         sprintf(name,"%d", iReg+1);
390         break;
391       case 2:
392         strcpy(name, "2-3");
393         break;
394       case 3:
395       case 4:
396       case 5:
397       case 6:
398       case 7:
399         sprintf(name,"%d", iReg);
400         break;
401       }
402
403       // crate Right for first DDL
404       if (iDDL == 0)
405         strcat(name, "R");
406       else 
407         strcat(name, "L"); 
408 }