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