diff --git a/GeoModelTools/GDMLtoGM/GDMLInterface/GDMLController.h b/GeoModelTools/GDMLtoGM/GDMLInterface/GDMLController.h index 3fe7bd7fc7d0ac36294ab8b5d1844e26d32015fb..e9140900215ec45dcbc3742111f0d8782a76e1d3 100644 --- a/GeoModelTools/GDMLtoGM/GDMLInterface/GDMLController.h +++ b/GeoModelTools/GDMLtoGM/GDMLInterface/GDMLController.h @@ -17,7 +17,7 @@ class GeoMaterial; class GeoLogVol; class GeoPhysVol; -typedef std::pair<GeoLogVol*,GeoPhysVol* > GeoVolume; +typedef std::pair<GeoLogVol*,GeoPhysVol*> GeoVolume; typedef std::map<std::string, GeoShape*, std::less<std::string> > solidStore; @@ -63,7 +63,7 @@ public: GeoVolume retrieveLogicalVolume(std::string); void setWorld(GeoVolume v) {world=v;} - GeoPhysVol* getWorld() {return world.second;} + GeoPhysVol* getWorld() {return (world.second);} protected: void registerHandlers(); diff --git a/GeoModelTools/GDMLtoGM/GDMLInterface/physvolHandler.h b/GeoModelTools/GDMLtoGM/GDMLInterface/physvolHandler.h index 75fb29f979dddcdb2110507e357b5771c3924100..5d98caeb5b75fd4bbeb920b0a15b068e86bc2994 100644 --- a/GeoModelTools/GDMLtoGM/GDMLInterface/physvolHandler.h +++ b/GeoModelTools/GDMLtoGM/GDMLInterface/physvolHandler.h @@ -16,10 +16,12 @@ public: void ElementHandle(); GeoPhysVol* getPhysicalVolume(); GeoTransform* getTransform(); - + void setPhysicalVolume(GeoPhysVol* pV) {thePhysicalVolume=pV;} + void setMotherVolume(GeoPhysVol* lV) {theMotherVolume=lV;} private: std::string name; GeoPhysVol* thePhysicalVolume=0; + GeoPhysVol* theMotherVolume=0; GeoTransform* trf=0; }; diff --git a/GeoModelTools/GDMLtoGM/GDMLInterface/replicaHandler.h b/GeoModelTools/GDMLtoGM/GDMLInterface/replicaHandler.h index 4cf1d7d5537d39b6552543821d0714d592411fe4..c87f81d8b81b6d1487e47872659b880fbe36a523 100644 --- a/GeoModelTools/GDMLtoGM/GDMLInterface/replicaHandler.h +++ b/GeoModelTools/GDMLtoGM/GDMLInterface/replicaHandler.h @@ -9,7 +9,8 @@ class GDMLController; #include <vector> class GeoPhysVol; -class GeoTransform; +class GeoSerialTransformer; +class GeoLogVol; class replicaHandler:public GDMLHandler { public: @@ -17,14 +18,17 @@ public: replicaHandler(std::string n, GDMLController* c); void ElementHandle(); GeoPhysVol* getPhysicalVolume(); - GeoTransform* getTransform(int); + GeoSerialTransformer* getTransform(); int getNCopies(); void postLoopHandling(); + void setPhysicalVolume(GeoPhysVol* pV) {thePhysicalVolume=pV;} + void setMotherVolume(GeoPhysVol* lV) {theMotherVolume=lV;} private: std::string name; int nCopies=0; GeoPhysVol* thePhysicalVolume; - std::vector<GeoTransform*> transforms; + GeoPhysVol* theMotherVolume; + GeoSerialTransformer* transform; }; diff --git a/GeoModelTools/GDMLtoGM/src/GDMLController.cxx b/GeoModelTools/GDMLtoGM/src/GDMLController.cxx index 4e010014f8cde7878860ded99cca8cb1163fa194..ea1d7dce35cb18577c3511c284dcc89209b7a358 100644 --- a/GeoModelTools/GDMLtoGM/src/GDMLController.cxx +++ b/GeoModelTools/GDMLtoGM/src/GDMLController.cxx @@ -218,6 +218,7 @@ GeoVolume GDMLController::retrieveLogicalVolume(std::string name) else { std::cout << " Warning! logical volume "<< name << " not found in store! returning empty"<<std::endl; + std::vector<GeoPhysVol*> v; return std::make_pair(nullptr,nullptr); } } diff --git a/GeoModelTools/GDMLtoGM/src/physvolHandler.cxx b/GeoModelTools/GDMLtoGM/src/physvolHandler.cxx index c20882b88a7b9dcb26902752b77775ecbfd169bf..a460cf55c54f5258c6f2d2b2a119046016200578 100644 --- a/GeoModelTools/GDMLtoGM/src/physvolHandler.cxx +++ b/GeoModelTools/GDMLtoGM/src/physvolHandler.cxx @@ -17,11 +17,10 @@ physvolHandler::physvolHandler(std::string n, GDMLController* c): GDMLHandler(n, { } void physvolHandler::ElementHandle() { - thePhysicalVolume=0; //NB the attribute 'name' is not mandatory //better to use the getAttributeAsString with the boolean option - bool isPresent; + bool isPresent; name=getAttributeAsString("name", isPresent); //std::cout<<" this is physvolHandler: name "<<name<<std::endl; @@ -31,9 +30,11 @@ void physvolHandler::ElementHandle() { // GeoTrf::Transform3D pVRotation=GeoTrf::Transform3D::Identity(); // GeoTrf::Vector3D pVTranslation=GeoTrf::Vector3D(0,0,0); - GeoTrf::Transform3D pVRotation=GeoTrf::Transform3D::Identity(); - GeoTrf::Vector3D pVTranslation=GeoTrf::Vector3D(0,0,0); - GeoTrf::Transform3D pVScale=GeoTrf::Scale3D::Identity(); + GeoTrf::Transform3D pVRotation=GeoTrf::Transform3D::Identity(); + GeoTrf::Vector3D pVTranslation=GeoTrf::Vector3D(0,0,0); + GeoTrf::Transform3D pVScale=GeoTrf::Scale3D::Identity(); + + GeoLogVol* theLogicalVolume; for (child=XercesParser::GetCurrentElement()->getFirstChild();child!=0;child=child->getNextSibling()) { @@ -41,48 +42,59 @@ void physvolHandler::ElementHandle() { { XercesParser::elementLoop(child); XMLHandler *h=theController->XMLStore()->GetHandler(child); - if(h){ - std::string nH=h->GetName(); - //std::cout<<" handler name "<<nH<<std::endl; - if (nH=="volumeref") { - volumerefHandler* vH=dynamic_cast<volumerefHandler*>(h); - if (!vH) std::cout<<" something is wrong! can not retrieve volumerefHandler!!!"<<std::endl; - else thePhysicalVolume=(vH->getVolume()).second; - } - else if (nH=="positionref" || nH=="position") - { - positionHandler* pH=dynamic_cast<positionHandler*>(h); - if (!pH) std::cout<<" something is wrong! can not retrieve positionHandler!!!"<<std::endl; - else - { - pVTranslation=pH->getPosition().v3d; - } - } - else if (nH=="rotationref" || nH=="rotation" ) + if(h) + { + std::string nH=h->GetName(); + //std::cout<<" handler name "<<nH<<std::endl; + if (nH=="volumeref") { - rotationHandler* rH=dynamic_cast<rotationHandler*>(h); - if (!rH) std::cout<<" something is wrong! can not retrieve rotationHandler!!!"<<std::endl; - else + volumerefHandler* vH=dynamic_cast<volumerefHandler*>(h); + if (!vH) std::cout<<" something is wrong! can not retrieve volumerefHandler!!!"<<std::endl; + else + { + theLogicalVolume=(vH->getVolume()).first; + thePhysicalVolume=(vH->getVolume()).second; + } + //std::cout<<" physvol "<<thePhysicalVolume<<std::endl; + } + else if (nH=="positionref" || nH=="position") + { + positionHandler* pH=dynamic_cast<positionHandler*>(h); + if (!pH) std::cout<<" something is wrong! can not retrieve positionHandler!!!"<<std::endl; + else + { + pVTranslation=pH->getPosition().v3d; + } + } + else if (nH=="rotationref" || nH=="rotation" ) + { + rotationHandler* rH=dynamic_cast<rotationHandler*>(h); + if (!rH) std::cout<<" something is wrong! can not retrieve rotationHandler!!!"<<std::endl; + else + { + rotation r=rH->getRotation(); + pVRotation=GeoTrf::RotateX3D(-r.rotx)*GeoTrf::RotateY3D(-r.roty)*GeoTrf::RotateZ3D(-r.rotz); + } + } + else if (nH=="scale") + { + scaleHandler* rH=dynamic_cast<scaleHandler*>(h); + if (!rH) std::cout<<" something is wrong! can not retrieve scaleHandler!!!"<<std::endl; + else { - rotation r=rH->getRotation(); - pVRotation=GeoTrf::RotateX3D(-r.rotx)*GeoTrf::RotateY3D(-r.roty)*GeoTrf::RotateZ3D(-r.rotz); - } - } - else if (nH=="scale") { - scaleHandler* rH=dynamic_cast<scaleHandler*>(h); - if (!rH) std::cout<<" something is wrong! can not retrieve scaleHandler!!!"<<std::endl; - else { - scale r=rH->getScale(); - pVScale=GeoTrf::Scale3D(r.scalex, r.scaley, r.scalez); - } - } - else std::cout<<" Name of the handler not defined "<<nH<<std::endl; - } - else std::cout<<"WARNING: handler not defined.. continuing"<<std::endl; - } + scale r=rH->getScale(); + pVScale=GeoTrf::Scale3D(r.scalex, r.scaley, r.scalez); + } + } + else std::cout<<" Name of the handler not defined "<<nH<<std::endl; + } + else std::cout<<"WARNING: handler not defined.. continuing"<<std::endl; + } } - //trf=new GeoTransform(GeoTrf::Translate3D(pVTranslation.x(),pVTranslation.y(),pVTranslation.z())*pVRotation); - trf=new GeoTransform(GeoTrf::Translate3D(pVTranslation.x(),pVTranslation.y(),pVTranslation.z())*pVRotation*pVScale); + + trf=new GeoTransform(GeoTrf::Translate3D(pVTranslation.x(),pVTranslation.y(),pVTranslation.z())*pVRotation*pVScale); + theMotherVolume->add(thePhysicalVolume); + theMotherVolume->add(trf); } GeoPhysVol* physvolHandler::getPhysicalVolume() { diff --git a/GeoModelTools/GDMLtoGM/src/replicaHandler.cxx b/GeoModelTools/GDMLtoGM/src/replicaHandler.cxx index 3ef8b4559156e82338c1d62ddaf653a2237614a6..95a2736c78ffc633a40eb96761950d2fe6c0962d 100644 --- a/GeoModelTools/GDMLtoGM/src/replicaHandler.cxx +++ b/GeoModelTools/GDMLtoGM/src/replicaHandler.cxx @@ -12,6 +12,12 @@ #include "GeoModelKernel/GeoDefinitions.h" #include "GeoModelKernel/GeoTransform.h" +#include "GeoModelKernel/GeoSerialDenominator.h" +#include "GeoModelKernel/GeoSerialTransformer.h" +#include "GeoGenericFunctions/Variable.h" +#include "GeoGenericFunctions/AbsFunction.h" +#include "GeoModelKernel/GeoXF.h" + #include "GDMLInterface/replicate_axisHandler.h" #include "GDMLInterface/Axis.h" @@ -21,81 +27,106 @@ replicaHandler::replicaHandler(std::string n, GDMLController* c): GDMLHandler(n, } void replicaHandler::ElementHandle() { + nCopies=getAttributeAsInt("number"); - std::cout<<"this is replicaHandler::ElementHandle(): nCopies= "<<nCopies<<std::endl; + //std::cout<<"this is replicaHandler::ElementHandle(): nCopies= "<<nCopies<<std::endl; - StopLoop(true); + StopLoop(true); xercesc::DOMNode *child; GeoTrf::Transform3D pVRotation=GeoTrf::Transform3D::Identity(); GeoTrf::Vector3D pVTranslation=GeoTrf::Vector3D(0,0,0); axis_params p; + + GeoLogVol* theLogicalVolume; + - GeoPhysVol* DaughterPV=0; - - for (child=XercesParser::GetCurrentElement()->getFirstChild();child!=0;child=child->getNextSibling()) + for (child=XercesParser::GetCurrentElement()->getFirstChild();child!=0;child=child->getNextSibling()) + { + if (child->getNodeType()==xercesc::DOMNode::ELEMENT_NODE) { - if (child->getNodeType()==xercesc::DOMNode::ELEMENT_NODE) - { - XercesParser::elementLoop(child); - XMLHandler *h=theController->XMLStore()->GetHandler(child); - if(h){ - std::string nH=h->GetName(); - //std::cout<<" handler name "<<nH<<std::endl; - if (nH=="replicate_along_axis") { - replicate_axisHandler* rH=dynamic_cast<replicate_axisHandler*>(h); - if (!rH) std::cout<<" something is wrong! can not retrieve replicate_axisHandler!!!"<<std::endl; - else p=rH->getAxisParameters(); - } - else if (nH=="volumeref") { - volumerefHandler* vH=dynamic_cast<volumerefHandler*>(h); - if (!vH) std::cout<<" something is wrong! can not retrieve volumerefHandler!!!"<<std::endl; - else DaughterPV=(vH->getVolume()).second; - thePhysicalVolume=DaughterPV; - } - } + + XercesParser::elementLoop(child); + XMLHandler *h=theController->XMLStore()->GetHandler(child); + //std::cout<<" namenamename "<<h->GetName()<<std::endl; + if(h){ + std::string nH=h->GetName(); + //std::cout<<" handler name "<<nH<<std::endl; + if (nH=="replicate_along_axis") + { + replicate_axisHandler* rH=dynamic_cast<replicate_axisHandler*>(h); + if (!rH) std::cout<<" something is wrong! can not retrieve replicate_axisHandler!!!"<<std::endl; + else p=rH->getAxisParameters(); + } + else if (nH=="volumeref") + { + volumerefHandler* vH=dynamic_cast<volumerefHandler*>(h); + if (!vH) std::cout<<" something is wrong! can not retrieve volumerefHandler!!!"<<std::endl; + else + { + theLogicalVolume=(vH->getVolume()).first; + //std::cout<<" replicaHandler: log vol name "<<theLogicalVolume->getName()<<std::endl; + thePhysicalVolume=new GeoPhysVol(theLogicalVolume); + //thePhysicalVolume=(vH->getVolume()).second; + + } + } + } } } - double pStartXYZ,pStartPhi, pCurrent; - GeoTransform *tr; + //std::cout<<" start serial transform "<<std::endl; + + double pStartXYZ,pStartPhi; pStartXYZ=-0.5*nCopies*p.w+p.o; pStartPhi=p.o; + + const unsigned int NREPLICAS=nCopies; + GeoGenfun::Variable i; + GeoSerialTransformer* s1=0; + - for (int i=0;i<nCopies;i++) - { - switch (p.a) +// for (int i=0;i<nCopies;i++) +// { + if (p.a == PHI_axis) { - case PHI_axis: - pCurrent=pStartPhi + i*p.w + p.w/2.; - tr=new GeoTransform(GeoTrf::RotateZ3D(pCurrent)); - break; - case X_axis: - pCurrent=pStartXYZ+i*p.w + p.w/2.; - tr=new GeoTransform(GeoTrf::TranslateX3D(pCurrent)); - break; - case Y_axis: - pCurrent=pStartXYZ+i*p.w + p.w/2.; - tr=new GeoTransform(GeoTrf::TranslateY3D(pCurrent)); - break; - case Z_axis: - pCurrent=pStartXYZ+i*p.w + p.w/2.; - tr=new GeoTransform(GeoTrf::TranslateZ3D(pCurrent)); - break; - default: - std::cout<< " WARNING - GDMLtoGM::replicaHandle: unknown axis!"<<std::endl; + GeoGenfun::GENFUNCTION pCurrent=pStartPhi + i*p.w + p.w/2.; + GeoXF::TRANSFUNCTION tr=GeoXF::Pow(GeoTrf::RotateZ3D(1.0),pCurrent); + s1 = new GeoSerialTransformer(thePhysicalVolume,&tr, NREPLICAS); + } + else if (p.a == X_axis) + { + GeoGenfun::GENFUNCTION pCurrent=pStartXYZ+p.w/2.+i*p.w ; + GeoXF::TRANSFUNCTION tr=GeoXF::Pow(GeoTrf::TranslateX3D(1.0),pCurrent); + s1 = new GeoSerialTransformer(thePhysicalVolume,&tr, NREPLICAS); + } + else if (p.a == Y_axis) + { + GeoGenfun::GENFUNCTION pCurrent=pStartXYZ+p.w/2.+i*p.w ; + GeoXF::TRANSFUNCTION tr=GeoXF::Pow(GeoTrf::TranslateY3D(1.0),pCurrent); + s1 = new GeoSerialTransformer(thePhysicalVolume,&tr, NREPLICAS); } - transforms.push_back(tr); - } + else if (p.a == Z_axis) + { + GeoGenfun::GENFUNCTION pCurrent=pStartXYZ+p.w/2.+i*p.w ; + GeoXF::TRANSFUNCTION tr=GeoXF::Pow(GeoTrf::TranslateZ3D(1.0),pCurrent); + s1 = new GeoSerialTransformer(thePhysicalVolume,&tr, NREPLICAS); + } + else + std::cout<< " WARNING - GDMLtoGM::replicaHandle: unknown axis!"<<std::endl; + + theMotherVolume->add(s1); + } GeoPhysVol* replicaHandler::getPhysicalVolume() { return thePhysicalVolume; } -GeoTransform* replicaHandler::getTransform(int i) +GeoSerialTransformer* replicaHandler::getTransform() { - return transforms[i]; + if (!transform) std::cout<<" replicaHandler: transform is 0!!!!!"<<std::endl; + return transform; } void replicaHandler::postLoopHandling() { diff --git a/GeoModelTools/GDMLtoGM/src/volumeHandler.cxx b/GeoModelTools/GDMLtoGM/src/volumeHandler.cxx index 371babd9bda322cde169a13ae3b21059dafd3942..6d53ac513ced1bbcdc322fb32ace0766b50b9c42 100644 --- a/GeoModelTools/GDMLtoGM/src/volumeHandler.cxx +++ b/GeoModelTools/GDMLtoGM/src/volumeHandler.cxx @@ -5,6 +5,7 @@ #include "GDMLInterface/replicaHandler.h" #include "GeoModelKernel/GeoTransform.h" +#include "GeoModelKernel/GeoSerialTransformer.h" volumeHandler::volumeHandler(std::string n, GDMLController* c): GDMLHandler(n,c) @@ -14,80 +15,92 @@ volumeHandler::volumeHandler(std::string n, GDMLController* c): GDMLHandler(n,c) void volumeHandler::ElementHandle() { - theVolume=std::make_pair(nullptr,nullptr); material=nullptr; shape=nullptr; name=getAttributeAsString("name"); //name=stripPointer(getAttributeAsString("name")); - // std::cout<<" this is volumeHandler: name "<<name<<std::endl; + //std::cout<<" this is volumeHandler: name "<<name<<std::endl; StopLoop(true); xercesc::DOMNode *child; - std::vector<GeoPhysVol*> tempPhys; - std::vector<GeoTransform*> tempTransform; + GeoPhysVol* tempPhys=0; + GeoGraphNode* tempTransform=0; + + GeoLogVol* tempLV=0; for (child=XercesParser::GetCurrentElement()->getFirstChild();child!=0;child=child->getNextSibling()) { if (child->getNodeType()==xercesc::DOMNode::ELEMENT_NODE) { - XercesParser::elementLoop(child); + // XercesParser::elementLoop(child); XMLHandler *h=theController->XMLStore()->GetHandler(child); if (h){ - std::string nH=h->GetName(); + std::string nH=h->GetName(); //std::cout<<" handler name "<<nH<<std::endl; + if (nH=="materialref") { + XercesParser::elementLoop(child); materialrefHandler* mH=dynamic_cast<materialrefHandler*>(h); if (!mH) std::cout<<" something is wrong! can not retrieve materialrefHandler!!!"<<std::endl; else material=mH->getMaterial(); } else if (nH=="solidref") { + XercesParser::elementLoop(child); solidrefHandler* sH=dynamic_cast<solidrefHandler*>(h); if (!sH) std::cout<<" something is wrong! can not retrieve solidrefHandler!!!"<<std::endl; else shape=sH->getSolid(); } - else if (nH=="physvol") { + else if (nH=="physvol") { physvolHandler* pH=dynamic_cast<physvolHandler*>(h); if (!pH) std::cout<<" something is wrong! can not retrieve solidrefHandler!!!"<<std::endl; else { - tempPhys.push_back(pH->getPhysicalVolume()); - tempTransform.push_back(pH->getTransform()); + GeoPhysVol* tempPV; + if (!tempLV) + { + //std::cout<<" volumeHandler new volume "<<name<<std::endl; + // std::cout<<" replicaHandler: tempLV is 0!!!!!!"<<std::endl; + tempLV=new GeoLogVol(name,shape,material); + tempPV=new GeoPhysVol(tempLV); + + theVolume=std::make_pair(tempLV,tempPV); + theController->saveLogicalVolume(name,theVolume); + } + pH->setMotherVolume(tempPV); } + XercesParser::elementLoop(child); } - else if (nH=="replicavol") { - replicaHandler* rH=dynamic_cast<replicaHandler*>(h); - if (!rH) std::cout<<" something is wrong! can not retrieve replicaHandler!!!"<<std::endl; - else - { - // std::cout<<" from replicaHandler: nCopies="<<rH->getNCopies()<<std::endl; - for (int i=0;i<rH->getNCopies();i++) - { - tempPhys.push_back(rH->getPhysicalVolume()); - tempTransform.push_back(rH->getTransform(i)); - } - } - } - else std::cout<<" handler name not defined "<<nH<<std::endl; - } + else if (nH=="replicavol") { + replicaHandler* rH=dynamic_cast<replicaHandler*>(h); + if (!rH) std::cout<<" something is wrong! can not retrieve replicaHandler!!!"<<std::endl; + else + { + GeoPhysVol* tempPV; + if (!tempLV) + { + tempLV=new GeoLogVol(name,shape,material); + tempPV=new GeoPhysVol(tempLV); + theVolume=std::make_pair(tempLV,tempPV); + theController->saveLogicalVolume(name,theVolume); + } + rH->setMotherVolume(tempPV); + } + XercesParser::elementLoop(child); + } + } - } //else std::cout<<"WARNING: handler not defined.. continuing"<<std::endl; + } //else std::cout<<"WARNING: handler not defined.. continuing"<<std::endl; } - //std::cout << "Creating logical volume "<<name<<" shape "<<shape<<" mat "<<material<<std::endl; - GeoLogVol* tempLV=new GeoLogVol(name,shape,material); - GeoPhysVol* tempPV=new GeoPhysVol(tempLV); - theVolume=std::make_pair(tempLV,tempPV); - if (tempPhys.size()!=0) + if (!tempLV) { - for (unsigned long i=0; i< tempPhys.size(); i++) - { - GeoPhysVol* pV=tempPhys[i]; - if (tempTransform[i]) - { - theVolume.second->add(tempTransform[i]); - } - theVolume.second->add(pV); - } + //std::cout<< " creating new GeoLogVol "<<name<<" "; + tempLV=new GeoLogVol(name,shape,material); + + GeoPhysVol* tempPV=new GeoPhysVol(tempLV); + + theVolume=std::make_pair(tempLV,tempPV); + theController->saveLogicalVolume(name,theVolume); } - theController->saveLogicalVolume(name,theVolume); + } void volumeHandler::postLoopHandling() { diff --git a/GeoModelTools/GDMLtoGM/src/volumerefHandler.cxx b/GeoModelTools/GDMLtoGM/src/volumerefHandler.cxx index 9e90b5bd02a6ac38e5505df02271876775a5df1b..74064e133381129a8d1e1c77e59f95e54b828bfb 100644 --- a/GeoModelTools/GDMLtoGM/src/volumerefHandler.cxx +++ b/GeoModelTools/GDMLtoGM/src/volumerefHandler.cxx @@ -6,8 +6,8 @@ volumerefHandler::volumerefHandler(std::string n, GDMLController* c): GDMLHandle void volumerefHandler::ElementHandle() { - theVolume=std::make_pair(nullptr,nullptr); ref=getAttributeAsString("ref"); + //std::cout<<" volumeref name "<<ref<<std::endl; theVolume=theController->retrieveLogicalVolume(ref); //theVolume=theController->retrieveLogicalVolume(stripPointer(ref)); }