]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONVGeometryBuilder.cxx
Updated with refactoring of geometry & segmentation classes;
[u/mrichter/AliRoot.git] / MUON / AliMUONVGeometryBuilder.cxx
CommitLineData
30178c30 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
d1cd2474 16// $Id$
17//
18// Class AliMUONVGeometryBuilder
19// -----------------------------
e118b27e 20// Abstract base class for geometry construction per geometry module(s).
d1cd2474 21// Author: Ivana Hrivnacova, IPN Orsay
5f1df83a 22// 23/01/2004
d1cd2474 23
2811276d 24#include <Riostream.h>
d1cd2474 25#include <TObjArray.h>
2811276d 26#include <TSystem.h>
27#include <TGeoMatrix.h>
28#include <TVirtualMC.h>
d1cd2474 29
30#include "AliMUONVGeometryBuilder.h"
e118b27e 31#include "AliMUONGeometryModule.h"
32#include "AliMUONGeometryDetElement.h"
33#include "AliMUONGeometryStore.h"
2811276d 34#include "AliMUONGeometrySVMap.h"
35#include "AliMUONGeometryEnvelopeStore.h"
36#include "AliMUONGeometryEnvelope.h"
37#include "AliMUONGeometryConstituent.h"
e118b27e 38#include "AliMUONVGeometryDEIndexing.h"
067866a3 39#include "AliMUONGeometryBuilder.h"
8c343c7c 40#include "AliLog.h"
d1cd2474 41
42ClassImp(AliMUONVGeometryBuilder)
43
2811276d 44const TString AliMUONVGeometryBuilder::fgkTransformFileNamePrefix = "transform_";
45const TString AliMUONVGeometryBuilder::fgkSVMapFileNamePrefix = "svmap_";
46const TString AliMUONVGeometryBuilder::fgkOutFileNameSuffix = ".out";
47
d1cd2474 48//______________________________________________________________________________
2811276d 49AliMUONVGeometryBuilder::AliMUONVGeometryBuilder(const TString& fileName,
e118b27e 50 AliMUONGeometryModule* mg1, AliMUONGeometryModule* mg2,
51 AliMUONGeometryModule* mg3, AliMUONGeometryModule* mg4,
52 AliMUONGeometryModule* mg5, AliMUONGeometryModule* mg6)
d1cd2474 53 : TObject(),
2811276d 54 fTransformFileName(fgkTransformFileNamePrefix+fileName),
55 fSVMapFileName(fgkSVMapFileNamePrefix+fileName),
067866a3 56 fModuleGeometries(0),
57 fReferenceFrame()
d1cd2474 58 {
59// Standard constructor
60
e118b27e 61 // Create the module geometries array
62 fModuleGeometries = new TObjArray();
d1cd2474 63
e118b27e 64 if (mg1) fModuleGeometries->Add(mg1);
65 if (mg2) fModuleGeometries->Add(mg2);
66 if (mg3) fModuleGeometries->Add(mg3);
67 if (mg4) fModuleGeometries->Add(mg4);
68 if (mg5) fModuleGeometries->Add(mg5);
69 if (mg6) fModuleGeometries->Add(mg6);
d1cd2474 70}
71
72
73//______________________________________________________________________________
74AliMUONVGeometryBuilder::AliMUONVGeometryBuilder()
75 : TObject(),
2811276d 76 fTransformFileName(),
77 fSVMapFileName(),
067866a3 78 fModuleGeometries(0),
79 fReferenceFrame()
d1cd2474 80{
81// Default constructor
82}
83
84
85//______________________________________________________________________________
86AliMUONVGeometryBuilder::AliMUONVGeometryBuilder(const AliMUONVGeometryBuilder& rhs)
87 : TObject(rhs)
88{
30178c30 89// Protected copy constructor
90
8c343c7c 91 AliFatal("Copy constructor is not implemented.");
d1cd2474 92}
93
94//______________________________________________________________________________
95AliMUONVGeometryBuilder::~AliMUONVGeometryBuilder() {
96//
e118b27e 97 if (fModuleGeometries) {
98 fModuleGeometries->Clear(); // Sets pointers to 0 since it is not the owner
99 delete fModuleGeometries;
86b48c39 100 }
d1cd2474 101}
102
103//______________________________________________________________________________
104AliMUONVGeometryBuilder&
105AliMUONVGeometryBuilder::operator = (const AliMUONVGeometryBuilder& rhs)
106{
30178c30 107// Protected assignement operator
108
d1cd2474 109 // check assignement to self
110 if (this == &rhs) return *this;
111
8c343c7c 112 AliFatal("Assignment operator is not implemented.");
d1cd2474 113
114 return *this;
115}
116
117//
2811276d 118// private methods
119//
120
121//______________________________________________________________________________
122 TString AliMUONVGeometryBuilder::ComposePath(const TString& volName,
123 Int_t copyNo) const
124{
125// Compose path from given volName and copyNo
126// ---
127
128 TString path(volName);
129 path += ".";
130 path += copyNo;
131
132 return path;
133}
134
2811276d 135//______________________________________________________________________________
136void AliMUONVGeometryBuilder::MapSV(const TString& path0,
137 const TString& volName, Int_t detElemId) const
138{
139// Update the path with all daughters volumes recursively
140// and map it to the detection element Id if it is a sensitive volume
141// ---
142
143 Int_t nofDaughters = gMC->NofVolDaughters(volName);
144 if (nofDaughters == 0) {
145
146 // Get the name of the last volume in the path
147 Ssiz_t npos1 = path0.Last('/')+1;
148 Ssiz_t npos2 = path0.Last('.');
149 TString volName(path0(npos1, npos2-npos1));
150
151 // Check if it is sensitive volume
e0a49962 152 Int_t moduleId = AliMUONVGeometryDEIndexing::GetModuleId(detElemId);
e118b27e 153 AliMUONGeometryModule* geometry = GetGeometry(moduleId);
2811276d 154 if (geometry->IsSensitiveVolume(volName)) {
155 //cout << ".. adding to the map "
156 // << path0 << " " << detElemId << endl;
157 FillData(path0, detElemId);
158 }
159 return;
160 }
161
162 for (Int_t i=0; i<nofDaughters; i++) {
163 Int_t copyNo = gMC->VolDaughterCopyNo(volName, i);
164 TString newName = gMC->VolDaughterName(volName, i);
165
166 TString path = path0;
167 path += "/";
168 path += ComposePath(newName, copyNo);
169
170 MapSV(path, newName, detElemId);
171 }
172}
e118b27e 173
067866a3 174//______________________________________________________________________________
175TGeoHMatrix AliMUONVGeometryBuilder::GetTransform(
176 Double_t x, Double_t y, Double_t z,
177 Double_t a1, Double_t a2, Double_t a3,
178 Double_t a4, Double_t a5, Double_t a6) const
179{
180// Builds the transformation from the given parameters
181// ---
182
183 // Compose transform
184 TGeoCombiTrans transform(TGeoTranslation(x, y, z),
185 TGeoRotation("rot", a1, a2, a3, a4, a5, a6));
186
187 // Convert transform to the given reference frame
ff32e20d 188 TGeoHMatrix newTransform;
189 if ( fReferenceFrame.IsIdentity() )
190 newTransform = transform;
191 else {
192 newTransform
193 = AliMUONGeometryBuilder::Multiply( fReferenceFrame.Inverse(),
194 transform,
195 fReferenceFrame );
196 }
067866a3 197
198 return newTransform;
199}
200
201
2811276d 202//______________________________________________________________________________
e118b27e 203void AliMUONVGeometryBuilder::FillData(Int_t moduleId, Int_t nofDetElements,
2811276d 204 Double_t x, Double_t y, Double_t z,
205 Double_t a1, Double_t a2, Double_t a3,
206 Double_t a4, Double_t a5, Double_t a6) const
207{
e118b27e 208// Fill the transformation of the module.
2811276d 209// ---
210
e118b27e 211 moduleId--;
212 // Modules numbers in the file are starting from 1
213
067866a3 214 // Build the transformation from the parameters
215 TGeoHMatrix newTransform
216 = GetTransform(x, y, z, a1, a2, a3, a4, a5, a6);
217
218 const Double_t* xyz = newTransform.GetTranslation();
219 const Double_t* rm = newTransform.GetRotationMatrix();
220 TGeoRotation rotation2;
221 rotation2.SetMatrix(const_cast<Double_t*>(rm));
222
e118b27e 223 GetGeometry(moduleId)
224 ->GetDEIndexing()->SetNofDetElements(nofDetElements);
225 GetGeometry(moduleId)
067866a3 226 ->SetTranslation(TGeoTranslation(xyz[0], xyz[1], xyz[2]));
e118b27e 227 GetGeometry(moduleId)
067866a3 228 ->SetRotation(rotation2);
2811276d 229}
230
231//______________________________________________________________________________
232void AliMUONVGeometryBuilder::FillData(
233 Int_t detElemId, const TString& volName, Int_t copyNo,
234 Double_t x, Double_t y, Double_t z,
235 Double_t a1, Double_t a2, Double_t a3,
236 Double_t a4, Double_t a5, Double_t a6) const
237{
238// Fill the transformation of the detection element.
239// ---
240
e118b27e 241 // Module Id
242 Int_t moduleId
243 = AliMUONVGeometryDEIndexing::GetModuleId(detElemId);
2811276d 244
245 // Compose path
246 TString path = ComposePath(volName, copyNo);
247
067866a3 248 // Build the transformation from the parameters
249 TGeoHMatrix newTransform
250 = GetTransform(x, y, z, a1, a2, a3, a4, a5, a6);
251
252 // Compose TGeoCombiTrans
253 TGeoCombiTrans newCombiTransform(newTransform);
2811276d 254
e118b27e 255 // Get detection element store
256 AliMUONGeometryStore* detElements = GetDetElements(moduleId);
257
258 // Add detection element
259 detElements->Add(detElemId,
067866a3 260 new AliMUONGeometryDetElement(detElemId, path, newCombiTransform));
2811276d 261}
262
263//______________________________________________________________________________
264void AliMUONVGeometryBuilder::FillData(
265 const TString& sensVolumePath, Int_t detElemId) const
266{
267// Fill the mapping of the sensitive volume path to the detection element.
268// ---
269
e118b27e 270 // Module Id
271 Int_t moduleId
272 = AliMUONVGeometryDEIndexing::GetModuleId(detElemId);
2811276d 273
e118b27e 274 // Get module sensitive volumes map
275 AliMUONGeometrySVMap* svMap = GetSVMap(moduleId);
2811276d 276
277 // Map the sensitive volume to detection element
278 svMap->Add(sensVolumePath, detElemId);
279}
280
281//______________________________________________________________________________
282TString AliMUONVGeometryBuilder::ReadData1(ifstream& in) const
283{
e118b27e 284// Reads and fills modules transformations from a file
2811276d 285// Returns true, if reading finished correctly.
286// ---
287
288 TString key("CH");
289 while ( key == TString("CH") ) {
e118b27e 290 Int_t id, n;
2811276d 291 Double_t x, y, z;
292 Double_t a1, a2, a3, a4, a5, a6;
293 TString dummy;
294
295 in >> id;
e118b27e 296 in >> n;
2811276d 297 in >> dummy;
298 in >> x;
299 in >> y;
300 in >> z;
301 in >> dummy;
302 in >> a1;
303 in >> a2;
304 in >> a3;
305 in >> a4;
306 in >> a5;
307 in >> a6;
308
309 //cout << "id=" << id << " "
310 // << "position= " << x << ", " << y << ", " << z << " "
311 // << "rotation= " << a1 << ", " << a2 << ", " << a3 << ", "
312 // << a4 << ", " << a5 << ", " << a6
313 // << endl;
314
315 // Fill data
e118b27e 316 FillData(id, n, x, y, z, a1, a2, a3, a4, a5, a6);
2811276d 317
318 // Go to next line
319 in >> key;
320 }
321
322 return key;
323}
324
325//______________________________________________________________________________
326TString AliMUONVGeometryBuilder::ReadData2(ifstream& in) const
327{
328// Reads detection elements transformations from a file
329// Returns true, if reading finished correctly.
330// ---
331
332 TString key("DE");
333 while ( key == TString("DE") ) {
334
335 // Input data
336 Int_t detElemId;
337 TString volumeName;
338 Int_t copyNo;
339 Double_t x, y, z;
340 Double_t a1, a2, a3, a4, a5, a6;
341 TString dummy;
342
343 in >> detElemId;
344 in >> volumeName;
345 in >> copyNo;
346 in >> dummy;
347 in >> x;
348 in >> y;
349 in >> z;
350 in >> dummy;
351 in >> a1;
352 in >> a2;
353 in >> a3;
354 in >> a4;
355 in >> a5;
356 in >> a6;
357
358 //cout << "detElemId=" << detElemId << " "
359 // << "volume=" << volumeName << " "
360 // << "copyNo=" << copyNo << " "
361 // << "position= " << x << ", " << y << ", " << z << " "
362 // << "rotation= " << a1 << ", " << a2 << ", " << a3 << ", "
363 // << a4 << ", " << a5 << ", " << a6
364 // << endl;
365
366 // Fill data
367 FillData(detElemId, volumeName, copyNo, x, y, z, a1, a2, a3, a4, a5, a6);
368
369 // Go to next line
370 in >> key;
371 }
372
373 return key;
374}
375
376//______________________________________________________________________________
377TString AliMUONVGeometryBuilder::ReadData3(ifstream& in) const
378{
379// Reads detection elements transformations from a file
380// Returns true, if reading finished correctly.
381// ---
382
383 TString key("SV");
384 while ( key == TString("SV") ) {
385
386 // Input data
387 TString volumePath;
388 Int_t detElemId;
389
390 in >> volumePath;
391 in >> detElemId;
392
393 //cout << "volumePath=" << volumePath << " "
394 // << "detElemId=" << detElemId
395 // << endl;
396
397 // Fill data
398 FillData(volumePath, detElemId);
399
400 // Go to next line
401 in >> key;
402 }
403
404 return key;
405}
406
407//______________________________________________________________________________
067866a3 408void AliMUONVGeometryBuilder::WriteTransform(ofstream& out,
2811276d 409 const TGeoCombiTrans* transform) const
410{
411// Writes the transformations
067866a3 412// after converting them into the specified reference frame
2811276d 413// ---
414
067866a3 415 // Convert transform to the given reference frame
ff32e20d 416 TGeoHMatrix newTransform;
417 if ( fReferenceFrame.IsIdentity() )
418 newTransform = *transform;
419 else {
420 newTransform = AliMUONGeometryBuilder::Multiply( fReferenceFrame,
421 *transform,
422 fReferenceFrame.Inverse() );
423 }
067866a3 424
2811276d 425 out << " pos: ";
067866a3 426 const Double_t* xyz = newTransform.GetTranslation();
2811276d 427 out << setw(10) << setprecision(4) << xyz[0] << " "
428 << setw(10) << setprecision(4) << xyz[1] << " "
429 << setw(10) << setprecision(4) << xyz[2];
430
431 out << " rot: ";
067866a3 432 const Double_t* rm = newTransform.GetRotationMatrix();
433 TGeoRotation rotation;
434 rotation.SetMatrix(const_cast<Double_t*>(rm));
2811276d 435 Double_t a1, a2, a3, a4, a5, a6;
067866a3 436 rotation.GetAngles(a1, a2, a3, a4, a5, a6);
e118b27e 437
2811276d 438 out << setw(8) << setprecision(4) << a1 << " "
439 << setw(8) << setprecision(4) << a2 << " "
440 << setw(8) << setprecision(4) << a3 << " "
441 << setw(8) << setprecision(4) << a4 << " "
442 << setw(8) << setprecision(4) << a5 << " "
443 << setw(8) << setprecision(4) << a6 << " " << endl;
444}
445
446//______________________________________________________________________________
447void AliMUONVGeometryBuilder::WriteData1(ofstream& out) const
448{
e118b27e 449// Writes modules transformations
2811276d 450// ---
451
e118b27e 452 for (Int_t i=0; i<fModuleGeometries->GetEntriesFast(); i++) {
453 AliMUONGeometryModule* geometry
454 = (AliMUONGeometryModule*)fModuleGeometries->At(i);
2811276d 455 const TGeoCombiTrans* transform
e118b27e 456 = geometry->GetTransformation();
2811276d 457
458 out << "CH "
e118b27e 459 << setw(4) << geometry->GetModuleId() + 1 << " "
460 << setw(4) << geometry->GetDetElementStore()->GetNofEntries() << " ";
2811276d 461
462 WriteTransform(out, transform);
463 }
464 out << endl;
465}
466
467//______________________________________________________________________________
468void AliMUONVGeometryBuilder::WriteData2(ofstream& out) const
469{
470// Writes detection elements (envelopes) transformations
471// ---
472
473
e118b27e 474 for (Int_t i=0; i<fModuleGeometries->GetEntriesFast(); i++) {
475 AliMUONGeometryModule* geometry
476 = (AliMUONGeometryModule*)fModuleGeometries->At(i);
2811276d 477 const TObjArray* envelopes
e118b27e 478 = geometry->GetEnvelopeStore()->GetEnvelopes();
2811276d 479
480 for (Int_t j=0; j<envelopes->GetEntriesFast(); j++) {
481 AliMUONGeometryEnvelope* envelope
482 = (AliMUONGeometryEnvelope*)envelopes->At(j);
483 const TGeoCombiTrans* transform
484 = envelope->GetTransformation();
485
486 // skip envelope not corresponding to detection element
487 if(envelope->GetUniqueID() == 0) continue;
488
489 out << "DE "
490 << setw(4) << envelope->GetUniqueID() << " "
491 << envelope->GetName() << " "
492 << setw(4)<< envelope->GetCopyNo();
493
494 WriteTransform(out, transform);
495 }
496 out << endl;
497 }
498}
499
500//______________________________________________________________________________
501void AliMUONVGeometryBuilder::WriteData3(ofstream& out) const
502{
503// Writes association of sensitive volumes and detection elements
504// from the sensitive volume map
505// ---
506
e118b27e 507 for (Int_t i=0; i<fModuleGeometries->GetEntriesFast(); i++) {
508 AliMUONGeometryModule* geometry
509 = (AliMUONGeometryModule*)fModuleGeometries->At(i);
2811276d 510 AliMUONGeometrySVMap* svMap
e118b27e 511 = geometry->GetSVMap();
2811276d 512
513 svMap->WriteMap(out);
514 out << endl;
515 }
516}
517
518//
519// protected methods
d1cd2474 520//
521
522//______________________________________________________________________________
e118b27e 523AliMUONGeometryModule*
524AliMUONVGeometryBuilder::GetGeometry(Int_t moduleId) const
d1cd2474 525{
e118b27e 526// Returns the module geometry specified by moduleId
d1cd2474 527// ---
528
e118b27e 529 for (Int_t i=0; i<fModuleGeometries->GetEntriesFast(); i++) {
530
531 AliMUONGeometryModule* geometry
532 = (AliMUONGeometryModule*)fModuleGeometries->At(i);
533
534 if ( geometry->GetModuleId() == moduleId) return geometry;
d1cd2474 535 }
536
537 return 0;
538}
2811276d 539
540//______________________________________________________________________________
541AliMUONGeometryEnvelopeStore*
e118b27e 542AliMUONVGeometryBuilder::GetEnvelopes(Int_t moduleId) const
2811276d 543{
e118b27e 544// Returns the envelope store of the module geometry specified by moduleId
2811276d 545// ---
546
e118b27e 547 AliMUONGeometryModule* geometry = GetGeometry(moduleId);
2811276d 548
e118b27e 549 if (!geometry) {
550 AliFatal(Form("Module geometry %d is not defined", moduleId));
2811276d 551 return 0;
552 }
553
e118b27e 554 return geometry->GetEnvelopeStore();
2811276d 555}
556
557//______________________________________________________________________________
e118b27e 558AliMUONGeometryStore*
559AliMUONVGeometryBuilder::GetDetElements(Int_t moduleId) const
2811276d 560{
e118b27e 561// Returns the detection elemnts store of the module geometry specified
562// by moduleId
2811276d 563// ---
564
e118b27e 565 AliMUONGeometryModule* geometry = GetGeometry(moduleId);
2811276d 566
e118b27e 567 if (!geometry) {
568 AliFatal(Form("Module geometry %d is not defined", moduleId));
2811276d 569 return 0;
570 }
571
e118b27e 572 return geometry->GetDetElementStore();
2811276d 573}
574
575//______________________________________________________________________________
576AliMUONGeometrySVMap*
e118b27e 577AliMUONVGeometryBuilder::GetSVMap(Int_t moduleId) const
2811276d 578{
e118b27e 579// Returns the transformation store of the module geometry specified by moduleId
2811276d 580// ---
581
e118b27e 582 AliMUONGeometryModule* geometry = GetGeometry(moduleId);
2811276d 583
e118b27e 584 if (!geometry) {
585 AliFatal(Form("Geometry %d is not defined", moduleId));
2811276d 586 return 0;
587 }
588
e118b27e 589 return geometry->GetSVMap();
2811276d 590}
591
592//
593// public functions
594//
595
596//______________________________________________________________________________
e118b27e 597void AliMUONVGeometryBuilder::FillTransformations() const
2811276d 598{
599// Fills transformations store from defined geometry.
600// ---
601
e118b27e 602 for (Int_t i=0; i<fModuleGeometries->GetEntriesFast(); i++) {
603 AliMUONGeometryModule* geometry
604 = (AliMUONGeometryModule*)fModuleGeometries->At(i);
2811276d 605 const TObjArray* envelopes
e118b27e 606 = geometry->GetEnvelopeStore()->GetEnvelopes();
607
608 AliMUONGeometryStore* detElements = geometry->GetDetElementStore();
609
610 // Set nof detection elements to the indexing
611 geometry->GetDEIndexing()
612 ->SetNofDetElements(geometry->GetEnvelopeStore()->GetNofDetElements());
2811276d 613
614 for (Int_t j=0; j<envelopes->GetEntriesFast(); j++) {
615 AliMUONGeometryEnvelope* envelope
616 = (AliMUONGeometryEnvelope*)envelopes->At(j);
617
618 // skip envelope not corresponding to detection element
619 if(envelope->GetUniqueID() == 0) continue;
620
621 // Get envelope data
622 Int_t detElemId = envelope->GetUniqueID();
623 TString path = ComposePath(envelope->GetName(),
624 envelope->GetCopyNo());
625 const TGeoCombiTrans* transform = envelope->GetTransformation();
626
627 // Add detection element transformation
e118b27e 628 detElements->Add(detElemId,
629 new AliMUONGeometryDetElement(detElemId, path, *transform));
2811276d 630 }
631 }
632}
633
634//_____ _________________________________________________________________________
635void AliMUONVGeometryBuilder::RebuildSVMaps() const
636{
637// Clear the SV maps in memory and fill them from defined geometry.
638// ---
639
e118b27e 640 for (Int_t i=0; i<fModuleGeometries->GetEntriesFast(); i++) {
641 AliMUONGeometryModule* geometry
642 = (AliMUONGeometryModule*)fModuleGeometries->At(i);
2811276d 643
644 // Clear the map
e118b27e 645 geometry->GetSVMap()->Clear();
2811276d 646
647 // Fill the map from geometry
648 const TObjArray* envelopes
e118b27e 649 = geometry->GetEnvelopeStore()->GetEnvelopes();
2811276d 650
651 for (Int_t j=0; j<envelopes->GetEntriesFast(); j++) {
652 AliMUONGeometryEnvelope* envelope
653 = (AliMUONGeometryEnvelope*)envelopes->At(j);
654
655 // skip envelope not corresponding to detection element
656 if(envelope->GetUniqueID() == 0) continue;
657
658 TString path0("/ALIC.1");
e118b27e 659 if (geometry->GetMotherVolume() != "ALIC") {
2811276d 660 path0 += "/";
e118b27e 661 path0 += ComposePath(geometry->GetMotherVolume(), 1);
2811276d 662 }
d639fb9f 663 if (! geometry->IsVirtual() ) {
664 path0 += "/";
665 path0 += ComposePath(geometry->GetVolume(), 1);
666 }
2811276d 667
668 if (!envelope->IsVirtual()) {
669 TString path = path0;
670 path += "/";
671 path += ComposePath(envelope->GetName(), envelope->GetCopyNo());
672 MapSV(path, envelope->GetName(), envelope->GetUniqueID());
673 }
674 else {
675 for (Int_t k=0; k<envelope->GetConstituents()->GetEntriesFast(); k++) {
676 AliMUONGeometryConstituent* constituent
677 = (AliMUONGeometryConstituent*)envelope->GetConstituents()->At(k);
678 TString path = path0;
679 path += "/";
680 path += ComposePath(constituent->GetName(), constituent->GetCopyNo());
681 MapSV(path, constituent->GetName(), envelope->GetUniqueID());
682 }
683 }
684 }
685 }
686}
687
688//______________________________________________________________________________
067866a3 689Bool_t
690AliMUONVGeometryBuilder::ReadTransformations() const
2811276d 691{
692// Reads transformations from a file
693// Returns true, if reading finished correctly.
694// ---
695
e118b27e 696 // No reading
697 // if builder is not associated with any geometry module
698 if (fModuleGeometries->GetEntriesFast() == 0) return false;
699
2811276d 700 // File path
701 TString filePath = gSystem->Getenv("ALICE_ROOT");
702 filePath += "/MUON/data/";
703 filePath += fTransformFileName;
704
705 // Open input file
706 ifstream in(filePath, ios::in);
707 if (!in) {
708 cerr << filePath << endl;
8c343c7c 709 AliFatal("File not found.");
2811276d 710 return false;
711 }
712
713 TString key;
714 in >> key;
715 while ( !in.eof() ) {
716 if (key == TString("CH"))
717 key = ReadData1(in);
718 else if (key == TString("DE"))
719 key = ReadData2(in);
720 else {
8c343c7c 721 AliFatal(Form("%s key not recognized", key.Data()));
2811276d 722 return false;
723 }
724 }
725
726 return true;
727}
728
729//______________________________________________________________________________
730Bool_t AliMUONVGeometryBuilder::ReadSVMap() const
731{
732// Reads the sensitive volume from a file
733// Returns true, if reading finished correctly.
734// ---
735
e118b27e 736 // No reading
737 // if builder is not associated with any geometry module
738 if (fModuleGeometries->GetEntriesFast() == 0) return false;
739
2811276d 740 // File path
741 TString filePath = gSystem->Getenv("ALICE_ROOT");
742 filePath += "/MUON/data/";
743 filePath += fSVMapFileName;
744
745 // Open input file
746 ifstream in(filePath, ios::in);
747 if (!in) {
748 cerr << filePath << endl;
8c343c7c 749 AliFatal("File not found.");
2811276d 750 return false;
751 }
752
753 TString key;
754 in >> key;
755 while ( !in.eof() ) {
756 if (key == TString("SV"))
757 key = ReadData3(in);
758 else {
8c343c7c 759 AliFatal(Form("%s key not recognized", key.Data()));
2811276d 760 return false;
761 }
762 }
763
764 return true;
765}
766
767//______________________________________________________________________________
067866a3 768Bool_t
769AliMUONVGeometryBuilder::WriteTransformations() const
2811276d 770{
771// Writes transformations into a file
772// Returns true, if writing finished correctly.
773// ---
774
e118b27e 775 // No writing
776 // if builder is not associated with any geometry module
777 if (fModuleGeometries->GetEntriesFast() == 0) return false;
778
2811276d 779 // File path
780 TString filePath = gSystem->Getenv("ALICE_ROOT");
781 filePath += "/MUON/data/";
782 filePath += fTransformFileName;
783 filePath += fgkOutFileNameSuffix;
784
785 // Open input file
786 ofstream out(filePath, ios::out);
787 if (!out) {
788 cerr << filePath << endl;
8c343c7c 789 AliError("File not found.");
2811276d 790 return false;
791 }
e516b01d 792#if !defined (__DECCXX)
2811276d 793 out.setf(std::ios::fixed);
e516b01d 794#endif
2811276d 795 WriteData1(out);
796 WriteData2(out);
797
798 return true;
799}
800
801//______________________________________________________________________________
802Bool_t AliMUONVGeometryBuilder::WriteSVMap(Bool_t rebuild) const
803{
804// Writes sensitive volume map into a file
805// Returns true, if writing finished correctly.
806// ---
807
e118b27e 808 // No writing
809 // if builder is not associated with any geometry module
810 if (fModuleGeometries->GetEntriesFast() == 0) return false;
811
2811276d 812 // File path
813 TString filePath = gSystem->Getenv("ALICE_ROOT");
814 filePath += "/MUON/data/";
815 filePath += fSVMapFileName;
816 filePath += fgkOutFileNameSuffix;
817
818 // Open input file
819 ofstream out(filePath, ios::out);
820 if (!out) {
821 cerr << filePath << endl;
8c343c7c 822 AliError("File not found.");
2811276d 823 return false;
824 }
e516b01d 825#if !defined (__DECCXX)
2811276d 826 out.setf(std::ios::fixed);
e516b01d 827#endif
2811276d 828 if (rebuild) RebuildSVMaps();
829
830 WriteData3(out);
831
832 return true;
833}
834