ROOT logo
/**************************************************************************
 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
 *      SigmaEffect_thetadegrees                                                                  *
 * Author: The ALICE Off-line Project.                                    *
 * Contributors are mentioned in the code where appropriate.              *
 *                                                                        *
 * Permission to use, copy, modify and distribute this software and its   *
 * documentation strictly for non-commercial purposes is hereby granted   *
 * without fee, provided that the above copyright notice appears in all   *
 * copies and that both the copyright notice and this permission notice   *
 * appear in the supporting documentation. The authors make no claims     *
 * about the suitability of this software for any purpeateose. It is      *
 * provided "as is" without express or implied warranty.                  *
 **************************************************************************/

// $Id$

//-----------------------------------------------------------------------------
// Class AliMUONGeometry
// ----------------------------
// Manager class for geometry construction via geometry builders.
// Author: Ivana Hrivnacova, IPN Orsay
//-----------------------------------------------------------------------------

#include "AliMUONGeometry.h"
#include "AliMUONGeometryTransformer.h"
#include "AliMUONGeometryModule.h"
#include "AliMUONStringIntMap.h"

#include "AliMpDEManager.h"

#include "AliLog.h"

#include <TObjArray.h>
#include <Riostream.h>
#include <TSystem.h>

#include <iostream>

using std::cerr;
using std::endl;
using std::ios;
/// \cond CLASSIMP
ClassImp(AliMUONGeometry)
/// \endcond
 
//______________________________________________________________________________
AliMUONGeometry::AliMUONGeometry(Bool_t isOwner)
  : TObject(),
    fModules(0),
    fTransformer(0)
    
{
/// Standard constructor

  // Create array for geometry modules
  fModules = new TObjArray();
  fModules->SetOwner(isOwner);
  
  // Geometry parametrisation
  fTransformer = new AliMUONGeometryTransformer();
  fTransformer->SetOwner(false); 
}

//______________________________________________________________________________
AliMUONGeometry::AliMUONGeometry() 
  : TObject(),
    fModules(0),
    fTransformer(0)
{
/// Default constructor
} 

//______________________________________________________________________________
AliMUONGeometry::~AliMUONGeometry()
{
/// Destructor

  delete fModules;
  delete fTransformer;
}

//
// private methods
//

//______________________________________________________________________________
TString  AliMUONGeometry::ComposePath(const TString& volName, 
                                       Int_t copyNo) const
{
/// Compose path from given volName and copyNo

  TString path(volName);
  path += ".";
  path += copyNo;
  
  return path;
}  

//______________________________________________________________________________
void AliMUONGeometry::FillData3(const TString& sensVolumePath, 
                                Int_t detElemId)
{
/// Fill the mapping of the sensitive volume path to the detection element.

  // Module Id
  Int_t moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
    
  // Get module
  AliMUONGeometryModule* module 
    = (AliMUONGeometryModule*)fModules->At(moduleId);
    
  if ( !module ) {
    AliWarningStream()
      << "Geometry module for det element " << detElemId << " not defined."
      << endl;
    return;
  }    
    
  // Get module sensitive volumes map
  AliMUONStringIntMap* svMap = module->GetSVMap();     

  // Map the sensitive volume to detection element
  svMap->Add(sensVolumePath, detElemId); 
}		   
  
//______________________________________________________________________________
TString  AliMUONGeometry::ReadData3(ifstream& in)
{
/// Read SV maps from a file.
/// Return true, if reading finished correctly.

  TString key("SV");
  while ( key == TString("SV") ) {

    // Input data
    TString   volumePath;
    Int_t     detElemId;
  
    in >> volumePath;
    in >> detElemId;

    //cout << "volumePath=" << volumePath << "  "
    //	 << "detElemId=" << detElemId 	 
    //     << endl;   

    // Fill data
    FillData3(volumePath, detElemId); 
     
    // Go to next line
    in >> key;
  } 
  
  return key;
}

