]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpBusPatch.cxx
Removing dependences on AliDAQ class (in raw)
[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
35 #include "TArrayI.h"
36 #include "Riostream.h"
37
38 /// \cond CLASSIMP
39 ClassImp(AliMpBusPatch)
40 /// \endcond
41
42 //_____________________________________________________________________________
43 AliMpBusPatch::AliMpBusPatch()
44   : TObject(),
45     fDetElemIdToBusPatch(300),
46     fBusPatchToDetElem(300),
47     fBusPatchToDDL(300)
48 {
49 /// Default constructor
50 }
51
52 //_____________________________________________________________________________
53 AliMpBusPatch::~AliMpBusPatch() 
54 {
55 /// Destructor
56
57   fDetElemIdToBusPatch.Delete();
58   fBusPatchToDetElem.Delete();
59   fBusPatchToDDL.Delete();
60
61 }
62
63 //____________________________________________________________________
64 Int_t AliMpBusPatch::GetDEfromBus(Int_t busPatchId)
65 {
66  /// getting DE id from bus patch
67   Long_t it = fBusPatchToDetElem.GetValue(busPatchId);
68
69  if ( it ) 
70    return (Int_t)it;
71  else 
72    return -1;
73 }
74
75 //____________________________________________________________________
76 TArrayI*  AliMpBusPatch::GetBusfromDE(Int_t idDE)
77 {
78 /// getting bus patch from DE id 
79
80   return (TArrayI*)fDetElemIdToBusPatch.GetValue(idDE);
81 }
82 //____________________________________________________________________
83 Int_t AliMpBusPatch::GetDDLfromBus(Int_t busPatchId)
84 {
85 /// getting DE id from bus patch
86   Long_t it = fBusPatchToDDL.GetValue(busPatchId);
87
88  if ( it ) 
89    return (Int_t)it;
90  else 
91    return -1;
92 }
93
94 //____________________________________________________________________
95 void AliMpBusPatch::GetDspInfo(Int_t iDDL, Int_t& iDspMax, Int_t* iBusPerDSP) 
96 const
97 {
98 /// calculates the number of DSP & buspatch per block
99
100   Int_t iBusPerBlk = fBusInDDL[iDDL].GetSize()/2; //per block
101
102   iDspMax =  iBusPerBlk/5; //number max of DSP per block
103   if (iBusPerBlk % 5 != 0)
104     iDspMax += 1;
105   
106   for (Int_t i = 0; i < iDspMax; i++) {
107     if ((iBusPerBlk -= 5) > 0) 
108       iBusPerDSP[i] = 5;
109     else 
110       iBusPerDSP[i] = iBusPerBlk + 5;
111   }
112   
113 }
114 //____________________________________________________________________
115 void AliMpBusPatch::ReadBusPatchFile()
116 {
117 /// idDE <> buspatch <> iDDL map's
118   
119    TString infile = AliMpFiles::BusPatchFilePath();
120
121    ifstream in(infile, ios::in);
122    if (!in) AliError("DetElemIdToBusPatch.dat not found.");
123        
124    char line[80];
125
126    while ( in.getline(line,80) ) {
127
128       if ( line[0] == '#' ) continue;
129
130       TString tmp(AliMpHelper::Normalize(line));
131
132       Int_t blankPos  = tmp.First(' ');
133       Int_t blankPos1 = tmp.Last(' ');
134
135       TString sDE(tmp(0, blankPos));
136
137       Int_t idDE = atoi(sDE.Data());
138
139       TString sDDL(tmp(blankPos1 + 1, tmp.Length()-blankPos1));
140
141       Int_t iDDL = atoi(sDDL.Data());
142
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");
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   // put it hardware wise
208   // this method is not used for the moment.
209   Int_t numberOfDdls = 20;
210
211   for (Int_t j = 0; j < numberOfDdls; j++) {
212     Sort(fBusInDDL[j], 0, fBusInDDL[j].GetSize() - 1);
213
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);
218     }
219   } 
220
221 }
222
223 //____________________________________________________________________
224 void AliMpBusPatch::Sort(TArrayI& arr, Int_t start, Int_t end)
225 {
226 /// sort bus patch number per DDL
227 /// not really needed, but for future developments ?
228 /// quicksort method, not in Root ?
229
230   Int_t pivot;
231   Int_t starth;
232   Int_t endh; // store pivot # keep start & end in memory for split
233
234   starth = start;
235   endh = end;
236   pivot = arr[start];
237
238   while(start < end) {
239       while((arr[end] >= pivot) && (start < end))
240         end--;
241
242       if (start != end) {
243           arr[start] = arr[end];
244           start++;
245       }
246       while ((arr[start] <= pivot) && (start < end))
247         start++;
248
249       if (start != end) {
250           arr[end] = arr[start];
251           end--;
252       }
253   }
254
255   arr[start] = pivot;
256   pivot = start;
257   start = starth;
258   end   = endh;
259
260   if(start < pivot)
261     Sort(arr, start, pivot-1);
262
263   if(end > pivot)
264     Sort(arr, pivot+1, end);
265
266 }