]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONDigitMaker.cxx
Bug fix (selection of RawReaderDate from Yuri was not correct)
[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 "AliCodeTimer.h"
48 #include "AliLog.h"
49 #include "AliMUONDDLTrigger.h"
50 #include "AliMUONDarcHeader.h"
51 #include "AliMUONVDigit.h"
52 #include "AliMUONVDigitStore.h"
53 #include "AliMUONGlobalTrigger.h"
54 #include "AliMUONLocalStruct.h"
55 #include "AliMUONLocalTrigger.h"
56 #include "AliMUONLogger.h"
57 #include "AliMUONRawStreamTracker.h"
58 #include "AliMUONRawStreamTrackerHP.h"
59 #include "AliMUONRawStreamTrigger.h"
60 #include "AliMUONRegHeader.h"
61 #include "AliMUONTriggerCircuit.h"
62 #include "AliMpTriggerCrate.h"
63 #include "AliMpLocalBoard.h"
64 #include "AliMUONVTriggerStore.h"
65 #include "AliMpCathodType.h"
66 #include "AliMpDDLStore.h"
67 #include "AliMpDEManager.h"
68 #include "AliMpPad.h"
69 #include "AliMpSegmentation.h"
70 #include "AliMpVSegmentation.h"
71 #include "AliRawReader.h"
72 #include <TArrayS.h>
73
74 /// \cond CLASSIMP
75 ClassImp(AliMUONDigitMaker) // Class implementation in ROOT context
76 /// \endcond
77
78 //__________________________________________________________________________
79 AliMUONDigitMaker::AliMUONDigitMaker(Bool_t enableErrorLogger, Bool_t useFastDecoder)
80   : TObject(),
81     fScalerEvent(kFALSE),
82     fMakeTriggerDigits(kFALSE),
83     fRawStreamTracker(NULL),
84     fRawStreamTrigger(new AliMUONRawStreamTrigger()),    
85     fDigitStore(0x0),
86     fTriggerStore(0x0),
87   fLogger(new AliMUONLogger(10000))
88 {
89   /// ctor 
90
91   AliDebug(1,"");
92   
93   CreateRawStreamTracker(useFastDecoder);
94
95   // Standard Constructor
96   if (enableErrorLogger) {
97     fRawStreamTracker->EnabbleErrorLogger();
98     fRawStreamTrigger->EnabbleErrorLogger();
99   }
100
101   SetMakeTriggerDigits();
102
103 }
104
105 //__________________________________________________________________________
106 AliMUONDigitMaker::~AliMUONDigitMaker()
107 {
108   /// clean up
109   /// and time processing measure
110
111   delete fRawStreamTracker;
112   delete fRawStreamTrigger;
113
114   delete fLogger;
115 }
116
117 //__________________________________________________________________________
118 void AliMUONDigitMaker::CreateRawStreamTracker(Bool_t useFastDecoder)
119 {
120 /// Create raw stream tracker according to the passed option
121
122   if (useFastDecoder)
123   {
124     AliInfo("Using fast decoder.");
125     fRawStreamTracker = new AliMUONRawStreamTrackerHP();
126   }
127   else
128     fRawStreamTracker = new AliMUONRawStreamTracker();
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     fLogger->Log("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       fLogger->Log("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   AliCodeTimerAuto("");
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     if (!seg)
203     {
204       fLogger->Log(Form("(DE,MANUID)=(%04d,%04d) is not valid",detElemId,manuId));
205       continue;
206     }
207     
208     AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId, 
209                                                               seg->PlaneType());
210
211     AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,channelId),kFALSE);
212     
213     if (!pad.IsValid())
214     {
215       fLogger->Log(Form("No pad for detElemId: %d, manuId: %d, channelId: %d",
216                     detElemId, manuId, channelId));
217       continue;
218     } 
219     
220     AliMUONVDigit* digit = fDigitStore->Add(detElemId,manuId,channelId,cathodeType,
221                                             AliMUONVDigitStore::kDeny);
222     if (!digit)
223     {
224       fLogger->Log(Form("Digit DE %04d Manu %04d Channel %02d could not be added",
225                     detElemId, manuId, channelId));
226       continue;
227     }
228     
229     digit->SetPadXY(pad.GetIndices().GetFirst(),
230                    pad.GetIndices().GetSecond());
231     
232           digit->SetADC(charge);
233
234   }
235   
236   return kTRUE;
237 }
238
239 //____________________________________________________________________
240 Int_t AliMUONDigitMaker::ReadTriggerDDL(AliRawReader* rawReader)
241 {
242   /// reading tracker DDL
243   /// filling the fTriggerStore container, which must not be null
244
245   AliDebug(1,"");
246   
247   AliMUONDDLTrigger*       ddlTrigger      = 0x0;
248   AliMUONDarcHeader*       darcHeader      = 0x0;
249   AliMUONRegHeader*        regHeader       = 0x0;
250   AliMUONLocalStruct*      localStruct     = 0x0;
251
252   Int_t loCircuit;
253
254   AliCodeTimerAuto("");
255
256   fRawStreamTrigger->SetReader(rawReader);
257
258   while (fRawStreamTrigger->NextDDL()) 
259   {
260     ddlTrigger = fRawStreamTrigger->GetDDLTrigger();
261     darcHeader = ddlTrigger->GetDarcHeader();
262     
263     // fill global trigger information
264     if (fTriggerStore) 
265     {
266       if (darcHeader->GetGlobalFlag()) 
267       {
268           AliMUONGlobalTrigger globalTrigger;
269           globalTrigger.SetFromGlobalResponse(darcHeader->GetGlobalOutput());
270           fTriggerStore->SetGlobal(globalTrigger);
271       }
272     }
273     
274     Int_t nReg = darcHeader->GetRegHeaderEntries();
275     
276     for(Int_t iReg = 0; iReg < nReg ;iReg++)
277     {   //reg loop
278       
279
280       // crate info  
281       AliMpTriggerCrate* crate = AliMpDDLStore::Instance()->
282                                 GetTriggerCrate(fRawStreamTrigger->GetDDL(), iReg);
283       
284       if (!crate) 
285         fLogger->Log(Form("Missing crate number %d in DDL %d\n", iReg, fRawStreamTrigger->GetDDL()));
286      
287       
288       regHeader =  darcHeader->GetRegHeaderEntry(iReg);
289       
290       Int_t nLocal = regHeader->GetLocalEntries();
291       for(Int_t iLocal = 0; iLocal < nLocal; iLocal++) 
292       {  
293         
294         localStruct = regHeader->GetLocalEntry(iLocal);
295         
296         // if card exist
297         if (localStruct) {
298           
299           loCircuit = crate->GetLocalBoardId(localStruct->GetId());
300
301           if ( !loCircuit ) continue; // empty slot
302
303           AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(loCircuit, false);
304
305           // skip copy cards
306           if( !localBoard->IsNotified()) 
307              continue;
308           
309           if (fTriggerStore) 
310           {
311             // fill local trigger
312             AliMUONLocalTrigger localTrigger;
313             localTrigger.SetLocalStruct(loCircuit, *localStruct);
314             fTriggerStore->Add(localTrigger);
315           } 
316           
317           if ( fMakeTriggerDigits )
318           {
319             //FIXEME should find something better than a TArray
320             TArrayS xyPattern[2];
321             
322             localStruct->GetXPattern(xyPattern[0]);
323             localStruct->GetYPattern(xyPattern[1]);
324             
325             TriggerDigits(loCircuit, xyPattern, *fDigitStore);
326           }          
327         } // if triggerY
328       } // iLocal
329     } // iReg
330   } // NextDDL
331   
332   return kTRUE;
333
334 }
335
336 //____________________________________________________________________
337 Int_t AliMUONDigitMaker::TriggerDigits(Int_t nBoard, 
338                                        TArrayS* xyPattern,
339                                        AliMUONVDigitStore& digitStore) const
340 {
341   /// make digits for trigger from pattern, and add them to digitStore
342
343   AliCodeTimerAuto("");
344   
345   Int_t detElemId;
346
347   AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(nBoard);
348
349   Int_t n,b;
350
351   // loop over x1-4 and y1-4
352   for (Int_t iChamber = 0; iChamber < 4; ++iChamber)
353   {
354     for (Int_t iCath = 0; iCath < 2; ++iCath)
355     {
356       Int_t pattern = (Int_t)xyPattern[iCath].At(iChamber); 
357       if (!pattern) continue;
358       
359       // get detElemId
360       detElemId = AliMpDDLStore::Instance()->GetDEfromLocalBoard(nBoard, iChamber);
361         
362         const AliMpVSegmentation* seg 
363           = AliMpSegmentation::Instance()
364           ->GetMpSegmentation(detElemId, AliMp::GetCathodType(iCath));  
365         
366         // loop over the 16 bits of pattern
367         for (Int_t ibitxy = 0; ibitxy < 16; ++ibitxy) 
368         {
369           if ((pattern >> ibitxy) & 0x1) 
370           {            
371             // not quite sure about this
372             Int_t offset = 0;
373             if (iCath && localBoard->GetSwitch(6)) offset = -8;
374             
375             AliMpPad pad = seg->PadByLocation(AliMpIntPair(nBoard,ibitxy+offset),kTRUE);
376                         
377             if (!pad.IsValid()) 
378             {
379               fLogger->Log(Form("No pad for detElemId: %d, nboard %d, ibitxy: %d\n",
380                               detElemId, nBoard, ibitxy));
381               continue;
382             }
383
384             n = pad.GetLocation(0).GetFirst(); // always take first location so that digits are not inserted several times
385             b = pad.GetLocation(0).GetSecond();
386
387             AliDebug(1,Form("Using localBoard %d ixy %d instead of %d,%d",
388                             n,b,nBoard,ibitxy));
389
390             AliMUONVDigit* digit = digitStore.Add(detElemId,n,b,iCath,AliMUONVDigitStore::kDeny);
391             
392             if (!digit)
393             {
394                 AliDebug(1, Form("Digit DE %04d LocalBoard %03d ibitxy %02d cath %d already in store",
395                                  detElemId,nBoard,ibitxy,iCath));
396                 continue;
397             }
398             
399             Int_t padX = pad.GetIndices().GetFirst();
400             Int_t padY = pad.GetIndices().GetSecond();
401             
402             // fill digit
403             digit->SetPadXY(padX,padY);
404             digit->SetCharge(1.);
405           }// xyPattern
406         }// ibitxy
407     }// cath
408   } // ichamber
409   
410   return kTRUE;
411
412
413 //____________________________________________________________________
414 void  AliMUONDigitMaker::SetFastDecoder(Bool_t useFastDecoder)
415 {
416 /// Set fast raw data decoder
417
418   delete fRawStreamTracker;
419   CreateRawStreamTracker(useFastDecoder);
420 }  
421   
422     
423