]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpRegionalTrigger.cxx
Separating run-dependent mapping data from data, which are not
[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 fill objects. Return false if reading fails
115   
116   if ( !in.good() ) return kFALSE;
117    
118   Int_t localBoardId = 0;
119   TArrayI listInt;
120   UShort_t crateId;
121   Int_t nofBoards;
122   char line[80];
123  
124   // decode file and store in objects
125   while (!in.eof())
126   {
127     in.getline(line,80);
128     if (!strlen(line)) break;
129     TString crateName(AliMpHelper::Normalize(line));
130     
131     in.getline(line,80);    
132     sscanf(line,"%hx",&crateId);
133
134     // skip data which are not stored in mapping object
135     // (mode, coincidence, mask)
136     in.getline(line,80);
137     in.getline(line,80);
138     in.getline(line,80);
139     
140     // read # local board
141     in.getline(line,80);
142     sscanf(line,"%d",&nofBoards);
143     
144     AliMpTriggerCrate* crate 
145       = (AliMpTriggerCrate*)(fTriggerCrates.GetValue(crateName.Data()));
146     if (!crate)  {
147       crate = new AliMpTriggerCrate(crateName.Data(), crateId);
148       fTriggerCrates.Add(crateName.Data(), crate);
149     }
150
151     Char_t localBoardName[20];
152     Int_t slot;
153     UInt_t switches;
154     
155     for ( Int_t i = 0; i < nofBoards; ++i ) 
156     {
157         in.getline(line,80);
158         sscanf(line,"%02d %s %03d %03x",&slot,localBoardName,&localBoardId,&switches);
159         AliMpLocalBoard* board = new AliMpLocalBoard(localBoardId, localBoardName, slot); 
160         board->SetSwitch(switches);
161         board->SetCrate(crateName);
162         
163         if (localBoardId > AliMpConstants::NofLocalBoards())
164           board->SetNotified(false); // copy cards
165         
166         crate->AddLocalBoard(localBoardId);
167         
168         // add  list of DEs for local board
169         listInt.Reset();
170         in.getline(line,80);
171         TString tmp(AliMpHelper::Normalize(line));
172         AliMpHelper::DecodeName(tmp,' ',listInt);
173         for (Int_t ii = 0; ii < listInt.GetSize(); ++ii) { 
174           if ( listInt[ii] ) board->AddDE(listInt[ii]);
175         }  
176          
177         // set copy number and transverse connector
178         in.getline(line,80);
179         TString tmp1 = AliMpHelper::Normalize(line);
180         AliMpHelper::DecodeName(tmp1,' ',listInt);
181         
182         board->SetInputXfrom(listInt[0]);
183         board->SetInputXto(listInt[1]);
184         
185         board->SetInputYfrom(listInt[2]);
186         board->SetInputYto(listInt[3]);
187         
188         board->SetTC(listInt[4]);
189         
190         // add local board into array
191         fLocalBoardArray.AddAt(board,board->GetId());
192         fLocalBoardMap.Add(board->GetId(),board);
193     }
194   }
195   return kTRUE;
196 }  
197
198 //
199 // public methods
200 //
201
202 //______________________________________________________________________________
203 Bool_t AliMpRegionalTrigger::ReadData(const TString& fileName)
204 {
205 /// Load the Regional trigger from ASCII data files
206 /// and return its instance
207     
208     AliDebugStream(2) << "Read data from file " << fileName.Data() << endl;
209     
210     TString inFileName(fileName);
211     inFileName = gSystem->ExpandPathName(inFileName.Data());
212     ifstream inFile(inFileName.Data(), ios::in);
213     if ( ! inFile.good() ) {
214       AliErrorStream()
215          << "Local Trigger Board Mapping File " << fileName.Data() << " not found" << endl;
216       return kFALSE;
217     }
218     
219     return ReadData(inFile);  
220 }
221
222 //______________________________________________________________________________
223 Bool_t AliMpRegionalTrigger::ReadData(const AliMpDataStreams& dataStreams)
224 {
225 /// Load the Regional trigger from ASCII data files
226 /// and return its instance
227     
228     AliDebugStream(2) << "Read data from stream " << endl;
229     istream& in
230        = dataStreams.
231            CreateDataStream(AliMpFiles::LocalTriggerBoardMapping());
232            
233     Bool_t result = ReadData(in);
234     
235     delete &in;
236     return result;        
237 }
238
239 //______________________________________________________________________________
240 AliMpLocalBoard* AliMpRegionalTrigger::FindLocalBoard(Int_t localBoardId, 
241                                                       Bool_t warn) const {
242     /// Return local board with given Id
243
244     AliMpLocalBoard* localBoard
245       = static_cast<AliMpLocalBoard*>(fLocalBoardMap.GetValue(localBoardId));
246     
247     if ( ! localBoard && warn ) {
248         AliErrorStream()
249         << "Loacl board with localBoardId = " << localBoardId << " not found." << endl;
250     }      
251
252     return localBoard;
253 }
254
255 //______________________________________________________________________________
256 AliMpTriggerCrate* AliMpRegionalTrigger::FindTriggerCrate(TString name, 
257                                                           Bool_t warn) const  {
258     /// Return trigger crate with given name
259
260     AliMpTriggerCrate* crate
261     = (AliMpTriggerCrate*) fTriggerCrates.GetValue(name.Data());
262
263     if ( ! crate && warn ) {
264         AliErrorStream()
265         << "Trigger crate with name = " << name.Data() << " not defined." << endl;
266     }
267
268     return crate;
269 }
270
271 //______________________________________________________________________________
272 Int_t AliMpRegionalTrigger::GetNofTriggerCrates() const 
273
274     /// Return number of trigger crates
275
276     return fTriggerCrates.GetSize(); 
277 }
278
279 //______________________________________________________________________________
280 Int_t AliMpRegionalTrigger::GetNofLocalBoards() const
281
282     /// Return number of local boards
283     
284     return fLocalBoardArray.GetSize(); 
285 }
286
287 //______________________________________________________________________________
288 TIterator* 
289 AliMpRegionalTrigger::CreateCrateIterator() const
290 {
291   /// Create iterator over crates
292
293   return fTriggerCrates.CreateIterator();
294 }
295
296 //______________________________________________________________________________
297 TIterator* 
298 AliMpRegionalTrigger::CreateLocalBoardIterator() const
299 {
300   /// Create iterator over local boards
301
302   return fLocalBoardArray.MakeIterator();
303 }
304
305 //______________________________________________________________________________
306 Int_t 
307 AliMpRegionalTrigger::LocalBoardId(Int_t index) const
308 {
309   /// Return local board Id for the local boards with a given index
310
311   AliMpLocalBoard* lb = static_cast<AliMpLocalBoard*>(fLocalBoardArray.At(index));
312   if (lb)
313   {
314     return lb->GetId();
315   }
316   AliError(Form("Could not get local board at index %d",index));
317   return -1;
318 }
319
320 //______________________________________________________________________________
321 void AliMpRegionalTrigger::SetTriggerCratesOwner(Bool_t owner)
322 {
323   /// Set ownership to trigger crates
324
325   fTriggerCrates.SetOwner(owner);
326 }