]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTriggerCrateStore.cxx
Changes needed by the following commit: coding convention for type (_t) and access...
[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
20 #include "AliMUONTriggerCrate.h"
21 #include "AliMUONLocalTriggerBoard.h"
22 #include "AliMUONRegionalTriggerBoard.h"
23
24 #include "AliMpTriggerCrate.h"
25 #include "AliMpLocalBoard.h"
26 #include "AliMpDDLStore.h"
27 #include "AliMpExMap.h"
28 #include "AliLog.h"
29
30 #include <TString.h>
31 #include <TSystem.h>
32 #include <Riostream.h>
33
34
35 //-----------------------------------------------------------------------------
36 /// \class AliMUONTriggerCrateStore
37 /// 
38 /// A container of trigger crate objects that offers iteration
39 /// over both the crates themselves and the local boards they contain
40 ///
41 /// \author Laurent Aphecetche
42 //-----------------------------------------------------------------------------
43
44 /// \cond CLASSIMP
45 ClassImp(AliMUONTriggerCrateStore)
46 /// \endcond
47
48 //_____________________________________________________________________________
49 AliMUONTriggerCrateStore::AliMUONTriggerCrateStore()
50 : TObject(),
51 fCrates(0x0),
52 fLocalBoards(0x0),
53 fCrateIterator(0x0),
54 fLBIterator(0x0),
55 fCurrentCrate(0x0),
56 fCurrentLocalBoard(-1)
57 {
58 /// Default constructor
59 }
60
61 //_____________________________________________________________________________
62 AliMUONTriggerCrateStore::~AliMUONTriggerCrateStore()
63 {
64 /// Destructor
65   delete fCrateIterator;
66   delete fLBIterator;
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 AliMUONTriggerCrate* 
111 AliMUONTriggerCrateStore::Crate(const char *name) const
112 {
113   /// return a crate by name
114   if ( !fCrates )
115   {
116     AliError("Object not properly initialized");
117     return 0x0;
118   }
119   return static_cast<AliMUONTriggerCrate*>(fCrates->GetValue(name));
120 }
121
122 // to be removed once AliMUONDigitMaker is linked with new mapping
123 //_____________________________________________________________________________
124 AliMUONTriggerCrate* 
125 AliMUONTriggerCrateStore::Crate(Int_t ddl, Int_t reg) const
126 {
127   /// return a crate by name
128   if ( !fCrates )
129   {
130     AliError("Object not properly initialized");
131     return 0x0;
132   }
133   TString name = GetCrateName(ddl, reg);
134   return static_cast<AliMUONTriggerCrate*>(fCrates->GetValue(name.Data()));
135 }
136 //____________________________________________________________________
137 TString AliMUONTriggerCrateStore::GetCrateName(Int_t ddl, Int_t reg) const
138 {
139   /// set crate name from DDL & reg number
140
141   Char_t name[10];
142   switch(reg) {
143       case 0:
144       case 1:
145         sprintf(name,"%d", reg+1);
146         break;
147       case 2:
148         strcpy(name, "2-3");
149         break;
150       case 3:
151       case 4:
152       case 5:
153       case 6:
154       case 7:
155         sprintf(name,"%d", reg);
156         break;
157   }
158
159   // crate Right for first DDL
160   if (ddl == 0)
161     strcat(name, "R");
162   else 
163     strcat(name, "L"); 
164
165   return TString(name);
166 }
167 //_____________________________________________________________________________
168 void
169 AliMUONTriggerCrateStore::FirstCrate()
170 {
171   /// initialize iteration
172   if ( !fCrates )
173   {
174     AliError("Object not properly initialized");
175     return;
176   }
177   if (!fCrateIterator)
178   {
179     fCrateIterator = new TExMapIter(fCrates->GetIterator());
180   }
181   fCrateIterator->Reset();
182 }
183
184 //_____________________________________________________________________________
185 void
186 AliMUONTriggerCrateStore::FirstLocalBoard()
187 {
188   /// Initialize iterator on local boards.
189   /// Please note that we're not using directly the FirstCrate() and
190   /// NextCrate() methods here to avoid mix and match between crate iterator
191   /// and local board iterator
192   fCurrentCrate = 0x0;
193   fCurrentLocalBoard = 0;
194
195   if ( !fLBIterator ) 
196   {
197     fLBIterator = new TExMapIter(fCrates->GetIterator());
198   }
199   fLBIterator->Reset();
200   Long_t key, value;
201   Bool_t ok = fLBIterator->Next(key,value);
202   if ( ok )
203   {
204     fCurrentCrate = reinterpret_cast<AliMUONTriggerCrate*>(value);
205     fCurrentLocalBoard = 1;
206   }
207 }
208
209 //_____________________________________________________________________________
210 AliMUONTriggerCrate*
211 AliMUONTriggerCrateStore::NextCrate()
212 {
213   /// Return the next crate in iteration, or 0 if iteration is ended.
214   if (!fCrateIterator) return 0x0;
215   
216   Long_t key, value;
217   Bool_t ok = fCrateIterator->Next(key,value);
218   if (ok)
219   {
220     return reinterpret_cast<AliMUONTriggerCrate*>(value);
221   }
222   else
223   {
224     return 0x0;
225   }
226 }
227
228 //_____________________________________________________________________________
229 AliMUONLocalTriggerBoard*
230 AliMUONTriggerCrateStore::NextLocalBoard()
231 {  
232   /// Return the next local board in iteration, or 0 if iteration is ended.
233   if ( !fLBIterator ) return 0x0;
234
235   if ( fCurrentLocalBoard >= fCurrentCrate->Boards()->GetLast() +1)
236 //  if ( fCurrentLocalBoard >= fCurrentCrate->Boards()->GetLast() )
237   {
238     // try to go to next crate, if some are left
239     Long_t key, value;
240     Bool_t ok = fLBIterator->Next(key,value);
241     if ( ok )
242     {
243       fCurrentCrate = reinterpret_cast<AliMUONTriggerCrate*>(value);
244       fCurrentLocalBoard = 1;
245     }
246     else
247     {
248       fCurrentLocalBoard = 0;
249       return 0x0;
250     }
251   }
252
253   AliMUONLocalTriggerBoard* lb = static_cast<AliMUONLocalTriggerBoard*>
254     (fCurrentCrate->Boards()->At(fCurrentLocalBoard));
255   
256   ++fCurrentLocalBoard;
257   
258   return lb;
259 }
260
261 //_____________________________________________________________________________
262 Int_t
263 AliMUONTriggerCrateStore::NumberOfCrates() const
264 {
265   /// Number of crates we're holding
266   if ( fCrates ) return fCrates->GetSize();
267   return 0;
268 }
269
270 //_____________________________________________________________________________
271 Int_t
272 AliMUONTriggerCrateStore::NumberOfLocalBoards() const
273 {
274   /// Number of local boards we're holding
275   if ( fLocalBoards ) return fLocalBoards->GetSize();
276   return 0;
277 }
278
279 //_____________________________________________________________________________
280 void
281 AliMUONTriggerCrateStore::ReadFromFile(const char* /*file*/) // keep old name for the moment
282 {
283     /// create crate and local board objects from mapping (Ch.F)
284     fCrates = new AliMpExMap(kTRUE);
285     fCrates->SetOwner(kTRUE);
286     fLocalBoards = new AliMpExMap(kTRUE);
287     fLocalBoards->SetOwner(kFALSE);
288   
289     TExMapIter itr = AliMpDDLStore::Instance()->GetTriggerCrateItr();
290
291     Long_t key, value;
292
293     while(itr.Next(key, value))
294     {
295       AliMpTriggerCrate* crateMapping =  reinterpret_cast<AliMpTriggerCrate*>(value);
296
297       TString crateName = crateMapping->GetName();
298       AliMUONTriggerCrate *crate = Crate(crateName.Data());
299
300       if (!crate) 
301       {
302         AddCrate(crateName.Data()); 
303         crate = Crate(crateName.Data());
304         AliDebug(3, Form("crate name %s\n", crateName.Data()));
305         AliMUONRegionalTriggerBoard *rboard = new AliMUONRegionalTriggerBoard();
306         crate->AddBoard(rboard, 0);
307       }   
308         
309       for(Int_t iLocal = 0; iLocal < crateMapping->GetNofLocalBoards(); ++iLocal) { 
310
311         Int_t localBoardId = crateMapping->GetLocalBoardId(iLocal);
312         if (!localBoardId) continue; //empty slot, should not happen
313
314         AliMpLocalBoard* localBoardMapping = AliMpDDLStore::Instance()->GetLocalBoard(localBoardId);
315         AliDebug(3, Form("local name %s id %d\n", localBoardMapping->GetName(), localBoardId));
316
317         Int_t slot = localBoardMapping->GetSlot();
318         AliMUONLocalTriggerBoard *board = 
319             new AliMUONLocalTriggerBoard(localBoardMapping);
320
321         if (localBoardMapping->IsNotified()) {
322           fLocalBoards->Add(localBoardId, board);
323         }
324
325         crate->AddBoard(board, slot);
326
327       } // iLocal
328     } // while
329 }