Moving MUON.Digits.root file into MUON.Digit directory after simulation
[u/mrichter/AliRoot.git] / MUON / AliMUONTriggerCrateStore.cxx
CommitLineData
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"
23#include "AliMpExMap.h"
24#include "TString.h"
25#include "TSystem.h"
26#include "AliLog.h"
27#include "Riostream.h"
28
29///
30/// \class AliMUONTriggerCrateStore
31///
32/// A container of trigger crate objects that offers iteration
33/// over both the crates themselves and the local boards they contain
34///
35/// \author Laurent Aphecetche
36
5398f946 37/// \cond CLASSIMP
30dd09e2 38ClassImp(AliMUONTriggerCrateStore)
5398f946 39/// \endcond
30dd09e2 40
41//_____________________________________________________________________________
42AliMUONTriggerCrateStore::AliMUONTriggerCrateStore()
43: TObject(),
44fCrates(0x0),
45fLocalBoards(0x0),
46fCrateIterator(0x0),
47fLBIterator(0x0),
48fCurrentCrate(0x0),
49fCurrentLocalBoard(-1)
50{
5398f946 51/// Default constructor
30dd09e2 52}
53
54//_____________________________________________________________________________
55AliMUONTriggerCrateStore::~AliMUONTriggerCrateStore()
56{
5398f946 57/// Destructor
30dd09e2 58 delete fCrateIterator;
59 delete fLBIterator;
60 delete fCrates;
61 delete fLocalBoards;
62}
63
64//_____________________________________________________________________________
65void
66AliMUONTriggerCrateStore::AddCrate(const char *name)
67{
68 /// create and add a crate to our map
69 if (!fCrates)
70 {
71 AliError("Object not properly initialized");
72 return;
73 }
74
75 AliDebug(1,Form("Adding crate %s",name));
76 TObject* there = fCrates->GetValue(name);
77 if (there)
78 {
79 AliError(Form("Cannot add crate %s because it's already there !",name));
80 }
81 else
82 {
83 fCrates->Add(name,new AliMUONTriggerCrate(name,17));
84 }
85}
86
87//_____________________________________________________________________________
88AliMUONLocalTriggerBoard*
89AliMUONTriggerCrateStore::LocalBoard(Int_t boardNumber) const
90{
91 /// return a board by number
92
93 if ( !fLocalBoards )
94 {
95 AliError("Object not properly initialized");
96 return 0x0;
97 }
98
99 return static_cast<AliMUONLocalTriggerBoard*>(fLocalBoards->GetValue(boardNumber));
100}
101
102//_____________________________________________________________________________
103AliMUONTriggerCrate*
104AliMUONTriggerCrateStore::Crate(const char *name) const
105{
106 /// return a crate by name
107 if ( !fCrates )
108 {
109 AliError("Object not properly initialized");
110 return 0x0;
111 }
112 return static_cast<AliMUONTriggerCrate*>(fCrates->GetValue(name));
113}
114
115//_____________________________________________________________________________
aa6ecf89 116AliMUONTriggerCrate*
117AliMUONTriggerCrateStore::Crate(Int_t ddl, Int_t reg) const
118{
119 /// return a crate by name
120 if ( !fCrates )
121 {
122 AliError("Object not properly initialized");
123 return 0x0;
124 }
125 TString name = GetCrateName(ddl, reg);
126 return static_cast<AliMUONTriggerCrate*>(fCrates->GetValue(name.Data()));
127}
128// //____________________________________________________________________
129TString AliMUONTriggerCrateStore::GetCrateName(Int_t ddl, Int_t reg) const
130{
131 // set crate name from DDL & reg number
132
133 Char_t name[10];
134 switch(reg) {
135 case 0:
136 case 1:
137 sprintf(name,"%d", reg+1);
138 break;
139 case 2:
140 strcpy(name, "2-3");
141 break;
142 case 3:
143 case 4:
144 case 5:
145 case 6:
146 case 7:
147 sprintf(name,"%d", reg);
148 break;
149 }
150
151 // crate Right for first DDL
152 if (ddl == 0)
153 strcat(name, "R");
154 else
155 strcat(name, "L");
156
157 return TString(name);
158}
159//_____________________________________________________________________________
30dd09e2 160void
161AliMUONTriggerCrateStore::FirstCrate()
162{
163 /// initialize iteration
164 if ( !fCrates )
165 {
166 AliError("Object not properly initialized");
167 return;
168 }
169 if (!fCrateIterator)
170 {
171 fCrateIterator = new TExMapIter(fCrates->GetIterator());
172 }
173 fCrateIterator->Reset();
174}
175
176//_____________________________________________________________________________
177void
178AliMUONTriggerCrateStore::FirstLocalBoard()
179{
180 /// Initialize iterator on local boards.
181 /// Please note that we're not using directly the FirstCrate() and
182 /// NextCrate() methods here to avoid mix and match between crate iterator
183 /// and local board iterator
184 fCurrentCrate = 0x0;
185 fCurrentLocalBoard = 0;
186
187 if ( !fLBIterator )
188 {
189 fLBIterator = new TExMapIter(fCrates->GetIterator());
190 }
191 fLBIterator->Reset();
192 Long_t key, value;
193 Bool_t ok = fLBIterator->Next(key,value);
194 if ( ok )
195 {
196 fCurrentCrate = reinterpret_cast<AliMUONTriggerCrate*>(value);
197 fCurrentLocalBoard = 1;
198 }
199}
200
201//_____________________________________________________________________________
202AliMUONTriggerCrate*
203AliMUONTriggerCrateStore::NextCrate()
204{
205 /// Return the next crate in iteration, or 0 if iteration is ended.
206 if (!fCrateIterator) return 0x0;
207
208 Long_t key, value;
209 Bool_t ok = fCrateIterator->Next(key,value);
210 if (ok)
211 {
212 return reinterpret_cast<AliMUONTriggerCrate*>(value);
213 }
214 else
215 {
216 return 0x0;
217 }
218}
219
220//_____________________________________________________________________________
221AliMUONLocalTriggerBoard*
222AliMUONTriggerCrateStore::NextLocalBoard()
223{
224 /// Return the next local board in iteration, or 0 if iteration is ended.
225 if ( !fLBIterator ) return 0x0;
226
227 if ( fCurrentLocalBoard >= fCurrentCrate->Boards()->GetLast() +1)
228// if ( fCurrentLocalBoard >= fCurrentCrate->Boards()->GetLast() )
229 {
230 // try to go to next crate, if some are left
231 Long_t key, value;
232 Bool_t ok = fLBIterator->Next(key,value);
233 if ( ok )
234 {
235 fCurrentCrate = reinterpret_cast<AliMUONTriggerCrate*>(value);
236 fCurrentLocalBoard = 1;
237 }
238 else
239 {
240 fCurrentLocalBoard = 0;
241 return 0x0;
242 }
243 }
244
245 AliMUONLocalTriggerBoard* lb = static_cast<AliMUONLocalTriggerBoard*>
246 (fCurrentCrate->Boards()->At(fCurrentLocalBoard));
247
248 ++fCurrentLocalBoard;
249
250 return lb;
251}
252
253//_____________________________________________________________________________
254Int_t
255AliMUONTriggerCrateStore::NumberOfCrates() const
256{
257 /// Number of crates we're holding
258 if ( fCrates ) return fCrates->GetSize();
259 return 0;
260}
261
262//_____________________________________________________________________________
263Int_t
264AliMUONTriggerCrateStore::NumberOfLocalBoards() const
265{
266 /// Number of local boards we're holding
267 if ( fLocalBoards ) return fLocalBoards->GetSize();
268 return 0;
269}
270
271//_____________________________________________________________________________
272void
273AliMUONTriggerCrateStore::ReadFromFile(const char* file)
274{
275 /// Read crate and local board information from file.
276 fCrates = new AliMpExMap(kTRUE);
277 fLocalBoards = new AliMpExMap(kFALSE);
278
279 ifstream myInputFile(gSystem->ExpandPathName(file), ios::in);
280
281 string sLine, sValue;
282
283 if ( !myInputFile )
284 {
285 AliError("TRIGGER ELECTRONICS CONFIGURATION FILE COULD NOT BE OPENED");
286 }
287 else
288 {
289 while (getline(myInputFile,sLine))
290 {
291 if (sLine.empty()) continue; // Ignore empty lines
292 else
293 {
294 const Int_t kMaxfields = 15; char **fields = new char*[kMaxfields];
295
296 char s[100];
297
298 if (sLine.find("Board",0) != string::npos)
299 {
300 strcpy(s,sLine.c_str());
301
302 Int_t numlines = 0;
303
304 for (char *token = strtok(s, " ");
305 token != NULL;
306 token = strtok(NULL, " "))
307 {
308 fields[numlines] = new char[strlen(token)+1];
309 strcpy(fields[numlines++],token);
310 }
311
312 char str[10]; strcpy(str, fields[6]); strcat(str, fields[7]);
313
314 AliMUONTriggerCrate *crate = Crate(str);
315
316 if (!crate)
317 {
318 AddCrate(str); crate = Crate(str);
319
320 AliMUONRegionalTriggerBoard *rboard = new AliMUONRegionalTriggerBoard();
321 crate->AddBoard(rboard, 0);
322 }
323
324 // CONVENTION: SLOT 0 HOLDS THE REGIONAL BOARD
325 Int_t sl = atoi(fields[10]);
326
327// AliMUONTriggerLut* lut = calibData->TriggerLut();
328
329 AliMUONLocalTriggerBoard *board =
330 new AliMUONLocalTriggerBoard(fields[4], sl, 0x0);
331
332 if (strcmp(fields[1],"nn"))
333 {
334 Int_t sboard = atoi(fields[1]);
335
336 board->SetNumber(sboard);
337 fLocalBoards->Add(sboard,board);
338
339// fCrateMap[sboard-1] = new char[strlen(str)+1]; strcpy(fCrateMap[sboard-1], str);
340// fBoardMap[sboard-1] = sl;
341 }
342
343 board->SetCrate(str);
344
345 crate->AddBoard(board, sl);
346
347 while (getline(myInputFile,sLine)) if (sLine.find("transv",0) != string::npos) break;
348
349 strcpy(s,sLine.c_str());
350
351 for (char *token = strtok(s, " ");
352 token != NULL;
353 token = strtok(NULL, " ")) if (!strcmp(token,"NONE")) board->SetTC(kFALSE);
354
355 while (getline(myInputFile,sLine)) if (sLine.find("Switch",0) != string::npos) break;
356
357 while (getline(myInputFile,sLine)) if (!sLine.empty()) break;
358
359 strcpy(s,sLine.c_str());
360
361 Int_t lines = 0;
362
363 for (char *token = strtok(s, " ");
364 token != NULL;
365 token = strtok(NULL, " ")) board->SetSwitch(lines++, atoi(token));
366
367 for (Int_t i = 0; i<numlines; i++)
368 if (fields[i]) {delete [] fields[i]; fields[i] = 0;}
369
370 delete [] fields; fields = 0;
371 }
372 }
373 }
374 }
375}