//______________________________________________________________________________
void AliMUONGeometry::WriteData3(ofstream& out) const
{
/// Write association of sensitive volumes and detection elements
/// from the sensitive volume map

  for (Int_t i=0; i<fModules->GetEntriesFast(); i++) {
    AliMUONGeometryModule* geometry 
      = (AliMUONGeometryModule*)fModules->At(i);
    AliMUONStringIntMap* svMap
      = geometry->GetSVMap();

    svMap->Print("SV", out);
    out << endl;  
  }    
}

//
// public functions
//

//_____________________________________________________________________________
void AliMUONGeometry::AddModule(AliMUONGeometryModule* module)
{
/// Add the geometry module to the array

  fModules->Add(module);

  if (module)
    fTransformer->AddModuleTransformer(module->GetTransformer());
}

//______________________________________________________________________________
Bool_t  
AliMUONGeometry::ReadSVMap(const TString& fileName)
{
/// Read the sensitive volume maps from a file.
/// Return true, if reading finished correctly.

  // No reading
  // if builder is not associated with any geometry module
  if (fModules->GetEntriesFast() == 0) return false;

  // File path
  TString filePath = gSystem->Getenv("ALICE_ROOT");
  filePath += "/MUON/data/";
  filePath += fileName;
  
  // Open input file
  ifstream in(filePath, ios::in);
  if (!in) {
    cerr << filePath << endl;	
    AliFatal("File not found.");
    return false;
  }

  TString key;
  in >> key;
  while ( !in.eof() ) {
    if (key == TString("SV")) 
      key = ReadData3(in);
    else {
      AliFatal(Form("%s key not recognized",  key.Data()));
      return false;
    }
  }     

  return true;
}

//______________________________________________________________________________
Bool_t  
AliMUONGeometry::WriteSVMap(const TString& fileName) const
{
/// Write sensitive volume map into a file.
/// Return true, if writing finished correctly.

  // No writing
  // if builder is not associated with any geometry module
  if (fModules->GetEntriesFast() == 0) return false;

  // File path
  TString filePath = gSystem->Getenv("ALICE_ROOT");
  filePath += "/MUON/data/";
  filePath += fileName;
  
  // Open input file
  ofstream out(filePath, ios::out);
  if (!out) {
    cerr << filePath << endl;	
    AliError("File not found.");
    return false;
  }
#if !defined (__DECCXX)
  out.setf(std::ios::fixed);
#endif  
  WriteData3(out);
  
  return true;
}  

//_____________________________________________________________________________
const AliMUONGeometryModule* 
AliMUONGeometry::GetModule(Int_t index, Bool_t warn) const
{
/// Return the geometry module specified by index

  if (index < 0 || index >= fModules->GetEntriesFast()) {
    if (warn) {
      AliWarningStream() 
        << "Index: " << index << " outside limits" << std::endl;
    }			 
    return 0;  
  }  

  return (const AliMUONGeometryModule*) fModules->At(index);
}    

