1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 // $MpId: AliMpBusPatch.cxx,v 1.5 2006/05/24 13:58:34 ivana Exp $
18 // Category: management
20 // Class AliMpBusPatch
22 // Class that manages the maps buspatch<>DDL<>DE
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
28 // Author: Ch. Finck; Subatech Nantes
30 #include "AliMpBusPatch.h"
31 #include "AliMpFiles.h"
32 #include "AliMpHelper.h"
35 #include "Riostream.h"
38 ClassImp(AliMpBusPatch)
41 const Int_t AliMpBusPatch::fgkOffset = 100;
43 //_____________________________________________________________________________
44 AliMpBusPatch::AliMpBusPatch()
46 fDetElemIdToBusPatch(300),
47 fBusPatchToDetElem(300),
50 /// Default constructor
53 //_____________________________________________________________________________
54 AliMpBusPatch::~AliMpBusPatch()
58 fDetElemIdToBusPatch.Delete();
59 fBusPatchToDetElem.Delete();
60 fBusPatchToDDL.Delete();
63 //____________________________________________________________________
64 Int_t AliMpBusPatch::GetGlobalBusID(Int_t localID, Int_t ddlID)
66 /// return global bus id from local bus and ddl id
68 return ddlID*fgkOffset + localID;
71 //____________________________________________________________________
72 Int_t AliMpBusPatch::GetLocalBusID(Int_t globalID, Int_t ddlID)
74 /// return local bus id from local bus id
76 return globalID - ddlID*fgkOffset;
79 //____________________________________________________________________
80 Int_t AliMpBusPatch::GetDEfromBus(Int_t busPatchId)
82 /// getting DE id from bus patch
83 Long_t it = fBusPatchToDetElem.GetValue(busPatchId);
91 //____________________________________________________________________
92 TArrayI* AliMpBusPatch::GetBusfromDE(Int_t idDE)
94 /// getting bus patch from DE id
96 return (TArrayI*)fDetElemIdToBusPatch.GetValue(idDE);
98 //____________________________________________________________________
99 Int_t AliMpBusPatch::GetDDLfromBus(Int_t busPatchId)
101 /// getting DE id from bus patch
102 Long_t it = fBusPatchToDDL.GetValue(busPatchId);
110 //____________________________________________________________________
111 void AliMpBusPatch::GetDspInfo(Int_t iDDL, Int_t& iDspMax, Int_t* iBusPerDSP)
114 /// calculates the number of DSP & buspatch per block
116 Int_t iBusPerBlk = fBusInDDL[iDDL].GetSize()/2; //per block
118 iDspMax = iBusPerBlk/5; //number max of DSP per block
119 if (iBusPerBlk % 5 != 0)
122 for (Int_t i = 0; i < iDspMax; i++) {
123 if ((iBusPerBlk -= 5) > 0)
126 iBusPerDSP[i] = iBusPerBlk + 5;
130 //____________________________________________________________________
131 void AliMpBusPatch::ReadBusPatchFile()
133 /// idDE <> buspatch <> iDDL map's
135 TString infile = AliMpFiles::BusPatchFilePath();
137 ifstream in(infile, ios::in);
138 if (!in) AliError("DetElemIdToBusPatch.dat not found.");
142 while ( in.getline(line,80) ) {
144 if ( line[0] == '#' ) continue;
146 TString tmp(AliMpHelper::Normalize(line));
148 Int_t blankPos = tmp.First(' ');
149 Int_t blankPos1 = tmp.Last(' ');
151 TString sDE(tmp(0, blankPos));
153 Int_t idDE = atoi(sDE.Data());
155 TString sDDL(tmp(blankPos1 + 1, tmp.Length()-blankPos1));
157 Int_t iDDL = atoi(sDDL.Data());
159 // always working local DDL number... for the moment.
161 // not really needed remove for stand alone purpose (Ch.F)
162 // if (iDDL >= AliDAQ::DdlIDOffset("MUONTRK"))
163 // iDDL -= AliDAQ::DdlIDOffset("MUONTRK");
166 TString busPatch(tmp(blankPos + 1,blankPos1-blankPos-1));
167 AliDebug(3,Form("idDE %d buspatch %s iDDL %d\n", idDE, busPatch.Data(), iDDL));
168 AddDetElem(iDDL, idDE);
170 TArrayI busPatchList;
171 // decoding range of buspatch
172 AliMpHelper::DecodeName(busPatch,';',busPatchList);
174 // filling buspatch -> idDE
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);
179 AddBus(iDDL, busPatchList[i]);
182 // filling idDE -> buspatch list (vector)
183 fDetElemIdToBusPatch.Add((Long_t)idDE, (Long_t)(new TArrayI(busPatchList)));
190 //____________________________________________________________________
191 void AliMpBusPatch::AddBus(Int_t iDDL, Int_t busPatch)
193 /// add bus patch number per DDL
195 fBusInDDL[iDDL].Set(fBusInDDL[iDDL].GetSize() + 1);
196 fBusInDDL[iDDL].AddAt(busPatch, fBusInDDL[iDDL].GetSize() - 1);
200 //____________________________________________________________________
201 void AliMpBusPatch::AddDetElem(Int_t iDDL, Int_t detElem)
205 fDeInDDL[iDDL].Set(fDeInDDL[iDDL].GetSize() + 1);
206 fDeInDDL[iDDL].AddAt(detElem, fDeInDDL[iDDL].GetSize() - 1);
209 //____________________________________________________________________
210 Int_t AliMpBusPatch::NextBusInDDL(Int_t iDDL)
212 /// Next bus patch number in DDL
214 if (fBusItr[iDDL] >= fBusInDDL[iDDL].GetSize())
217 return fBusInDDL[iDDL].At(fBusItr[iDDL]++);
222 //____________________________________________________________________
223 void AliMpBusPatch::ResetBusItr(Int_t iDDL)
225 /// reset bus iterator for the given DDL
230 //____________________________________________________________________
231 void AliMpBusPatch::Sort()
233 /// sort bus patch number for all DDL
235 // put it hardware wise
236 // this method is not used for the moment.
237 Int_t numberOfDdls = 20;
239 for (Int_t j = 0; j < numberOfDdls; j++) {
240 Sort(fBusInDDL[j], 0, fBusInDDL[j].GetSize() - 1);
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);
251 //____________________________________________________________________
252 void AliMpBusPatch::Sort(TArrayI& arr, Int_t start, Int_t end)
254 /// sort bus patch number per DDL
255 /// not really needed, but for future developments ?
256 /// quicksort method, not in Root ?
260 Int_t endh; // store pivot # keep start & end in memory for split
267 while((arr[end] >= pivot) && (start < end))
271 arr[start] = arr[end];
274 while ((arr[start] <= pivot) && (start < end))
278 arr[end] = arr[start];
289 Sort(arr, start, pivot-1);
292 Sort(arr, pivot+1, end);