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