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