]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpRegionalTrigger.cxx
Gros chantier trigger:
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpRegionalTrigger.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 AliMpRegionalTrigger
21 // --------------------
22 // The class defines the properties of regional trigger crate
23 // Author: Ch. Finck, Subatech Nantes
24 //-----------------------------------------------------------------------------
25
26 #include "AliMpRegionalTrigger.h"
27 #include "AliMpTriggerCrate.h"
28 #include "AliMpLocalBoard.h"
29 #include "AliMpConstants.h"
30 #include "AliMpFiles.h"
31 #include "AliMpHelper.h"
32
33 #include "AliLog.h"
34
35 #include <TArrayI.h>
36 #include <Riostream.h>
37 #include <TClass.h>
38 #include <TSystem.h>
39
40
41 /// \cond CLASSIMP
42 ClassImp(AliMpRegionalTrigger)
43 /// \endcond
44
45
46 //______________________________________________________________________________
47 AliMpRegionalTrigger::AliMpRegionalTrigger()
48   : TObject(),
49     fTriggerCrates(true),
50     fLocalBoards(true)
51 {
52 /// Standard constructor
53   
54     fTriggerCrates.SetOwner(true);
55     fTriggerCrates.SetSize(AliMpConstants::LocalBoardNofChannels());
56
57     fLocalBoards.SetOwner(true);
58     fLocalBoards.SetSize(AliMpConstants::TotalNofLocalBoards()); // included non-notified boards
59 }
60
61 //______________________________________________________________________________
62 AliMpRegionalTrigger::AliMpRegionalTrigger(const AliMpRegionalTrigger& rhs)
63   : TObject(rhs),
64     fTriggerCrates(rhs.fTriggerCrates),
65     fLocalBoards(rhs.fLocalBoards)
66 {
67 /// Copy constructor
68 }  
69
70 //______________________________________________________________________________
71 AliMpRegionalTrigger::AliMpRegionalTrigger(TRootIOCtor* /*ioCtor*/)
72   : TObject(),
73     fTriggerCrates(),
74     fLocalBoards()
75 {
76 /// Constructor for I0
77 }
78
79 //______________________________________________________________________________
80 AliMpRegionalTrigger& AliMpRegionalTrigger::operator=(const AliMpRegionalTrigger& rhs)
81 {
82 /// Assignment operator
83
84   // check assignment to self
85   if (this == &rhs) return *this;
86
87   // base class assignment
88   TObject::operator=(rhs);
89
90   // assignment operator
91   fTriggerCrates = rhs.fTriggerCrates;
92   fLocalBoards = rhs.fLocalBoards;
93   
94   return *this;
95 }  
96
97 //______________________________________________________________________________
98 AliMpRegionalTrigger::~AliMpRegionalTrigger()
99 {
100 /// Destructor
101 }
102
103 //
104 // public methods
105 //
106
107 //______________________________________________________________________________
108 Bool_t AliMpRegionalTrigger::ReadData(const TString& fileName)
109 {
110 /// Load the Regional trigger from ASCII data files
111 /// and return its instance
112     
113     TString inFileName(fileName);
114     if ( inFileName == "" )
115       inFileName = AliMpFiles::LocalTriggerBoardMapping();
116     
117     inFileName = gSystem->ExpandPathName(inFileName.Data());
118
119     ifstream in(inFileName.Data(), ios::in);
120
121     if (!in) {
122       AliErrorStream()
123          << "Local Trigger Board Mapping File " << fileName.Data() << " not found" << endl;
124       return kFALSE;
125     }
126
127     AliMpLocalBoard* board = 0x0;
128     AliMpTriggerCrate* crate = 0x0;
129
130
131     Int_t localBoardId = 0;
132     TArrayI list;
133     UShort_t crateId, mask;
134     
135     char line[80];
136    
137     while (!in.eof())
138     {
139       in.getline(line,80);
140       if (!strlen(line)) break;
141       TString crateName(AliMpHelper::Normalize(line));
142       
143       in.getline(line,80);    
144       sscanf(line,"%hx",&crateId);
145   
146       // skip mode
147       in.getline(line,80);
148       
149       // skip coincidence
150       in.getline(line,80);
151       
152       // skip mask
153       in.getline(line,80);
154       sscanf(line,"%hx",&mask);
155       
156       crate = (AliMpTriggerCrate*)(fTriggerCrates.GetValue(crateName.Data()));
157       if (!crate) 
158       {
159         // cout << "Creating crate: " << crateName.Data() << endl;
160         crate = new AliMpTriggerCrate(crateName.Data(), crateId);
161         fTriggerCrates.Add(crateName.Data(), crate);
162       }
163       
164       Char_t localBoardName[20];
165       Int_t slot;
166       UInt_t switches;
167       
168       for ( Int_t i = 0; i < AliMpConstants::LocalBoardNofChannels(); ++i ) 
169       {
170         if ( (mask >> i ) & 0x1 )
171         {
172           in.getline(line,80);
173           sscanf(line,"%02d %s %03d %03x",&slot,localBoardName,&localBoardId,&switches);
174           // cout << "  Creating local board: " << localBoardId << endl;
175           board = new AliMpLocalBoard(localBoardId, localBoardName, slot); 
176           board->SetSwitch(switches);
177           board->SetCrate(crateName);
178           
179           if (localBoardId > AliMpConstants::NofLocalBoards())
180             board->SetNotified(false); // copy cards
181           
182           crate->AddLocalBoard(localBoardId);
183
184           // add  list of DEs for local board
185           list.Reset();
186           in.getline(line,80);
187           TString tmp(AliMpHelper::Normalize(line));
188           AliMpHelper::DecodeName(tmp,' ',list);
189           for (Int_t i = 0; i < list.GetSize(); ++i) { 
190             if ( list[i] ) board->AddDE(list[i]);
191           }  
192
193           // set copy number and transverse connector
194           in.getline(line,80);
195           tmp = AliMpHelper::Normalize(line);
196           AliMpHelper::DecodeName(tmp,' ',list);
197     
198           board->SetInputXfrom(list[0]);
199           board->SetInputXto(list[1]);
200           
201           board->SetInputYfrom(list[2]);
202           board->SetInputYto(list[3]);
203           
204           board->SetTC(list[4]);
205           
206           // add local board into map
207           fLocalBoards.Add(board->GetId(), board);
208         }
209       }
210     }
211     return kTRUE;
212 }
213
214 //______________________________________________________________________________
215 AliMpLocalBoard* AliMpRegionalTrigger::FindLocalBoard(Int_t localBoardId, 
216                                                       Bool_t warn) const {
217     /// Return bus patch with given Id
218
219     AliMpLocalBoard* localBoard
220       = (AliMpLocalBoard*) fLocalBoards.GetValue(localBoardId);
221
222     if ( ! localBoard && warn ) {
223         AliErrorStream()
224         << "Local board with Id = " << localBoardId << " not defined." << endl;
225     }
226
227     return localBoard;
228 }
229
230 //______________________________________________________________________________
231 AliMpTriggerCrate* AliMpRegionalTrigger::FindTriggerCrate(TString name, 
232                                                           Bool_t warn) const  {
233     /// Return trigger crate with given name
234
235     AliMpTriggerCrate* crate
236     = (AliMpTriggerCrate*) fTriggerCrates.GetValue(name.Data());
237
238     if ( ! crate && warn ) {
239         AliErrorStream()
240         << "Trigger crate with name = " << name.Data() << " not defined." << endl;
241     }
242
243     return crate;
244 }
245
246 //______________________________________________________________________________
247 Int_t AliMpRegionalTrigger::GetNofTriggerCrates() const 
248
249     /// Return number of trigger crates
250
251     return fTriggerCrates.GetSize(); 
252 }
253
254 //______________________________________________________________________________
255 AliMpTriggerCrate* AliMpRegionalTrigger::GetTriggerCrate(Int_t index) const
256
257     /// Return the trigger crates with given index;
258
259     return static_cast<AliMpTriggerCrate*>(fTriggerCrates.GetObject(index)); 
260 }
261
262 //______________________________________________________________________________
263 AliMpTriggerCrate* AliMpRegionalTrigger::GetTriggerCrateFast(Int_t index) const
264
265     /// Return the trigger crates with given index;
266     /// the index is not checked as we use the fast method in AliMpExMap.
267
268     return static_cast<AliMpTriggerCrate*>(fTriggerCrates.GetObjectFast(index)); 
269 }
270
271 //______________________________________________________________________________
272 Int_t AliMpRegionalTrigger::GetNofLocalBoards() const
273
274     /// Return number of local boards
275     
276     return fLocalBoards.GetSize(); 
277 }
278
279 //______________________________________________________________________________
280 AliMpLocalBoard* AliMpRegionalTrigger::GetLocalBoard(Int_t index) const
281
282     /// Return local board with given index;
283     
284     return static_cast<AliMpLocalBoard*>(fLocalBoards.GetObject(index)); 
285 }
286
287 //______________________________________________________________________________
288 AliMpLocalBoard* AliMpRegionalTrigger::GetLocalBoardFast(Int_t index) const
289
290     /// Return local board with given index;
291     /// the index is not checked as we use the fast method in AliMpExMap.
292     
293     return static_cast<AliMpLocalBoard*>(fLocalBoards.GetObjectFast(index)); 
294 }
295
296
297
298