From 80ed9a9964a2266847842638a062e1f72c02e74c Mon Sep 17 00:00:00 2001 From: ivana Date: Thu, 25 Oct 2001 12:12:42 +0000 Subject: [PATCH] redesign of detector construction classes (see AliGeant4_geometry_History) --- AliGeant4/AliDetConstruction.cxx | 206 +++++--- AliGeant4/AliDetConstruction.h | 12 +- AliGeant4/AliModuleConstruction.cxx | 342 +++---------- AliGeant4/AliModuleConstruction.h | 100 ++-- AliGeant4/AliModulesComposition.cxx | 500 +++++-------------- AliGeant4/AliModulesComposition.h | 64 +-- AliGeant4/AliModulesCompositionMessenger.cxx | 74 +-- AliGeant4/AliModulesCompositionMessenger.h | 6 - 8 files changed, 390 insertions(+), 914 deletions(-) diff --git a/AliGeant4/AliDetConstruction.cxx b/AliGeant4/AliDetConstruction.cxx index cba3f8cb79a..0519a213b85 100644 --- a/AliGeant4/AliDetConstruction.cxx +++ b/AliGeant4/AliDetConstruction.cxx @@ -8,60 +8,50 @@ // See the class description in the header file. #include "AliDetConstruction.h" -#include "AliSingleModuleConstruction.h" #include "AliDetSwitch.h" +#include "AliLVTree.h" #include "AliGlobals.h" +#include "AliFiles.h" #include "AliRun.h" #include "AliModule.h" +#include "TG4XMLGeometryGenerator.h" +#include "TG4GeometryServices.h" + +#include + //_____________________________________________________________________________ AliDetConstruction::AliDetConstruction() - : fTopVolumeName("ALIC") + : AliModulesComposition() { // initialize det switch vector: - // moduleName nofVersions defaultVersion [type isStandalone] - // det switch objects are deleted in - // the base class (AliModulesCompositions) destructor - - AliDetSwitch* detSwitch; - detSwitch = new AliDetSwitch("ABSO", 1, 0, kStructure); - AddDetSwitch(detSwitch); - detSwitch = new AliDetSwitch("DIPO", 3, 2, kStructure, false); - AddDetSwitch(detSwitch); - detSwitch = new AliDetSwitch("FRAME", 3, 2, kStructure, false); - AddDetSwitch(detSwitch); - detSwitch = new AliDetSwitch("HALL", 1, 0, kStructure); - AddDetSwitch(detSwitch); - detSwitch = new AliDetSwitch("MAG", 1, 0, kStructure); - AddDetSwitch(detSwitch); - detSwitch = new AliDetSwitch("PIPE", 5, 0, kStructure); - AddDetSwitch(detSwitch); - detSwitch = new AliDetSwitch("SHIL", 1, 0, kStructure); - AddDetSwitch(detSwitch); - detSwitch = new AliDetSwitch("CASTOR", 2, 1); - AddDetSwitch(detSwitch); - detSwitch = new AliDetSwitch("FMD", 2, 1); - AddDetSwitch(detSwitch); - detSwitch = new AliDetSwitch("ITS", 7, 5); - AddDetSwitch(detSwitch); - detSwitch = new AliDetSwitch("MUON", 2, 1, kDetector, false); - AddDetSwitch(detSwitch); - detSwitch = new AliDetSwitch("PHOS", 2, 1); - AddDetSwitch(detSwitch); - detSwitch = new AliDetSwitch("PMD", 3, 1); - AddDetSwitch(detSwitch); - detSwitch = new AliDetSwitch("RICH", 3, 1); - AddDetSwitch(detSwitch); - detSwitch = new AliDetSwitch("START", 2, 1); - AddDetSwitch(detSwitch); - detSwitch = new AliDetSwitch("TOF", 5, 2, kDetector, false); - AddDetSwitch(detSwitch); - detSwitch = new AliDetSwitch("TPC", 4, 2); - AddDetSwitch(detSwitch); - detSwitch = new AliDetSwitch("TRD", 2, 1, kDetector, false); - AddDetSwitch(detSwitch); - detSwitch = new AliDetSwitch("ZDC", 3, 2, kDetector, false); - AddDetSwitch(detSwitch); + // moduleName nofVersions defaultVersion [type] + // det switch objects are deleted in fDetSwitchVector destructor + + fDetSwitchVector.Add(new AliDetSwitch("ABSO", 1, 0, kStructure)); + fDetSwitchVector.Add(new AliDetSwitch("DIPO", 3, 2, kStructure)); + fDetSwitchVector.Add(new AliDetSwitch("FRAME", 3, 2, kStructure)); + fDetSwitchVector.Add(new AliDetSwitch("HALL", 1, 0, kStructure)); + //fDetSwitchVector.Add(new AliDetSwitch("MAG", 1, 0, kStructure)); + fDetSwitchVector.Add(new AliDetSwitch("MAG", 1, 0, kStructure)); + fDetSwitchVector.Add(new AliDetSwitch("PIPE", 5, 0, kStructure)); + fDetSwitchVector.Add(new AliDetSwitch("SHIL", 1, 0, kStructure)); + fDetSwitchVector.Add(new AliDetSwitch("CASTOR", 2, 1)); + fDetSwitchVector.Add(new AliDetSwitch("FMD", 2, 1)); + fDetSwitchVector.Add(new AliDetSwitch("ITS", 7, 5)); + fDetSwitchVector.Add(new AliDetSwitch("MUON", 2, 1)); + //fDetSwitchVector.Add(new AliDetSwitch("MUON", 2, 1)); + fDetSwitchVector.Add(new AliDetSwitch("PHOS", 2, 1)); + fDetSwitchVector.Add(new AliDetSwitch("PMD", 3, 1)); + fDetSwitchVector.Add(new AliDetSwitch("RICH", 3, 1)); + fDetSwitchVector.Add(new AliDetSwitch("START", 2, 1)); + fDetSwitchVector.Add(new AliDetSwitch("TOF", 5, 2)); + fDetSwitchVector.Add(new AliDetSwitch("TPC", 4, 2)); + fDetSwitchVector.Add(new AliDetSwitch("TRD", 2, 1)); + fDetSwitchVector.Add(new AliDetSwitch("ZDC", 3, 2)); + + // instantiate LVtree browser + AliLVTree::Instance(); } //_____________________________________________________________________________ @@ -72,8 +62,10 @@ AliDetConstruction::AliDetConstruction(const AliDetConstruction& right) } //_____________________________________________________________________________ -AliDetConstruction::~AliDetConstruction() { -// +AliDetConstruction::~AliDetConstruction() +{ + // delete LVtree browser + delete AliLVTree::Instance(); } // operators @@ -112,22 +104,23 @@ void AliDetConstruction::BuildDetectors() text = text + module->GetName() + " has been found."; AliGlobals::Exception(text); } - AddSingleModuleConstruction("BODY", 0, kStructure); + AddModule("BODY", 0, kStructure); G4bool first = true; while ((module = (AliModule*)next())) { + // register moduleConstruction in fDetSwitchVector - // in order to keep availability of /AlDet/list command + // in order to keep availability of /aliDet/list command G4String modName = module->GetName(); G4int modVersion = module->IsVersion(); if (first) // skip registering of the top volume first = false; else - SwitchDetOn(modName, modVersion); + fDetSwitchVector.SwitchDetOn(modName, modVersion); // all modules will be processed alltogether - AddMoreModuleConstruction(modName, modVersion); + AddModule(modName, modVersion); G4cout << "Created module construction for " << modName << "v" << modVersion << "." << G4endl; @@ -146,21 +139,18 @@ void AliDetConstruction::CreateDetectors() // --- // add top volume (AliBODY) construction first - AddSingleModuleConstruction("BODY", 0, kStructure); + AddModule("BODY", 0, kStructure); // add modules constructions - for (G4int id=0; idGetDetName(); - G4int version = fDetSwitchVector[id]->GetSwitchedVersion(); - G4bool isStandalone = fDetSwitchVector[id]->IsStandalone(); - AliModuleType type = fDetSwitchVector[id]->GetType(); + AliDetSwitch* detSwitch = fDetSwitchVector.GetDetSwitch(i); + G4String detName = detSwitch->GetDetName(); + G4int version = detSwitch->GetSwitchedVersion(); + AliModuleType type = detSwitch->GetType(); if (version > -1) - if (isStandalone) - AddSingleModuleConstruction(detName, version, type); - else - AddMoreModuleConstruction(detName, version, type); + AddModule(detName, version, type); } } @@ -175,17 +165,18 @@ void AliDetConstruction::CheckDetDependencies() // --- // get switched versions of dependent modules - G4int verMUON = GetDetSwitch("MUON")->GetSwitchedVersion(); - G4int verTOF = GetDetSwitch("TOF")->GetSwitchedVersion(); - G4int verTRD = GetDetSwitch("TRD")->GetSwitchedVersion(); - G4int verZDC = GetDetSwitch("ZDC")->GetSwitchedVersion(); - G4int verFRAME = GetDetSwitch("FRAME")->GetSwitchedVersion(); + G4int verMUON = fDetSwitchVector.GetDetSwitch("MUON")->GetSwitchedVersion(); + G4int verTOF = fDetSwitchVector.GetDetSwitch("TOF")->GetSwitchedVersion(); + G4int verTRD = fDetSwitchVector.GetDetSwitch("TRD")->GetSwitchedVersion(); + G4int verZDC = fDetSwitchVector.GetDetSwitch("ZDC")->GetSwitchedVersion(); + G4int verFRAME = fDetSwitchVector.GetDetSwitch("FRAME")->GetSwitchedVersion(); // check dependencies + if (verMUON > -1) { // MUON requires DIPO - if(GetDetSwitch("DIPO")->GetSwitchedVersion()<0) { - GetDetSwitch("DIPO")->SwitchOnDefault(); + if(fDetSwitchVector.GetDetSwitch("DIPO")->GetSwitchedVersion()<0) { + fDetSwitchVector.GetDetSwitch("DIPO")->SwitchOnDefault(); G4String text = "AliDetConstruction::CheckDetDependencies: \n"; text = text + " Switched MUON requires DIPO.\n"; text = text + " The det switch for DIPO has been changed."; @@ -193,20 +184,20 @@ void AliDetConstruction::CheckDetDependencies() } } if (verTOF > -1) { - // TOF requires FRAMEv1 - obsolete? - if (verFRAME != 2) { - GetDetSwitch("FRAME")->SwitchOn(2); + // TOF requires FRAME + if (verFRAME < 0) { + fDetSwitchVector.GetDetSwitch("FRAME")->SwitchOnDefault(); G4String text = "AliDetConstruction::CheckDetDependencies: \n"; - text = text + " Switched TOF requires FRAME v1.\n"; + text = text + " Switched TOF requires FRAME.\n"; text = text + " The det switch for FRAME has been changed."; AliGlobals::Warning(text); } } if (verTRD > -1) { // TRD requires FRAME - verFRAME = GetDetSwitch("FRAME")->GetSwitchedVersion(); + verFRAME = fDetSwitchVector.GetDetSwitch("FRAME")->GetSwitchedVersion(); if (verFRAME < 0) { - GetDetSwitch("FRAME")->SwitchOnDefault(); + fDetSwitchVector.GetDetSwitch("FRAME")->SwitchOnDefault(); G4String text = "AliDetConstruction::CheckDetDependencies: \n"; text = text + " Switched TRD requires FRAME.\n"; text = text + " The det switch for FRAME has been changed."; @@ -215,27 +206,27 @@ void AliDetConstruction::CheckDetDependencies() } if (verZDC > -1) { // ZDC requires PIPE, ABSO, DIPO, SHIL - G4int verPIPE = GetDetSwitch("PIPE")->GetSwitchedVersion(); - G4int verABSO = GetDetSwitch("ABSO")->GetSwitchedVersion(); - G4int verDIPO = GetDetSwitch("DIPO")->GetSwitchedVersion(); - G4int verSHIL = GetDetSwitch("SHIL")->GetSwitchedVersion(); + G4int verPIPE = fDetSwitchVector.GetDetSwitch("PIPE")->GetSwitchedVersion(); + G4int verABSO = fDetSwitchVector.GetDetSwitch("ABSO")->GetSwitchedVersion(); + G4int verDIPO = fDetSwitchVector.GetDetSwitch("DIPO")->GetSwitchedVersion(); + G4int verSHIL = fDetSwitchVector.GetDetSwitch("SHIL")->GetSwitchedVersion(); if ( verPIPE != 1 || verABSO !=0 || verDIPO == -1 || verSHIL == -1) { G4String text = "AliDetConstruction::CheckDetDependencies: \n"; text = text + " Switched ZDC requires PIPE, ABSO, DIPO and SHIL.\n"; if (verPIPE == -1) { - GetDetSwitch("PIPE")->SwitchOnDefault(); + fDetSwitchVector.GetDetSwitch("PIPE")->SwitchOnDefault(); text = text + " The det switch for PIPE has been changed.\n"; } if (verABSO == -1) { - GetDetSwitch("ABSO")->SwitchOnDefault(); + fDetSwitchVector.GetDetSwitch("ABSO")->SwitchOnDefault(); text = text + " The det switch for ABSO has been changed.\n"; } if (verDIPO == -1) { - GetDetSwitch("DIPO")->SwitchOnDefault(); + fDetSwitchVector.GetDetSwitch("DIPO")->SwitchOnDefault(); text = text + " The det switch for DIPO has been changed.\n"; } if (verSHIL == -1) { - GetDetSwitch("SHIL")->SwitchOnDefault(); + fDetSwitchVector.GetDetSwitch("SHIL")->SwitchOnDefault(); text = text + " The det switch for SHIL has been changed."; } AliGlobals::Warning(text); @@ -266,6 +257,55 @@ G4VPhysicalVolume* AliDetConstruction::Construct() // construct modules geometry ConstructModules(); - return AliSingleModuleConstruction::GetWorld(); + return TG4GeometryServices::Instance()->GetWorld(); } +//_____________________________________________________________________________ +void AliDetConstruction::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 = TG4GeometryServices::Instance()->GetWorld(); + + // XML filename + // according to last switched detector + G4String detName; + G4String detVersion = ""; + G4int version = -1; + for (G4int i=fDetSwitchVector.GetSize()-1; i>=0; i--) { + version = fDetSwitchVector.GetDetSwitch(i)->GetSwitchedVersion(); + if (version > -1) { + detName = fDetSwitchVector.GetDetSwitch(i)->GetDetName(); + AliGlobals::AppendNumberToString(detVersion,version); + break; + } + } + G4String filePath + = AliFiles::Instance()->GetXMLFilePath(detName, version); + + // set top volume name + G4String topName = world->GetName() + "_comp"; + + // generate XML + + TG4XMLGeometryGenerator xml; + xml.OpenFile(filePath); + + // generate materials + // not implemented + // xml.GenerateMaterials(version, "today", "Generated from G4", + // "v4", world->GetLogicalVolume()); + + // generate volumes tree + xml.GenerateSection(detName, detVersion, "today", "Generated from Geant4", + topName, world->GetLogicalVolume()); + xml.CloseFile(); + + // set verbose + G4cout << "File " << detName << "v" << version << ".xml has been generated." + << G4endl; +} + diff --git a/AliGeant4/AliDetConstruction.h b/AliGeant4/AliDetConstruction.h index 63f8646f638..34772085dbc 100644 --- a/AliGeant4/AliDetConstruction.h +++ b/AliGeant4/AliDetConstruction.h @@ -15,6 +15,7 @@ #define ALI_DET_CONSTRUCTION_H #include "AliModulesComposition.h" +#include "AliDetSwitchVector.h" #include @@ -30,9 +31,7 @@ class AliDetConstruction : public AliModulesComposition // methods virtual G4VPhysicalVolume* Construct(); - - // set methods - void SetTopVolumeName(G4String name); + virtual void GenerateXMLGeometry() const; protected: AliDetConstruction(const AliDetConstruction& right); @@ -47,13 +46,8 @@ class AliDetConstruction : public AliModulesComposition void CheckDetDependencies(); // data members - G4String fTopVolumeName; //top volume name + AliDetSwitchVector fDetSwitchVector; //vector of AliDetSwitch }; -// inline methods - -inline void AliDetConstruction::SetTopVolumeName(G4String name) -{ fTopVolumeName = name; } - #endif //ALI_DET_CONSTRUCTION_H diff --git a/AliGeant4/AliModuleConstruction.cxx b/AliGeant4/AliModuleConstruction.cxx index 91fff39b7e2..3b1fe59fc1d 100644 --- a/AliGeant4/AliModuleConstruction.cxx +++ b/AliGeant4/AliModuleConstruction.cxx @@ -9,61 +9,56 @@ #include "AliModuleConstruction.h" #include "AliGlobals.h" -#include "AliLVStructure.h" +#include "AliFiles.h" +#include "AliRun.h" #include "AliModule.h" -#ifdef ALICE_VISUALIZE -#include "AliColourStore.h" -#endif -#include "TG4GeometryServices.h" +#include + +#include +#include -#include -#include -#ifdef ALICE_VISUALIZE -#include -#include -#endif //_____________________________________________________________________________ -AliModuleConstruction::AliModuleConstruction(const 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(""), - fMessenger(this, moduleName) { + fDataFilePath("") { // } //_____________________________________________________________________________ -AliModuleConstruction::AliModuleConstruction(const AliModuleConstruction& right) - : fMessenger(this, right.fModuleName) -{ +AliModuleConstruction::AliModuleConstruction() + : fAliModule(0), + fModuleName(""), + fType(kDetector), + fVersion(-1), + fProcessConfig(true), + fReadGeometry(false), + fWriteGeometry(false), + fDataFilePath("") { // - // copy stuff - *this = right; } //_____________________________________________________________________________ -AliModuleConstruction::AliModuleConstruction() - : fModuleName(""), - fModuleFrameName(""), - fModuleFrameLV(0), - fAliModule(0), - fReadGeometry(false), - fWriteGeometry(false), - fDataFilePath(""), - fMessenger(this, "") { +AliModuleConstruction::AliModuleConstruction(const AliModuleConstruction& right) +{ // + // copy stuff + *this = right; } //_____________________________________________________________________________ AliModuleConstruction::~AliModuleConstruction() { // - delete fAliModule; } // operators @@ -75,14 +70,14 @@ 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; - //fMessenger = right.fMessenger; return *this; } @@ -106,247 +101,48 @@ AliModuleConstruction::operator!=(const AliModuleConstruction& right) const return returnValue; } -// protected methods - -//_____________________________________________________________________________ -void AliModuleConstruction::RegisterLogicalVolume( - G4LogicalVolume* lv, const G4String& path, - AliLVStructure& lvStructure) const -{ -// 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; iGetDaughter(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 - = TG4GeometryServices::Instance()->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(const G4String& frameName, G4bool warn) -{ -// The logical volume with frameName -// is retrieved from G4LogicalVolumeStore. -// --- - - fModuleFrameName = frameName; - SetDetFrame(warn); -} - -//_____________________________________________________________________________ -void AliModuleConstruction::ListAllLVTree() const -{ -// 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() const -{ -// 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(const G4String& lvName) const -{ -// Lists logical volumes tree (daughters) of the logical volume -// with specified lvName. -// ---- - - G4LogicalVolume* lv - = TG4GeometryServices::Instance()->FindLogicalVolume(lvName); - - if (lv) - { - G4String path = ""; - AliLVStructure lvStructure(path); - RegisterLogicalVolume(lv, path, lvStructure); - lvStructure.ListTree(); - } -} - -//_____________________________________________________________________________ -void AliModuleConstruction::ListLVTreeLong(const G4String& lvName) const -{ -// Lists logical volumes tree (daughters) of the logical volume -// with specified lvName with numbers of daughters (physical volumes). -// ---- - - G4LogicalVolume* lv - = TG4GeometryServices::Instance()->FindLogicalVolume(lvName); - - if (lv) { - G4String path = ""; - AliLVStructure lvStructure(path); - RegisterLogicalVolume(lv, path, lvStructure); - lvStructure.ListTreeLong(); - } -} - -#ifdef ALICE_VISUALIZE - -//_____________________________________________________________________________ -void AliModuleConstruction::SetDetVisibility(G4bool visibility) const -{ -// 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) const +void AliModuleConstruction::Configure() { -// Sets visibility to the logical volumes tree (daughters) of -// the logical volume lv. +// Executes the detector setup Root macro +// (extracted from AliRoot Config.C) and +// G4 macro. // --- - if (lv) { - G4String path = ""; - AliLVStructure lvStructure(path); - RegisterLogicalVolume(lv, path, lvStructure); - lvStructure.SetTreeVisibility(visibility); - } -} - -//_____________________________________________________________________________ -void AliModuleConstruction::SetVolumeVisibility(G4LogicalVolume* lv, - G4bool visibility) const -{ -// 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); + AliFiles* files = AliFiles::Instance(); - lv->SetVisAttributes(newVisAttributes); - } -} - -//_____________________________________________________________________________ -void AliModuleConstruction::SetDetColour(G4String colName) const -{ -// 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); + // 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); + + // 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); + } + + // 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 = "AliSingleModuleConstruction::Configure:\n"; + text = text + " AliModule " + GetDetName(); + text = text + " has not been found in gAlice."; + AliGlobals::Exception(text); } } -//_____________________________________________________________________________ -void AliModuleConstruction::SetLVTreeColour(G4LogicalVolume* lv, - const G4String& colName) const -{ -// 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, - const G4String& colName) const -{ -// 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 - diff --git a/AliGeant4/AliModuleConstruction.h b/AliGeant4/AliModuleConstruction.h index cf439226ab9..9c44099f3f4 100644 --- a/AliGeant4/AliModuleConstruction.h +++ b/AliGeant4/AliModuleConstruction.h @@ -5,30 +5,28 @@ // // Class AliModuleConstruction // --------------------------- -// Abstract base class for modular construction of geometry, -// providing methods for browsing geometry (list volumes trees, -// visualization). +// Composite of AliDetector and additional parameters +// used for optional writing/reading geometry ASCII +// files, interactive detector setup and processing +// of module related G4 macros. + #ifndef ALI_MODULE_CONSTRUCTION_H #define ALI_MODULE_CONSTRUCTION_H -#include "AliModuleConstructionMessenger.h" +#include "AliModuleType.h" #include -class AliLVStructure; class AliModule; - -class G4VPhysicalVolume; -class G4LogicalVolume; -#ifdef ALICE_VISUALIZE -class G4Colour; -#endif +class AliFiles; class AliModuleConstruction { public: - AliModuleConstruction(const G4String& moduleName); + AliModuleConstruction(const G4String& moduleName, + G4int version, + AliModuleType moduleType = kDetector); AliModuleConstruction(const AliModuleConstruction& right); // --> protected // AliModuleConstruction(); @@ -40,76 +38,68 @@ class AliModuleConstruction G4int operator!=(const AliModuleConstruction& right) const; // methods - virtual void Construct() = 0; - void ListAllLVTree() const; - void ListAllLVTreeLong() const; - void ListLVTree(const G4String& lvName) const; - void ListLVTreeLong(const G4String& lvName) const; + void Configure(); // set methods - void SetDetFrame(G4bool warn = true); - void SetDetFrame(const G4String& frameName, G4bool warn = true); + void SetModuleType(AliModuleType type); + void SetProcessConfig(G4bool processConfig); void SetReadGeometry(G4bool readGeometry); void SetWriteGeometry(G4bool writeGeometry); -#ifdef ALICE_VISUALIZE - void SetDetVisibility(G4bool visibility) const; - void SetLVTreeVisibility(G4LogicalVolume* lv, G4bool visibility) const; - void SetVolumeVisibility(G4LogicalVolume* lv, G4bool visibility) const; - void SetDetColour(G4String colName) const; - void SetLVTreeColour(G4LogicalVolume* lv, const G4String& colName) const; - void SetVolumeColour(G4LogicalVolume* lv, const G4String& colName) const; -#endif // get methods - G4String GetDetName() const; - G4LogicalVolume* GetDetFrame() const; AliModule* GetAliModule() const; - G4bool GetReadGeometry() const; - G4bool GetWriteGeometry() const; - G4String GetDataFilePath() const; + AliModuleType GetType() const; + G4String GetDetName() const; + G4int GetVersion() const; + G4bool GetProcessConfig() const; + G4bool GetReadGeometry() const; + G4bool GetWriteGeometry() const; + G4String GetDataFilePath() const; - protected: + private: AliModuleConstruction(); // data members - G4String fModuleName; //module name - G4String fModuleFrameName; //module frame name - //(used for retrieving the frame LV) - G4LogicalVolume* fModuleFrameLV; //module frame logical volume - - // to be moved to AliSingleModuleConstruction - // in order to make AliModuleConstruction independent on - // AliRoot - AliModule* fAliModule; //AliModule - G4bool fReadGeometry; //if true: geometry is read from file - G4bool fWriteGeometry; //if true: geometry is written to file - G4String fDataFilePath; //path to geometry data file - - private: - // methods - void RegisterLogicalVolume(G4LogicalVolume* lv, const G4String& path, - AliLVStructure& lvStructure) const; + AliModule* fAliModule; //AliModule + G4String fModuleName; //module name + AliModuleType fType; //module type (detector/structure) + G4int fVersion; //module version + G4bool fProcessConfig; //control for processing Config.C + G4bool fReadGeometry; //if true: geometry is read from file + G4bool fWriteGeometry; //if true: geometry is written to file + G4String fDataFilePath; //path to geometry data file // data members - AliModuleConstructionMessenger fMessenger; //messenger }; // inline methods +inline void AliModuleConstruction::SetModuleType(AliModuleType type) +{ fType = type; } + +inline void AliModuleConstruction::SetProcessConfig(G4bool processConfig) +{ fProcessConfig = processConfig; } + inline void AliModuleConstruction::SetReadGeometry(G4bool readGeometry) { fReadGeometry = readGeometry; } inline void AliModuleConstruction::SetWriteGeometry(G4bool writeGeometry) { fWriteGeometry = writeGeometry; } +inline AliModuleType AliModuleConstruction::GetType() const +{ return fType; } + +inline AliModule* AliModuleConstruction::GetAliModule() const +{ return fAliModule; } + inline G4String AliModuleConstruction::GetDetName() const { return fModuleName; } -inline G4LogicalVolume* AliModuleConstruction::GetDetFrame() const -{ return fModuleFrameLV; } +inline G4int AliModuleConstruction::GetVersion() const +{ return fVersion; } -inline AliModule* AliModuleConstruction::GetAliModule() const -{ return fAliModule; } +inline G4bool AliModuleConstruction::GetProcessConfig() const +{ return fProcessConfig; } inline G4bool AliModuleConstruction::GetReadGeometry() const { return fReadGeometry; } diff --git a/AliGeant4/AliModulesComposition.cxx b/AliGeant4/AliModulesComposition.cxx index 1dd0bbee068..f4b1271e63d 100644 --- a/AliGeant4/AliModulesComposition.cxx +++ b/AliGeant4/AliModulesComposition.cxx @@ -8,28 +8,23 @@ // See the class description in the header file. #include "AliModulesComposition.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 -#include //_____________________________________________________________________________ AliModulesComposition::AliModulesComposition() : fReadGeometry(false), fWriteGeometry(false), fMagneticField(0), - fMessenger(this) -{ + fMessenger(this) { // - fMoreModulesConstruction = new AliMoreModulesConstruction(); } //_____________________________________________________________________________ @@ -43,19 +38,7 @@ AliModulesComposition::AliModulesComposition(const AliModulesComposition& right) //_____________________________________________________________________________ AliModulesComposition::~AliModulesComposition() { // - delete fMoreModulesConstruction; delete fMagneticField; - - // destroy det switch vector - DetSwitchIterator it; - for (it = fDetSwitchVector.begin(); it != fDetSwitchVector.end(); it++) - delete *it; - - // destroy det construction vector - SingleModuleIterator itm; - for (itm = fModuleConstructionVector.begin(); - itm != fModuleConstructionVector.end(); it++) - delete *itm; } // operators @@ -72,97 +55,111 @@ 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.push_back(detSwitch); - fMessenger.SetCandidates(); -} + if (nofModules == 0) { + AliGlobals::Warning( + "AliModulesComposition::Configure: No modules are defined."); + return; + } -//_____________________________________________________________________________ -void AliModulesComposition::AddSingleModuleConstruction( - const G4String& name, G4int version, - AliModuleType moduleType) -{ -// Adds SingleModuleConstruction. -// --- + for (G4int i=0; iConfigure(); +} - fModuleConstructionVector - .push_back(new AliSingleModuleConstruction(name, version, moduleType)); -} - -//_____________________________________________________________________________ -void AliModulesComposition::AddMoreModuleConstruction( - const G4String& name, G4int version, - AliModuleType moduleType) -{ -// Adds module to MoreModulesConstruction (construction of dependent -// modules.) -// --- - fMoreModulesConstruction->AddModule(name, 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); + // 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; iConfigure(files); - // configure single modules - SingleModuleIterator it; - for (it = fModuleConstructionVector.begin(); - it != fModuleConstructionVector.end(); it++) { - - (*it)->Configure(*AliFiles::Instance()); - cout << "Module " << (*it)->GetDetName() << " configured." << endl; - } - - // configure dependent modules - if (fMoreModulesConstruction->GetNofModules() > 0) - fMoreModulesConstruction->Configure(*AliFiles::Instance()); - - // construct single modules - for (it = fModuleConstructionVector.begin(); - it != fModuleConstructionVector.end(); it++) { - - G4cout << "Module " << (*it)->GetDetName() - << " will be constructed now." << G4endl; - (*it)->Construct(); - } - - // construct dependent modules - if (fMoreModulesConstruction->GetNofModules() > 0) { - 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(); -//_____________________________________________________________________________ -AliDetSwitch* AliModulesComposition::GetDetSwitch( - const G4String& moduleName) const -{ -// Returns the detector switch with given detector name. -// --- + // print name map + // pGeometryManager->PrintNameMap(); - DetSwitchConstIterator it; - for (it = fDetSwitchVector.begin(); it != fDetSwitchVector.end(); it++) - if ((*it)->GetDetName() == moduleName) return *it; + for (i=0; iGetAliModule()->BuildGeometry(); + } + + // reset TG4GeometryManager + pGeometryManager->ClearG3Tables(); +} //_____________________________________________________________________________ void AliModulesComposition::SetReadGeometryToModules(G4bool readGeometry) @@ -170,16 +167,8 @@ void AliModulesComposition::SetReadGeometryToModules(G4bool readGeometry) // Sets readGeometry control to all modules. // --- - // single module constructions - SingleModuleIterator it; - for (it = fModuleConstructionVector.begin(); - it != fModuleConstructionVector.end(); it++) - (*it)->SetReadGeometry(readGeometry); - - // more modules construction - for (G4int i=0; iGetNofModules(); i++) - fMoreModulesConstruction - ->GetModuleConstruction(i)->SetReadGeometry(readGeometry); + for (G4int i=0; iSetReadGeometry(readGeometry); } //_____________________________________________________________________________ @@ -188,130 +177,58 @@ void AliModulesComposition::SetWriteGeometryToModules(G4bool writeGeometry) // Sets writeGeometry control to all modules. // --- - // single module constructions - SingleModuleIterator it; - for (it = fModuleConstructionVector.begin(); - it != fModuleConstructionVector.end(); it++) - (*it)->SetWriteGeometry(writeGeometry); - - // more modules construction - for (G4int i=0; iGetNofModules(); i++) - fMoreModulesConstruction - ->GetModuleConstruction(i)->SetWriteGeometry(writeGeometry); -} - -//_____________________________________________________________________________ -void AliModulesComposition::SetProcessConfigToModules(G4bool processConfig) -{ -// Sets processConfig control to all modules. -// --- - - // single module constructions - SingleModuleIterator it; - for (it = fModuleConstructionVector.begin(); - it != fModuleConstructionVector.end(); it++) - (*it)->SetProcessConfig(processConfig); - - // more modules construction - for (G4int i=0; iGetNofModules(); i++) - fMoreModulesConstruction - ->GetModuleConstruction(i)->SetProcessConfig(processConfig); + for (G4int i=0; iSetWriteGeometry(writeGeometry); } -// public methods - -//_____________________________________________________________________________ -void AliModulesComposition::SwitchDetOn(const G4String& moduleNameVer) -{ -// Switchs on module specified by name and version. -// --- - - DetSwitchIterator it; - - if (moduleNameVer == "ALL") { - for (it = fDetSwitchVector.begin(); it != fDetSwitchVector.end(); it++) - (*it)->SwitchOnDefault(); - } - else if (moduleNameVer == "NONE") { - for (it = fDetSwitchVector.begin(); it != fDetSwitchVector.end(); it++) - (*it)->SwitchOff(); - } - else { - // get version number - G4int len = moduleNameVer.length(); - G4String moduleName = moduleNameVer.substr(0, len-1); - G4String version = moduleNameVer.substr(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); - } -} +// +// protected methods +// //_____________________________________________________________________________ -void AliModulesComposition::SwitchDetOn(const G4String& moduleName, - G4int version) -{ -// Switchs on module specified by name and version. +void AliModulesComposition::AddModule(const G4String& name, + G4int version, + AliModuleType moduleType) +{ +// Adds module to the module construction vector. // --- - GetDetSwitch(moduleName)->SwitchOn(version); -} + AliModuleConstruction* moduleConstruction + = new AliModuleConstruction(name, version, moduleType); + fModuleConstructionVector.push_back(moduleConstruction); +} + //_____________________________________________________________________________ -void AliModulesComposition::SwitchDetOnDefault(const G4String& moduleName) -{ -// Switchs on module specified by name with default version. +void AliModulesComposition::ConstructModules() +{ +// Construct geometry of all modules (both standalone and dependent.) // --- - GetDetSwitch(moduleName)->SwitchOnDefault(); -} - -//_____________________________________________________________________________ -void AliModulesComposition::SwitchDetOff(const G4String& moduleName) -{ -// Switchs off module specified by name. -// --- + // set common options + SetReadGeometryToModules(fReadGeometry); + SetWriteGeometryToModules(fWriteGeometry); + + // configure modules + Configure(); - if (moduleName == "ALL") { - DetSwitchIterator it; - for (it = fDetSwitchVector.begin(); it != fDetSwitchVector.end(); it++) - (*it)->SwitchOff(); - } - else - GetDetSwitch(moduleName)->SwitchOff(); -} + // 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; iSetProcessConfig(processConfig); +} - G4String avList = GetAvailableDetsList(); - - G4cout << "Available Alice detectors: " << G4endl; - G4cout << "---------------------------" << G4endl; - G4cout << avList << G4endl; -} +// +// public methods +// //_____________________________________________________________________________ void AliModulesComposition::PrintMaterials() const @@ -323,159 +240,6 @@ 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(); - - // XML filename - // according to last switched detector - G4String detName; - G4String detVersion = ""; - G4int version = -1; - for (G4int i=fDetSwitchVector.size()-1; i>=0; i--) { - version = fDetSwitchVector[i]->GetSwitchedVersion(); - if (version > -1) { - detName = fDetSwitchVector[i]->GetDetName(); - AliGlobals::AppendNumberToString(detVersion,version); - break; - } - } - G4String filePath - = AliFiles::Instance()->GetXMLFilePath(detName, version); - - // 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, detVersion, "today", "Generated from Geant4", - topName, world->GetLogicalVolume()); - xml.CloseFile(); - - // set verbose - G4cout << "File " << detName << "v" << version << ".xml has been generated." - << G4endl; -} - -//_____________________________________________________________________________ -G4String AliModulesComposition::GetSwitchedDetsList() const -{ -// Returns list of switched detectors. -// --- - - G4String svList = ""; - G4int nofSwitchedDets = 0; - DetSwitchConstIterator it; - - for (it = fDetSwitchVector.begin(); it != fDetSwitchVector.end(); it++) { - G4int iVersion = (*it)->GetSwitchedVersion(); - if (iVersion > -1) { - nofSwitchedDets++; - G4String moduleNameVer = (*it)->GetDetName(); - AliGlobals::AppendNumberToString(moduleNameVer, iVersion); - svList += moduleNameVer; - svList += " "; - } - } - - if (nofSwitchedDets == fDetSwitchVector.size()) svList = "ALL: " + svList; - if (nofSwitchedDets == 0) svList = "NONE"; - - return svList; -} - -//_____________________________________________________________________________ -G4String AliModulesComposition::GetAvailableDetsList() const -{ -// Returns list of available detectors. -// --- - - G4String svList = ""; - DetSwitchConstIterator it; - - for (it = fDetSwitchVector.begin(); it != fDetSwitchVector.end(); it++) - for (G4int iv=0; iv<(*it)->GetNofVersions(); iv++) { - G4String moduleNameVer = (*it)->GetDetName(); - AliGlobals::AppendNumberToString(moduleNameVer, iv); - svList += moduleNameVer; - svList += " "; - } - - return svList; -} - -//_____________________________________________________________________________ -G4String AliModulesComposition::GetAvailableDetsListWithCommas() const -{ -// Returns list of available detectors with commas. -// --- - - G4String svList = ""; - G4int id =0; - DetSwitchConstIterator it; - - for (it = fDetSwitchVector.begin(); it != fDetSwitchVector.end(); it++) - for (G4int iv=0; iv<(*it)->GetNofVersions(); iv++) { - G4String moduleNameVer = (*it)->GetDetName(); - AliGlobals::AppendNumberToString(moduleNameVer, iv); - svList += moduleNameVer; - if (iv < (*it)->GetNofVersions()-1) svList += "/"; - else if (id++ < fDetSwitchVector.size()-1) svList += ", "; - } - - return svList; -} - -//_____________________________________________________________________________ -G4String AliModulesComposition::GetDetNamesList() const -{ -// Returns list of detector names. -// --- - - G4String svList = ""; - DetSwitchConstIterator it; - - for (it = fDetSwitchVector.begin(); it != fDetSwitchVector.end(); it++) { - svList += (*it)->GetDetName(); - svList += " "; - } - - return svList; -} - -//_____________________________________________________________________________ -G4String AliModulesComposition::GetDetNamesListWithCommas() const -{ -// Returns list of detector names with commas. -// --- - - G4String svList = ""; - G4int id =0; - DetSwitchConstIterator it; - - for (it = fDetSwitchVector.begin(); it != fDetSwitchVector.end(); it++) { - svList += (*it)->GetDetName(); - if (id++ < fDetSwitchVector.size()-1) svList += ", "; - } - - return svList; -} - //_____________________________________________________________________________ void AliModulesComposition::SetMagField(G4double fieldValue) { diff --git a/AliGeant4/AliModulesComposition.h b/AliGeant4/AliModulesComposition.h index 3867890785c..5914f7bbe6e 100644 --- a/AliGeant4/AliModulesComposition.h +++ b/AliGeant4/AliModulesComposition.h @@ -6,8 +6,7 @@ // Class AliModulesComposition // --------------------------- // Detector construction base class for building geometry -// composed from independent modules with availability of interactive modules -// setup. +// composed from modules. #ifndef ALI_MODULES_COMPOSITION_H #define ALI_MODULES_COMPOSITION_H @@ -19,22 +18,15 @@ #include #include -class AliSingleModuleConstruction; -class AliDetSwitch; -class AliMoreModulesConstruction; +class AliModuleConstruction; class AliMagneticField; class G4VPhysicalVolume; class AliModulesComposition : public G4VUserDetectorConstruction { - typedef G4std::vector DetSwitchVector; - typedef DetSwitchVector::iterator DetSwitchIterator; - typedef DetSwitchVector::const_iterator DetSwitchConstIterator; - - typedef G4std::vector SingleModuleVector; - typedef SingleModuleVector::iterator SingleModuleIterator; - + typedef G4std::vector AliModuleConstructionVector; + public: AliModulesComposition(); // --> protected @@ -43,27 +35,13 @@ class AliModulesComposition : public G4VUserDetectorConstruction // methods virtual G4VPhysicalVolume* Construct() = 0; - void SwitchDetOn(const G4String& moduleNameVer); - void SwitchDetOn(const G4String& moduleName, G4int version); - void SwitchDetOnDefault(const G4String& moduleName); - void SwitchDetOff(const G4String& moduleName); - void PrintSwitchedDets() const; - void PrintAvailableDets() const; - void PrintMaterials() const; - void GenerateXMLGeometry() const; + virtual void GenerateXMLGeometry() const = 0; + virtual void PrintMaterials() const; // set methods void SetMagField(G4double fieldValue); void SetReadGeometry(G4bool readGeometry); void SetWriteGeometry(G4bool writeGeometry); - void SetProcessConfigToModules(G4bool processConfig); - - // get methods - G4String GetSwitchedDetsList() const; - G4String GetAvailableDetsList() const; - G4String GetAvailableDetsListWithCommas() const; - G4String GetDetNamesList() const; - G4String GetDetNamesListWithCommas() const; protected: AliModulesComposition(const AliModulesComposition& right); @@ -72,34 +50,26 @@ class AliModulesComposition : public G4VUserDetectorConstruction AliModulesComposition& operator=(const AliModulesComposition& right); // methods - void AddDetSwitch(AliDetSwitch* detSwitch); - void AddSingleModuleConstruction(const G4String& name, G4int version, - AliModuleType moduleType = kDetector); - void AddMoreModuleConstruction(const G4String& name, G4int version, - AliModuleType moduleType = kDetector); + void AddModule(const G4String& name, + G4int version, + AliModuleType moduleType = kDetector); void ConstructModules(); - - // get methods - AliDetSwitch* GetDetSwitch(const G4String& moduleName) const; - - // data members - DetSwitchVector fDetSwitchVector; //vector of AliDetSwitch + void SetProcessConfigToModules(G4bool processConfig); private: // methods + void Configure(); + void CreateG4Geometry(); void SetReadGeometryToModules(G4bool readGeometry); void SetWriteGeometryToModules(G4bool writeGeometry); // data members - SingleModuleVector fModuleConstructionVector; //vector of - //single module constructions - AliMoreModulesConstruction* fMoreModulesConstruction; //.. - //dependent modules construction - - AliMagneticField* fMagneticField; //magnetic field AliModulesCompositionMessenger fMessenger; //messenger - G4bool fReadGeometry; //option applied to all modules - G4bool fWriteGeometry; //option applied to all modules + AliModuleConstructionVector fModuleConstructionVector; //.. + //vector of AliModuleConstruction + AliMagneticField* fMagneticField; //magnetic field + G4bool fReadGeometry; //option applied to all modules + G4bool fWriteGeometry; //option applied to all modules }; // inline methods diff --git a/AliGeant4/AliModulesCompositionMessenger.cxx b/AliGeant4/AliModulesCompositionMessenger.cxx index f7fc39c370a..a2ce898a32e 100644 --- a/AliGeant4/AliModulesCompositionMessenger.cxx +++ b/AliGeant4/AliModulesCompositionMessenger.cxx @@ -12,7 +12,6 @@ #include "AliGlobals.h" #include -#include #include #include #include @@ -26,38 +25,6 @@ AliModulesCompositionMessenger::AliModulesCompositionMessenger( fDirectory = new G4UIdirectory("/aliDet/"); fDirectory->SetGuidance("Detector construction control commands."); - fSwitchOnCmd = new G4UIcmdWithAString("/aliDet/switchOn", this); - fSwitchOnCmd->SetGuidance("Define the module to be built."); - fSwitchOnCmd->SetGuidance("Available modules:"); - G4String listAvailableDets = "NONE, ALL, "; - listAvailableDets - = listAvailableDets + modulesComposition->GetAvailableDetsListWithCommas(); - fSwitchOnCmd->SetGuidance(listAvailableDets); - fSwitchOnCmd->SetParameterName("module", false); - fSwitchOnCmd->AvailableForStates(PreInit);; - - fSwitchOffCmd = new G4UIcmdWithAString("/aliDet/switchOff", this); - fSwitchOffCmd->SetGuidance("Define the module not to be built."); - fSwitchOffCmd->SetGuidance("Available modules:"); - G4String listDetsNames = "ALL, "; - listDetsNames - = listDetsNames + modulesComposition->GetDetNamesListWithCommas(); - fSwitchOffCmd->SetGuidance(listDetsNames); - fSwitchOffCmd->SetParameterName("module", false); - fSwitchOffCmd->AvailableForStates(PreInit);; - - fListCmd - = new G4UIcmdWithoutParameter("/aliDet/list", this); - fListCmd->SetGuidance("List the currently switched modules."); - fListCmd - ->AvailableForStates(PreInit, Init, Idle, GeomClosed, EventProc); - - fListAvailableCmd - = new G4UIcmdWithoutParameter("/aliDet/listAvailable", this); - fListAvailableCmd->SetGuidance("List all available modules."); - fListAvailableCmd - ->AvailableForStates(PreInit, Init, Idle, GeomClosed, EventProc); - fFieldValueCmd = new G4UIcmdWithADoubleAndUnit("/aliDet/fieldValue", this); fFieldValueCmd->SetGuidance("Define magnetic field in Z direction."); fFieldValueCmd->SetParameterName("fieldValue", false, false); @@ -86,13 +53,6 @@ AliModulesCompositionMessenger::AliModulesCompositionMessenger( = new G4UIcmdWithoutParameter("/aliDet/generateXML", this); fGenerateXMLCmd->SetGuidance("Generate geometry XML file."); fGenerateXMLCmd->AvailableForStates(Idle); - - - // set candidates list - SetCandidates(); - - // set default values to a detector - fModulesComposition->SwitchDetOn("NONE"); } //_____________________________________________________________________________ @@ -113,10 +73,6 @@ AliModulesCompositionMessenger::AliModulesCompositionMessenger( AliModulesCompositionMessenger::~AliModulesCompositionMessenger() { // delete fDirectory; - delete fSwitchOnCmd; - delete fSwitchOffCmd; - delete fListCmd; - delete fListAvailableCmd; delete fFieldValueCmd; delete fSetReadGeometryCmd; delete fSetWriteGeometryCmd; @@ -148,19 +104,7 @@ void AliModulesCompositionMessenger::SetNewValue(G4UIcommand* command, G4String // Applies command to the associated object. // --- - if (command == fSwitchOnCmd) { - fModulesComposition->SwitchDetOn(newValues); - } - else if (command == fSwitchOffCmd) { - fModulesComposition->SwitchDetOff(newValues); - } - else if (command == fListCmd) { - fModulesComposition->PrintSwitchedDets(); - } - else if (command == fListAvailableCmd) { - fModulesComposition->PrintAvailableDets(); - } - else if (command == fFieldValueCmd) { + if (command == fFieldValueCmd) { fModulesComposition ->SetMagField(fFieldValueCmd->GetNewDoubleValue(newValues)); } @@ -179,19 +123,3 @@ void AliModulesCompositionMessenger::SetNewValue(G4UIcommand* command, G4String fModulesComposition->GenerateXMLGeometry(); } } - -//_____________________________________________________________________________ -void AliModulesCompositionMessenger::SetCandidates() -{ -// Builds candidates list. -// --- - - G4String candidatesList = "NONE ALL "; - candidatesList += fModulesComposition->GetDetNamesList();; - candidatesList += fModulesComposition->GetAvailableDetsList(); - fSwitchOnCmd->SetCandidates(candidatesList); - - candidatesList = "ALL "; - candidatesList += fModulesComposition->GetDetNamesList();; - fSwitchOffCmd->SetCandidates(candidatesList); -} diff --git a/AliGeant4/AliModulesCompositionMessenger.h b/AliGeant4/AliModulesCompositionMessenger.h index e91a33c1b00..44fba27117d 100644 --- a/AliGeant4/AliModulesCompositionMessenger.h +++ b/AliGeant4/AliModulesCompositionMessenger.h @@ -17,7 +17,6 @@ class AliModulesComposition; class G4UIcommand; class G4UIdirectory; -class G4UIcmdWithAString; class G4UIcmdWithoutParameter; class G4UIcmdWithABool; class G4UIcmdWithADoubleAndUnit; @@ -34,7 +33,6 @@ class AliModulesCompositionMessenger: public G4UImessenger // methods virtual void SetNewValue(G4UIcommand* command, G4String newValues); - void SetCandidates(); protected: AliModulesCompositionMessenger(); @@ -50,10 +48,6 @@ class AliModulesCompositionMessenger: public G4UImessenger G4UIdirectory* fDirectory; //command directory // commands data members - G4UIcmdWithAString* fSwitchOnCmd; //command: switchOn - G4UIcmdWithAString* fSwitchOffCmd; //command: switchOn - G4UIcmdWithoutParameter* fListCmd; //command: list - G4UIcmdWithoutParameter* fListAvailableCmd; //command: listAvailable G4UIcmdWithADoubleAndUnit* fFieldValueCmd; //command: fieldValue G4UIcmdWithABool* fSetReadGeometryCmd; //command: readGeometry G4UIcmdWithABool* fSetWriteGeometryCmd; //command: writeGeometry -- 2.43.0