]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpGlobalCrate.cxx
4cfcc9d46942c7cfc9d79f3715cda74a5d63d62c
[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     if (tmp.Contains(GetJtagName())) {
146         // vme addr
147         in.getline(line, 255);
148         tmp = AliMpHelper::Normalize(line);
149         ULong_t addr;
150         sscanf(tmp.Data(), "%lx", &addr);
151         SetJtagVmeAddr(addr);
152         //AliDebug(1, Form("Jtag Vme Address: 0x%x", addr));
153
154         // clk div, rx phase, read delay
155         in.getline(line, 255);
156         tmp = AliMpHelper::Normalize(line);
157         TArrayI list;
158         AliMpHelper::DecodeName(line, ' ', list);
159         SetJtagClockDiv(list[0]);
160         SetJtagRxPhase(list[1]);
161         SetJtagRdDelay(list[2]);
162         //AliDebug(1, Form("Jtag Clock Div: %d, Rx Phase: %d, Read Delay %d", list[0], list[1], list[2]));
163
164         // enable
165         in.getline(line, 255);
166         tmp = AliMpHelper::Normalize(line);
167         AliMpHelper::DecodeName(line, ' ', list);
168         UChar_t enable = 0;
169         for (Int_t i = 0; i < GetJtagNofLines(); ++i)
170             enable |= (list[i] << i);
171         SetEnableJtag(enable);
172         //AliDebug(1, Form("Jtag Enable: 0x%x", enable));
173
174         for (Int_t i = 0; i < GetJtagNofLines(); ++i) {
175             in.getline(line, 255);
176             for (Int_t j = 0; j < GetJtagNofLines(); ++j) {
177                 in.getline(line, 255);
178                 tmp = AliMpHelper::Normalize(line);
179                 SetJtagCrateName(i*GetJtagNofLines() + j, tmp);
180                 //AliDebug(1, Form("Jtag Crate Name: %s", tmp.Data()));
181             }
182         }
183     }
184
185     in.getline(line, 255);
186     tmp = AliMpHelper::Normalize(line);
187     if (tmp.Contains(GetFirstDarcName())) {
188         // vme addr
189         in.getline(line, 255);
190         tmp = AliMpHelper::Normalize(line);
191         ULong_t addr;
192         sscanf(tmp.Data(), "%lx", &addr);
193         SetFirstDarcVmeAddr(addr);
194         //AliDebug(1, Form("First Darc Vme Address: 0x%x", addr));
195
196         // type
197         in.getline(line, 255);
198         tmp = AliMpHelper::Normalize(line);
199         SetFirstDarcType(tmp.Atoi());
200         //AliDebug(1, Form("First Darc Type: %d", tmp.Atoi()));
201
202         // enable
203         in.getline(line, 255);
204         UInt_t item;
205         tmp = AliMpHelper::Normalize(line);
206         sscanf(tmp.Data(), "%x", &item);
207         SetFirstDarcDisable(item);
208         //AliDebug(1, Form("First Darc Enable: 0x%x", item));
209
210         // L0
211         in.getline(line, 255);
212         tmp = AliMpHelper::Normalize(line);
213         sscanf(tmp.Data(), "%x", &item);
214         SetFirstDarcL0Delay(item);
215         //AliDebug(1, Form("First Darc L0 Delay: 0x%x", item));
216
217         // L1
218         in.getline(line, 255);
219         tmp = AliMpHelper::Normalize(line);
220         sscanf(tmp.Data(), "%x", &item);
221         SetFirstDarcL1TimeOut(item);
222         //AliDebug(1, Form("First Darc L1 Time Out: 0x%x", item));
223     }
224
225     in.getline(line, 255);
226     tmp = AliMpHelper::Normalize(line);
227     if (tmp.Contains(GetSecondDarcName())) {
228         // vme addr
229         in.getline(line, 255);
230         tmp = AliMpHelper::Normalize(line);
231         ULong_t addr;
232         sscanf(tmp.Data(), "%lx", &addr);
233         SetSecondDarcVmeAddr(addr);
234         //AliDebug(1, Form("Second Darc Vme Address: 0x%x", addr));
235         
236         // type
237         in.getline(line, 255);
238         tmp = AliMpHelper::Normalize(line);
239         SetSecondDarcType(tmp.Atoi());
240         //AliDebug(1, Form("Second Darc Type: %d", tmp.Atoi()));
241         
242         // enable
243         in.getline(line, 255);
244         UInt_t item;
245         tmp = AliMpHelper::Normalize(line);
246         sscanf(tmp.Data(), "%x", &item);
247         SetSecondDarcDisable(item);
248         //AliDebug(1, Form("Second Darc Enable: 0x%x", item));
249         
250         // L0
251         in.getline(line, 255);
252         tmp = AliMpHelper::Normalize(line);
253         sscanf(tmp.Data(), "%x", &item);
254         SetSecondDarcL0Delay(item);
255         //AliDebug(1, Form("Second Darc L0 Delay: 0x%x", item));
256         
257         // L1
258         in.getline(line, 255);
259         tmp = AliMpHelper::Normalize(line);
260         sscanf(tmp.Data(), "%x", &item);
261         SetSecondDarcL1TimeOut(item);
262         //AliDebug(1, Form("Second Darc L1 Time Out: 0x%x", item));
263     }
264
265     in.getline(line, 255);
266     tmp = AliMpHelper::Normalize(line);
267     if (tmp.Contains(GetGlobalName())) {
268         in.getline(line, 255);
269         tmp = AliMpHelper::Normalize(line);
270         ULong_t addr;
271         sscanf(tmp.Data(), "%lx", &addr);
272         SetGlobalVmeAddr(addr);
273         //AliDebug(1, Form("Global Vme Address: 0x%x", addr));
274
275         for (Int_t i = 0; i < GetGlobalNofRegisters(); ++i) {
276             in.getline(line, 255);
277             tmp = AliMpHelper::Normalize(line);
278             UInt_t reg;
279             sscanf(tmp.Data(), "%x", &reg);
280             SetGlobalRegister(i, reg);
281             //AliDebug(1, Form("Global Register %d: 0x%x", i, reg));
282         }
283     }
284
285     in.getline(line, 255);
286     tmp = AliMpHelper::Normalize(line);
287     if (tmp.Contains(GetFetName())) {
288         in.getline(line, 255);
289         tmp = AliMpHelper::Normalize(line);
290         ULong_t addr;
291         sscanf(tmp.Data(), "%lx", &addr);
292         SetFetVmeAddr(addr);
293         //AliDebug(1, Form("Fet Vme Address: 0x%x", addr));
294
295         for (Int_t i = 0; i < GetFetNofRegisters(); ++i) {
296             in.getline(line, 255);
297             tmp = AliMpHelper::Normalize(line);
298             UInt_t reg;
299             sscanf(tmp.Data(), "%x", &reg);
300             SetFetRegister(i, reg);
301             //AliDebug(1, Form("Fet Register %d: 0x%x", i, reg));
302         }
303     }
304
305     return kTRUE;
306 }
307
308 //______________________________________________________________________________
309 Bool_t AliMpGlobalCrate::GetEnableJtag(Int_t index) const 
310 {
311   /// returns enable mask for a given Jtag line
312
313   if (index > fgkJtagNofLines) {
314     AliWarning("Index size too big for Jtag line");
315     return kFALSE;
316   }
317   return ((fEnableJtag >> index) & 0x1);
318
319 }
320
321 //______________________________________________________________________________
322 void AliMpGlobalCrate::SetJtagCrateName(Int_t index, TString name) 
323 {
324   /// Get Jtag crate name for a given index 
325   if (index > AliMpConstants::LocalBoardNofChannels()) {
326     AliWarning("Index size too big for Jtag line");
327     return;
328   }                                                 
329   fJtagCrateName[index] = name;
330 }
331
332 //______________________________________________________________________________
333 TString AliMpGlobalCrate::GetJtagCrateName(Int_t jtagLine, Int_t index) const 
334
335   /// Get the crate name for a given line and a given index 
336   if (jtagLine > AliMpConstants::LocalBoardNofChannels() || index > AliMpConstants::LocalBoardNofChannels())
337     return 0x0;
338   else                                       
339     return fJtagCrateName[jtagLine*fgkJtagNofLines + index];
340 }
341
342 //______________________________________________________________________________
343 UInt_t AliMpGlobalCrate::GetGlobalRegister(Int_t index) const       
344 {
345   /// return global register for a given index
346   if (index > fgkGlobalNofRegisters) {
347     AliWarning("Index size too big for Global Register");
348     return 0;
349   } else 
350     return fGlobalRegisters[index];
351 }
352
353 //______________________________________________________________________________
354 void AliMpGlobalCrate::SetGlobalRegister(Int_t index, UInt_t reg) 
355 {
356   /// set Global register for a given index
357   if (index > fgkGlobalNofRegisters) {
358     AliWarning("Index size too big for Global Register");
359     return;
360   } 
361   fGlobalRegisters[index] = reg;
362 }
363    
364 //______________________________________________________________________________
365 UInt_t AliMpGlobalCrate::GetFetRegister(Int_t index) const       
366 {
367   /// return global register for a given index
368   if (index > fgkFetNofRegisters) {
369     AliWarning("Index size too big for Fet Register");
370     return 0;
371   } else 
372     return fFetRegisters[index];
373 }
374
375 //______________________________________________________________________________
376 void AliMpGlobalCrate::SetFetRegister(Int_t index, UInt_t reg) 
377 {
378   /// set Global register for a given index
379   if (index > fgkFetNofRegisters) {
380     AliWarning("Index size too big for Global Register");
381     return;
382   } 
383   fFetRegisters[index] = reg;
384 }