]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - AliGeant4/AliModulesComposition.cxx
Bug fix reported by Jiri. Make atoi input zero terminated in StepManager()
[u/mrichter/AliRoot.git] / AliGeant4 / AliModulesComposition.cxx
index c81460d7351690925a10258127423af906321db5..1f07bc9360f1d03f16a08ecbfa6e60ad0b3ed526 100644 (file)
@@ -1,54 +1,51 @@
 // $Id$
 // Category: geometry
 //
+// Author: I. Hrivnacova
+//
+// Class AliModulesComposition
+// ---------------------------
 // See the class description in the header file.
 
 #include "AliModulesComposition.h"
-#include "AliModulesCompositionMessenger.h"
-#include "AliSingleModuleConstruction.h"
-#include "AliMoreModulesConstruction.h"
-#include "AliDetSwitch.h"
+#include "AliModuleConstruction.h"
 #include "AliMagneticField.h"
 #include "AliGlobals.h"
+#include "AliFiles.h"
+#include "AliModule.h"
 
-#include "TG4XMLGeometryGenerator.h"
+#include "TG4GeometryManager.h"
 
 #include <G4Material.hh>
-#include <G4VPhysicalVolume.hh>
 
+//_____________________________________________________________________________
 AliModulesComposition::AliModulesComposition()
-  : fAllLVSensitive(false),
-    fForceAllLVSensitive(false),
+  : AliVerbose("modulesComposition"),
     fReadGeometry(false),
     fWriteGeometry(false),
