]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - AliGeant4/AliModuleConstruction.cxx
Correcter eror by A. Dainese
[u/mrichter/AliRoot.git] / AliGeant4 / AliModuleConstruction.cxx
index 77542d56cc59829df42d98f08f3aad3cdb2a9109..41db407b1c6ca0137bab9afae065464df7c5b0ae 100644 (file)
@@ -1,92 +1,88 @@
 // $Id$
 // Category: geometry
 //
+// Author: I. Hrivnacova
+//
+// Class AliModuleConstruction
+// ---------------------------
 // See the class description in the header file.
 
 #include "AliModuleConstruction.h"
-#include "AliModuleConstructionMessenger.h"
 #include "AliGlobals.h"
-#include "AliLVStructure.h"
+#include "AliFiles.h"
+#include "AliRun.h"
 #include "AliModule.h"
 
-#ifdef ALICE_VISUALIZE
-#include "AliColourStore.h"
+#include <G4UImanager.hh>
+
+#include <TROOT.h> 
+#include <TCint.h> 
 
-#include <G4Colour.hh>
-#include <G4VisAttributes.hh>
-#endif //ALICE_VISUALIZE
-#include <G4LogicalVolumeStore.hh>
-#include <G4LogicalVolume.hh>
 
-AliModuleConstruction::AliModuleConstruction(G4String moduleName) 
-  : fModuleName(moduleName), 
-    fModuleFrameName(moduleName),
-    fModuleFrameLV(0),
-    fAliModule(0),
+//_____________________________________________________________________________
+AliModuleConstruction::AliModuleConstruction(const G4String& moduleName,
+                                             G4int version, 
+                                            AliModuleType moduleType)
+  : fAliModule(0),
+    fModuleName(moduleName), 
+    fType(moduleType),
+    fVersion(version),
+    fProcessConfig(true),
     fReadGeometry(false),
     fWriteGeometry(false),
