]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTriggerCrateStore.cxx
Fix bug in protection against division by 0.
[u/mrichter/AliRoot.git] / MUON / AliMUONTriggerCrateStore.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 #include "AliMUONTriggerCrateStore.h"
19 #include "AliMpExMapIterator.h"
20 #include "AliMUONTriggerCrate.h"
21 #include "AliMUONLocalTriggerBoard.h"
22 #include "AliMUONRegionalTriggerBoard.h"
23 #include "AliMUONRegionalTriggerConfig.h"
24 #include "AliMUONGlobalCrateConfig.h"
25 #include "AliMUONTriggerCrateConfig.h"
26 #include "AliMUONCalibrationData.h"
27 #include "AliMUONTriggerLut.h"
28
29 #include "AliMpTriggerCrate.h"
30 #include "AliMpLocalBoard.h"
31 #include "AliMpDDLStore.h"
32 #include "AliMpExMap.h"
33 #include "AliLog.h"
34
35 #include <TString.h>
36 #include <TSystem.h>
37 #include <Riostream.h>
38
39 #include <cstdio>
40
41 //-----------------------------------------------------------------------------
42 /// \class AliMUONTriggerCrateStore
43 /// 
44 /// A container of trigger crate objects that offers iteration
45 /// over both the crates themselves and the local boards they contain
46 ///
47 /// \author Laurent Aphecetche
48 //-----------------------------------------------------------------------------
49
50 /// \cond CLASSIMP
51 ClassImp(AliMUONTriggerCrateStore)
52 /// \endcond
53
54 //_____________________________________________________________________________
55 AliMUONTriggerCrateStore::AliMUONTriggerCrateStore()
56 : TObject(),
57 fCrates(0x0),
58 fLocalBoards(0x0)
59 {
60 /// Default constructor
61 }
62
63 //_____________________________________________________________________________
64 AliMUONTriggerCrateStore::~AliMUONTriggerCrateStore()
65 {
66 /// Destructor
67   delete fCrates;
68   delete fLocalBoards;
69 }
70
71 //_____________________________________________________________________________
72 void 
73 AliMUONTriggerCrateStore::AddCrate(const char *name)
74 {
75   /// create and add a crate to our map
76   if (!fCrates)
77   {
78     AliError("Object not properly initialized");
79     return;
80   }
81
82   AliDebug(1,Form("Adding crate %s",name));
83   TObject* there = fCrates->GetValue(name);
84   if (there)
85   {
86     AliError(Form("Cannot add crate %s because it's already there !",name));
87   }
88   else
89   {
90     fCrates->Add(name,new AliMUONTriggerCrate(name,17));
91   }
92 }
93
94 //_____________________________________________________________________________
95 AliMUONLocalTriggerBoard* 
96 AliMUONTriggerCrateStore::LocalBoard(Int_t boardNumber) const
97 {
98   /// return a board by number
99   
100   if ( !fLocalBoards )
101   {
102     AliError("Object not properly initialized");
103     return 0x0;
104   }
105
106   return static_cast<AliMUONLocalTriggerBoard*>(fLocalBoards->GetValue(boardNumber));
107 }
108
109 //_____________________________________________________________________________
110 TIterator*
111 AliMUONTriggerCrateStore::CreateCrateIterator() const
112 {
113   /// Create iterator over crates
114
115   return fCrates ? fCrates->CreateIterator() : 0x0;
116 }
117
118 //_____________________________________________________________________________
119 TIterator*
120 AliMUONTriggerCrateStore::CreateLocalBoardIterator() const
121 {
122   /// Create iterator over local boards
123
124   return fLocalBoards ? fLocalBoards->CreateIterator() : 0x0;
125 }
126
127 //_____________________________________________________________________________
128 AliMUONTriggerCrate* 
129 AliMUONTriggerCrateStore::Crate(const char *name) const
130 {
131   /// return a crate by name
132   if ( !fCrates )
133   {
134     AliError("Object not properly initialized");
135     return 0x0;
136   }
137   return static_cast<AliMUONTriggerCrate*>(fCrates->GetValue(name));
138 }
139
140 // to be removed once AliMUONDigitMaker is linked with new mapping
141 //_____________________________________________________________________________
142 AliMUONTriggerCrate* 
143 AliMUONTriggerCrateStore::Crate(Int_t ddl, Int_t reg) const
144 {
145   /// return a crate by name
146   if ( !fCrates )
147   {
148     AliError("Object not properly initialized");
149     return 0x0;
150   }
151   TString name = GetCrateName(ddl, reg);
152   return static_cast<AliMUONTriggerCrate*>(fCrates->GetValue(name.Data()));
153 }
154 //____________________________________________________________________
155 TString AliMUONTriggerCrateStore::GetCrateName(Int_t ddl, Int_t reg) const
156 {
157   /// set crate name from DDL & reg number
158
159   Char_t name[10];
160   switch(reg) {
161       case 0:
162       case 1:
163         snprintf(name,10,"%d", reg+1);
164         break;
165       case 2:
166         strcpy(name, "2-3");
167         break;
168       case 3:
169       case 4:
170       case 5:
171       case 6:
172       case 7:
173         snprintf(name,10,"%d", reg);
174         break;
175   }
176
177   // crate Right for first DDL
178   if (ddl == 0)
179     strncat(name, "R", 1);
180   else 
181     strncat(name, "L", 1); 
182
183   return TString(name);
184 }
185 //_____________________________________________________________________________
186 Int_t
187 AliMUONTriggerCrateStore::NumberOfCrates() const
188 {
189   /// Number of crates we're holding
190   if ( fCrates ) return fCrates->GetSize();
191   return 0;
192 }
193
194 //_____________________________________________________________________________
195 Int_t
196 AliMUONTriggerCrateStore::NumberOfLocalBoards() const
197 {
198   /// Number of local boards we're holding
199   if ( fLocalBoards ) return fLocalBoards->GetSize();
200   return 0;
201 }
202
203 //_____________________________________________________________________________
204 void
205 AliMUONTriggerCrateStore::ReadFromFile(AliMUONCalibrationData* calibData) 
206 {
207   /// create crate and local board objects from mapping & calib (Ch.F)
208     fCrates = new AliMpExMap;
209     fCrates->SetOwner(kTRUE);
210     fLocalBoards = new AliMpExMap;
211     fLocalBoards->SetOwner(kFALSE);
212   
213   
214    AliMUONTriggerLut* lut = calibData->TriggerLut();
215
216   if (!lut)
217    AliWarning("No valid trigger LUT in CDB");
218   
219   AliMUONRegionalTriggerConfig* regionalConfig = calibData->RegionalTriggerConfig();
220   if (!regionalConfig) {
221      AliError("No valid regional trigger configuration in CDB");
222      return;
223   }   
224   
225   TIter next(AliMpDDLStore::Instance()->GetRegionalTrigger()->CreateCrateIterator());
226   AliMpTriggerCrate* crateMapping;
227   
228   while ( ( crateMapping = static_cast<AliMpTriggerCrate*>(next()) ) )
229     {
230     
231       TString crateName = crateMapping->GetName();
232       AliMUONTriggerCrate *crate = Crate(crateName.Data());
233     
234     AliMUONTriggerCrateConfig* crateConfig =  regionalConfig->FindTriggerCrate(crateName);
235
236       if (!crate) 
237       {
238         AddCrate(crateName.Data()); 
239         crate = Crate(crateName.Data());
240         AliDebug(3, Form("crate name %s\n", crateName.Data()));
241         AliMUONRegionalTriggerBoard *rboard = new AliMUONRegionalTriggerBoard();
242         crate->AddBoard(rboard, 0);
243       }   
244         
245       for(Int_t iLocal = 0; iLocal < crateMapping->GetNofLocalBoards(); ++iLocal) { 
246       
247         Int_t localBoardId = crateMapping->GetLocalBoardId(iLocal);
248         if (!localBoardId) continue; //empty slot, should not happen
249
250         AliMpLocalBoard* localBoardMapping = AliMpDDLStore::Instance()->GetLocalBoard(localBoardId);
251         AliDebug(3, Form("local name %s id %d\n", localBoardMapping->GetName(), localBoardId));
252       
253         Int_t slot = localBoardMapping->GetSlot();
254       AliMUONLocalTriggerBoard *board = new AliMUONLocalTriggerBoard(localBoardMapping);
255       board->SetCoinc44(crateConfig->GetCoinc());
256       board->SetLUT(lut);
257
258       
259         if (localBoardMapping->IsNotified()) {
260           fLocalBoards->Add(localBoardId, board);
261         }
262       
263         crate->AddBoard(board, slot);
264       
265       } // iLocal
266     } // while
267 }
268