//_____________________________________________________________________________
const AliMUONGeometryModule* 
AliMUONGeometry::GetModuleByDEId(Int_t detElemId, Bool_t warn) const
{
/// Return the geometry module specified by detElemId

  // Get module index
  Int_t index = AliMpDEManager::GetGeomModuleId(detElemId);

  return GetModule(index, warn);
}    
 AliMUONGeometry.cxx:1
 AliMUONGeometry.cxx:2
 AliMUONGeometry.cxx:3
 AliMUONGeometry.cxx:4
 AliMUONGeometry.cxx:5
 AliMUONGeometry.cxx:6
 AliMUONGeometry.cxx:7
 AliMUONGeometry.cxx:8
 AliMUONGeometry.cxx:9
 AliMUONGeometry.cxx:10
 AliMUONGeometry.cxx:11
 AliMUONGeometry.cxx:12
 AliMUONGeometry.cxx:13
 AliMUONGeometry.cxx:14
 AliMUONGeometry.cxx:15
 AliMUONGeometry.cxx:16
 AliMUONGeometry.cxx:17
 AliMUONGeometry.cxx:18
 AliMUONGeometry.cxx:19
 AliMUONGeometry.cxx:20
 AliMUONGeometry.cxx:21
 AliMUONGeometry.cxx:22
 AliMUONGeometry.cxx:23
 AliMUONGeometry.cxx:24
 AliMUONGeometry.cxx:25
 AliMUONGeometry.cxx:26
 AliMUONGeometry.cxx:27
 AliMUONGeometry.cxx:28
 AliMUONGeometry.cxx:29
 AliMUONGeometry.cxx:30
 AliMUONGeometry.cxx:31
 AliMUONGeometry.cxx:32
 AliMUONGeometry.cxx:33
 AliMUONGeometry.cxx:34
 AliMUONGeometry.cxx:35
 AliMUONGeometry.cxx:36
 AliMUONGeometry.cxx:37
 AliMUONGeometry.cxx:38
 AliMUONGeometry.cxx:39
 AliMUONGeometry.cxx:40
 AliMUONGeometry.cxx:41
 AliMUONGeometry.cxx:42
 AliMUONGeometry.cxx:43
 AliMUONGeometry.cxx:44
 AliMUONGeometry.cxx:45
 AliMUONGeometry.cxx:46
 AliMUONGeometry.cxx:47
 AliMUONGeometry.cxx:48
 AliMUONGeometry.cxx:49
 AliMUONGeometry.cxx:50
 AliMUONGeometry.cxx:51
 AliMUONGeometry.cxx:52
 AliMUONGeometry.cxx:53
 AliMUONGeometry.cxx:54
 AliMUONGeometry.cxx:55
 AliMUONGeometry.cxx:56
 AliMUONGeometry.cxx:57
 AliMUONGeometry.cxx:58
 AliMUONGeometry.cxx:59
 AliMUONGeometry.cxx:60
 AliMUONGeometry.cxx:61
 AliMUONGeometry.cxx:62
 AliMUONGeometry.cxx:63
 AliMUONGeometry.cxx:64
 AliMUONGeometry.cxx:65
 AliMUONGeometry.cxx:66
 AliMUONGeometry.cxx:67
 AliMUONGeometry.cxx:68
 AliMUONGeometry.cxx:69
 AliMUONGeometry.cxx:70
 AliMUONGeometry.cxx:71
 AliMUONGeometry.cxx:72
 AliMUONGeometry.cxx:73
 AliMUONGeometry.cxx:74
 AliMUONGeometry.cxx:75
 AliMUONGeometry.cxx:76
 AliMUONGeometry.cxx:77
 AliMUONGeometry.cxx:78
 AliMUONGeometry.cxx:79
 AliMUONGeometry.cxx:80
 AliMUONGeometry.cxx:81
 AliMUONGeometry.cxx:82
 AliMUONGeometry.cxx:83
 AliMUONGeometry.cxx:84
 AliMUONGeometry.cxx:85
 AliMUONGeometry.cxx:86
 AliMUONGeometry.cxx:87
 AliMUONGeometry.cxx:88
 AliMUONGeometry.cxx:89
 AliMUONGeometry.cxx:90
 AliMUONGeometry.cxx:91
 AliMUONGeometry.cxx:92
 AliMUONGeometry.cxx:93
 AliMUONGeometry.cxx:94
 AliMUONGeometry.cxx:95
 AliMUONGeometry.cxx:96
 AliMUONGeometry.cxx:97
 AliMUONGeometry.cxx:98
 AliMUONGeometry.cxx:99
 AliMUONGeometry.cxx:100
 AliMUONGeometry.cxx:101
 AliMUONGeometry.cxx:102
 AliMUONGeometry.cxx:103
 AliMUONGeometry.cxx:104
 AliMUONGeometry.cxx:105
 AliMUONGeometry.cxx:106
 AliMUONGeometry.cxx:107
 AliMUONGeometry.cxx:108
 AliMUONGeometry.cxx:109
 AliMUONGeometry.cxx:110
 AliMUONGeometry.cxx:111
 AliMUONGeometry.cxx:112
 AliMUONGeometry.cxx:113
 AliMUONGeometry.cxx:114
 AliMUONGeometry.cxx:115
 AliMUONGeometry.cxx:116
 AliMUONGeometry.cxx:117
 AliMUONGeometry.cxx:118
 AliMUONGeometry.cxx:119
 AliMUONGeometry.cxx:120
 AliMUONGeometry.cxx:121
 AliMUONGeometry.cxx:122
 AliMUONGeometry.cxx:123
 AliMUONGeometry.cxx:124
 AliMUONGeometry.cxx:125
 AliMUONGeometry.cxx:126
 AliMUONGeometry.cxx:127
 AliMUONGeometry.cxx:128
 AliMUONGeometry.cxx:129
 AliMUONGeometry.cxx:130
 AliMUONGeometry.cxx:131
 AliMUONGeometry.cxx:132
 AliMUONGeometry.cxx:133
 AliMUONGeometry.cxx:134
 AliMUONGeometry.cxx:135
 AliMUONGeometry.cxx:136
 AliMUONGeometry.cxx:137
 AliMUONGeometry.cxx:138
 AliMUONGeometry.cxx:139
 AliMUONGeometry.cxx:140
 AliMUONGeometry.cxx:141
 AliMUONGeometry.cxx:142
 AliMUONGeometry.cxx:143
 AliMUONGeometry.cxx:144
 AliMUONGeometry.cxx:145
 AliMUONGeometry.cxx:146
 AliMUONGeometry.cxx:147
 AliMUONGeometry.cxx:148
 AliMUONGeometry.cxx:149
 AliMUONGeometry.cxx:150
 AliMUONGeometry.cxx:151
 AliMUONGeometry.cxx:152
 AliMUONGeometry.cxx:153
 AliMUONGeometry.cxx:154
 AliMUONGeometry.cxx:155
 AliMUONGeometry.cxx:156
 AliMUONGeometry.cxx:157
 AliMUONGeometry.cxx:158
 AliMUONGeometry.cxx:159
 AliMUONGeometry.cxx:160
 AliMUONGeometry.cxx:161
 AliMUONGeometry.cxx:162
 AliMUONGeometry.cxx:163
 AliMUONGeometry.cxx:164
 AliMUONGeometry.cxx:165
 AliMUONGeometry.cxx:166
 AliMUONGeometry.cxx:167
 AliMUONGeometry.cxx:168
 AliMUONGeometry.cxx:169
 AliMUONGeometry.cxx:170
 AliMUONGeometry.cxx:171
 AliMUONGeometry.cxx:172
 AliMUONGeometry.cxx:173
 AliMUONGeometry.cxx:174
 AliMUONGeometry.cxx:175
 AliMUONGeometry.cxx:176
 AliMUONGeometry.cxx:177
 AliMUONGeometry.cxx:178
 AliMUONGeometry.cxx:179
 AliMUONGeometry.cxx:180
 AliMUONGeometry.cxx:181
 AliMUONGeometry.cxx:182
 AliMUONGeometry.cxx:183
 AliMUONGeometry.cxx:184
 AliMUONGeometry.cxx:185
 AliMUONGeometry.cxx:186
 AliMUONGeometry.cxx:187
 AliMUONGeometry.cxx:188
 AliMUONGeometry.cxx:189
 AliMUONGeometry.cxx:190
 AliMUONGeometry.cxx:191
 AliMUONGeometry.cxx:192
 AliMUONGeometry.cxx:193
 AliMUONGeometry.cxx:194
 AliMUONGeometry.cxx:195
 AliMUONGeometry.cxx:196
 AliMUONGeometry.cxx:197
 AliMUONGeometry.cxx:198
 AliMUONGeometry.cxx:199
 AliMUONGeometry.cxx:200
 AliMUONGeometry.cxx:201
 AliMUONGeometry.cxx:202
 AliMUONGeometry.cxx:203
 AliMUONGeometry.cxx:204
 AliMUONGeometry.cxx:205
 AliMUONGeometry.cxx:206
 AliMUONGeometry.cxx:207
 AliMUONGeometry.cxx:208
 AliMUONGeometry.cxx:209
 AliMUONGeometry.cxx:210
 AliMUONGeometry.cxx:211
 AliMUONGeometry.cxx:212
 AliMUONGeometry.cxx:213
 AliMUONGeometry.cxx:214
 AliMUONGeometry.cxx:215
 AliMUONGeometry.cxx:216
 AliMUONGeometry.cxx:217
 AliMUONGeometry.cxx:218
 AliMUONGeometry.cxx:219
 AliMUONGeometry.cxx:220
 AliMUONGeometry.cxx:221
 AliMUONGeometry.cxx:222
 AliMUONGeometry.cxx:223
 AliMUONGeometry.cxx:224
 AliMUONGeometry.cxx:225
 AliMUONGeometry.cxx:226
 AliMUONGeometry.cxx:227
 AliMUONGeometry.cxx:228
 AliMUONGeometry.cxx:229
 AliMUONGeometry.cxx:230
 AliMUONGeometry.cxx:231
 AliMUONGeometry.cxx:232
 AliMUONGeometry.cxx:233
 AliMUONGeometry.cxx:234
 AliMUONGeometry.cxx:235
 AliMUONGeometry.cxx:236
 AliMUONGeometry.cxx:237
 AliMUONGeometry.cxx:238
 AliMUONGeometry.cxx:239
 AliMUONGeometry.cxx:240
 AliMUONGeometry.cxx:241
 AliMUONGeometry.cxx:242
 AliMUONGeometry.cxx:243
 AliMUONGeometry.cxx:244
 AliMUONGeometry.cxx:245
 AliMUONGeometry.cxx:246
 AliMUONGeometry.cxx:247
 AliMUONGeometry.cxx:248
 AliMUONGeometry.cxx:249
 AliMUONGeometry.cxx:250
 AliMUONGeometry.cxx:251
 AliMUONGeometry.cxx:252
 AliMUONGeometry.cxx:253
 AliMUONGeometry.cxx:254
 AliMUONGeometry.cxx:255
 AliMUONGeometry.cxx:256
 AliMUONGeometry.cxx:257
 AliMUONGeometry.cxx:258
 AliMUONGeometry.cxx:259
 AliMUONGeometry.cxx:260
 AliMUONGeometry.cxx:261
 AliMUONGeometry.cxx:262
 AliMUONGeometry.cxx:263
 AliMUONGeometry.cxx:264
 AliMUONGeometry.cxx:265
 AliMUONGeometry.cxx:266
 AliMUONGeometry.cxx:267
 AliMUONGeometry.cxx:268
 AliMUONGeometry.cxx:269
 AliMUONGeometry.cxx:270
 AliMUONGeometry.cxx:271
 AliMUONGeometry.cxx:272
 AliMUONGeometry.cxx:273
 AliMUONGeometry.cxx:274
 AliMUONGeometry.cxx:275
 AliMUONGeometry.cxx:276
 AliMUONGeometry.cxx:277
 AliMUONGeometry.cxx:278
 AliMUONGeometry.cxx:279
 AliMUONGeometry.cxx:280
 AliMUONGeometry.cxx:281
 AliMUONGeometry.cxx:282
 AliMUONGeometry.cxx:283
 AliMUONGeometry.cxx:284
 AliMUONGeometry.cxx:285