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