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 //_____________________________________________________________________________
42 AliMpBusPatch::AliMpBusPatch()
44 fDetElemIdToBusPatch(300),
45 fBusPatchToDetElem(300),
48 /// Default constructor
51 //_____________________________________________________________________________
52 AliMpBusPatch::~AliMpBusPatch()
56 fDetElemIdToBusPatch.Delete();
57 fBusPatchToDetElem.Delete();
58 fBusPatchToDDL.Delete();
62 //____________________________________________________________________
63 Int_t AliMpBusPatch::GetDEfromBus(Int_t busPatchId)
65 /// getting DE id from bus patch
66 Long_t it = fBusPatchToDetElem.GetValue(busPatchId);
74 //____________________________________________________________________
75 TArrayI* AliMpBusPatch::GetBusfromDE(Int_t idDE)
77 /// getting bus patch from DE id
79 return (TArrayI*)fDetElemIdToBusPatch.GetValue(idDE);
81 //____________________________________________________________________
82 Int_t AliMpBusPatch::GetDDLfromBus(Int_t busPatchId)
84 /// getting DE id from bus patch
85 Long_t it = fBusPatchToDDL.GetValue(busPatchId);
93 //____________________________________________________________________
94 void AliMpBusPatch::GetDspInfo(Int_t iDDL, Int_t& iDspMax, Int_t* iBusPerDSP)
97 /// calculates the number of DSP & buspatch per block
99 Int_t iBusPerBlk = fBusInDDL[iDDL].GetSize()/2; //per block
101 iDspMax = iBusPerBlk/5; //number max of DSP per block
102 if (iBusPerBlk % 5 != 0)
105 for (Int_t i = 0; i < iDspMax; i++) {
106 if ((iBusPerBlk -= 5) > 0)
109 iBusPerDSP[i] = iBusPerBlk + 5;
113 //____________________________________________________________________
114 void AliMpBusPatch::ReadBusPatchFile()
116 /// idDE <> buspatch <> iDDL map's
118 TString infile = AliMpFiles::BusPatchFilePath();
120 ifstream in(infile, ios::in);
121 if (!in) AliError("DetElemIdToBusPatch.dat not found.");
125 while ( in.getline(line,80) ) {
127 if ( line[0] == '#' ) continue;
129 TString tmp(AliMpHelper::Normalize(line));
131 Int_t blankPos = tmp.First(' ');
132 Int_t blankPos1 = tmp.Last(' ');
134 TString sDE(tmp(0, blankPos));
136 Int_t idDE = atoi(sDE.Data());
138 TString sDDL(tmp(blankPos1 + 1, tmp.Length()-blankPos1));
140 Int_t iDDL = atoi(sDDL.Data());
142 // always working local DDL number... for the moment.
144 // not really needed remove for stand alone purpose (Ch.F)
145 // if (iDDL >= AliDAQ::DdlIDOffset("MUONTRK"))
146 // iDDL -= AliDAQ::DdlIDOffset("MUONTRK");
149 TString busPatch(tmp(blankPos + 1,blankPos1-blankPos-1));
150 AliDebug(3,Form("idDE %d buspatch %s iDDL %d\n", idDE, busPatch.Data(), iDDL));
151 AddDetElem(iDDL, idDE);
153 TArrayI busPatchList;
154 // decoding range of buspatch
155 AliMpHelper::DecodeName(busPatch,';',busPatchList);
157 // filling buspatch -> idDE
159 for (Int_t i = 0; i < busPatchList.GetSize(); i++) {
160 fBusPatchToDetElem.Add((Long_t)busPatchList[i],(Long_t)idDE);
161 fBusPatchToDDL.Add((Long_t)busPatchList[i],(Long_t)iDDL);
162 AddBus(iDDL, busPatchList[i]);
165 // filling idDE -> buspatch list (vector)
166 fDetElemIdToBusPatch.Add((Long_t)idDE, (Long_t)(new TArrayI(busPatchList)));
173 //____________________________________________________________________
174 void AliMpBusPatch::AddBus(Int_t iDDL, Int_t busPatch)
176 /// add bus patch number per DDL
178 fBusInDDL[iDDL].Set(fBusInDDL[iDDL].GetSize() + 1);
179 fBusInDDL[iDDL].AddAt(busPatch, fBusInDDL[iDDL].GetSize() - 1);
183 //____________________________________________________________________
184 void AliMpBusPatch::AddDetElem(Int_t iDDL, Int_t detElem)
188 fDeInDDL[iDDL].Set(fDeInDDL[iDDL].GetSize() + 1);
189 fDeInDDL[iDDL].AddAt(detElem, fDeInDDL[iDDL].GetSize() - 1);
192 //____________________________________________________________________
193 Int_t AliMpBusPatch::NextBusInDDL(Int_t iDDL)
195 /// Next bus patch number in DDL
197 if (fBusItr[iDDL] >= fBusInDDL[iDDL].GetSize())
200 return fBusInDDL[iDDL].At(fBusItr[iDDL]++);
205 //____________________________________________________________________
206 void AliMpBusPatch::ResetBusItr(Int_t iDDL)
208 /// reset bus iterator for the given DDL
213 //____________________________________________________________________
214 void AliMpBusPatch::Sort()
216 /// sort bus patch number for all DDL
218 // put it hardware wise
219 // this method is not used for the moment.
220 Int_t numberOfDdls = 20;
222 for (Int_t j = 0; j < numberOfDdls; j++) {
223 Sort(fBusInDDL[j], 0, fBusInDDL[j].GetSize() - 1);
225 if (AliLog::GetGlobalDebugLevel() == 1) {
226 printf("DDL %d\n",j);
227 for (Int_t i = 0; i < fBusInDDL[j].GetSize(); i++)
228 printf("buspatch %d index %d\n",fBusInDDL[j].At(i), i);
234 //____________________________________________________________________
235 void AliMpBusPatch::Sort(TArrayI& arr, Int_t start, Int_t end)
237 /// sort bus patch number per DDL
238 /// not really needed, but for future developments ?
239 /// quicksort method, not in Root ?
243 Int_t endh; // store pivot # keep start & end in memory for split
250 while((arr[end] >= pivot) && (start < end))
254 arr[start] = arr[end];
257 while ((arr[start] <= pivot) && (start < end))
261 arr[end] = arr[start];
272 Sort(arr, start, pivot-1);
275 Sort(arr, pivot+1, end);