]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpBusPatch.cxx
Adding static functions for conversion between global/local
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpBusPatch.cxx
CommitLineData
1e738c3c 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$
13985652 17// $MpId: AliMpBusPatch.cxx,v 1.5 2006/05/24 13:58:34 ivana Exp $
700013f0 18// Category: management
19
1e738c3c 20// Class AliMpBusPatch
21// ---------------
22// Class that manages the maps buspatch<>DDL<>DE
23// for the mapping
5826f1df 24// Calculates also the maximum DSP and buspatch numbers for a given DDL
25// Create a bus Iterator for DDL, needed especially for station 3
26// Implementing a Sort method for Iterator, not really needed for the moment
1e738c3c 27//
28// Author: Ch. Finck; Subatech Nantes
29
30#include "AliMpBusPatch.h"
31#include "AliMpFiles.h"
32#include "AliMpHelper.h"
1e738c3c 33#include "AliLog.h"
85fec35d 34#include "TArrayI.h"
35#include "Riostream.h"
1e738c3c 36
13985652 37/// \cond CLASSIMP
1e738c3c 38ClassImp(AliMpBusPatch)
13985652 39/// \endcond
1e738c3c 40
d2892ef5 41const Int_t AliMpBusPatch::fgkOffset = 100;
42
1e738c3c 43//_____________________________________________________________________________
44AliMpBusPatch::AliMpBusPatch()
45 : TObject(),
46 fDetElemIdToBusPatch(300),
47 fBusPatchToDetElem(300),
48 fBusPatchToDDL(300)
49{
50/// Default constructor
1e738c3c 51}
52
1e738c3c 53//_____________________________________________________________________________
54AliMpBusPatch::~AliMpBusPatch()
55{
56/// Destructor
57
58 fDetElemIdToBusPatch.Delete();
59 fBusPatchToDetElem.Delete();
60 fBusPatchToDDL.Delete();
5826f1df 61
1e738c3c 62}
d2892ef5 63//____________________________________________________________________
64Int_t AliMpBusPatch::GetGlobalBusID(Int_t localID, Int_t ddlID)
65{
66 /// return global bus id from local bus and ddl id
67
68 return ddlID*fgkOffset + localID;
69
70}
71//____________________________________________________________________
72Int_t AliMpBusPatch::GetLocalBusID(Int_t globalID, Int_t ddlID)
73{
74 /// return local bus id from local bus id
1e738c3c 75
d2892ef5 76 return globalID - ddlID*fgkOffset;
77
78}
1e738c3c 79//____________________________________________________________________
80Int_t AliMpBusPatch::GetDEfromBus(Int_t busPatchId)
81{
82 /// getting DE id from bus patch
83 Long_t it = fBusPatchToDetElem.GetValue(busPatchId);
84
85 if ( it )
86 return (Int_t)it;
87 else
88 return -1;
89}
90
91//____________________________________________________________________
92TArrayI* AliMpBusPatch::GetBusfromDE(Int_t idDE)
93{
94/// getting bus patch from DE id
95
96 return (TArrayI*)fDetElemIdToBusPatch.GetValue(idDE);
97}
98//____________________________________________________________________
99Int_t AliMpBusPatch::GetDDLfromBus(Int_t busPatchId)
100{
101/// getting DE id from bus patch
102 Long_t it = fBusPatchToDDL.GetValue(busPatchId);
103
104 if ( it )
105 return (Int_t)it;
106 else
107 return -1;
108}
109
110//____________________________________________________________________
5826f1df 111void AliMpBusPatch::GetDspInfo(Int_t iDDL, Int_t& iDspMax, Int_t* iBusPerDSP)
85fec35d 112const
1e738c3c 113{
114/// calculates the number of DSP & buspatch per block
115
5826f1df 116 Int_t iBusPerBlk = fBusInDDL[iDDL].GetSize()/2; //per block
1e738c3c 117
118 iDspMax = iBusPerBlk/5; //number max of DSP per block
119 if (iBusPerBlk % 5 != 0)
120 iDspMax += 1;
121
122 for (Int_t i = 0; i < iDspMax; i++) {
123 if ((iBusPerBlk -= 5) > 0)
124 iBusPerDSP[i] = 5;
125 else
126 iBusPerDSP[i] = iBusPerBlk + 5;
127 }
128
129}
130//____________________________________________________________________
131void AliMpBusPatch::ReadBusPatchFile()
132{
133/// idDE <> buspatch <> iDDL map's
134
135 TString infile = AliMpFiles::BusPatchFilePath();
136
137 ifstream in(infile, ios::in);
138 if (!in) AliError("DetElemIdToBusPatch.dat not found.");
139
140 char line[80];
141
1e738c3c 142 while ( in.getline(line,80) ) {
143
144 if ( line[0] == '#' ) continue;
145
146 TString tmp(AliMpHelper::Normalize(line));
147
148 Int_t blankPos = tmp.First(' ');
149 Int_t blankPos1 = tmp.Last(' ');
150
151 TString sDE(tmp(0, blankPos));
152
153 Int_t idDE = atoi(sDE.Data());
1e738c3c 154
155 TString sDDL(tmp(blankPos1 + 1, tmp.Length()-blankPos1));
156
157 Int_t iDDL = atoi(sDDL.Data());
158
5826f1df 159 // always working local DDL number... for the moment.
528df1a6 160
5dfd43f7 161 // not really needed remove for stand alone purpose (Ch.F)
528df1a6 162 // if (iDDL >= AliDAQ::DdlIDOffset("MUONTRK"))
163 // iDDL -= AliDAQ::DdlIDOffset("MUONTRK");
164
5826f1df 165
1e738c3c 166 TString busPatch(tmp(blankPos + 1,blankPos1-blankPos-1));
167 AliDebug(3,Form("idDE %d buspatch %s iDDL %d\n", idDE, busPatch.Data(), iDDL));
528df1a6 168 AddDetElem(iDDL, idDE);
1e738c3c 169
170 TArrayI busPatchList;
171 // decoding range of buspatch
172 AliMpHelper::DecodeName(busPatch,';',busPatchList);
173
174 // filling buspatch -> idDE
5826f1df 175
1e738c3c 176 for (Int_t i = 0; i < busPatchList.GetSize(); i++) {
177 fBusPatchToDetElem.Add((Long_t)busPatchList[i],(Long_t)idDE);
178 fBusPatchToDDL.Add((Long_t)busPatchList[i],(Long_t)iDDL);
5826f1df 179 AddBus(iDDL, busPatchList[i]);
1e738c3c 180 }
181
182 // filling idDE -> buspatch list (vector)
183 fDetElemIdToBusPatch.Add((Long_t)idDE, (Long_t)(new TArrayI(busPatchList)));
184
185 }
186
1e738c3c 187 in.close();
188
189}
5826f1df 190//____________________________________________________________________
191void AliMpBusPatch::AddBus(Int_t iDDL, Int_t busPatch)
192{
193/// add bus patch number per DDL
194
195 fBusInDDL[iDDL].Set(fBusInDDL[iDDL].GetSize() + 1);
196 fBusInDDL[iDDL].AddAt(busPatch, fBusInDDL[iDDL].GetSize() - 1);
197
198}
199
528df1a6 200//____________________________________________________________________
201void AliMpBusPatch::AddDetElem(Int_t iDDL, Int_t detElem)
202{
203/// add DE per DDL
204
205 fDeInDDL[iDDL].Set(fDeInDDL[iDDL].GetSize() + 1);
206 fDeInDDL[iDDL].AddAt(detElem, fDeInDDL[iDDL].GetSize() - 1);
5826f1df 207
528df1a6 208}
5826f1df 209//____________________________________________________________________
210Int_t AliMpBusPatch::NextBusInDDL(Int_t iDDL)
211{
212/// Next bus patch number in DDL
213
214 if (fBusItr[iDDL] >= fBusInDDL[iDDL].GetSize())
215 return -1;
216
217 return fBusInDDL[iDDL].At(fBusItr[iDDL]++);
218
219}
220
528df1a6 221
5826f1df 222//____________________________________________________________________
223void AliMpBusPatch::ResetBusItr(Int_t iDDL)
224{
225/// reset bus iterator for the given DDL
226
227 fBusItr[iDDL] = 0;
228}
229
230//____________________________________________________________________
231void AliMpBusPatch::Sort()
232{
233/// sort bus patch number for all DDL
234
5dfd43f7 235 // put it hardware wise
236 // this method is not used for the moment.
237 Int_t numberOfDdls = 20;
238
239 for (Int_t j = 0; j < numberOfDdls; j++) {
5826f1df 240 Sort(fBusInDDL[j], 0, fBusInDDL[j].GetSize() - 1);
241
242 if (AliLog::GetGlobalDebugLevel() == 1) {
243 printf("DDL %d\n",j);
244 for (Int_t i = 0; i < fBusInDDL[j].GetSize(); i++)
245 printf("buspatch %d index %d\n",fBusInDDL[j].At(i), i);
246 }
247 }
248
249}
250
251//____________________________________________________________________
252void AliMpBusPatch::Sort(TArrayI& arr, Int_t start, Int_t end)
253{
254/// sort bus patch number per DDL
255/// not really needed, but for future developments ?
256/// quicksort method, not in Root ?
257
258 Int_t pivot;
259 Int_t starth;
260 Int_t endh; // store pivot # keep start & end in memory for split
261
262 starth = start;
263 endh = end;
264 pivot = arr[start];
265
266 while(start < end) {
267 while((arr[end] >= pivot) && (start < end))
268 end--;
269
270 if (start != end) {
271 arr[start] = arr[end];
272 start++;
273 }
274 while ((arr[start] <= pivot) && (start < end))
275 start++;
276
277 if (start != end) {
278 arr[end] = arr[start];
279 end--;
280 }
281 }
282
283 arr[start] = pivot;
284 pivot = start;
285 start = starth;
286 end = endh;
287
288 if(start < pivot)
289 Sort(arr, start, pivot-1);
290
291 if(end > pivot)
292 Sort(arr, pivot+1, end);
293
294}