diff --git a/DDCore/include/XML/UnicodeValues.h b/DDCore/include/XML/UnicodeValues.h index dd01285c0ce6cf2e617a760dc8a2ba3f68d88d3e..576ff45ddeb8db308da234f67885ad1feffb39de 100644 --- a/DDCore/include/XML/UnicodeValues.h +++ b/DDCore/include/XML/UnicodeValues.h @@ -320,6 +320,7 @@ UNICODE (offset); UNICODE (open); UNICODE (operation); UNICODE (opticalsurface); +UNICODE (option); UNICODE (overlap); UNICODE (outer); UNICODE (outer_field); diff --git a/DDCore/src/plugins/Compact2Objects.cpp b/DDCore/src/plugins/Compact2Objects.cpp index abc3c8431664544215fa8baa08ef74aa4ce9dd5d..dc2661812777cac729b767ffabc226e9efd23f51 100644 --- a/DDCore/src/plugins/Compact2Objects.cpp +++ b/DDCore/src/plugins/Compact2Objects.cpp @@ -731,8 +731,9 @@ template <> void Converter<OpticalSurface>::operator()(xml_h element) const { } continue; } - size_t cols = props.attr<long>(_U(coldim)); - string nam = props.attr<string>(_U(name)); + size_t cols = props.attr<long>(_U(coldim)); + string nam = props.attr<string>(_U(name)); + xml_attr_t opt = props.attr_nothrow(_U(option)); stringstream str(props.attr<string>(_U(values))), str_nam; string val; vector<double> values; @@ -744,6 +745,10 @@ template <> void Converter<OpticalSurface>::operator()(xml_h element) const { } /// Create table and register table TGDMLMatrix* table = new TGDMLMatrix("",values.size()/cols, cols); + if ( opt ) { + string tit = e.attr<string>(opt); + str_nam << tit << "|"; + } str_nam << nam << "__" << (void*)table; table->SetName(str_nam.str().c_str()); table->SetTitle(nam.c_str()); @@ -766,6 +771,17 @@ template <> void Converter<PropertyConstant>::operator()(xml_h e) const { if ( s_debug.matrix ) { printout(ALWAYS,"Compact","+++ Reading property %s : %f",name.c_str(), value); } +#if 0 + xml_attr_t opt = e.attr_nothrow(_U(title)); + if ( opt ) { + string val = e.attr<string>(opt); + TNamed* nam = description.manager().GetProperty(name.c_str()); + if ( !nam ) { + except("Compact","Failed to access just added manager property: %s",name.c_str()); + } + nam->SetTitle(val.c_str()); + } +#endif } /** Convert compact property table objects (defines) @@ -774,34 +790,37 @@ template <> void Converter<PropertyConstant>::operator()(xml_h e) const { * */ template <> void Converter<PropertyTable>::operator()(xml_h e) const { - string val; - vector<double> values; - size_t cols = e.attr<unsigned long>(_U(coldim)); - stringstream str(e.attr<string>(_U(values))); + vector<double> vals; + size_t cols = e.attr<unsigned long>(_U(coldim)); + stringstream str(e.attr<string>(_U(values))); if ( s_debug.matrix ) { printout(ALWAYS,"Compact","+++ Reading property table %s with %d columns.", e.attr<string>(_U(name)).c_str(), cols); } - values.reserve(1024); + vals.reserve(1024); while ( !str.eof() ) { - val = ""; - str >> val; - if ( val.empty() && !str.good() ) break; - values.emplace_back(_toDouble(val)); + string item; + str >> item; + if ( item.empty() && !str.good() ) break; + vals.emplace_back(_toDouble(item)); if ( s_debug.matrix ) { - cout << " state:" << (str.good() ? "OK " : "BAD") << " '" << val << "'"; - if ( 0 == (values.size()%cols) ) cout << endl; + cout << " state:" << (str.good() ? "OK " : "BAD") << " '" << item << "'"; + if ( 0 == (vals.size()%cols) ) cout << endl; } } if ( s_debug.matrix ) { cout << endl; } /// Create table and register table - PropertyTable table(description, e.attr<string>(_U(name)), "", values.size()/cols, cols); - for (size_t i=0, n=values.size(); i<n; ++i) - table->Set(i/cols, i%cols, values[i]); - //if ( s_debug.matrix ) table->Print(); + xml_attr_t opt = e.attr_nothrow(_U(option)); + PropertyTable tab(description, + e.attr<string>(_U(name)), + opt ? e.attr<string>(opt).c_str() : "", + vals.size()/cols, cols); + for( size_t i=0, n=vals.size(); i < n; ++i ) + tab->Set(i/cols, i%cols, vals[i]); + //if ( s_debug.matrix ) tab->Print(); } #endif diff --git a/DDG4/src/Geant4Converter.cpp b/DDG4/src/Geant4Converter.cpp index 18df9d9a20f55b2d81bb3797e6c345dd14cb5a4f..a0e44ad0d35100b62abbe01829c1068524755012 100644 --- a/DDG4/src/Geant4Converter.cpp +++ b/DDG4/src/Geant4Converter.cpp @@ -11,6 +11,7 @@ // //========================================================================== + // Framework include files #include "DD4hep/Detector.h" #include "DD4hep/Plugins.h" @@ -86,7 +87,8 @@ using namespace std; #include "DDG4/Geant4AssemblyVolume.h" #include "DD4hep/DetectorTools.h" -static const double CM_2_MM = (CLHEP::centimeter/dd4hep::centimeter); +static constexpr const double CM_2_MM = (CLHEP::centimeter/dd4hep::centimeter); +static constexpr const char* GEANT4_TAG_IGNORE = "Geant4-ignore"; namespace { static string indent = ""; @@ -375,6 +377,18 @@ void* Geant4Converter::handleMaterial(const string& name, Material medium) const string exc_str; TNamed* named = (TNamed*)obj; TGDMLMatrix* matrix = info.manager->GetGDMLMatrix(named->GetTitle()); + const char* cptr = ::strstr(matrix->GetName(), GEANT4_TAG_IGNORE); + if ( 0 != cptr ) { + printout(INFO,"Geant4MaterialProperties","++ Ignore property %s [%s].", + matrix->GetName(), matrix->GetTitle()); + continue; + } + cptr = ::strstr(matrix->GetTitle(), GEANT4_TAG_IGNORE); + if ( 0 != cptr ) { + printout(INFO,"Geant4MaterialProperties","++ Ignore property %s [%s].", + matrix->GetName(), matrix->GetTitle()); + continue; + } Geant4GeometryInfo::PropertyVector* v = (Geant4GeometryInfo::PropertyVector*)handleMaterialProperties(matrix); if ( 0 == v ) { @@ -408,7 +422,8 @@ void* Geant4Converter::handleMaterial(const string& name, Material medium) const for(size_t i=0, count=bins.size(); i<count; ++i) bins[i] *= conv.first, vals[i] *= conv.second; - G4MaterialPropertyVector* vec = new G4MaterialPropertyVector(&bins[0], &vals[0], bins.size()); + G4MaterialPropertyVector* vec = + new G4MaterialPropertyVector(&bins[0], &vals[0], bins.size()); tab->AddProperty(named->GetName(), vec); printout(lvl, "Geant4Converter", "++ Property: %-20s [%ld x %ld] -> %s ", named->GetName(), matrix->GetRows(), matrix->GetCols(), named->GetTitle()); @@ -422,7 +437,20 @@ void* Geant4Converter::handleMaterial(const string& name, Material medium) const string exc_str; Bool_t err = kFALSE; TNamed* named = (TNamed*)obj; - double v = info.manager->GetProperty(named->GetTitle(),&err); + + const char* cptr = ::strstr(named->GetName(), GEANT4_TAG_IGNORE); + if ( 0 != cptr ) { + printout(INFO,"Geant4MaterialProperties","++ Ignore property %s [%s].", + named->GetName(), named->GetTitle()); + continue; + } + cptr = ::strstr(named->GetTitle(), GEANT4_TAG_IGNORE); + if ( 0 != cptr ) { + printout(INFO,"Geant4MaterialProperties","++ Ignore property %s [%s].", + named->GetName(), named->GetTitle()); + continue; + } + double v = info.manager->GetProperty(named->GetTitle(),&err); if ( err != kFALSE ) { except("Geant4Converter", "++ FAILED to create G4 material %s " @@ -1034,14 +1062,14 @@ void Geant4Converter::handleProperties(Detector::Properties& prp) const { const Detector::PropertyValues& vals = prp[p.second]; string type = vals.find("type")->second; string tag = type + "_Geant4_action"; - Detector* detPtr = const_cast<Detector*>(&m_detDesc); - long result = PluginService::Create<long>(tag, detPtr, hdlr, &vals); - if (0 == result) { + Detector* det = const_cast<Detector*>(&m_detDesc); + long res = PluginService::Create<long>(tag, det, hdlr, &vals); + if ( 0 == res ) { throw runtime_error("Failed to locate plugin to interprete files of type" " \"" + tag + "\" - no factory:" + type); } - result = *(long*)result; - if (result != 1) { + res = *(long*)res; + if ( res != 1 ) { throw runtime_error("Failed to invoke the plugin " + tag + " of type " + type); } printout(outputLevel, "Geant4Converter", "+++++ Executed Successfully Geant4 setup module *%s*.", type.c_str()); @@ -1050,25 +1078,40 @@ void Geant4Converter::handleProperties(Detector::Properties& prp) const { #if ROOT_VERSION_CODE >= ROOT_VERSION(6,17,0) /// Convert the geometry type material into the corresponding Geant4 object(s). -void* Geant4Converter::handleMaterialProperties(TObject* matrix) const { - TGDMLMatrix* gdmlMat = (TGDMLMatrix*)matrix; - Geant4GeometryInfo& info = data(); - Geant4GeometryInfo::PropertyVector* g4 = info.g4OpticalProperties[gdmlMat]; - if ( !g4 ) { +void* Geant4Converter::handleMaterialProperties(TObject* mtx) const { + Geant4GeometryInfo& info = data(); + TGDMLMatrix* matrix = (TGDMLMatrix*)mtx; + const char* cptr = ::strstr(matrix->GetName(), GEANT4_TAG_IGNORE); + Geant4GeometryInfo::PropertyVector* g4 = info.g4OpticalProperties[matrix]; + + if ( 0 != cptr ) { // Check if the property should not be passed to Geant4 + printout(INFO,"Geant4MaterialProperties","++ Ignore property %s [%s].", + matrix->GetName(), matrix->GetTitle()); + return nullptr; + } + cptr = ::strstr(matrix->GetTitle(), GEANT4_TAG_IGNORE); + if ( 0 != cptr ) { // Check if the property should not be passed to Geant4 + printout(INFO,"Geant4MaterialProperties","++ Ignore property %s [%s].", + matrix->GetName(), matrix->GetTitle()); + return nullptr; + } + + if ( !g4 ) { PrintLevel lvl = debugMaterials ? ALWAYS : outputLevel; g4 = new Geant4GeometryInfo::PropertyVector(); - size_t rows = gdmlMat->GetRows(); - g4->name = gdmlMat->GetName(); - g4->title = gdmlMat->GetTitle(); + size_t rows = matrix->GetRows(); + g4->name = matrix->GetName(); + g4->title = matrix->GetTitle(); g4->bins.reserve(rows); g4->values.reserve(rows); for( size_t i=0; i<rows; ++i ) { - g4->bins.emplace_back(gdmlMat->Get(i,0) /* *CLHEP::eV/units::eV */); - g4->values.emplace_back(gdmlMat->Get(i,1)); + g4->bins.emplace_back(matrix->Get(i,0) /* *CLHEP::eV/units::eV */); + g4->values.emplace_back(matrix->Get(i,1)); } - printout(lvl, "Geant4Converter", "++ Successfully converted material property:%s : %s [%ld rows]", - gdmlMat->GetName(), gdmlMat->GetTitle(), rows); - info.g4OpticalProperties[gdmlMat] = g4; + printout(lvl, "Geant4Converter", + "++ Successfully converted material property:%s : %s [%ld rows]", + matrix->GetName(), matrix->GetTitle(), rows); + info.g4OpticalProperties[matrix] = g4; } return g4; } @@ -1185,12 +1228,17 @@ void* Geant4Converter::handleOpticalSurface(TObject* surface) const { TListIter it(&optSurf->GetProperties()); for(TObject* obj = it.Next(); obj; obj = it.Next()) { string exc_str; - TNamed* named = (TNamed*)obj; + TNamed* named = (TNamed*)obj; TGDMLMatrix* matrix = info.manager->GetGDMLMatrix(named->GetTitle()); + const char* cptr = ::strstr(matrix->GetName(), GEANT4_TAG_IGNORE); + if ( 0 != cptr ) // Check if the property should not be passed to Geant4 + continue; + if ( 0 == tab ) { tab = new G4MaterialPropertiesTable(); g4->SetMaterialPropertiesTable(tab); } + Geant4GeometryInfo::PropertyVector* v = (Geant4GeometryInfo::PropertyVector*)handleMaterialProperties(matrix); if ( !v ) { // Error!