]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpManuStore.cxx
Fixing compiler warning
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpManuStore.cxx
CommitLineData
ab167304 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// Category: management
18
19//-----------------------------------------------------------------------------
20// Class AliMpManuStore
21// --------------------
22// The container class for manu serial numbersd
23// Authors: Ivana Hrivnacova, IPN Orsay
24// Christian Finck, SUBATECH Nantes
25//-----------------------------------------------------------------------------
26
27#include "AliMpManuStore.h"
28
29#include "AliMpDEStore.h"
30#include "AliMpDEManager.h"
31#include "AliMpDetElement.h"
32#include "AliMpConstants.h"
33#include "AliMpDataStreams.h"
34#include "AliMpFiles.h"
35#include "AliMpHelper.h"
36#include "AliMpIntPair.h"
37#include "AliMpConstants.h"
38
39#include "AliLog.h"
40
41#include <Riostream.h>
42#include <TClass.h>
43#include <TSystem.h>
44#include <TObjString.h>
45#include <TObjArray.h>
46#include <TMap.h>
47
48#include <fstream>
6332274b 49#include <cstdlib>
ab167304 50
51/// \cond CLASSIMP
52ClassImp(AliMpManuStore)
53/// \endcond
54
55AliMpManuStore* AliMpManuStore::fgInstance = 0;
56Bool_t AliMpManuStore::fgWarnIfDoublon = kFALSE;
57
58//
59// static methods
60//
61
62//______________________________________________________________________________
63AliMpManuStore* AliMpManuStore::Instance(Bool_t warn)
64{
65 /// Create the DDL store if it does not yet exist
66 /// and return its instance
67
68 if ( ! fgInstance && warn ) {
69 AliWarningClass("Manu Store has not been loaded");
70 }
71
72 return fgInstance;
73}
74
75//______________________________________________________________________________
76AliMpManuStore* AliMpManuStore::ReadData(const AliMpDataStreams& dataStreams,
77 Bool_t warn)
78{
79 /// Load the DDL store from ASCII data files
80 /// and return its instance
81
82 if ( fgInstance ) {
83 if ( warn )
84 AliWarningClass("DDL Store has been already loaded");
85 return fgInstance;
86 }
87
88 if ( dataStreams.GetReadFromFiles() )
89 AliInfoClass("Reading Manu Store from ASCII files.");
90
91 fgInstance = new AliMpManuStore(dataStreams);
92 return fgInstance;
93}
94
95//
96// ctors, dtor
97//
98
99
100//______________________________________________________________________________
101AliMpManuStore::AliMpManuStore(const AliMpDataStreams& dataStreams)
102: TObject(),
103 fDataStreams(dataStreams),
104 fManuToSerialNbs(),
105 fSerialNbToManus(),
106 fNofManusInDE(),
107 fNofManus(0)
108{
109/// Standard constructor
110
111 AliDebug(1,"");
112
113 // Check if DE store is loaded
114 if ( ! AliMpDEStore::Instance(false) ) {
115 AliErrorStream()
116 << "Mapping segmentation has not be loaded. Cannont load Manu store"
117 << endl;
118 return;
119 }
120
121 ReadManuSerial();
122}
123
124//______________________________________________________________________________
125AliMpManuStore::AliMpManuStore(TRootIOCtor* ioCtor)
126: TObject(),
127 fDataStreams(ioCtor),
128 fManuToSerialNbs(),
129 fSerialNbToManus(),
130 fNofManusInDE(),
131 fNofManus(0)
132{
133/// Constructor for IO
134
135 AliDebug(1,"");
136}
137
138
139//______________________________________________________________________________
140AliMpManuStore::~AliMpManuStore()
141{
142/// Destructor
143
144 AliDebug(1,"");
145}
146
147//
148// private methods
149//
150
151//______________________________________________________________________________
152Bool_t AliMpManuStore::ReadData(const AliMpDetElement* de, Int_t& nofManus)
153{
154/// Read manu serial numbers for the given detection element
155
156 Int_t deId = de->GetId();
157 TString deName = de->GetDEName();
158 AliMp::StationType stationType
159 = AliMpDEManager::GetStationType(de->GetId());
160
161 // Nothing to be done for trigger
162 if ( stationType == AliMp::kStationTrigger ) {
163 nofManus = 0;
164 return kTRUE;
165 }
166
167 static Int_t manuMask = AliMpConstants::ManuMask(AliMp::kNonBendingPlane);
168
169 istream& in
170 = fDataStreams.
171 CreateDataStream(AliMpFiles::ManuToSerialPath(deName, stationType));
172
173 char line[80];
174
175 nofManus = 0;
176 while ( in.getline(line,80) ) {
177
178 if ( line[0] == '#' ) continue;
179
180 TString tmp(AliMpHelper::Normalize(line));
181
182 TObjArray* stringList = tmp.Tokenize(TString(" "));
183
184 Int_t manuId = atoi( ((TObjString*)stringList->At(0))->GetName());
185 Int_t manuSerial = atoi( ((TObjString*)stringList->At(2))->GetName());
186
187 TString sPlane = ((TObjString*)stringList->At(1))->GetString();
188
189 // filling manuId <> manuSerial
190 if (!sPlane.CompareTo(PlaneTypeName(AliMp::kBendingPlane)))
191 AddManu(deId, manuId, manuSerial);
192 else
193 AddManu(deId, manuId + manuMask, manuSerial);
194
195 ++nofManus;
196
197 delete stringList;
198 }
199
200 return kTRUE;
201}
202
203//______________________________________________________________________________
204Bool_t AliMpManuStore::ReadManuSerial()
205{
206/// Read data files for all detection elements.
207/// Return true if reading was successful.
208
209 Bool_t isOk = kTRUE;
210
211 // Loop over DE
212 AliMpDEIterator it;
213 for ( it.First(); ! it.IsDone(); it.Next() ) {
214
215 AliMpDetElement* detElement = it.CurrentDE();
216
217 Int_t nofManus;
218 Bool_t result = ReadData(detElement, nofManus);
219 fNofManusInDE.Add(detElement->GetId(), nofManus);
220 fNofManus += nofManus;
221
222 AliDebugStream(2)
223 << "Adding " << nofManus << " manus for de "
224 << detElement->GetId() << endl;
225
226 isOk = isOk && result;
227 }
228
229 return isOk;
230}
231
232//______________________________________________________________________________
233void AliMpManuStore::ReplaceManu(Int_t detElemId, Int_t manuId, Int_t serialNb)
234{
235/// Replace manu in the map.
236/// As TExMap has no replcae function, we have to rebuild map once again.
237/// Not yet in use, declared private.
238
239 Long_t index = AliMpExMap::GetIndex(AliMpIntPair(detElemId, manuId));
240
241 TExMap newManuToSerialNbs;
242 // Loop over map
243 TExMapIter it(&fManuToSerialNbs);
244 Long_t key;
245 Long_t value;
246 while ( ( it.Next(key, value) ) ) {
247
248 if ( key != index )
249 newManuToSerialNbs.Add(key, value);
250 else
251 newManuToSerialNbs.Add(index, Long_t(serialNb));
252 }
253
254 TExMap newSerialNbToManus;
255 // Loop over map
256 TExMapIter it2(&fSerialNbToManus);
257 while ( ( it2.Next(key, value) ) ) {
258
259 if ( value != index )
260 newSerialNbToManus.Add(key, value);
261 else
262 newSerialNbToManus.Add(Long_t(serialNb), index);
263 }
264
265 // And now replace the maps
266 fManuToSerialNbs = newManuToSerialNbs;
267 fSerialNbToManus = newManuToSerialNbs;
268}
269
270
271//______________________________________________________________________________
272Bool_t AliMpManuStore::WriteData(const TString& outDir)
273{
274/// Write data files for all detection elements.
275/// Return true if reading was successful.
276/// Not yet in use, declared private.
277
278 TString curDir = gSystem->pwd();
279
280 // Create top directory
281 //
282 if ( gSystem->OpenDirectory(outDir.Data()) ) {
283 AliErrorStream()
284 << "Directory " << outDir.Data() << " already exists" << endl;
285 return kFALSE;
286 }
287 else {
288 AliDebugStream(2) << "Making directory " << outDir.Data() << endl;
289 gSystem->mkdir(outDir.Data());
290 }
291
292 // Loop over DE
293 AliMpDEIterator it;
294 for ( it.First(); ! it.IsDone(); it.Next() ) {
295
296 AliMpDetElement* detElement = it.CurrentDE();
297 Int_t detElemId = detElement->GetId();
298 TString deName = detElement->GetDEName();
299 AliMp::StationType stationType
300 = AliMpDEManager::GetStationType(detElemId);
301
302 if ( stationType == AliMp::kStationTrigger ) continue;
303
304 // Create directory if it does not yet exist
305 //
306 TString dirPath = outDir + AliMpFiles::StationDataDir(stationType);
307 if ( ! gSystem->OpenDirectory(dirPath.Data()) ) {
308 AliDebugStream(2) << "Making directory " << dirPath.Data() << endl;
309 gSystem->mkdir(dirPath.Data());
310 }
311
312 // Compose output file path
313 //
314 string dataPath = AliMpFiles::ManuToSerialPath(deName, stationType).Data();
315 string top = AliMpFiles::GetTop().Data();
316 if ( dataPath.find(top) != string::npos ) dataPath.erase(0, top.size()+1);
317 dataPath.erase(0,dataPath.find('/')+1);
06d8fc51 318 TString dataPath1 = dataPath;
319 TString filePath = outDir + "/" + dataPath1;
ab167304 320
321 // Open file
322 //
323 ofstream out(filePath.Data());
324 if ( ! out.good() ) {
325 AliErrorStream()
326 << "Cannot open output file " << filePath.Data() << endl;
327 return kFALSE;
328 }
329
330 // Loop over map
53bf67e2 331 TExMapIter it2(&fManuToSerialNbs);
ab167304 332 Long_t key;
333 Long_t value;
53bf67e2 334 while ( ( it2.Next(key, value) ) ) {
ab167304 335 AliMpIntPair pair = AliMpExMap::GetPair(key);
336
337 if ( pair.GetFirst() != detElemId ) continue;
338
339 AliDebugStream(3)
340 << "Go to write " << key << " " << pair << " " << value << endl;
341
342 Int_t manuId = pair.GetSecond();
343 static Int_t manuMask = AliMpConstants::ManuMask(AliMp::kNonBendingPlane);
344
345 TString planeName = PlaneTypeName(AliMp::kBendingPlane);
346 if ( pair.GetSecond()> manuMask ) {
347 planeName = PlaneTypeName(AliMp::kNonBendingPlane);
348 manuId -= manuMask;
349 }
350 out << manuId << " " << planeName.Data() << " " << value << endl;
351
352 AliDebugStream(3)
353 << manuId << " " << planeName.Data() << " " << value << endl;
354 }
355 out.close();
356 }
357 gSystem->cd(curDir);
358 return kTRUE;
359}
360
361//
362// public methods
363//
364
365
366//______________________________________________________________________________
367Int_t AliMpManuStore::NofManus() const
368{
369/// Return total number of manus in the store
370
371 return fNofManus;
372}
373
374
375//______________________________________________________________________________
376Int_t AliMpManuStore::NofManus(Int_t detElemId) const
377{
378/// Return number of manus in given detection element
379
380 if ( ! AliMpDEManager::IsValidDetElemId(detElemId, kTRUE) ) return 0;
381
382 return fNofManusInDE.GetValue(detElemId);
383}
384
385//______________________________________________________________________________
386Bool_t AliMpManuStore::AddManu(Int_t detElemId, Int_t manuId, Int_t serialNb)
387{
388/// Add manu to the map
389
390 Long_t index = AliMpExMap::GetIndex(AliMpIntPair(detElemId, manuId));
391
392 AliDebugStream(2)
393 << "Adding (" << detElemId << "," << manuId
394 << ") as index=" << index << " and serialNb=" << serialNb << endl;
395
396 fManuToSerialNbs.Add(index, Long_t(serialNb));
397
398 Long_t value = fSerialNbToManus.GetValue(Long_t(serialNb));
399 if ( value ) {
400 if ( fgWarnIfDoublon ) {
401 AliWarningStream()
402 << "Serial number " << serialNb
403 << " already present for (detElemId, manuId) = " << AliMpExMap::GetPair(value)
404 << ", it will nod be added for ("
405 << detElemId << "," << manuId << ")" << endl;
406 }
407 return kFALSE;
408 }
409 else {
410 fSerialNbToManus.Add(Long_t(serialNb), index);
411 return kTRUE;
412 }
413}
414
415
416//______________________________________________________________________________
417Int_t AliMpManuStore::GetManuSerial(Int_t detElemId, Int_t manuId) const
418{
419/// Return manu serial number for given detElemId and manuId
420
421 Long_t index = AliMpExMap::GetIndex(AliMpIntPair(detElemId, manuId));
422 // cout << index << " " << fManuToSerialNbs.GetValue(index) << endl;
423
424 return fManuToSerialNbs.GetValue(index);
425}
426
427//______________________________________________________________________________
428AliMpIntPair AliMpManuStore::GetDetElemIdManu(Int_t manuSerial) const
429{
430/// Return detElemId and manuId for given manu serial number
431
432 Long_t value = fSerialNbToManus.GetValue(Long_t(manuSerial));
433 // cout << manuSerial << " " << value << endl;
434
435 return AliMpExMap::GetPair(value);
436}
437