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