]> 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 "AliMpRegionalTriggerReader.h"
28 #include "AliMpExMapIterator.h"
29 #include "AliMpTriggerCrate.h"
30 #include "AliMpLocalBoard.h"
31 #include "AliMpConstants.h"
32 #include "AliMpFiles.h"
33 #include "AliMpDataStreams.h"
34 #include "AliMpHelper.h"
35
36 #include "AliLog.h"
37
38 #include <TArrayI.h>
39 #include <Riostream.h>
40 #include <TClass.h>
41 #include <TSystem.h>
42
43
44 /// \cond CLASSIMP
45 ClassImp(AliMpRegionalTrigger)
46 /// \endcond
47
48
49 //______________________________________________________________________________
50 AliMpRegionalTrigger::AliMpRegionalTrigger()
51   : TObject(),
52     fTriggerCrates(),
53     fLocalBoardMap(),
54     fLocalBoardArray(AliMpConstants::TotalNofLocalBoards()+1) // included non-notified boards
55 {
56       /// Standard constructor
57   
58     fTriggerCrates.SetOwner(true);
59     fTriggerCrates.SetSize(AliMpConstants::LocalBoardNofChannels());
60 }
61
62 //______________________________________________________________________________
63 AliMpRegionalTrigger::AliMpRegionalTrigger(const AliMpRegionalTrigger& rhs)
64   : TObject(rhs),
65     fTriggerCrates(rhs.fTriggerCrates),
66     fLocalBoardMap(rhs.fLocalBoardMap),
67     fLocalBoardArray(rhs.fLocalBoardArray)
68 {
69 /// Copy constructor
70 }  
71
72 //______________________________________________________________________________
73 AliMpRegionalTrigger::AliMpRegionalTrigger(TRootIOCtor* ioCtor)
74   : TObject(),
75     fTriggerCrates(ioCtor),
76     fLocalBoardMap(ioCtor),
77     fLocalBoardArray()
78 {
79 /// Constructor for I0
80 }
81
82 //______________________________________________________________________________
83 AliMpRegionalTrigger& AliMpRegionalTrigger::operator=(const AliMpRegionalTrigger& rhs)
84 {
85 /// Assignment operator
86
87   // check assignment to self
88   if (this == &rhs) return *this;
89
90   // base class assignment
91   TObject::operator=(rhs);
92
93   // assignment operator
94   fTriggerCrates = rhs.fTriggerCrates;
95   fLocalBoardArray = rhs.fLocalBoardArray;
96   
97   return *this;
98 }  
99
100 //______________________________________________________________________________
101 AliMpRegionalTrigger::~AliMpRegionalTrigger()
102 {
103 /// Destructor
104 }
105
106
107 //
108 // private methods
109 //
110
111 //______________________________________________________________________________
112 Bool_t AliMpRegionalTrigger::ReadData(istream& in)
113 {
114 /// Load the Regional trigger from ASCII data files
115 /// and return its instance
116     
117     TList list;
118     list.AddAt(&fTriggerCrates, 0);
119     list.AddAt(&fLocalBoardMap, 1);
120     list.AddAt(&fLocalBoardArray, 2);
121
122     Int_t status = AliMpRegionalTriggerReader::ReadData(list, in);
123     
124     if (status == -1) {
125         AliErrorStream()
126         << "Regional Trigger Mapping File not found" << endl;
127         return kFALSE;
128     } 
129     
130     if (!status)
131       return kFALSE;
132       
133     
134     return kTRUE;
135 }
136
137 //
138 // public methods
139 //
140
141 //______________________________________________________________________________
142 Bool_t AliMpRegionalTrigger::ReadData(const TString& fileName)
143 {
144 /// Load the Regional trigger from ASCII data files
145 /// and return its instance
146     
147     if ( fileName != "" ) {
148       AliDebugStream(2) << "Read data from file " << fileName.Data() << endl;
149     
150       TString inFileName(fileName);
151       inFileName = gSystem->ExpandPathName(inFileName.Data());
152       ifstream inFile(inFileName.Data(), ios::in);
153       if ( ! inFile.good() ) {
154         AliErrorStream()
155            << "Local Trigger Board Mapping File " << fileName.Data() << " not found" << endl;
156         return kFALSE;
157       }
158       
159       return ReadData(inFile);  
160     } 
161     else {
162       AliDebugStream(2) << "Read data from stream " << fileName.Data() << endl;
163       istream& in
164          = AliMpDataStreams::Instance()
165              ->CreateDataStream(AliMpFiles::LocalTriggerBoardMapping());
166              
167       Bool_t result = ReadData(in);
168       
169       delete &in;
170       return result;        
171     }
172 }
173
174 //______________________________________________________________________________
175 AliMpLocalBoard* AliMpRegionalTrigger::FindLocalBoard(Int_t localBoardId, 
176                                                       Bool_t warn) const {
177     /// Return local board with given Id
178
179     AliMpLocalBoard* localBoard
180       = static_cast<AliMpLocalBoard*>(fLocalBoardMap.GetValue(localBoardId));
181     
182     if ( ! localBoard && warn ) {
183         AliErrorStream()
184         << "Loacl board with localBoardId = " << localBoardId << " not found." << endl;
185     }      
186
187     return localBoard;
188 }
189
190 //______________________________________________________________________________
191 AliMpTriggerCrate* AliMpRegionalTrigger::FindTriggerCrate(TString name, 
192                                                           Bool_t warn) const  {
193     /// Return trigger crate with given name
194
195     AliMpTriggerCrate* crate
196     = (AliMpTriggerCrate*) fTriggerCrates.GetValue(name.Data());
197
198     if ( ! crate && warn ) {
199         AliErrorStream()
200         << "Trigger crate with name = " << name.Data() << " not defined." << endl;
201     }
202
203     return crate;
204 }
205
206 //______________________________________________________________________________
207 Int_t AliMpRegionalTrigger::GetNofTriggerCrates() const 
208
209     /// Return number of trigger crates
210
211     return fTriggerCrates.GetSize(); 
212 }
213
214 //______________________________________________________________________________
215 Int_t AliMpRegionalTrigger::GetNofLocalBoards() const
216
217     /// Return number of local boards
218     
219     return fLocalBoardArray.GetSize(); 
220 }
221
222 //______________________________________________________________________________
223 TIterator* 
224 AliMpRegionalTrigger::CreateCrateIterator() const
225 {
226   /// Create iterator over crates
227
228   return fTriggerCrates.CreateIterator();
229 }
230
231 //______________________________________________________________________________
232 TIterator* 
233 AliMpRegionalTrigger::CreateLocalBoardIterator() const
234 {
235   /// Create iterator over local boards
236
237   return fLocalBoardArray.MakeIterator();
238 }
239
240 //______________________________________________________________________________
241 Int_t 
242 AliMpRegionalTrigger::LocalBoardId(Int_t index) const
243 {
244   /// Return local board Id for the local boards with a given index
245
246   AliMpLocalBoard* lb = static_cast<AliMpLocalBoard*>(fLocalBoardArray.At(index));
247   if (lb)
248   {
249     return lb->GetId();
250   }
251   AliError(Form("Could not get local board at index %d",index));
252   return -1;
253 }
254
255