ATLAS Offline Software
Loading...
Searching...
No Matches
compositeHandler.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4
14#include <iostream>
15
16using namespace xercesc;
17
20 : XMLHandler(s, c)
21{
22}
23
25 xercesc::DOMNode *t)
26{
27 std::string name=getAttributeAsString(c, t, "name");
28 double density=getAttributeAsDouble(c, t, "density");
29 StopLoop(true);
30
31 addmaterialHandler* addmatHand = dynamic_cast<addmaterialHandler*>
32 (c.GetHandlerStore().GetHandler("addmaterial"));
33 if (!addmatHand) std::abort();
34
35 natomsHandler* natomsHand = dynamic_cast<natomsHandler*>
36 (c.GetHandlerStore().GetHandler("natoms"));
37 if (!natomsHand) std::abort();
38
39 fractionmassHandler* fractionsHand = dynamic_cast<fractionmassHandler*>
40 (c.GetHandlerStore().GetHandler("fractionmass"));
41 if (!fractionsHand) std::abort();
42
43 addmatHand->GetNames();
44 natomsHand->GetNatoms();
45 fractionsHand->GetFractions();
46
47 DOMNode* child;
48
49 IAGDDParser& parser = *c.GetParser();
50 for (child=t->getFirstChild();child!=0;child=child->getNextSibling())
51 {
52 if (child->getNodeType()==DOMNode::ELEMENT_NODE) {
53 parser.elementLoop(c, child);
54 }
55 }
56
57 std::vector<std::string> names = addmatHand->GetNames();
58 std::vector<int> natoms = natomsHand->GetNatoms();
59 std::vector<double> fractions = fractionsHand->GetFractions();
60
61 if (!natoms.empty())
62 {
63 // it's a molecule
64 AGDDMolecule *m=new AGDDMolecule(c.GetMaterialStore(),name,density);
65 for (unsigned int i=0;i<natoms.size();i++)
66 {
67 m->AddElement(c.GetMaterialStore(), names[i]);
68 m->NAtoms(natoms[i]);
69 }
70 }
71 else if (!fractions.empty())
72 {
73 // it's a mixture
74 AGDDMixture *m=new AGDDMixture(c.GetMaterialStore(),name,density);
75 for (unsigned int i=0;i<fractions.size();i++)
76 {
77 m->AddMaterial(c.GetMaterialStore(), names[i]);
78 m->Fraction(fractions[i]);
79 }
80 }
81 else
82 std::cout<<"Something wrong: "<<name<<" neither molecule nor mixture!!!"<<std::endl;
83}
void StopLoop(bool)
double getAttributeAsDouble(AGDDController &c, const xercesc::DOMNode *t, const std::string &) const
XMLHandler(const std::string &n, AGDDController &c)
std::string getAttributeAsString(AGDDController &c, const xercesc::DOMNode *t, const std::string &) const
std::vector< std::string > GetNames()
virtual void ElementHandle(AGDDController &c, xercesc::DOMNode *t) override
compositeHandler(const std::string &, AGDDController &c)
std::vector< double > GetFractions()
std::vector< int > GetNatoms()