-    fMagneticField(0)    
-{
+    fMagneticField(0),
+    fMessenger(this) {
 //
-  fMoreModulesConstruction = new AliMoreModulesConstruction();
-  fMessenger = new AliModulesCompositionMessenger(this);
 }
 
+//_____________________________________________________________________________
 AliModulesComposition::AliModulesComposition(const AliModulesComposition& right)
+  : AliVerbose("modulesComposition"),
+    fMessenger(this)
 {
 //
   AliGlobals::Exception("AliModulesComposition is protected from copying.");  
 }
 
+//_____________________________________________________________________________
 AliModulesComposition::~AliModulesComposition() {
 //   
-  delete fMoreModulesConstruction;
   delete fMagneticField;
-  delete fMessenger; 
-  
-  // destroy det switch vector
-  fDetSwitchVector.clearAndDestroy();  
-  
-  // destroy det construction vector
-  fModuleConstructionVector.clearAndDestroy();
 }
 
 // operators
 
+//_____________________________________________________________________________
 AliModulesComposition& 
 AliModulesComposition::operator=(const AliModulesComposition& right)
 {
@@ -60,276 +57,187 @@ AliModulesComposition::operator=(const AliModulesComposition& right)
   return *this;  
 }    
           
-// protected methods
+//
+// private methods
+//
 
-void AliModulesComposition::AddDetSwitch(AliDetSwitch* detSwitch)
-{
-// Adds detSwitch to the detSwitch vector.
+//_____________________________________________________________________________
+void AliModulesComposition::Configure()
+{ 
+// Executes the detectors setup Root macros
+// (extracted from AliRoot Config.C) and
+// G4 macros.
 // ---
+  
+  // number of modules
+  G4int nofModules = fModuleConstructionVector.size();
 
-  fDetSwitchVector.insert(detSwitch);
-  fMessenger->SetCandidates();
-}  
+  if (nofModules == 0) {
+    AliGlobals::Warning(
+      "AliModulesComposition::Configure: No modules are defined.");
+    return;  
+  }
   
-void AliModulesComposition::AddSingleModuleConstruction(G4String moduleName, 
-                               G4int version, AliModuleType moduleType)
-{
-// Adds SingleModuleConstruction.
-// ---
+  for (G4int i=0; i<nofModules; i++) 
+    fModuleConstructionVector[i]->Configure();
+}      
 
-  AliSingleModuleConstruction* moduleConstruction
-    = new AliSingleModuleConstruction(moduleName, version, moduleType);
-  fModuleConstructionVector.insert(moduleConstruction);
-}  
-                 
-void AliModulesComposition::AddMoreModuleConstruction(G4String moduleName, 
-                               G4int version, AliModuleType moduleType)
-{
-// Adds module to MoreModulesConstruction (construction of dependent
-// modules.)
-// ---
 
-  fMoreModulesConstruction->AddModule(moduleName, version, moduleType);
-}  
-                                 
-void AliModulesComposition::ConstructModules()
-{
-// Construct geometry of all modules (both standalone and dependent.)
-// ---
+//_____________________________________________________________________________
+void AliModulesComposition::CreateG4Geometry()
+{ 
+// Constructs geometry.
+// G3 tables are process for all modules alltogether.
+// --
 
-  // set common options
-  SetReadGeometryToModules(fReadGeometry);
-  SetWriteGeometryToModules(fWriteGeometry);
-  SetAllLVSensitiveToModules(fAllLVSensitive);
-     // common setAllLVSensitive is overridden by Config.in
-     // macro
+  // number of modules
+  G4int nofModules = fModuleConstructionVector.size();
+
+  if (nofModules == 0) {
+    AliGlobals::Warning(
+      "AliModulesComposition::CreateG4Geometry: No modules are defined.");
+    return;  
+  }
+
+  // get geometry manager
+  TG4GeometryManager* pGeometryManager = TG4GeometryManager::Instance();
+
+  G4int i;
+  for (i=0; i<nofModules; i++) {
+
+    // fModuleConstructionVector[i]->Configure(files);
   
-  // one module constructions
-  G4int nofDets = fModuleConstructionVector.entries();
-  for (G4int i=0; i<nofDets; i++) {
-    fModuleConstructionVector[i]->Configure();
-  }  
-  if (fForceAllLVSensitive)
-    SetAllLVSensitiveToModules(fForceAllLVSensitive);
-      // override the setAllLVSensitive by Config.in macro
-      // if required
-     
-  for (G4int i=0; i<nofDets; i++) {
-    G4cout << "Module " << fModuleConstructionVector[i]->GetDetName()
-           << " will be constructed now." << G4endl;
-    fModuleConstructionVector[i]->Construct();
-  }  
-    
-  // more modules construction
-  G4int nofModules = fMoreModulesConstruction->GetNofModules();
-  if (nofModules>0) {
-    fMoreModulesConstruction->Configure();
-    if (fForceAllLVSensitive)
-      SetAllLVSensitiveToModules(fForceAllLVSensitive);
-        // override the setAllLVSensitive by Config.in macro
-        // if required
-
-    G4cout << "Dependent modules will be constructed now." << G4endl;
-    fMoreModulesConstruction->Construct();
+    // register module name in the name map
+    AliModule* module = fModuleConstructionVector[i]->GetAliModule();
+    pGeometryManager->SetMapSecond(module->GetName()); 
+
+    G4bool readGeometry = fModuleConstructionVector[i]->GetReadGeometry();
+    G4bool writeGeometry = fModuleConstructionVector[i]->GetWriteGeometry();
+    G4String dataFilePath = fModuleConstructionVector[i]->GetDataFilePath();
+
+    if (readGeometry) {
+      // TG4GeometryManager uses g3tog4 methods for reading
+      // g3calls.dat files - as these methods do not fill name map
+      // they cannot be used for constructing more modules
+      // together
+      //
+      // pGeometryManager->SetWriteGeometry(false);
+      // pGeometryManager->ReadG3Geometry(dataFilePath);
+       
+      G4String text = "AliModulesComposition::Construct - Limitation:\n";
+      text = text + "    Reading g3calls.dat is not implemented.";
+      AliGlobals::Exception(text);
+    }
+    else {                 
+      // set geometry output stream for this module
+      pGeometryManager->SetWriteGeometry(writeGeometry);
+      if (writeGeometry) 
+        pGeometryManager->OpenOutFile(dataFilePath);
+        
+      // create geometry from AliRoot
+      
+      // construct materials
+      module->CreateMaterials();   
+
+      // construct G3 geometry
+      module->CreateGeometry();
+      
+      if (writeGeometry) 
+        pGeometryManager->CloseOutFile();
+    }  
   }  
-}  
+  
+  // construct G4 geometry
+  pGeometryManager->CreateG4Geometry();
+
+  // print name map
+  // pGeometryManager->PrintNameMap();
+
+/*
+  // moved to AliSDConstruction
+  // to be performed after Init  (required for MUON)
+  
+  for (i=0; i<nofModules; i++) {
+
+    // construct geometry for display
+    fModuleConstructionVector[i]->GetAliModule()->BuildGeometry();
+  }
+*/
 
+  // reset TG4GeometryManager 
+  pGeometryManager->ClearG3Tables();
+}
+
+//_____________________________________________________________________________
 void AliModulesComposition::SetReadGeometryToModules(G4bool readGeometry)
 {
 // Sets readGeometry control to all modules.
 // ---
 
-  // single module constructions
-  G4int nofDets = fModuleConstructionVector.entries();
-  G4int i;
-  for (i=0; i<nofDets; i++)
+  for (G4int i=0; i<fModuleConstructionVector.size(); i++) 
     fModuleConstructionVector[i]->SetReadGeometry(readGeometry);
-
-  // more modules construction
-  nofDets = fMoreModulesConstruction->GetNofModules();
-  for (i=0; i<nofDets; i++) { 
-    AliSingleModuleConstruction* moduleConstruction
-      = fMoreModulesConstruction->GetModuleConstruction(i);
-    moduleConstruction->SetReadGeometry(readGeometry);
-  }  
 }    
   
+//_____________________________________________________________________________
 void AliModulesComposition::SetWriteGeometryToModules(G4bool writeGeometry)
 {
 // Sets writeGeometry control to all modules.
 // ---
 
-  // single module constructions
-  G4int nofDets = fModuleConstructionVector.entries();
-  G4int i;
-  for (i=0; i<nofDets; i++)
+  for (G4int i=0; i<fModuleConstructionVector.size(); i++) 
     fModuleConstructionVector[i]->SetWriteGeometry(writeGeometry);
-
-  // more modules construction
-  nofDets = fMoreModulesConstruction->GetNofModules();
-  for (i=0; i<nofDets; i++) { 
-    AliSingleModuleConstruction* moduleConstruction
-      = fMoreModulesConstruction->GetModuleConstruction(i);
-    moduleConstruction->SetWriteGeometry(writeGeometry);
-  }  
 }    
 
-void AliModulesComposition::SetAllLVSensitiveToModules(G4bool allSensitive)
+//
+// protected methods
+//
+
+//_____________________________________________________________________________
+void AliModulesComposition::AddModule(const G4String& name, 
+                                      G4int version, 
+                                     AliModuleType moduleType)
 {
-// Sets setAllSensitive control to all modules.
+// Adds module to the module construction vector.
 // ---
 
-  // single module constructions
-  G4int nofDets = fModuleConstructionVector.entries();
-  G4int i;
-  for (i=0; i<nofDets; i++)
-    fModuleConstructionVector[i]->SetAllLVSensitive(allSensitive);
-
-  // more modules construction
-  nofDets = fMoreModulesConstruction->GetNofModules();
-  for (i=0; i<nofDets; i++) { 
-    AliSingleModuleConstruction* moduleConstruction
-      = fMoreModulesConstruction->GetModuleConstruction(i);
-    moduleConstruction->SetAllLVSensitive(allSensitive);
-  }  
-}    
+  AliModuleConstruction* moduleConstruction 
+    = new AliModuleConstruction(name, version, moduleType);
 
-void AliModulesComposition::SetProcessConfigToModules(G4bool processConfig)
+  fModuleConstructionVector.push_back(moduleConstruction);
+}  
+                                 
+//_____________________________________________________________________________
+void AliModulesComposition::ConstructModules()
 {
-// Sets processConfig control to all modules.
+// Construct geometry of all modules (both standalone and dependent.)
 // ---
 
-  // single module constructions
-  G4int nofDets = fModuleConstructionVector.entries();
-  G4int i;
-  for (i=0; i<nofDets; i++)
-    fModuleConstructionVector[i]->SetProcessConfig(processConfig);
+  // set common options
+  SetReadGeometryToModules(fReadGeometry);
+  SetWriteGeometryToModules(fWriteGeometry);
   
-  // more modules construction
-  nofDets = fMoreModulesConstruction->GetNofModules();
-  for (i=0; i<nofDets; i++) { 
-    AliSingleModuleConstruction* moduleConstruction
-      = fMoreModulesConstruction->GetModuleConstruction(i);
-    moduleConstruction->SetProcessConfig(processConfig);
-  }    
-}    
-
-// public methods
-
-void AliModulesComposition::SwitchDetOn(G4String moduleNameVer)
-{ 
-// Switchs on module specified by name and version.
-// ---
-
-  G4int nofDets = fDetSwitchVector.entries(); 
-  if (moduleNameVer == "ALL") {
-    for (G4int id=0; id<nofDets; id++) {
-      G4int defaultVersion = fDetSwitchVector[id]->GetDefaultVersion();
-      fDetSwitchVector[id]->SwitchOn(defaultVersion); 
-    }  
-  }
-  else if (moduleNameVer == "NONE") {
-    for (G4int id=0; id<nofDets; id++)
-      fDetSwitchVector[id]->SwitchOff(); 
-  }
-  else {
-    // get version number
-    G4int len = moduleNameVer.length();
-    G4String moduleName = moduleNameVer(0, len-1);
-    G4String version = moduleNameVer(len-1, 1);
-    G4int iVersion = AliGlobals::StringToInt(version);
-
-    if (iVersion < 0) {
-      // in case the version number is not provided
-      // the default one is set
-      SwitchDetOnDefault(moduleNameVer);
-    }  
-    else 
-      SwitchDetOn(moduleName, iVersion);
-  }
-}
-
-void AliModulesComposition::SwitchDetOn(G4String moduleName, G4int version)
-{ 
-// Switchs on module specified by name and version.
-// ---
-
-  G4int nofDets = fDetSwitchVector.entries(); 
-  for (G4int id=0; id<nofDets; id++) {
-    G4String iDetName = fDetSwitchVector[id]->GetDetName();
-    if (iDetName == moduleName) {
-      fDetSwitchVector[id]->SwitchOn(version);
-      return;
-    }
-  }
-  AliGlobals::Exception(
-    "AliModulesComposition: Wrong detector name for " + moduleName + ".");
-}
+  // configure modules
+  Configure();
 
-void AliModulesComposition::SwitchDetOnDefault(G4String moduleName)
-{ 
-// Switchs on module specified by name with default version.
-// ---
-
-  G4int nofDets = fDetSwitchVector.entries(); 
-  for (G4int id=0; id<nofDets; id++) {
-    G4String iDetName = fDetSwitchVector[id]->GetDetName();
-    if (iDetName == moduleName) {
-      fDetSwitchVector[id]->SwitchOnDefault();
-      return;
-    }
-  }
-  AliGlobals::Exception(
-    "AliModulesComposition: Wrong detector name for " + moduleName + ".");
-}
-
-void AliModulesComposition::SwitchDetOff(G4String moduleName)
-{ 
-// Switchs off module specified by name.
-// ---
-
-  G4int nofDets = fDetSwitchVector.entries(); 
-  if (moduleName == "ALL") {
-    for (G4int id=0; id<nofDets; id++)
-      fDetSwitchVector[id]->SwitchOff(); 
-  }
-  else {
-    for (G4int id=0; id<nofDets; id++) {
-      G4String iDetName = fDetSwitchVector[id]->GetDetName();
-      if (iDetName == moduleName) { 
-        fDetSwitchVector[id]->SwitchOff();
-        return;
-      }
-    }
-  }
-  AliGlobals::Exception(
-    "AliModulesComposition: Wrong detector name for " + moduleName + ".");
-}
+  // construct dependent modules
+  CreateG4Geometry();
+}  
 
