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