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