-void AliModulesComposition::PrintSwitchedDets() const
-{ 
-// Lists switched detectors.
+//_____________________________________________________________________________
+void AliModulesComposition::SetProcessConfigToModules(G4bool processConfig)
+{
+// Sets processConfig control to all modules.
 // ---
 
-  G4String svList = GetSwitchedDetsList();
-    
-  G4cout << "Switched Alice detectors: " << G4endl;
-  G4cout << "--------------------------" << G4endl;
-  G4cout << svList << G4endl;
-}
-
-void AliModulesComposition::PrintAvailableDets() const
-{ 
-// Lists available detectors.
-// ---
+  for (G4int i=0; i<fModuleConstructionVector.size(); i++) 
+    fModuleConstructionVector[i]->SetProcessConfig(processConfig);
+}    
 
-  G4String avList = GetAvailableDetsList();
-    
-  G4cout << "Available Alice detectors: " << G4endl;
-  G4cout << "---------------------------" << G4endl;
-  G4cout << avList << G4endl;
-}
+//
+// public methods
+//
 
+//_____________________________________________________________________________
 void AliModulesComposition::PrintMaterials() const
 {
 // Prints all materials.
@@ -339,166 +247,7 @@ void AliModulesComposition::PrintMaterials() const
   G4cout << *matTable;
 }
 
