]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONVGeometryBuilder.cxx
Added <assert.h> include
[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     = AliMUONGeometryBuilder::Multiply( fReferenceFrame.Inverse(),
190                                         transform,
191                                         fReferenceFrame );  
192
193   return newTransform;   
194 }
195
196
197 //______________________________________________________________________________
198 void AliMUONVGeometryBuilder::FillData(Int_t moduleId, Int_t nofDetElements,
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 {
203 // Fill the transformation of the module.
204 // ---
205
206   moduleId--;
207       // Modules numbers in the file are starting from 1
208       
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       
218   GetGeometry(moduleId)
219     ->GetDEIndexing()->SetNofDetElements(nofDetElements);    
220   GetGeometry(moduleId)
221     ->SetTranslation(TGeoTranslation(xyz[0], xyz[1], xyz[2]));
222   GetGeometry(moduleId)
223     ->SetRotation(rotation2);
224 }                  
225   
226 //______________________________________________________________________________
227 void 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
236   // Module Id
237   Int_t moduleId 
238     = AliMUONVGeometryDEIndexing::GetModuleId(detElemId);
239
240   // Compose path
241   TString path = ComposePath(volName, copyNo);
242   
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);
249     
250   // Get detection element store
251   AliMUONGeometryStore* detElements = GetDetElements(moduleId);     
252
253   // Add detection element
254   detElements->Add(detElemId,
255      new AliMUONGeometryDetElement(detElemId, path, newCombiTransform)); 
256 }                  
257   
258 //______________________________________________________________________________
259 void 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
265   // Module Id
266   Int_t moduleId 
267     = AliMUONVGeometryDEIndexing::GetModuleId(detElemId);
268
269   // Get module sensitive volumes map
270   AliMUONGeometrySVMap* svMap = GetSVMap(moduleId);     
271
272   // Map the sensitive volume to detection element
273   svMap->Add(sensVolumePath, detElemId); 
274 }                  
275   
276 //______________________________________________________________________________
277 TString  AliMUONVGeometryBuilder::ReadData1(ifstream& in) const
278 {
279 // Reads and fills modules transformations from a file
280 // Returns true, if reading finished correctly.
281 // ---
282
283   TString key("CH");
284   while ( key == TString("CH") ) {
285     Int_t id, n;
286     Double_t  x, y, z;
287     Double_t  a1, a2, a3, a4, a5, a6;
288     TString dummy;
289   
290     in >> id;
291     in >> n;
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
311     FillData(id, n, x, y, z, a1, a2, a3, a4, a5, a6);
312     
313     // Go to next line
314     in >> key;
315   }
316   
317   return key;            
318 }
319
320 //______________________________________________________________________________
321 TString  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 //______________________________________________________________________________
372 TString  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 //______________________________________________________________________________
403 void AliMUONVGeometryBuilder::WriteTransform(ofstream& out,
404                                    const TGeoCombiTrans* transform) const
405 {
406 // Writes the transformations 
407 // after converting them into the specified reference frame
408 // ---
409
410   // Convert transform to the given reference frame
411   TGeoHMatrix newTransform
412     = fReferenceFrame * (*transform) * (fReferenceFrame.Inverse());  
413
414   out << "   pos: ";
415   const Double_t* xyz = newTransform.GetTranslation();
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: ";
421   const Double_t* rm = newTransform.GetRotationMatrix();
422   TGeoRotation rotation;
423   rotation.SetMatrix(const_cast<Double_t*>(rm));
424   Double_t a1, a2, a3, a4, a5, a6;
425   rotation.GetAngles(a1, a2, a3, a4, a5, a6);
426       
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 //______________________________________________________________________________
436 void AliMUONVGeometryBuilder::WriteData1(ofstream& out) const
437 {
438 // Writes modules transformations
439 // ---
440
441   for (Int_t i=0; i<fModuleGeometries->GetEntriesFast(); i++) {
442     AliMUONGeometryModule* geometry 
443       = (AliMUONGeometryModule*)fModuleGeometries->At(i);
444     const TGeoCombiTrans* transform 
445       = geometry->GetTransformation();    
446
447     out << "CH " 
448         << setw(4) << geometry->GetModuleId() + 1 << "  "
449         << setw(4) << geometry->GetDetElementStore()->GetNofEntries() << "  ";
450     
451     WriteTransform(out, transform);
452   }
453   out << endl;
454 }
455
456 //______________________________________________________________________________
457 void AliMUONVGeometryBuilder::WriteData2(ofstream& out) const
458 {
459 // Writes detection elements (envelopes) transformations
460 // ---
461
462
463   for (Int_t i=0; i<fModuleGeometries->GetEntriesFast(); i++) {
464     AliMUONGeometryModule* geometry 
465       = (AliMUONGeometryModule*)fModuleGeometries->At(i);
466     const TObjArray* envelopes 
467       = geometry->GetEnvelopeStore()->GetEnvelopes();    
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 //______________________________________________________________________________
490 void AliMUONVGeometryBuilder::WriteData3(ofstream& out) const
491 {
492 // Writes association of sensitive volumes and detection elements
493 // from the sensitive volume map
494 // ---
495
496   for (Int_t i=0; i<fModuleGeometries->GetEntriesFast(); i++) {
497     AliMUONGeometryModule* geometry 
498       = (AliMUONGeometryModule*)fModuleGeometries->At(i);
499     AliMUONGeometrySVMap* svMap
500       = geometry->GetSVMap();
501
502     svMap->WriteMap(out);
503     out << endl;  
504   }    
505 }
506
507 //
508 // protected methods
509 //
510
511 //______________________________________________________________________________
512 AliMUONGeometryModule*  
513 AliMUONVGeometryBuilder::GetGeometry(Int_t moduleId) const
514 {
515 // Returns the module geometry specified by moduleId
516 // ---
517
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;
524   }   
525   
526   return 0;
527 }  
528
529 //______________________________________________________________________________
530 AliMUONGeometryEnvelopeStore*  
531 AliMUONVGeometryBuilder::GetEnvelopes(Int_t moduleId) const
532 {
533 // Returns the envelope store of the module geometry specified by moduleId
534 // ---
535
536   AliMUONGeometryModule* geometry = GetGeometry(moduleId);
537   
538   if (!geometry) {
539     AliFatal(Form("Module geometry %d is not defined", moduleId)); 
540     return 0;
541   }
542   
543   return geometry->GetEnvelopeStore();
544 }  
545
546 //______________________________________________________________________________
547 AliMUONGeometryStore*  
548 AliMUONVGeometryBuilder::GetDetElements(Int_t moduleId) const
549 {
550 // Returns the detection elemnts store of the module geometry specified 
551 // by moduleId
552 // ---
553
554   AliMUONGeometryModule* geometry = GetGeometry(moduleId);
555   
556   if (!geometry) {
557     AliFatal(Form("Module geometry %d is not defined", moduleId)); 
558     return 0;
559   }
560   
561   return geometry->GetDetElementStore();
562 }  
563
564 //______________________________________________________________________________
565 AliMUONGeometrySVMap*  
566 AliMUONVGeometryBuilder::GetSVMap(Int_t moduleId) const
567 {
568 // Returns the transformation store of the module geometry specified by moduleId
569 // ---
570
571   AliMUONGeometryModule* geometry = GetGeometry(moduleId);
572   
573   if (!geometry) {
574     AliFatal(Form("Geometry %d is not defined", moduleId)); 
575     return 0;
576   }
577   
578   return geometry->GetSVMap();
579 }  
580
581 //
582 // public functions
583 //
584
585 //______________________________________________________________________________
586 void  AliMUONVGeometryBuilder::FillTransformations() const
587 {
588 // Fills transformations store from defined geometry.
589 // ---
590
591   for (Int_t i=0; i<fModuleGeometries->GetEntriesFast(); i++) {
592     AliMUONGeometryModule* geometry 
593       = (AliMUONGeometryModule*)fModuleGeometries->At(i);
594     const TObjArray* envelopes 
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()); 
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 
617       detElements->Add(detElemId,
618         new AliMUONGeometryDetElement(detElemId, path, *transform)); 
619     }  
620   }
621 }
622
623 //_____ _________________________________________________________________________
624 void  AliMUONVGeometryBuilder::RebuildSVMaps() const
625 {
626 // Clear the SV maps in memory and fill them from defined geometry.
627 // ---
628
629   for (Int_t i=0; i<fModuleGeometries->GetEntriesFast(); i++) {
630     AliMUONGeometryModule* geometry 
631       = (AliMUONGeometryModule*)fModuleGeometries->At(i);
632     
633     // Clear the map   
634     geometry->GetSVMap()->Clear();
635      
636     // Fill the map from geometry
637     const TObjArray* envelopes 
638       = geometry->GetEnvelopeStore()->GetEnvelopes();    
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");
648       if (geometry->GetMotherVolume() != "ALIC") {
649         path0 += "/";
650         path0 += ComposePath(geometry->GetMotherVolume(), 1);
651       }  
652       if (! geometry->IsVirtual() ) {
653         path0 += "/";
654         path0 += ComposePath(geometry->GetVolume(), 1);
655       }  
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 //______________________________________________________________________________
678 Bool_t  
679 AliMUONVGeometryBuilder::ReadTransformations() const
680 {
681 // Reads transformations from a file
682 // Returns true, if reading finished correctly.
683 // ---
684
685   // No reading
686   // if builder is not associated with any geometry module
687   if (fModuleGeometries->GetEntriesFast() == 0) return false;
688
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;   
698     AliFatal("File not found.");
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 {
710       AliFatal(Form("%s key not recognized",  key.Data()));
711       return false;
712     }
713   }     
714
715   return true;
716 }
717
718 //______________________________________________________________________________
719 Bool_t  AliMUONVGeometryBuilder::ReadSVMap() const
720 {
721 // Reads the sensitive volume from a file
722 // Returns true, if reading finished correctly.
723 // ---
724
725   // No reading
726   // if builder is not associated with any geometry module
727   if (fModuleGeometries->GetEntriesFast() == 0) return false;
728
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;   
738     AliFatal("File not found.");
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 {
748       AliFatal(Form("%s key not recognized",  key.Data()));
749       return false;
750     }
751   }     
752
753   return true;
754 }
755
756 //______________________________________________________________________________
757 Bool_t  
758 AliMUONVGeometryBuilder::WriteTransformations() const
759 {
760 // Writes transformations into a file
761 // Returns true, if writing finished correctly.
762 // ---
763
764   // No writing
765   // if builder is not associated with any geometry module
766   if (fModuleGeometries->GetEntriesFast() == 0) return false;
767
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;   
778     AliError("File not found.");
779     return false;
780   }
781 #if !defined (__DECCXX)
782   out.setf(std::ios::fixed);
783 #endif
784   WriteData1(out);
785   WriteData2(out);
786   
787   return true;
788 }  
789
790 //______________________________________________________________________________
791 Bool_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
797   // No writing
798   // if builder is not associated with any geometry module
799   if (fModuleGeometries->GetEntriesFast() == 0) return false;
800
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;   
811     AliError("File not found.");
812     return false;
813   }
814 #if !defined (__DECCXX)
815   out.setf(std::ios::fixed);
816 #endif  
817   if (rebuild)  RebuildSVMaps();
818
819   WriteData3(out);
820   
821   return true;
822 }  
823