]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpGlobalCrate.cxx
Fixing part of the Coding violation
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpGlobalCrate.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 // $MpId: AliMpTrigger.cxx,v 1.4 2006/05/24 13:58:52 ivana Exp $
18
19 //-----------------------------------------------------------------------------
20 // Class AliMpGlobalCrate
21 // --------------------
22 // The class defines the properties of trigger crate
23 // Author: Ch. Finck, Subatech Nantes
24 //-----------------------------------------------------------------------------
25
26 #include "AliMpGlobalCrate.h"
27 #include "AliMpConstants.h"
28 #include "AliMpFiles.h"
29 #include "AliMpHelper.h"
30
31 #include "AliLog.h"
32
33 #include <TArrayI.h>
34 #include <Riostream.h>
35 #include <TSystem.h>
36
37 /// \cond CLASSIMP
38 ClassImp(AliMpGlobalCrate)
39 /// \endcond
40
41 const Char_t*  AliMpGlobalCrate::fgkJtagName       = "JtagBoard";
42 const Char_t*  AliMpGlobalCrate::fgkFirstDarcName  = "LeftDarcBoard";
43 const Char_t*  AliMpGlobalCrate::fgkSecondDarcName = "RightDarcBoard";
44 const Char_t*  AliMpGlobalCrate::fgkGlobalName     = "GlobalBoard";  
45 const Char_t*  AliMpGlobalCrate::fgkFetName        = "FetBoard"; 
46
47 const Int_t   AliMpGlobalCrate::fgkGlobalNofRegisters =  13; 
48 const Int_t   AliMpGlobalCrate::fgkFetNofRegisters    =  7; 
49 const Int_t   AliMpGlobalCrate::fgkJtagNofLines       =  4; 
50 //______________________________________________________________________________
51 AliMpGlobalCrate::AliMpGlobalCrate()
52   : TNamed("GlobalCrate", "mapping trigger global crate"),
53     fJtagVmeAddr(0x0),
54     fJtagClockDiv(0),
55     fJtagRxPhase(0),
56     fJtagRdDelay(0),
57     fEnableJtag(0),
58     fJtagCrateName(),                  
59     fFirstDarcVmeAddr(0x0),
60     fFirstDarcType(0),
61     fFirstDarcDisable(0),
62     fFirstDarcL0Delay(0),
63     fFirstDarcL1TimeOut(0),
64     fSecondDarcVmeAddr(0x0),
65     fSecondDarcType(0),
66     fSecondDarcDisable(0),
67     fSecondDarcL0Delay(0),
68     fSecondDarcL1TimeOut(0),
69     fGlobalVmeAddr(0x0),
70     fFetVmeAddr(0x0)
71 {
72 /// Standard constructor
73
74   for (Int_t i = 0; i < fgkGlobalNofRegisters; ++i)
75     fGlobalRegisters[i] = 0;
76   
77   for (Int_t j = 0; j < fgkFetNofRegisters; ++j)
78     fFetRegisters[j] = 0;
79 }
80
81 //______________________________________________________________________________
82 AliMpGlobalCrate::AliMpGlobalCrate(TRootIOCtor* /*ioCtor*/)
83   : TNamed("GlobalCrate", "mapping trigger global crate"),
84     fJtagVmeAddr(0x0),
85     fJtagClockDiv(0),
86     fJtagRxPhase(0),
87     fJtagRdDelay(0),
88     fEnableJtag(0),
89     fJtagCrateName(),                  
90     fFirstDarcVmeAddr(0x0),
91     fFirstDarcType(0),
92     fFirstDarcDisable(0),
93     fFirstDarcL0Delay(0),
94     fFirstDarcL1TimeOut(0),
95     fSecondDarcVmeAddr(0x0),
96     fSecondDarcType(0),
97     fSecondDarcDisable(0),
98     fSecondDarcL0Delay(0),
99     fSecondDarcL1TimeOut(0),
100     fGlobalVmeAddr(0x0),
101     fGlobalRegisters(),
102     fFetVmeAddr(0x0),
103     fFetRegisters()
104 {
105 /// Root IO constructor
106 }
107
108 //______________________________________________________________________________
109 AliMpGlobalCrate::~AliMpGlobalCrate()
110 {
111 /// Destructor
112 }
113
114 //______________________________________________________________________________
115 Bool_t AliMpGlobalCrate::ReadData(const TString& fileName)
116 {
117     /// Fill trigger global crate object from ascii file
118     /// put the method static to be used by other class w/o initializing object
119   
120     TString inFileName(fileName);
121     if ( inFileName == "" )
122       inFileName = AliMpFiles::GlobalTriggerBoardMapping();
123     
124     inFileName = gSystem->ExpandPathName(inFileName.Data());
125
126     ifstream in(inFileName.Data(), ios::in);
127
128     if (!in) {
129       AliErrorStream()
130          << "Global Trigger Board Mapping File " << fileName.Data() << " not found" << endl;
131       return kFALSE;
132     }
133
134     TArrayI list;
135
136     char line[255];
137     in.getline(line, 255);
138     TString tmp(AliMpHelper::Normalize(line));
139
140     if (!tmp.Contains(GetName()))
141         printf("Wrong Global Crate File");
142
143     in.getline(line, 255);
144     tmp = AliMpHelper::Normalize(line);
145
146     if (tmp.Contains(GetJtagName())) {
147         // vme addr
148         in.getline(line, 255);
149         TString tmp(AliMpHelper::Normalize(line));
150         ULong_t addr;
151         sscanf(tmp.Data(), "%lx", &addr);
152         SetJtagVmeAddr(addr);
153         //AliDebug(1, Form("Jtag Vme Address: 0x%x", addr));
154
155         // clk div, rx phase, read delay
156         in.getline(line, 255);
157         tmp = AliMpHelper::Normalize(line);
158         TArrayI list;
159         AliMpHelper::DecodeName(line, ' ', list);
160         SetJtagClockDiv(list[0]);
161         SetJtagRxPhase(list[1]);
162         SetJtagRdDelay(list[2]);
163         //AliDebug(1, Form("Jtag Clock Div: %d, Rx Phase: %d, Read Delay %d", list[0], list[1], list[2]));
164
165         // enable
166         in.getline(line, 255);
167         tmp = AliMpHelper::Normalize(line);
168         AliMpHelper::DecodeName(line, ' ', list);
169         UChar_t enable = 0;
170         for (Int_t i = 0; i < GetJtagNofLines(); ++i)
171             enable |= (list[i] << i);
172         SetEnableJtag(enable);
173         //AliDebug(1, Form("Jtag Enable: 0x%x", enable));
174
175         for (Int_t i = 0; i < GetJtagNofLines(); ++i) {
176             in.getline(line, 255);
177             for (Int_t j = 0; j < GetJtagNofLines(); ++j) {
178                 in.getline(line, 255);
179                 tmp = AliMpHelper::Normalize(line);
180                 SetJtagCrateName(i*GetJtagNofLines() + j, tmp);
181                 //AliDebug(1, Form("Jtag Crate Name: %s", tmp.Data()));
182             }
183         }
184     }
185
186     in.getline(line, 255);
187     tmp = AliMpHelper::Normalize(line);
188     if (tmp.Contains(GetFirstDarcName())) {
189         // vme addr
190         in.getline(line, 255);
191         TString tmp(AliMpHelper::Normalize(line));
192         ULong_t addr;
193         sscanf(tmp.Data(), "%lx", &addr);
194         SetFirstDarcVmeAddr(addr);
195         //AliDebug(1, Form("First Darc Vme Address: 0x%x", addr));
196
197         // type
198         in.getline(line, 255);
199         tmp = AliMpHelper::Normalize(line);
200         SetFirstDarcType(tmp.Atoi());
201         //AliDebug(1, Form("First Darc Type: %d", tmp.Atoi()));
202
203         // enable
204         in.getline(line, 255);
205         UInt_t item;
206         tmp = AliMpHelper::Normalize(line);
207         sscanf(tmp.Data(), "%x", &item);
208         SetFirstDarcDisable(item);
209         //AliDebug(1, Form("First Darc Enable: 0x%x", item));
210
211         // L0
212         in.getline(line, 255);
213         tmp = AliMpHelper::Normalize(line);
214         sscanf(tmp.Data(), "%x", &item);
215         SetFirstDarcL0Delay(item);
216         //AliDebug(1, Form("First Darc L0 Delay: 0x%x", item));
217
218         // L1
219         in.getline(line, 255);
220         tmp = AliMpHelper::Normalize(line);
221         sscanf(tmp.Data(), "%x", &item);
222         SetFirstDarcL1TimeOut(item);
223         //AliDebug(1, Form("First Darc L1 Time Out: 0x%x", item));
224     }
225
226     in.getline(line, 255);
227     tmp = AliMpHelper::Normalize(line);
228     if (tmp.Contains(GetSecondDarcName())) {
229         // vme addr
230         in.getline(line, 255);
231         TString tmp(AliMpHelper::Normalize(line));
232         ULong_t addr;
233         sscanf(tmp.Data(), "%lx", &addr);
234         SetSecondDarcVmeAddr(addr);
235         //AliDebug(1, Form("Second Darc Vme Address: 0x%x", addr));
236         
237         // type
238         in.getline(line, 255);
239         tmp = AliMpHelper::Normalize(line);
240         SetSecondDarcType(tmp.Atoi());
241         //AliDebug(1, Form("Second Darc Type: %d", tmp.Atoi()));
242         
243         // enable
244         in.getline(line, 255);
245         UInt_t item;
246         tmp = AliMpHelper::Normalize(line);
247         sscanf(tmp.Data(), "%x", &item);
248         SetSecondDarcDisable(item);
249         //AliDebug(1, Form("Second Darc Enable: 0x%x", item));
250         
251         // L0
252         in.getline(line, 255);
253         tmp = AliMpHelper::Normalize(line);
254         sscanf(tmp.Data(), "%x", &item);
255         SetSecondDarcL0Delay(item);
256         //AliDebug(1, Form("Second Darc L0 Delay: 0x%x", item));
257         
258         // L1
259         in.getline(line, 255);
260         tmp = AliMpHelper::Normalize(line);
261         sscanf(tmp.Data(), "%x", &item);
262         SetSecondDarcL1TimeOut(item);
263         //AliDebug(1, Form("Second Darc L1 Time Out: 0x%x", item));
264     }
265
266     in.getline(line, 255);
267     tmp = AliMpHelper::Normalize(line);
268     if (tmp.Contains(GetGlobalName())) {
269         in.getline(line, 255);
270         TString tmp(AliMpHelper::Normalize(line));
271         ULong_t addr;
272         sscanf(tmp.Data(), "%lx", &addr);
273         SetGlobalVmeAddr(addr);
274         //AliDebug(1, Form("Global Vme Address: 0x%x", addr));
275
276         for (Int_t i = 0; i < GetGlobalNofRegisters(); ++i) {
277             in.getline(line, 255);
278             TString tmp(AliMpHelper::Normalize(line));
279             UInt_t reg;
280             sscanf(tmp.Data(), "%x", &reg);
281             SetGlobalRegister(i, reg);
282             //AliDebug(1, Form("Global Register %d: 0x%x", i, reg));
283         }
284     }
285
286     in.getline(line, 255);
287     tmp = AliMpHelper::Normalize(line);
288     if (tmp.Contains(GetFetName())) {
289         in.getline(line, 255);
290         TString tmp(AliMpHelper::Normalize(line));
291         ULong_t addr;
292         sscanf(tmp.Data(), "%lx", &addr);
293         SetFetVmeAddr(addr);
294         //AliDebug(1, Form("Fet Vme Address: 0x%x", addr));
295
296         for (Int_t i = 0; i < GetFetNofRegisters(); ++i) {
297             in.getline(line, 255);
298             TString tmp(AliMpHelper::Normalize(line));
299             UInt_t reg;
300             sscanf(tmp.Data(), "%x", &reg);
301             SetFetRegister(i, reg);
302             //AliDebug(1, Form("Fet Register %d: 0x%x", i, reg));
303         }
304     }
305
306     return kTRUE;
307 }
308
309 //______________________________________________________________________________
310 Bool_t AliMpGlobalCrate::GetEnableJtag(Int_t index) const 
311 {
312   /// returns enable mask for a given Jtag line
313
314   if (index > fgkJtagNofLines) {
315     AliWarning("Index size too big for Jtag line");
316     return kFALSE;
317   }
318   return ((fEnableJtag >> index) & 0x1);
319
320 }
321
322 //______________________________________________________________________________
323 void AliMpGlobalCrate::SetJtagCrateName(Int_t index, TString name) 
324 {
325   /// Get Jtag crate name for a given index 
326   if (index > AliMpConstants::LocalBoardNofChannels()) {
327     AliWarning("Index size too big for Jtag line");
328     return;
329   }                                                 
330   fJtagCrateName[index] = name;
331 }
332
333 //______________________________________________________________________________
334 TString AliMpGlobalCrate::GetJtagCrateName(Int_t jtagLine, Int_t index) const 
335
336   /// Get the crate name for a given line and a given index 
337   if (jtagLine > AliMpConstants::LocalBoardNofChannels() || index > AliMpConstants::LocalBoardNofChannels())
338     return 0x0;
339   else                                       
340     return fJtagCrateName[jtagLine*fgkJtagNofLines + index];
341 }
342
343 //______________________________________________________________________________
344 UInt_t AliMpGlobalCrate::GetGlobalRegister(Int_t index) const       
345 {
346   /// return global register for a given index
347   if (index > fgkGlobalNofRegisters) {
348     AliWarning("Index size too big for Global Register");
349     return 0;
350   } else 
351     return fGlobalRegisters[index];
352 }
353
354 //______________________________________________________________________________
355 void AliMpGlobalCrate::SetGlobalRegister(Int_t index, UInt_t reg) 
356 {
357   /// set Global register for a given index
358   if (index > fgkGlobalNofRegisters) {
359     AliWarning("Index size too big for Global Register");
360     return;
361   } 
362   fGlobalRegisters[index] = reg;
363 }
364    
365 //______________________________________________________________________________
366 UInt_t AliMpGlobalCrate::GetFetRegister(Int_t index) const       
367 {
368   /// return global register for a given index
369   if (index > fgkFetNofRegisters) {
370     AliWarning("Index size too big for Fet Register");
371     return 0;
372   } else 
373     return fFetRegisters[index];
374 }
375
376 //______________________________________________________________________________
377 void AliMpGlobalCrate::SetFetRegister(Int_t index, UInt_t reg) 
378 {
379   /// set Global register for a given index
380   if (index > fgkFetNofRegisters) {
381     AliWarning("Index size too big for Global Register");
382     return;
383   } 
384   fFetRegisters[index] = reg;
385 }