-void AliModulesComposition::GenerateXMLGeometry() const 
-{
-// Generates XML geometry file from the top volume.
-// The file name is set according the last switched detector
-// registered in the det switch vector.
-// ---
-
-  G4VPhysicalVolume* world = AliSingleModuleConstruction::GetWorld();
-
-  // set filename
-  G4String detName;
-  G4String version = "v";
-  G4String filePath= getenv("AG4_INSTALL");   
-  filePath = filePath + "/xml/";  
-  for (G4int i=fDetSwitchVector.entries()-1; i>=0; i--) {
-    G4int versionNumber = fDetSwitchVector[i]->GetSwitchedVersion();
-    if (versionNumber > -1) {
-      detName = fDetSwitchVector[i]->GetDetName();
-      AliGlobals::AppendNumberToString(version, versionNumber); 
-      filePath = filePath + detName + version + ".xml";
-      break;
-    }  
-  }  
-  
-  // set top volume name
-  G4String topName = world->GetName() + "_comp";
-  
-  // generate XML
-  
-  TG4XMLGeometryGenerator xml;
-  xml.OpenFile(filePath);
-
-  // generate materials 
-  // not yet implemented
-  // xml.GenerateMaterials(version, "today", "Generated from G4",
-  //                     "v4", world->GetLogicalVolume());
-
-  // generate volumes tree
-  xml.GenerateSection(detName, version, "today", "Generated from Geant4",
-                      topName, world->GetLogicalVolume());
-  xml.CloseFile();
-  
-  // set verbose
-  G4cout << "File " << detName << version << ".xml has been generated." 
-         << G4endl;
-}  
-
-
-G4String AliModulesComposition::GetSwitchedDetsList() const
-{ 
-// Returns list of switched detectors.
-// ---
-
-  G4String svList = "";
-  
-  G4int nofDets = fDetSwitchVector.entries(); 
-  G4int nofSwitchedDets = 0;
-  for (G4int id=0; id<nofDets; id++) {
-    G4int iVersion = fDetSwitchVector[id]->GetSwitchedVersion();
-    if (iVersion > -1) {
-      nofSwitchedDets++;
-      G4String moduleNameVer = fDetSwitchVector[id]->GetDetName();
-      AliGlobals::AppendNumberToString(moduleNameVer, iVersion);
-      svList += moduleNameVer;
-      svList += " "; 
-    }
-  }
-
-  if (nofSwitchedDets ==  nofDets) svList = "ALL: " + svList;
-  if (nofSwitchedDets ==  0)       svList = "NONE";   
-
-  return svList;
-}
-
-const G4RWTPtrOrderedVector<AliDetSwitch>& 
-AliModulesComposition::GetDetSwitchVector() const
-{
-// Returns detSwitch vector.
-// ---
-
-  //const AliDetSwitchVector& vector = fDetSwitchVector;
-  const G4RWTPtrOrderedVector<AliDetSwitch>& vector = fDetSwitchVector;
-  return vector;
-}  
-
-G4String AliModulesComposition::GetAvailableDetsList() const
-{ 
-// Returns list of available detectors.
-// ---
-
-  G4String svList = "";
-  
-  G4int nofDets = fDetSwitchVector.entries(); 
-  for (G4int id=0; id<nofDets; id++) {
-    G4int nofVersions = fDetSwitchVector[id]->GetNofVersions();
-    for (G4int iv=0; iv<nofVersions; iv++) {
-      G4String moduleNameVer = fDetSwitchVector[id]->GetDetName();
-      AliGlobals::AppendNumberToString(moduleNameVer, iv);
-      svList += moduleNameVer;
-      svList += " ";
-    }
-  }
-
-  return svList;
-}
-
-G4String AliModulesComposition::GetAvailableDetsListWithCommas() const
-{ 
-// Returns list of available detectors with commas.
-// ---
-
-  G4String svList = "";
-  
-  G4int nofDets = fDetSwitchVector.entries(); 
-  for (G4int id=0; id<nofDets; id++) {
-    G4int nofVersions = fDetSwitchVector[id]->GetNofVersions();
-    for (G4int iv=0; iv<nofVersions; iv++) {
-      G4String moduleNameVer = fDetSwitchVector[id]->GetDetName();
-      AliGlobals::AppendNumberToString(moduleNameVer, iv);
-      svList += moduleNameVer;
-      if (iv<nofVersions-1)    svList += "/";
-      else if (id < nofDets-1) svList += ", ";
-    }
-  }
-
-  return svList;
-}
-
-G4String AliModulesComposition::GetDetNamesList() const
-{ 
-// Returns list of detector names.
-// ---
-
-  G4String svList = "";
-  
-  G4int nofDets = fDetSwitchVector.entries(); 
-  for (G4int id=0; id<nofDets; id++) { 
-    svList += fDetSwitchVector[id]->GetDetName();
-    svList += " ";
-  }
-
-  return svList;
-}
-
-G4String AliModulesComposition::GetDetNamesListWithCommas() const
-{ 
-// Returns list of detector names with commas.
-// ---
-
-  G4String svList = "";
-  
-  G4int nofDets = fDetSwitchVector.entries(); 
-  for (G4int id=0; id<nofDets; id++) { 
-    svList += fDetSwitchVector[id]->GetDetName();
-    if (id < nofDets-1) svList += ", ";
-  }
-
-  return svList;
-}
-
+//_____________________________________________________________________________
 void AliModulesComposition::SetMagField(G4double fieldValue)
 {
 // Sets uniform magnetic field to specified value.