From 4bc060add1f154d3daee29379c85a93b380ff6ee Mon Sep 17 00:00:00 2001 From: agheata <Andrei.Gheata@cern.ch> Date: Sun, 17 Aug 2014 11:23:26 +0200 Subject: [PATCH] Added TGeoElementTable::AddElement(TGeoElement *elem) interface to add user elements to the element table. Added TGeoElement::Print(option) to allow printing the element table. Several options available (cherry picked from commit dda50a55fb33b1ef216ae678b638ab397af30506) --- geom/geom/inc/TGeoElement.h | 2 ++ geom/geom/src/TGeoElement.cxx | 58 ++++++++++++++++++++++++++++++++++- 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/geom/geom/inc/TGeoElement.h b/geom/geom/inc/TGeoElement.h index 612077e7790..84269fca312 100644 --- a/geom/geom/inc/TGeoElement.h +++ b/geom/geom/inc/TGeoElement.h @@ -397,6 +397,7 @@ public: }; void AddElement(const char *name, const char *title, Int_t z, Double_t a); void AddElement(const char *name, const char *title, Int_t z, Int_t n, Double_t a); + void AddElement(TGeoElement *elem); void AddElementRN(TGeoElementRN *elem); void AddIsotope(TGeoIsotope *isotope); void BuildDefaultElements(); @@ -414,6 +415,7 @@ public: Int_t GetNelements() const {return fNelements;} Int_t GetNelementsRN() const {return fNelementsRN;} void ExportElementsRN(const char *filename=""); + virtual void Print(Option_t *option = "") const; ClassDef(TGeoElementTable,4) // table of elements }; diff --git a/geom/geom/src/TGeoElement.cxx b/geom/geom/src/TGeoElement.cxx index b68a4b2fdec..68d2a9fe63f 100644 --- a/geom/geom/src/TGeoElement.cxx +++ b/geom/geom/src/TGeoElement.cxx @@ -888,6 +888,20 @@ void TGeoElementTable::AddElement(const char *name, const char *title, Int_t z, fList->AddAtAndExpand(new TGeoElement(name,title,z,n,a), fNelements++); } +//______________________________________________________________________________ +void TGeoElementTable::AddElement(TGeoElement *elem) +{ +// Add a custom element to the table. + if (!fList) fList = new TObjArray(128); + TGeoElement *orig = FindElement(elem->GetName()); + if (orig) { + Error("AddElement", "Found element with same name: %s (%s). Cannot add to table.", + orig->GetName(), orig->GetTitle()); + return; + } + fList->AddAtAndExpand(elem, fNelements++); +} + //______________________________________________________________________________ void TGeoElementTable::AddElementRN(TGeoElementRN *elem) { @@ -1117,9 +1131,13 @@ void TGeoElementTable::ExportElementsRN(const char *filename) TGeoElement *TGeoElementTable::FindElement(const char *name) const { // Search an element by symbol or full name + // Exact matching + TGeoElement *elem; + elem = (TGeoElement*)fList->FindObject(name); + if (elem) return elem; + // Search case insensitive by element name TString s(name); s.ToUpper(); - TGeoElement *elem; elem = (TGeoElement*)fList->FindObject(s.Data()); if (elem) return elem; // Search by full name @@ -1159,6 +1177,44 @@ TGeoElementRN *TGeoElementTable::GetElementRN(Int_t a, Int_t z, Int_t iso) const return GetElementRN(TGeoElementRN::ENDF(a,z,iso)); } +//______________________________________________________________________________ +void TGeoElementTable::Print(Option_t *option) const +{ +// Print table of elements. The accepted options are: +// "" - prints everything by default +// "D" - prints default elements only +// "I" - prints isotopes +// "R" - prints radio-nuclides only if imported +// "U" - prints user-defined elements only + TString opt(option); + opt.ToUpper(); + Int_t induser = HasDefaultElements() ? 113 : 0; + // Default elements + if (opt=="" || opt=="D") { + if (induser) printf("================\nDefault elements\n================\n"); + for (Int_t iel=0; iel<induser; ++iel) fList->At(iel)->Print(); + } + // Isotopes + if (opt=="" || opt=="I") { + if (fIsotopes) { + printf("================\nIsotopes\n================\n"); + fIsotopes->Print(); + } + } + // Radio-nuclides + if (opt=="" || opt=="R") { + if (HasRNElements()) { + printf("================\nRadio-nuclides\n================\n"); + fListRN->Print(); + } + } + // User-defined elements + if (opt=="" || opt=="U") { + if (fNelements>induser) printf("================\nUser elements\n================\n"); + for (Int_t iel=induser; iel<fNelements; ++iel) fList->At(iel)->Print(); + } +} + ClassImp(TGeoBatemanSol) //______________________________________________________________________________ -- GitLab