]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONVGeometryBuilder.cxx
30655057e9c07859c503155ea74f48ee5c52e7d5
[u/mrichter/AliRoot.git] / MUON / AliMUONVGeometryBuilder.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 //
18 // Class AliMUONVGeometryBuilder
19 // -----------------------------
20 // Abstract base class for geometry construction per geometry module(s).
21 // Author: Ivana Hrivnacova, IPN Orsay
22 // 23/01/2004
23
24 #include <Riostream.h>
25 #include <TObjArray.h>
26 #include <TSystem.h>
27 #include <TGeoMatrix.h>
28 #include <TVirtualMC.h>
29
30 #include "AliMUONVGeometryBuilder.h"
31 #include "AliMUONGeometryModule.h"
32 #include "AliMUONGeometryDetElement.h"
33 #include "AliMUONGeometryStore.h"
34 #include "AliMUONGeometrySVMap.h"
35 #include "AliMUONGeometryEnvelopeStore.h"
36 #include "AliMUONGeometryEnvelope.h"
37 #include "AliMUONGeometryConstituent.h"
38 #include "AliMUONVGeometryDEIndexing.h"
39 #include "AliMUONGeometryBuilder.h"
40 #include "AliLog.h"
41
42 ClassImp(AliMUONVGeometryBuilder)
43
44 const TString AliMUONVGeometryBuilder::fgkTransformFileNamePrefix = "transform_";
45 const TString AliMUONVGeometryBuilder::fgkSVMapFileNamePrefix = "svmap_";
46 const TString AliMUONVGeometryBuilder::fgkOutFileNameSuffix = ".out";
47
48 //______________________________________________________________________________
49 AliMUONVGeometryBuilder::AliMUONVGeometryBuilder(const TString& fileName,
50                             AliMUONGeometryModule* mg1, AliMUONGeometryModule* mg2,
51                             AliMUONGeometryModule* mg3, AliMUONGeometryModule* mg4,
52                             AliMUONGeometryModule* mg5, AliMUONGeometryModule* mg6)
53  : TObject(),
54    fTransformFileName(fgkTransformFileNamePrefix+fileName),
55    fSVMapFileName(fgkSVMapFileNamePrefix+fileName),
56    fModuleGeometries(0),
57    fReferenceFrame()
58  {
59 // Standard constructor
60
61   // Create the module geometries array
62   fModuleGeometries = new TObjArray();
63   
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);
70 }
71
72
73 //______________________________________________________________________________
74 AliMUONVGeometryBuilder::AliMUONVGeometryBuilder()
75  : TObject(),
76    fTransformFileName(),
77    fSVMapFileName(),
78    fModuleGeometries(0),
79    fReferenceFrame()
80 {
81 // Default constructor
82 }
83
84
85 //______________________________________________________________________________
86 AliMUONVGeometryBuilder::AliMUONVGeometryBuilder(const AliMUONVGeometryBuilder& rhs)
87   : TObject(rhs)
88 {
89 // Protected copy constructor
90
91   AliFatal("Copy constructor is not implemented.");
92 }
93
94 //______________________________________________________________________________
95 AliMUONVGeometryBuilder::~AliMUONVGeometryBuilder() {
96 //
97   if (fModuleGeometries) {
98     fModuleGeometries->Clear(); // Sets pointers to 0 since it is not the owner
99     delete fModuleGeometries;
100   }
101 }
102
103 //______________________________________________________________________________
104 AliMUONVGeometryBuilder& 
105 AliMUONVGeometryBuilder::operator = (const AliMUONVGeometryBuilder& rhs) 
106 {
107 // Protected assignement operator
108
109   // check assignement to self
110   if (this == &rhs) return *this;
111
112   AliFatal("Assignment operator is not implemented.");
113     
114   return *this;  
115 }
116
117 //
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
135 //______________________________________________________________________________
136 void 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
152     Int_t moduleId = AliMUONVGeometryDEIndexing::GetModuleId(detElemId);
153     AliMUONGeometryModule* geometry = GetGeometry(moduleId);
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 }     
173
174 //______________________________________________________________________________
175 TGeoHMatrix 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   if ( fReferenceFrame.IsIdentity() )
190      newTransform = transform;
191   else  {
192      newTransform
193        = AliMUONGeometryBuilder::Multiply( fReferenceFrame.Inverse(),
194                                            transform,
195                                            fReferenceFrame );  
196   }                             
197
198   return newTransform;   
199 }
200
201
202 //______________________________________________________________________________
203 void AliMUONVGeometryBuilder::FillData(Int_t moduleId, Int_t nofDetElements,
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 {
208 // Fill the transformation of the module.
209 // ---
210
211   moduleId--;
212       // Modules numbers in the file are starting from 1
213       
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       
223   GetGeometry(moduleId)
224     ->GetDEIndexing()->SetNofDetElements(nofDetElements);    
225   GetGeometry(moduleId)
226     ->SetTranslation(TGeoTranslation(xyz[0], xyz[1], xyz[2]));
227   GetGeometry(moduleId)
228     ->SetRotation(rotation2);
229 }                  
230   
231 //______________________________________________________________________________
232 void 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
241   // Module Id
242   Int_t moduleId 
243     = AliMUONVGeometryDEIndexing::GetModuleId(detElemId);
244
245   // Compose path
246   TString path = ComposePath(volName, copyNo);
247   
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);
254     
255   // Get detection element store
256   AliMUONGeometryStore* detElements = GetDetElements(moduleId);     
257
258   // Add detection element
259   detElements->Add(detElemId,
260      new AliMUONGeometryDetElement(detElemId, path, newCombiTransform)); 
261 }                  
262   
263 //______________________________________________________________________________
264 void 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
270   // Module Id
271   Int_t moduleId 
272     = AliMUONVGeometryDEIndexing::GetModuleId(detElemId);
273
274   // Get module sensitive volumes map
275   AliMUONGeometrySVMap* svMap = GetSVMap(moduleId);     
276
277   // Map the sensitive volume to detection element
278   svMap->Add(sensVolumePath, detElemId); 
279 }                  
280   
281 //______________________________________________________________________________
282 TString  AliMUONVGeometryBuilder::ReadData1(ifstream& in) const
283 {
284 // Reads and fills modules transformations from a file
285 // Returns true, if reading finished correctly.
286 // ---
287
288   TString key("CH");
289   while ( key == TString("CH") ) {
290     Int_t id, n;
291     Double_t  x, y, z;
292     Double_t  a1, a2, a3, a4, a5, a6;
293     TString dummy;
294   
295     in >> id;
296     in >> n;
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
316     FillData(id, n, x, y, z, a1, a2, a3, a4, a5, a6);
317     
318     // Go to next line
319     in >> key;
320   }
321   
322   return key;            
323 }
324
325 //______________________________________________________________________________
326 TString  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 //______________________________________________________________________________
377 TString  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 //______________________________________________________________________________
408 void AliMUONVGeometryBuilder::WriteTransform(ofstream& out,
409                                    const TGeoCombiTrans* transform) const
410 {
411 // Writes the transformations 
412 // after converting them into the specified reference frame
413 // ---
414
415   // Convert transform to the given reference frame
416   TGeoHMatrix newTransform;
417   if ( fReferenceFrame.IsIdentity() )
418      newTransform = *transform;
419   else  {
420      newTransform = AliMUONGeometryBuilder::Multiply( fReferenceFrame,
421                                                       *transform,
422                                                       fReferenceFrame.Inverse() ); 
423   }                             
424
425   out << "   pos: ";
426   const Double_t* xyz = newTransform.GetTranslation();
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: ";
432   const Double_t* rm = newTransform.GetRotationMatrix();
433   TGeoRotation rotation;
434   rotation.SetMatrix(const_cast<Double_t*>(rm));
435   Double_t a1, a2, a3, a4, a5, a6;
436   rotation.GetAngles(a1, a2, a3, a4, a5, a6);
437       
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 //______________________________________________________________________________
447 void AliMUONVGeometryBuilder::WriteData1(ofstream& out) const
448 {
449 // Writes modules transformations
450 // ---
451
452   for (Int_t i=0; i<fModuleGeometries->GetEntriesFast(); i++) {
453     AliMUONGeometryModule* geometry 
454       = (AliMUONGeometryModule*)fModuleGeometries->At(i);
455     const TGeoCombiTrans* transform 
456       = geometry->GetTransformation();    
457
458     out << "CH " 
459         << setw(4) << geometry->GetModuleId() + 1 << "  "
460         << setw(4) << geometry->GetDetElementStore()->GetNofEntries() << "  ";
461     
462     WriteTransform(out, transform);
463   }
464   out << endl;
465 }
466
467 //______________________________________________________________________________
468 void AliMUONVGeometryBuilder::WriteData2(ofstream& out) const
469 {
470 // Writes detection elements (envelopes) transformations
471 // ---
472
473
474   for (Int_t i=0; i<fModuleGeometries->GetEntriesFast(); i++) {
475     AliMUONGeometryModule* geometry 
476       = (AliMUONGeometryModule*)fModuleGeometries->At(i);
477     const TObjArray* envelopes 
478       = geometry->GetEnvelopeStore()->GetEnvelopes();    
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 //______________________________________________________________________________
501 void AliMUONVGeometryBuilder::WriteData3(ofstream& out) const
502 {
503 // Writes association of sensitive volumes and detection elements
504 // from the sensitive volume map
505 // ---
506
507   for (Int_t i=0; i<fModuleGeometries->GetEntriesFast(); i++) {
508     AliMUONGeometryModule* geometry 
509       = (AliMUONGeometryModule*)fModuleGeometries->At(i);
510     AliMUONGeometrySVMap* svMap
511       = geometry->GetSVMap();
512
513     svMap->WriteMap(out);
514     out << endl;  
515   }    
516 }
517
518 //
519 // protected methods
520 //
521
522 //______________________________________________________________________________
523 AliMUONGeometryModule*  
524 AliMUONVGeometryBuilder::GetGeometry(Int_t moduleId) const
525 {
526 // Returns the module geometry specified by moduleId
527 // ---
528
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;
535   }   
536   
537   return 0;
538 }  
539
540 //______________________________________________________________________________
541 AliMUONGeometryEnvelopeStore*  
542 AliMUONVGeometryBuilder::GetEnvelopes(Int_t moduleId) const
543 {
544 // Returns the envelope store of the module geometry specified by moduleId
545 // ---
546
547   AliMUONGeometryModule* geometry = GetGeometry(moduleId);
548   
549   if (!geometry) {
550     AliFatal(Form("Module geometry %d is not defined", moduleId)); 
551     return 0;
552   }
553   
554   return geometry->GetEnvelopeStore();
555 }  
556
557 //______________________________________________________________________________
558 AliMUONGeometryStore*  
559 AliMUONVGeometryBuilder::GetDetElements(Int_t moduleId) const
560 {
561 // Returns the detection elemnts store of the module geometry specified 
562 // by moduleId
563 // ---
564
565   AliMUONGeometryModule* geometry = GetGeometry(moduleId);
566   
567   if (!geometry) {
568     AliFatal(Form("Module geometry %d is not defined", moduleId)); 
569     return 0;
570   }
571   
572   return geometry->GetDetElementStore();
573 }  
574
575 //______________________________________________________________________________
576 AliMUONGeometrySVMap*  
577 AliMUONVGeometryBuilder::GetSVMap(Int_t moduleId) const
578 {
579 // Returns the transformation store of the module geometry specified by moduleId
580 // ---
581
582   AliMUONGeometryModule* geometry = GetGeometry(moduleId);
583   
584   if (!geometry) {
585     AliFatal(Form("Geometry %d is not defined", moduleId)); 
586     return 0;
587   }
588   
589   return geometry->GetSVMap();
590 }  
591
592 //
593 // public functions
594 //
595
596 //______________________________________________________________________________
597 void  AliMUONVGeometryBuilder::FillTransformations() const
598 {
599 // Fills transformations store from defined geometry.
600 // ---
601
602   for (Int_t i=0; i<fModuleGeometries->GetEntriesFast(); i++) {
603     AliMUONGeometryModule* geometry 
604       = (AliMUONGeometryModule*)fModuleGeometries->At(i);
605     const TObjArray* envelopes 
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()); 
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 
628       detElements->Add(detElemId,
629         new AliMUONGeometryDetElement(detElemId, path, *transform)); 
630     }  
631   }
632 }
633
634 //_____ _________________________________________________________________________
635 void  AliMUONVGeometryBuilder::RebuildSVMaps() const
636 {
637 // Clear the SV maps in memory and fill them from defined geometry.
638 // ---
639
640   for (Int_t i=0; i<fModuleGeometries->GetEntriesFast(); i++) {
641     AliMUONGeometryModule* geometry 
642       = (AliMUONGeometryModule*)fModuleGeometries->At(i);
643     
644     // Clear the map   
645     geometry->GetSVMap()->Clear();
646      
647     // Fill the map from geometry
648     const TObjArray* envelopes 
649       = geometry->GetEnvelopeStore()->GetEnvelopes();    
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");
659       if (geometry->GetMotherVolume() != "ALIC") {
660         path0 += "/";
661         path0 += ComposePath(geometry->GetMotherVolume(), 1);
662       }  
663       if (! geometry->IsVirtual() ) {
664         path0 += "/";
665         path0 += ComposePath(geometry->GetVolume(), 1);
666       }  
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 //______________________________________________________________________________
689 Bool_t  
690 AliMUONVGeometryBuilder::ReadTransformations() const
691 {
692 // Reads transformations from a file
693 // Returns true, if reading finished correctly.
694 // ---
695
696   // No reading
697   // if builder is not associated with any geometry module
698   if (fModuleGeometries->GetEntriesFast() == 0) return false;
699
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;   
709     AliFatal("File not found.");
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 {
721       AliFatal(Form("%s key not recognized",  key.Data()));
722       return false;
723     }
724   }     
725
726   return true;
727 }
728
729 //______________________________________________________________________________
730 Bool_t  AliMUONVGeometryBuilder::ReadSVMap() const
731 {
732 // Reads the sensitive volume from a file
733 // Returns true, if reading finished correctly.
734 // ---
735
736   // No reading
737   // if builder is not associated with any geometry module
738   if (fModuleGeometries->GetEntriesFast() == 0) return false;
739
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;   
749     AliFatal("File not found.");
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 {
759       AliFatal(Form("%s key not recognized",  key.Data()));
760       return false;
761     }
762   }     
763
764   return true;
765 }
766
767 //______________________________________________________________________________
768 Bool_t  
769 AliMUONVGeometryBuilder::WriteTransformations() const
770 {
771 // Writes transformations into a file
772 // Returns true, if writing finished correctly.
773 // ---
774
775   // No writing
776   // if builder is not associated with any geometry module
777   if (fModuleGeometries->GetEntriesFast() == 0) return false;
778
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;   
789     AliError("File not found.");
790     return false;
791   }
792 #if !defined (__DECCXX)
793   out.setf(std::ios::fixed);
794 #endif
795   WriteData1(out);
796   WriteData2(out);
797   
798   return true;
799 }  
800
801 //______________________________________________________________________________
802 Bool_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
808   // No writing
809   // if builder is not associated with any geometry module
810   if (fModuleGeometries->GetEntriesFast() == 0) return false;
811
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;   
822     AliError("File not found.");
823     return false;
824   }
825 #if !defined (__DECCXX)
826   out.setf(std::ios::fixed);
827 #endif  
828   if (rebuild)  RebuildSVMaps();
829
830   WriteData3(out);
831   
832   return true;
833 }  
834