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"
36 #include "Riostream.h"
39 ClassImp(AliMpBusPatch)
42 //_____________________________________________________________________________
43 AliMpBusPatch::AliMpBusPatch()
45 fDetElemIdToBusPatch(300),
46 fBusPatchToDetElem(300),
49 /// Default constructor
52 //_____________________________________________________________________________
53 AliMpBusPatch::~AliMpBusPatch()
57 fDetElemIdToBusPatch.Delete();
58 fBusPatchToDetElem.Delete();
59 fBusPatchToDDL.Delete();
63 //____________________________________________________________________
64 Int_t AliMpBusPatch::GetDEfromBus(Int_t busPatchId)
66 /// getting DE id from bus patch
67 Long_t it = fBusPatchToDetElem.GetValue(busPatchId);
75 //____________________________________________________________________
76 TArrayI* AliMpBusPatch::GetBusfromDE(Int_t idDE)
78 /// getting bus patch from DE id
80 return (TArrayI*)fDetElemIdToBusPatch.GetValue(idDE);
82 //____________________________________________________________________
83 Int_t AliMpBusPatch::GetDDLfromBus(Int_t busPatchId)
85 /// getting DE id from bus patch
86 Long_t it = fBusPatchToDDL.GetValue(busPatchId);
94 //____________________________________________________________________
95 void AliMpBusPatch::GetDspInfo(Int_t iDDL, Int_t& iDspMax, Int_t* iBusPerDSP)
98 /// calculates the number of DSP & buspatch per block
100 Int_t iBusPerBlk = fBusInDDL[iDDL].GetSize()/2; //per block
102 iDspMax = iBusPerBlk/5; //number max of DSP per block
103 if (iBusPerBlk % 5 != 0)
106 for (Int_t i = 0; i < iDspMax; i++) {
107 if ((iBusPerBlk -= 5) > 0)
110 iBusPerDSP[i] = iBusPerBlk + 5;
114 //____________________________________________________________________
115 void AliMpBusPatch::ReadBusPatchFile()
117 /// idDE <> buspatch <> iDDL map's
119 TString infile = AliMpFiles::BusPatchFilePath();
121 ifstream in(infile, ios::in);
122 if (!in) AliError("DetElemIdToBusPatch.dat not found.");
126 while ( in.getline(line,80) ) {
128 if ( line[0] == '#' ) continue;
130 TString tmp(AliMpHelper::Normalize(line));
132 Int_t blankPos = tmp.First(' ');
133 Int_t blankPos1 = tmp.Last(' ');
135 TString sDE(tmp(0, blankPos));
137 Int_t idDE = atoi(sDE.Data());
139 TString sDDL(tmp(blankPos1 + 1, tmp.Length()-blankPos1));
141 Int_t iDDL = atoi(sDDL.Data());
143 // 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");
148 TString busPatch(tmp(blankPos + 1,blankPos1-blankPos-1));
149 AliDebug(3,Form("idDE %d buspatch %s iDDL %d\n", idDE, busPatch.Data(), iDDL));
151 TArrayI busPatchList;
152 // decoding range of buspatch
153 AliMpHelper::DecodeName(busPatch,';',busPatchList);
155 // filling buspatch -> idDE
157 for (Int_t i = 0; i < busPatchList.GetSize(); i++) {
158 fBusPatchToDetElem.Add((Long_t)busPatchList[i],(Long_t)idDE);
159 fBusPatchToDDL.Add((Long_t)busPatchList[i],(Long_t)iDDL);
160 AddBus(iDDL, busPatchList[i]);
163 // filling idDE -> buspatch list (vector)
164 fDetElemIdToBusPatch.Add((Long_t)idDE, (Long_t)(new TArrayI(busPatchList)));
171 //____________________________________________________________________
172 void AliMpBusPatch::AddBus(Int_t iDDL, Int_t busPatch)
174 /// add bus patch number per DDL
176 fBusInDDL[iDDL].Set(fBusInDDL[iDDL].GetSize() + 1);
177 fBusInDDL[iDDL].AddAt(busPatch, fBusInDDL[iDDL].GetSize() - 1);
182 //____________________________________________________________________
183 Int_t AliMpBusPatch::NextBusInDDL(Int_t iDDL)
185 /// Next bus patch number in DDL
187 if (fBusItr[iDDL] >= fBusInDDL[iDDL].GetSize())
190 return fBusInDDL[iDDL].At(fBusItr[iDDL]++);
194 //____________________________________________________________________
195 void AliMpBusPatch::ResetBusItr(Int_t iDDL)
197 /// reset bus iterator for the given DDL
202 //____________________________________________________________________
203 void AliMpBusPatch::Sort()
205 /// sort bus patch number for all DDL
207 // put it hardware wise
208 // this method is not used for the moment.
209 Int_t numberOfDdls = 20;
211 for (Int_t j = 0; j < numberOfDdls; j++) {
212 Sort(fBusInDDL[j], 0, fBusInDDL[j].GetSize() - 1);
214 if (AliLog::GetGlobalDebugLevel() == 1) {
215 printf("DDL %d\n",j);
216 for (Int_t i = 0; i < fBusInDDL[j].GetSize(); i++)
217 printf("buspatch %d index %d\n",fBusInDDL[j].At(i), i);
223 //____________________________________________________________________
224 void AliMpBusPatch::Sort(TArrayI& arr, Int_t start, Int_t end)
226 /// sort bus patch number per DDL
227 /// not really needed, but for future developments ?
228 /// quicksort method, not in Root ?
232 Int_t endh; // store pivot # keep start & end in memory for split
239 while((arr[end] >= pivot) && (start < end))
243 arr[start] = arr[end];
246 while ((arr[start] <= pivot) && (start < end))
250 arr[end] = arr[start];
261 Sort(arr, start, pivot-1);
264 Sort(arr, pivot+1, end);