]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONVGeometryBuilder.cxx
BuildStation6 made consistent with AliMUONFactoryV2
[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
188 TGeoHMatrix newTransform
189 = AliMUONGeometryBuilder::Multiply( fReferenceFrame.Inverse(),
190 transform,
191 fReferenceFrame );
192
193 return newTransform;
194}
195
196
2811276d 197//______________________________________________________________________________
e118b27e 198void AliMUONVGeometryBuilder::FillData(Int_t moduleId, Int_t nofDetElements,
2811276d 199 Double_t x, Double_t y, Double_t z,
200 Double_t a1, Double_t a2, Double_t a3,
201 Double_t a4, Double_t a5, Double_t a6) const
202{
e118b27e 203// Fill the transformation of the module.
2811276d 204// ---
205
e118b27e 206 moduleId--;
207 // Modules numbers in the file are starting from 1
208
067866a3 209 // Build the transformation from the parameters
210 TGeoHMatrix newTransform
211 = GetTransform(x, y, z, a1, a2, a3, a4, a5, a6);
212
213 const Double_t* xyz = newTransform.GetTranslation();
214 const Double_t* rm = newTransform.GetRotationMatrix();
215 TGeoRotation rotation2;
216 rotation2.SetMatrix(const_cast<Double_t*>(rm));
217
e118b27e 218 GetGeometry(moduleId)
219 ->GetDEIndexing()->SetNofDetElements(nofDetElements);
220 GetGeometry(moduleId)
067866a3 221 ->SetTranslation(TGeoTranslation(xyz[0], xyz[1], xyz[2]));
e118b27e 222 GetGeometry(moduleId)
067866a3 223 ->SetRotation(rotation2);
2811276d 224}
225
226//______________________________________________________________________________
227void AliMUONVGeometryBuilder::FillData(
228 Int_t detElemId, const TString& volName, Int_t copyNo,
229 Double_t x, Double_t y, Double_t z,
230 Double_t a1, Double_t a2, Double_t a3,
231 Double_t a4, Double_t a5, Double_t a6) const
232{
233// Fill the transformation of the detection element.
234// ---
235
e118b27e 236 // Module Id
237 Int_t moduleId
238 = AliMUONVGeometryDEIndexing::GetModuleId(detElemId);
2811276d 239
240 // Compose path
241 TString path = ComposePath(volName, copyNo);
242
067866a3 243 // Build the transformation from the parameters
244 TGeoHMatrix newTransform
245 = GetTransform(x, y, z, a1, a2, a3, a4, a5, a6);
246
247 // Compose TGeoCombiTrans
248 TGeoCombiTrans newCombiTransform(newTransform);
2811276d 249
e118b27e 250 // Get detection element store
251 AliMUONGeometryStore* detElements = GetDetElements(moduleId);
252
253 // Add detection element
254 detElements->Add(detElemId,
067866a3 255 new AliMUONGeometryDetElement(detElemId, path, newCombiTransform));
2811276d 256}
257
258//______________________________________________________________________________
259void AliMUONVGeometryBuilder::FillData(
260 const TString& sensVolumePath, Int_t detElemId) const
261{
262// Fill the mapping of the sensitive volume path to the detection element.
263// ---
264
e118b27e 265 // Module Id
266 Int_t moduleId
267 = AliMUONVGeometryDEIndexing::GetModuleId(detElemId);
2811276d 268
e118b27e 269 // Get module sensitive volumes map
270 AliMUONGeometrySVMap* svMap = GetSVMap(moduleId);
2811276d 271
272 // Map the sensitive volume to detection element
273 svMap->Add(sensVolumePath, detElemId);
274}
275
276//______________________________________________________________________________
277TString AliMUONVGeometryBuilder::ReadData1(ifstream& in) const
278{
e118b27e 279// Reads and fills modules transformations from a file
2811276d 280// Returns true, if reading finished correctly.
281// ---
282
283 TString key("CH");
284 while ( key == TString("CH") ) {
e118b27e 285 Int_t id, n;
2811276d 286 Double_t x, y, z;
287 Double_t a1, a2, a3, a4, a5, a6;
288 TString dummy;
289
290 in >> id;
e118b27e 291 in >> n;
2811276d 292 in >> dummy;
293 in >> x;
294 in >> y;
295 in >> z;
296 in >> dummy;
297 in >> a1;
298 in >> a2;
299 in >> a3;
300 in >> a4;
301 in >> a5;
302 in >> a6;
303
304 //cout << "id=" << id << " "
305 // << "position= " << x << ", " << y << ", " << z << " "
306 // << "rotation= " << a1 << ", " << a2 << ", " << a3 << ", "
307 // << a4 << ", " << a5 << ", " << a6
308 // << endl;
309
310 // Fill data
e118b27e 311 FillData(id, n, x, y, z, a1, a2, a3, a4, a5, a6);
2811276d 312
313 // Go to next line
314 in >> key;
315 }
316
317 return key;
318}
319
320//______________________________________________________________________________
321TString AliMUONVGeometryBuilder::ReadData2(ifstream& in) const
322{
323// Reads detection elements transformations from a file
324// Returns true, if reading finished correctly.
325// ---
326
327 TString key("DE");
328 while ( key == TString("DE") ) {
329
330 // Input data
331 Int_t detElemId;
332 TString volumeName;
333 Int_t copyNo;
334 Double_t x, y, z;
335 Double_t a1, a2, a3, a4, a5, a6;
336 TString dummy;
337
338 in >> detElemId;
339 in >> volumeName;
340 in >> copyNo;
341 in >> dummy;
342 in >> x;
343 in >> y;
344 in >> z;
345 in >> dummy;
346 in >> a1;
347 in >> a2;
348 in >> a3;
349 in >> a4;
350 in >> a5;
351 in >> a6;
352
353 //cout << "detElemId=" << detElemId << " "
354 // << "volume=" << volumeName << " "
355 // << "copyNo=" << copyNo << " "
356 // << "position= " << x << ", " << y << ", " << z << " "
357 // << "rotation= " << a1 << ", " << a2 << ", " << a3 << ", "
358 // << a4 << ", " << a5 << ", " << a6
359 // << endl;
360
361 // Fill data
362 FillData(detElemId, volumeName, copyNo, x, y, z, a1, a2, a3, a4, a5, a6);
363
364 // Go to next line
365 in >> key;
366 }
367
368 return key;
369}
370
371//______________________________________________________________________________
372TString AliMUONVGeometryBuilder::ReadData3(ifstream& in) const
373{
374// Reads detection elements transformations from a file
375// Returns true, if reading finished correctly.
376// ---
377
378 TString key("SV");
379 while ( key == TString("SV") ) {
380
381 // Input data
382 TString volumePath;
383 Int_t detElemId;
384
385 in >> volumePath;
386 in >> detElemId;
387
388 //cout << "volumePath=" << volumePath << " "
389 // << "detElemId=" << detElemId
390 // << endl;
391
392 // Fill data
393 FillData(volumePath, detElemId);
394
395 // Go to next line
396 in >> key;
397 }
398
399 return key;
400}
401
402//______________________________________________________________________________
067866a3 403void AliMUONVGeometryBuilder::WriteTransform(ofstream& out,
2811276d 404 const TGeoCombiTrans* transform) const
405{
406// Writes the transformations
067866a3 407// after converting them into the specified reference frame
2811276d 408// ---
409
067866a3 410 // Convert transform to the given reference frame
411 TGeoHMatrix newTransform
412 = fReferenceFrame * (*transform) * (fReferenceFrame.Inverse());
413
2811276d 414 out << " pos: ";
067866a3 415 const Double_t* xyz = newTransform.GetTranslation();
2811276d 416 out << setw(10) << setprecision(4) << xyz[0] << " "
417 << setw(10) << setprecision(4) << xyz[1] << " "
418 << setw(10) << setprecision(4) << xyz[2];
419
420 out << " rot: ";
067866a3 421 const Double_t* rm = newTransform.GetRotationMatrix();
422 TGeoRotation rotation;
423 rotation.SetMatrix(const_cast<Double_t*>(rm));
2811276d 424 Double_t a1, a2, a3, a4, a5, a6;
067866a3 425 rotation.GetAngles(a1, a2, a3, a4, a5, a6);
e118b27e 426
2811276d 427 out << setw(8) << setprecision(4) << a1 << " "
428 << setw(8) << setprecision(4) << a2 << " "
429 << setw(8) << setprecision(4) << a3 << " "
430 << setw(8) << setprecision(4) << a4 << " "
431 << setw(8) << setprecision(4) << a5 << " "
432 << setw(8) << setprecision(4) << a6 << " " << endl;
433}
434
435//______________________________________________________________________________
436void AliMUONVGeometryBuilder::WriteData1(ofstream& out) const
437{
e118b27e 438// Writes modules transformations
2811276d 439// ---
440
e118b27e 441 for (Int_t i=0; i<fModuleGeometries->GetEntriesFast(); i++) {
442 AliMUONGeometryModule* geometry
443 = (AliMUONGeometryModule*)fModuleGeometries->At(i);
2811276d 444 const TGeoCombiTrans* transform
e118b27e 445 = geometry->GetTransformation();
2811276d 446
447 out << "CH "
e118b27e 448 << setw(4) << geometry->GetModuleId() + 1 << " "
449 << setw(4) << geometry->GetDetElementStore()->GetNofEntries() << " ";
2811276d 450
451 WriteTransform(out, transform);
452 }
453 out << endl;
454}
455
456//______________________________________________________________________________
457void AliMUONVGeometryBuilder::WriteData2(ofstream& out) const
458{
459// Writes detection elements (envelopes) transformations
460// ---
461
462
e118b27e 463 for (Int_t i=0; i<fModuleGeometries->GetEntriesFast(); i++) {
464 AliMUONGeometryModule* geometry
465 = (AliMUONGeometryModule*)fModuleGeometries->At(i);
2811276d 466 const TObjArray* envelopes
e118b27e 467 = geometry->GetEnvelopeStore()->GetEnvelopes();
2811276d 468
469 for (Int_t j=0; j<envelopes->GetEntriesFast(); j++) {
470 AliMUONGeometryEnvelope* envelope
471 = (AliMUONGeometryEnvelope*)envelopes->At(j);
472 const TGeoCombiTrans* transform
473 = envelope->GetTransformation();
474
475 // skip envelope not corresponding to detection element
476 if(envelope->GetUniqueID() == 0) continue;
477
478 out << "DE "
479 << setw(4) << envelope->GetUniqueID() << " "
480 << envelope->GetName() << " "
481 << setw(4)<< envelope->GetCopyNo();
482
483 WriteTransform(out, transform);
484 }
485 out << endl;
486 }
487}
488
489//______________________________________________________________________________
490void AliMUONVGeometryBuilder::WriteData3(ofstream& out) const
491{
492// Writes association of sensitive volumes and detection elements
493// from the sensitive volume map
494// ---
495
e118b27e 496 for (Int_t i=0; i<fModuleGeometries->GetEntriesFast(); i++) {
497 AliMUONGeometryModule* geometry
498 = (AliMUONGeometryModule*)fModuleGeometries->At(i);
2811276d 499 AliMUONGeometrySVMap* svMap
e118b27e 500 = geometry->GetSVMap();
2811276d 501
502 svMap->WriteMap(out);
503 out << endl;
504 }
505}
506
507//
508// protected methods
d1cd2474 509//
510
511//______________________________________________________________________________
e118b27e 512AliMUONGeometryModule*
513AliMUONVGeometryBuilder::GetGeometry(Int_t moduleId) const
d1cd2474 514{
e118b27e 515// Returns the module geometry specified by moduleId
d1cd2474 516// ---
517
e118b27e 518 for (Int_t i=0; i<fModuleGeometries->GetEntriesFast(); i++) {
519
520 AliMUONGeometryModule* geometry
521 = (AliMUONGeometryModule*)fModuleGeometries->At(i);
522
523 if ( geometry->GetModuleId() == moduleId) return geometry;
d1cd2474 524 }
525
526 return 0;
527}
2811276d 528
529//______________________________________________________________________________
530AliMUONGeometryEnvelopeStore*
e118b27e 531AliMUONVGeometryBuilder::GetEnvelopes(Int_t moduleId) const
2811276d 532{
e118b27e 533// Returns the envelope store of the module geometry specified by moduleId
2811276d 534// ---
535
e118b27e 536 AliMUONGeometryModule* geometry = GetGeometry(moduleId);
2811276d 537
e118b27e 538 if (!geometry) {
539 AliFatal(Form("Module geometry %d is not defined", moduleId));
2811276d 540 return 0;
541 }
542
e118b27e 543 return geometry->GetEnvelopeStore();
2811276d 544}
545
546//______________________________________________________________________________
e118b27e 547AliMUONGeometryStore*
548AliMUONVGeometryBuilder::GetDetElements(Int_t moduleId) const
2811276d 549{
e118b27e 550// Returns the detection elemnts store of the module geometry specified
551// by moduleId
2811276d 552// ---
553
e118b27e 554 AliMUONGeometryModule* geometry = GetGeometry(moduleId);
2811276d 555
e118b27e 556 if (!geometry) {
557 AliFatal(Form("Module geometry %d is not defined", moduleId));
2811276d 558 return 0;
559 }
560
e118b27e 561 return geometry->GetDetElementStore();
2811276d 562}
563
564//______________________________________________________________________________
565AliMUONGeometrySVMap*
e118b27e 566AliMUONVGeometryBuilder::GetSVMap(Int_t moduleId) const
2811276d 567{
e118b27e 568// Returns the transformation store of the module geometry specified by moduleId
2811276d 569// ---
570
e118b27e 571 AliMUONGeometryModule* geometry = GetGeometry(moduleId);
2811276d 572
e118b27e 573 if (!geometry) {
574 AliFatal(Form("Geometry %d is not defined", moduleId));
2811276d 575 return 0;
576 }
577
e118b27e 578 return geometry->GetSVMap();
2811276d 579}
580
581//
582// public functions
583//
584
585//______________________________________________________________________________
e118b27e 586void AliMUONVGeometryBuilder::FillTransformations() const
2811276d 587{
588// Fills transformations store from defined geometry.
589// ---
590
e118b27e 591 for (Int_t i=0; i<fModuleGeometries->GetEntriesFast(); i++) {
592 AliMUONGeometryModule* geometry
593 = (AliMUONGeometryModule*)fModuleGeometries->At(i);
2811276d 594 const TObjArray* envelopes
e118b27e 595 = geometry->GetEnvelopeStore()->GetEnvelopes();
596
597 AliMUONGeometryStore* detElements = geometry->GetDetElementStore();
598
599 // Set nof detection elements to the indexing
600 geometry->GetDEIndexing()
601 ->SetNofDetElements(geometry->GetEnvelopeStore()->GetNofDetElements());
2811276d 602
603 for (Int_t j=0; j<envelopes->GetEntriesFast(); j++) {
604 AliMUONGeometryEnvelope* envelope
605 = (AliMUONGeometryEnvelope*)envelopes->At(j);
606
607 // skip envelope not corresponding to detection element
608 if(envelope->GetUniqueID() == 0) continue;
609
610 // Get envelope data
611 Int_t detElemId = envelope->GetUniqueID();
612 TString path = ComposePath(envelope->GetName(),
613 envelope->GetCopyNo());
614 const TGeoCombiTrans* transform = envelope->GetTransformation();
615
616 // Add detection element transformation
e118b27e 617 detElements->Add(detElemId,
618 new AliMUONGeometryDetElement(detElemId, path, *transform));
2811276d 619 }
620 }
621}
622
623//_____ _________________________________________________________________________
624void AliMUONVGeometryBuilder::RebuildSVMaps() const
625{
626// Clear the SV maps in memory and fill them from defined geometry.
627// ---
628
e118b27e 629 for (Int_t i=0; i<fModuleGeometries->GetEntriesFast(); i++) {
630 AliMUONGeometryModule* geometry
631 = (AliMUONGeometryModule*)fModuleGeometries->At(i);
2811276d 632
633 // Clear the map
e118b27e 634 geometry->GetSVMap()->Clear();
2811276d 635
636 // Fill the map from geometry
637 const TObjArray* envelopes
e118b27e 638 = geometry->GetEnvelopeStore()->GetEnvelopes();
2811276d 639
640 for (Int_t j=0; j<envelopes->GetEntriesFast(); j++) {
641 AliMUONGeometryEnvelope* envelope
642 = (AliMUONGeometryEnvelope*)envelopes->At(j);
643
644 // skip envelope not corresponding to detection element
645 if(envelope->GetUniqueID() == 0) continue;
646
647 TString path0("/ALIC.1");
e118b27e 648 if (geometry->GetMotherVolume() != "ALIC") {
2811276d 649 path0 += "/";
e118b27e 650 path0 += ComposePath(geometry->GetMotherVolume(), 1);
2811276d 651 }
d639fb9f 652 if (! geometry->IsVirtual() ) {
653 path0 += "/";
654 path0 += ComposePath(geometry->GetVolume(), 1);
655 }
2811276d 656
657 if (!envelope->IsVirtual()) {
658 TString path = path0;
659 path += "/";
660 path += ComposePath(envelope->GetName(), envelope->GetCopyNo());
661 MapSV(path, envelope->GetName(), envelope->GetUniqueID());
662 }
663 else {
664 for (Int_t k=0; k<envelope->GetConstituents()->GetEntriesFast(); k++) {
665 AliMUONGeometryConstituent* constituent
666 = (AliMUONGeometryConstituent*)envelope->GetConstituents()->At(k);
667 TString path = path0;
668 path += "/";
669 path += ComposePath(constituent->GetName(), constituent->GetCopyNo());
670 MapSV(path, constituent->GetName(), envelope->GetUniqueID());
671 }
672 }
673 }
674 }
675}
676
677//______________________________________________________________________________
067866a3 678Bool_t
679AliMUONVGeometryBuilder::ReadTransformations() const
2811276d 680{
681// Reads transformations from a file
682// Returns true, if reading finished correctly.
683// ---
684
e118b27e 685 // No reading
686 // if builder is not associated with any geometry module
687 if (fModuleGeometries->GetEntriesFast() == 0) return false;
688
2811276d 689 // File path
690 TString filePath = gSystem->Getenv("ALICE_ROOT");
691 filePath += "/MUON/data/";
692 filePath += fTransformFileName;
693
694 // Open input file
695 ifstream in(filePath, ios::in);
696 if (!in) {
697 cerr << filePath << endl;
8c343c7c 698 AliFatal("File not found.");
2811276d 699 return false;
700 }
701
702 TString key;
703 in >> key;
704 while ( !in.eof() ) {
705 if (key == TString("CH"))
706 key = ReadData1(in);
707 else if (key == TString("DE"))
708 key = ReadData2(in);
709 else {
8c343c7c 710 AliFatal(Form("%s key not recognized", key.Data()));
2811276d 711 return false;
712 }
713 }
714
715 return true;
716}
717
718//______________________________________________________________________________
719Bool_t AliMUONVGeometryBuilder::ReadSVMap() const
720{
721// Reads the sensitive volume from a file
722// Returns true, if reading finished correctly.
723// ---
724
e118b27e 725 // No reading
726 // if builder is not associated with any geometry module
727 if (fModuleGeometries->GetEntriesFast() == 0) return false;
728
2811276d 729 // File path
730 TString filePath = gSystem->Getenv("ALICE_ROOT");
731 filePath += "/MUON/data/";
732 filePath += fSVMapFileName;
733
734 // Open input file
735 ifstream in(filePath, ios::in);
736 if (!in) {
737 cerr << filePath << endl;
8c343c7c 738 AliFatal("File not found.");
2811276d 739 return false;
740 }
741
742 TString key;
743 in >> key;
744 while ( !in.eof() ) {
745 if (key == TString("SV"))
746 key = ReadData3(in);
747 else {
8c343c7c 748 AliFatal(Form("%s key not recognized", key.Data()));
2811276d 749 return false;
750 }
751 }
752
753 return true;
754}
755
756//______________________________________________________________________________
067866a3 757Bool_t
758AliMUONVGeometryBuilder::WriteTransformations() const
2811276d 759{
760// Writes transformations into a file
761// Returns true, if writing finished correctly.
762// ---
763
e118b27e 764 // No writing
765 // if builder is not associated with any geometry module
766 if (fModuleGeometries->GetEntriesFast() == 0) return false;
767
2811276d 768 // File path
769 TString filePath = gSystem->Getenv("ALICE_ROOT");
770 filePath += "/MUON/data/";
771 filePath += fTransformFileName;
772 filePath += fgkOutFileNameSuffix;
773
774 // Open input file
775 ofstream out(filePath, ios::out);
776 if (!out) {
777 cerr << filePath << endl;
8c343c7c 778 AliError("File not found.");
2811276d 779 return false;
780 }
e516b01d 781#if !defined (__DECCXX)
2811276d 782 out.setf(std::ios::fixed);
e516b01d 783#endif
2811276d 784 WriteData1(out);
785 WriteData2(out);
786
787 return true;
788}
789
790//______________________________________________________________________________
791Bool_t AliMUONVGeometryBuilder::WriteSVMap(Bool_t rebuild) const
792{
793// Writes sensitive volume map into a file
794// Returns true, if writing finished correctly.
795// ---
796
e118b27e 797 // No writing
798 // if builder is not associated with any geometry module
799 if (fModuleGeometries->GetEntriesFast() == 0) return false;
800
2811276d 801 // File path
802 TString filePath = gSystem->Getenv("ALICE_ROOT");
803 filePath += "/MUON/data/";
804 filePath += fSVMapFileName;
805 filePath += fgkOutFileNameSuffix;
806
807 // Open input file
808 ofstream out(filePath, ios::out);
809 if (!out) {
810 cerr << filePath << endl;
8c343c7c 811 AliError("File not found.");
2811276d 812 return false;
813 }
e516b01d 814#if !defined (__DECCXX)
2811276d 815 out.setf(std::ios::fixed);
e516b01d 816#endif
2811276d 817 if (rebuild) RebuildSVMaps();
818
819 WriteData3(out);
820
821 return true;
822}
823