-    fDataFilePath("")    
-{
-//
-  moduleName.toLower();
-  fMessenger = new AliModuleConstructionMessenger(this, moduleName);
-}
-
-AliModuleConstruction::AliModuleConstruction(const AliModuleConstruction& right)
-{
+    fDataFilePath("") {
 //
-  // allocation in assignement operator
-  fMessenger = 0;
-  
-  // copy stuff
-  *this = right;
 }
 
+//_____________________________________________________________________________
 AliModuleConstruction::AliModuleConstruction()
-  : fModuleName(""), 
-    fModuleFrameName(""),
-    fModuleFrameLV(0),
-    fMessenger(0),
-    fAliModule(0),
+  : fAliModule(0),
+    fModuleName(""), 
+    fType(kDetector),
+    fVersion(-1),
+    fProcessConfig(true),
     fReadGeometry(false),
     fWriteGeometry(false),
-    fDataFilePath("")    
+    fDataFilePath("") {
+//
+}
+
+//_____________________________________________________________________________
+AliModuleConstruction::AliModuleConstruction(const AliModuleConstruction& right)
 {
 //
+  // copy stuff
+  *this = right;
 }
 
+//_____________________________________________________________________________
 AliModuleConstruction::~AliModuleConstruction()
 {
 //
-  delete fMessenger;
-  delete fAliModule;
 }
 
 // operators
 
+//_____________________________________________________________________________
 AliModuleConstruction& 
 AliModuleConstruction::operator=(const AliModuleConstruction& right)
 {    
   // check assignement to self
   if (this == &right) return *this;
   
-  fModuleName = right.fModuleName; 
-  fModuleFrameName = right.fModuleFrameName;
-  fModuleFrameLV = right.fModuleFrameLV;
   fAliModule = right.fAliModule;
+  fModuleName = right.fModuleName; 
+  fVersion = right.fVersion;
+  fType = right.fType;
+  fProcessConfig = right.fProcessConfig;
   fReadGeometry = right.fReadGeometry;
   fWriteGeometry = right.fWriteGeometry;
   fDataFilePath = right.fDataFilePath;
 
-  // new messenger
-  if (fMessenger) delete fMessenger;
-  G4String moduleName = fModuleName;
-  moduleName.toLower();
-  fMessenger = new AliModuleConstructionMessenger(this, moduleName);
-
   return *this;
 }
 
+//_____________________________________________________________________________
 G4int 
 AliModuleConstruction::operator==(const AliModuleConstruction& right) const
 {
@@ -94,6 +90,7 @@ AliModuleConstruction::operator==(const AliModuleConstruction& right) const
   return 0;
 }
 
+//_____________________________________________________________________________
 G4int 
 AliModuleConstruction::operator!=(const AliModuleConstruction& right) const
 {
@@ -104,250 +101,48 @@ AliModuleConstruction::operator!=(const AliModuleConstruction& right) const
   return returnValue;
 }
 
-// protected methods
-
-void AliModuleConstruction::RegisterLogicalVolume(G4LogicalVolume* lv,
-       G4String path, AliLVStructure& lvStructure)
-{
-// Registers logical volume lv in the structure.
-// ---        
-
-  G4String lvName = lv->GetName();
-  lvStructure.AddNewVolume(lv, path);
-  
-  // register daughters
-  G4int nofDaughters = lv->GetNoDaughters();
-  if (nofDaughters>0) {
-    G4String previousName = "";
-    for (G4int i=0; i<nofDaughters; i++) {
-      G4LogicalVolume* lvd = lv->GetDaughter(i)->GetLogicalVolume();
-      G4String currentName = lvd->GetName();
-      if (currentName != lvName && currentName != previousName) { 
-        G4String newPath = path + lvName +"/";
-        RegisterLogicalVolume(lvd, newPath, lvStructure);
-       previousName = currentName;
-      }
-    }
-  }     
-}          
-
-// public methods
-
-void AliModuleConstruction::SetDetFrame(G4bool warn)
-{ 
-// The logical volume with name identical with
-// fModuleName is retrieved from G4LogicalVolumeStore.
-// ---
-
-  fModuleFrameLV = FindLogicalVolume(fModuleFrameName, true);
-  
-  if (fModuleFrameLV == 0 && warn) {
-    G4String text = "AliModuleConstruction: Detector frame for ";
-    text = text + fModuleFrameName + " has not been found.";
-    AliGlobals::Warning(text); 
-  }  
-}
-
-void AliModuleConstruction::SetDetFrame(G4String frameName, G4bool warn)
+//_____________________________________________________________________________
+void AliModuleConstruction::Configure()
 { 
-// The logical volume with frameName
-// is retrieved from G4LogicalVolumeStore.
+// Executes the detector setup Root macro
+// (extracted from AliRoot Config.C) and
+// G4 macro.
 // ---
 
-  fModuleFrameName = frameName;
-  SetDetFrame(warn);
-}
-
-void AliModuleConstruction::ListAllLVTree()
-{
-// Lists all logical volumes tree if the frame logical volume 
-// is defined.
-// ---- 
-
-  if (fModuleFrameLV) 
-    ListLVTree(fModuleFrameLV->GetName());
-  else {
-    G4String text = "AliModuleConstruction::ListAllLVTree:\n";
-    text = text + "    Detector frame is not defined.";    
-    AliGlobals::Warning(text);
-  }   
-}
-
-void AliModuleConstruction::ListAllLVTreeLong()
-{
-// Lists all logical volume tree if the frame logical volume 
-// is defined with numbers of daughters (physical volumes).
-// ---- 
-
-  if (fModuleFrameLV) 
-    ListLVTreeLong(fModuleFrameLV->GetName());
-  else {
-    G4String text = "AliModuleConstruction::ListAllLVTreeLong:\n";
-    text = text + "    Detector frame is not defined.";    
-    AliGlobals::Warning(text);
-  }  
-}
-
-void AliModuleConstruction::ListLVTree(G4String lvName)
-{
-// Lists logical volumes tree (daughters) of the logical volume 
-// with specified lvName.
-// ---- 
-
-  G4LogicalVolume* lv = FindLogicalVolume(lvName);
-  if (lv)
-  {
-    G4String path = "";
-    AliLVStructure lvStructure(path);
-    RegisterLogicalVolume(lv, path, lvStructure);
-    lvStructure.ListTree();
-  }
-}
+  AliFiles* files = AliFiles::Instance();
 
-void AliModuleConstruction::ListLVTreeLong(G4String lvName)
-{
-// Lists logical volumes tree (daughters) of the logical volume 
-// with specified lvName with numbers of daughters (physical volumes).
-// ---- 
-
-  G4LogicalVolume* lv = FindLogicalVolume(lvName);
-  if (lv) {
-    G4String path = "";
-    AliLVStructure lvStructure(path);
-    RegisterLogicalVolume(lv, path, lvStructure);
-    lvStructure.ListTreeLong();
-  }
-}
-
-G4LogicalVolume* AliModuleConstruction::FindLogicalVolume(
-                                          G4String name, G4bool silent) const
-{
-// Finds logical volume with specified name in G4LogicalVolumeStore.
-// (To do: use this method only for retrieving detector frame;
-//  add method FindLogicalVolumeInDet - that will search only
-//  in the detector frame LVTree.)
-// ---
-
-  G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance();
+  // filepaths and macro names 
+  G4bool isStructure = (fType == kStructure);
+  G4String rootFilePath 
+    = files->GetRootMacroPath(GetDetName(), isStructure);
+  G4String g4FilePath
+    = files->GetG4MacroPath(GetDetName(), isStructure);
+  fDataFilePath 
+    = files->GetG3CallsDatPath(GetDetName(), fVersion, isStructure); 
   
-  for (G4int i=0; i<pLVStore->size(); i++) {
-    G4LogicalVolume* lv = (*pLVStore)[i];
-    if (lv->GetName() == name) return lv;
-  }
+  // load and execute aliroot config macro
+  if (fProcessConfig) {
+    gROOT->LoadMacro(rootFilePath);
+    G4String macroName = files->GetDefaultMacroName();
+    //macroName = macroName + "_" + GetDetName();
+    macroName = macroName + "(";
+    AliGlobals::AppendNumberToString(macroName, fVersion);
+    macroName = macroName + ")";
+    gInterpreter->ProcessLine(macroName);
+  } 
   
-  G4String text = "AliModuleConstruction: Logical volume "; 
-  text = text + name + " does not exist.";
-  if (!silent) AliGlobals::Warning(text);
-  return 0;                     
-}  
-
-#ifdef ALICE_VISUALIZE
-
-void AliModuleConstruction::SetDetVisibility(G4bool visibility)
-{
-// Sets visibility to all detector logical volumes if
-// frame logical volume is defined.
-// ---
-
-  if (fModuleFrameLV) 
-    SetLVTreeVisibility(fModuleFrameLV, visibility);  
-  else  {
-    G4String text = "AliModuleConstruction::SetDetVisibility:\n";
-    text = text + "    Detector frame is not defined.";    
-    AliGlobals::Warning(text);
-  }  
-}
-
-
-void AliModuleConstruction::SetLVTreeVisibility(G4LogicalVolume* lv, 
-                             G4bool visibility)
-{ 
-// Sets visibility to the logical volumes tree (daughters) of 
-// the logical volume lv.
-// ---
-
-  if (lv) {
-    G4String path = "";
-    AliLVStructure lvStructure(path);
-    RegisterLogicalVolume(lv, path, lvStructure);
-    lvStructure.SetTreeVisibility(visibility);
-  }
-}
-
-void AliModuleConstruction::SetVolumeVisibility(G4LogicalVolume* lv, 
-                             G4bool visibility)
-{ 
-// Sets visibility to the specified logical volume.
-// ---
-
-  if (lv) {
-    const G4VisAttributes* kpVisAttributes = lv->GetVisAttributes ();
-    G4VisAttributes* newVisAttributes; 
-    if (kpVisAttributes) {
-      G4Colour oldColour   = kpVisAttributes->GetColour();
-      newVisAttributes = new G4VisAttributes(oldColour); 
-    }  
-    else
-      newVisAttributes = new G4VisAttributes();
-    delete kpVisAttributes;
-
-    newVisAttributes->SetVisibility(visibility); 
-
-    lv->SetVisAttributes(newVisAttributes);
-  }
-}
-
-void AliModuleConstruction::SetDetColour(G4String colName)
-{
-// Sets colour to all detector logical volumes if
-// frame logical volume is defined.
-// ---
-
-  if (fModuleFrameLV) 
-    SetLVTreeColour(fModuleFrameLV, colName);  
-  else { 
-    G4String text = "AliModuleConstruction::SetDetColour:\n";
-    text = text + "    Detector frame is not defined.";    
-    AliGlobals::Warning(text);
+  // process g4 config macro
+  G4String command = "/control/execute ";
+  G4UImanager* pUI = G4UImanager::GetUIpointer();  
+  pUI->ApplyCommand(command + g4FilePath);
+  
+  // get AliModule created in Config.C macro
+  fAliModule = gAlice->GetModule(GetDetName());
+  if (!fAliModule) {
+    G4String text = "AliModuleConstruction::Configure:\n";
+    text = text + "    AliModule " + GetDetName();
+    text = text + " has not been found in gAlice.";
+    AliGlobals::Exception(text);
   }  
 }
 
-void AliModuleConstruction::SetLVTreeColour(G4LogicalVolume* lv, 
-                             G4String colName)
-{ 
-// Sets colour to the logical volumes tree (daughters) of 
-// the logical volume lv.
-// ---
-
-  if (lv) {
-    G4String path = "";
-    AliLVStructure lvStructure(path);
-    RegisterLogicalVolume(lv, path, lvStructure);
-    lvStructure.SetTreeVisibility(true);
-    lvStructure.SetTreeColour(colName);
-  }
-}
-
-void AliModuleConstruction::SetVolumeColour(G4LogicalVolume* lv,
-                             G4String colName)
-{
-// Sets colour to the specified logical volume.
-// ---
-
-  if (lv) {
-    const G4VisAttributes* kpVisAttributes = lv->GetVisAttributes ();
-    delete kpVisAttributes;
-
-    G4VisAttributes* newVisAttributes = new G4VisAttributes(); 
-
-    AliColourStore* pColours = AliColourStore::Instance();
-    const G4Colour kColour = pColours->GetColour(colName);
-    newVisAttributes->SetVisibility(true); 
-    newVisAttributes->SetColour(kColour);
-
-    lv->SetVisAttributes(newVisAttributes);
-  }      
-}
-
-#endif //ALICE_VISUALIZE
-