]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTriggerCrateStore.cxx
- Adapted comments for Doxygen
[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 #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
37 /// \cond CLASSIMP
38 ClassImp(AliMUONTriggerCrateStore)
39 /// \endcond
40
41 //_____________________________________________________________________________
42 AliMUONTriggerCrateStore::AliMUONTriggerCrateStore()
43 : TObject(),
44 fCrates(0x0),
45 fLocalBoards(0x0),
46 fCrateIterator(0x0),
47 fLBIterator(0x0),
48 fCurrentCrate(0x0),
49 fCurrentLocalBoard(-1)
50 {
51 /// Default constructor
52 }
53
54 //_____________________________________________________________________________
55 AliMUONTriggerCrateStore::~AliMUONTriggerCrateStore()
56 {
57 /// Destructor
58   delete fCrateIterator;
59   delete fLBIterator;
60   delete fCrates;
61   delete fLocalBoards;
62 }
63
64 //_____________________________________________________________________________
65 void 
66 AliMUONTriggerCrateStore::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 //_____________________________________________________________________________
88 AliMUONLocalTriggerBoard* 
89 AliMUONTriggerCrateStore::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 //_____________________________________________________________________________
103 AliMUONTriggerCrate* 
104 AliMUONTriggerCrateStore::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 //_____________________________________________________________________________
116 void
117 AliMUONTriggerCrateStore::FirstCrate()
118 {
119   /// initialize iteration
120   if ( !fCrates )
121   {
122     AliError("Object not properly initialized");
123     return;
124   }
125   if (!fCrateIterator)
126   {
127     fCrateIterator = new TExMapIter(fCrates->GetIterator());
128   }
129   fCrateIterator->Reset();
130 }
131
132 //_____________________________________________________________________________
133 void
134 AliMUONTriggerCrateStore::FirstLocalBoard()
135 {
136   /// Initialize iterator on local boards.
137   /// Please note that we're not using directly the FirstCrate() and
138   /// NextCrate() methods here to avoid mix and match between crate iterator
139   /// and local board iterator
140   fCurrentCrate = 0x0;
141   fCurrentLocalBoard = 0;
142
143   if ( !fLBIterator ) 
144   {
145     fLBIterator = new TExMapIter(fCrates->GetIterator());
146   }
147   fLBIterator->Reset();
148   Long_t key, value;
149   Bool_t ok = fLBIterator->Next(key,value);
150   if ( ok )
151   {
152     fCurrentCrate = reinterpret_cast<AliMUONTriggerCrate*>(value);
153     fCurrentLocalBoard = 1;
154   }
155 }
156
157 //_____________________________________________________________________________
158 AliMUONTriggerCrate*
159 AliMUONTriggerCrateStore::NextCrate()
160 {
161   /// Return the next crate in iteration, or 0 if iteration is ended.
162   if (!fCrateIterator) return 0x0;
163   
164   Long_t key, value;
165   Bool_t ok = fCrateIterator->Next(key,value);
166   if (ok)
167   {
168     return reinterpret_cast<AliMUONTriggerCrate*>(value);
169   }
170   else
171   {
172     return 0x0;
173   }
174 }
175
176 //_____________________________________________________________________________
177 AliMUONLocalTriggerBoard*
178 AliMUONTriggerCrateStore::NextLocalBoard()
179 {  
180   /// Return the next local board in iteration, or 0 if iteration is ended.
181   if ( !fLBIterator ) return 0x0;
182
183   if ( fCurrentLocalBoard >= fCurrentCrate->Boards()->GetLast() +1)
184 //  if ( fCurrentLocalBoard >= fCurrentCrate->Boards()->GetLast() )
185   {
186     // try to go to next crate, if some are left
187     Long_t key, value;
188     Bool_t ok = fLBIterator->Next(key,value);
189     if ( ok )
190     {
191       fCurrentCrate = reinterpret_cast<AliMUONTriggerCrate*>(value);
192       fCurrentLocalBoard = 1;
193     }
194     else
195     {
196       fCurrentLocalBoard = 0;
197       return 0x0;
198     }
199   }
200
201   AliMUONLocalTriggerBoard* lb = static_cast<AliMUONLocalTriggerBoard*>
202     (fCurrentCrate->Boards()->At(fCurrentLocalBoard));
203   
204   ++fCurrentLocalBoard;
205   
206   return lb;
207 }
208
209 //_____________________________________________________________________________
210 Int_t
211 AliMUONTriggerCrateStore::NumberOfCrates() const
212 {
213   /// Number of crates we're holding
214   if ( fCrates ) return fCrates->GetSize();
215   return 0;
216 }
217
218 //_____________________________________________________________________________
219 Int_t
220 AliMUONTriggerCrateStore::NumberOfLocalBoards() const
221 {
222   /// Number of local boards we're holding
223   if ( fLocalBoards ) return fLocalBoards->GetSize();
224   return 0;
225 }
226
227 //_____________________________________________________________________________
228 void
229 AliMUONTriggerCrateStore::ReadFromFile(const char* file)
230 {
231   /// Read crate and local board information from file.
232   fCrates = new AliMpExMap(kTRUE);
233   fLocalBoards = new AliMpExMap(kFALSE);
234   
235   ifstream myInputFile(gSystem->ExpandPathName(file), ios::in);
236   
237   string sLine, sValue;
238   
239   if ( !myInputFile ) 
240   {
241     AliError("TRIGGER ELECTRONICS CONFIGURATION FILE COULD NOT BE OPENED");
242   }
243   else
244   {
245     while (getline(myInputFile,sLine))
246     {
247       if (sLine.empty()) continue; // Ignore empty lines
248       else
249       {
250         const Int_t kMaxfields = 15; char **fields = new char*[kMaxfields];
251         
252         char s[100]; 
253         
254         if (sLine.find("Board",0) != string::npos) 
255         {   
256           strcpy(s,sLine.c_str());
257           
258           Int_t numlines = 0;
259           
260           for (char *token = strtok(s, " ");
261                token != NULL;
262                token = strtok(NULL, " "))
263           {
264             fields[numlines] = new char[strlen(token)+1];
265             strcpy(fields[numlines++],token);
266           }
267           
268           char str[10]; strcpy(str, fields[6]); strcat(str, fields[7]);
269           
270           AliMUONTriggerCrate *crate = Crate(str); 
271           
272           if (!crate) 
273           {
274             AddCrate(str); crate = Crate(str);
275             
276             AliMUONRegionalTriggerBoard *rboard = new AliMUONRegionalTriggerBoard();
277             crate->AddBoard(rboard, 0);
278           }               
279           
280           //             CONVENTION: SLOT 0 HOLDS THE REGIONAL BOARD
281           Int_t sl = atoi(fields[10]);
282           
283 //          AliMUONTriggerLut* lut = calibData->TriggerLut();
284           
285           AliMUONLocalTriggerBoard *board = 
286             new AliMUONLocalTriggerBoard(fields[4], sl, 0x0);
287           
288                                         if (strcmp(fields[1],"nn")) 
289                                         {
290                                                 Int_t sboard = atoi(fields[1]);
291             
292                                                 board->SetNumber(sboard);
293             fLocalBoards->Add(sboard,board);
294             
295 //                                              fCrateMap[sboard-1] = new char[strlen(str)+1]; strcpy(fCrateMap[sboard-1], str);
296 //                                              fBoardMap[sboard-1] = sl;
297                                         }
298           
299                                         board->SetCrate(str);
300           
301           crate->AddBoard(board, sl);
302           
303           while (getline(myInputFile,sLine)) if (sLine.find("transv",0) != string::npos) break;
304           
305           strcpy(s,sLine.c_str());
306           
307           for (char *token = strtok(s, " ");
308                token != NULL;
309                token = strtok(NULL, " ")) if (!strcmp(token,"NONE")) board->SetTC(kFALSE);
310           
311           while (getline(myInputFile,sLine)) if (sLine.find("Switch",0) != string::npos) break;
312           
313           while (getline(myInputFile,sLine)) if (!sLine.empty()) break;   
314           
315           strcpy(s,sLine.c_str());
316           
317           Int_t lines = 0;
318           
319           for (char *token = strtok(s, " ");
320                token != NULL;
321                token = strtok(NULL, " ")) board->SetSwitch(lines++, atoi(token));
322           
323           for (Int_t i = 0; i<numlines; i++) 
324             if (fields[i]) {delete [] fields[i]; fields[i] = 0;}
325               
326               delete [] fields; fields = 0;
327         }
328       }
329     }
330   }
331 }