Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-04 02:02:26

0001 #include "DetectorDescription/Core/interface/DDCompactView.h"
0002 
0003 #include <cstdlib>
0004 
0005 #include "DetectorDescription/Core/interface/DDRotationMatrix.h"
0006 #include "DetectorDescription/Core/interface/DDBase.h"
0007 #include "DetectorDescription/Core/interface/DDCompactViewImpl.h"
0008 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
0009 #include "DetectorDescription/Core/interface/DDMaterial.h"
0010 #include "DetectorDescription/Core/interface/DDPosData.h"
0011 #include "DetectorDescription/Core/interface/DDSolid.h"
0012 #include "DetectorDescription/Core/interface/DDSpecifics.h"
0013 #include "DetectorDescription/Core/interface/DDVector.h"
0014 #include "DetectorDescription/Core/interface/LogicalPart.h"
0015 #include "DetectorDescription/Core/interface/Material.h"
0016 #include "DetectorDescription/Core/interface/Solid.h"
0017 #include "DetectorDescription/Core/interface/Specific.h"
0018 
0019 class DDDivision;
0020 
0021 /** 
0022    Compact-views can be created only after an appropriate geometrical hierarchy
0023    has been defined using DDpos(). 
0024       
0025    Further it is assumed that the DDLogicalPart defining the root of the
0026    geometrical hierarchy has been defined using DDRootDef - singleton.
0027    It will be extracted from this singleton using DDRootDef::instance().root()!
0028       
0029    The first time this constructor gets called, the internal graph representation
0030    is build up. Subsequent calls will return immidiately providing access to
0031    the already built up compact-view representation.
0032       
0033    Currently the only usefull methods are DDCompactView::graph(), DDCompactView::root() !
0034        
0035    \todo define a stable interface for navigation (don't expose the user to the graph!)
0036 */
0037 //
0038 DDCompactView::DDCompactView(const DDLogicalPart& rootnodedata)
0039     : rep_(std::make_unique<DDCompactViewImpl>(rootnodedata)),
0040       worldpos_(std::make_unique<DDPosData>(DDTranslation(), DDRotation(), 0)) {}
0041 
0042 DDCompactView::DDCompactView(const DDName& name) {
0043   DDMaterial::StoreT::instance().setReadOnly(false);
0044   DDSolid::StoreT::instance().setReadOnly(false);
0045   DDLogicalPart::StoreT::instance().setReadOnly(false);
0046   DDSpecifics::StoreT::instance().setReadOnly(false);
0047   DDRotation::StoreT::instance().setReadOnly(false);
0048   rep_ = std::make_unique<DDCompactViewImpl>(DDLogicalPart(name));
0049   worldpos_ = std::make_unique<DDPosData>(DDTranslation(), DDRotation(), 0);
0050 }
0051 
0052 DDCompactView::~DDCompactView() = default;
0053 
0054 /** 
0055    The compact-view is kept in an acyclic directed multigraph represented
0056    by an instance of class Graph<DDLogicalPart, DDPosData*). 
0057    Graph provides methods for navigating its content.
0058 */
0059 const DDCompactView::Graph& DDCompactView::graph() const { return rep_->graph(); }
0060 
0061 DDCompactView::GraphWalker DDCompactView::walker() const { return rep_->walker(); }
0062 
0063 const DDLogicalPart& DDCompactView::root() const { return rep_->root(); }
0064 
0065 const DDPosData* DDCompactView::worldPosition() const { return worldpos_.get(); }
0066 
0067 const std::vector<double>& DDCompactView::vector(std::string_view iKey) const {
0068   auto itFind = vectors_.find(std::string(iKey));
0069   if (itFind != vectors_.end()) {
0070     return itFind->second;
0071   }
0072   static const std::vector<double> s_empty;
0073   return s_empty;
0074 }
0075 
0076 void DDCompactView::position(const DDLogicalPart& self,
0077                              const DDLogicalPart& parent,
0078                              const std::string& copyno,
0079                              const DDTranslation& trans,
0080                              const DDRotation& rot,
0081                              const DDDivision* div) {
0082   int cpno = atoi(copyno.c_str());
0083   position(self, parent, cpno, trans, rot, div);
0084 }
0085 
0086 void DDCompactView::position(const DDLogicalPart& self,
0087                              const DDLogicalPart& parent,
0088                              int copyno,
0089                              const DDTranslation& trans,
0090                              const DDRotation& rot,
0091                              const DDDivision* div) {
0092   rep_->position(self, parent, copyno, trans, rot, div);
0093 }
0094 
0095 // UNSTABLE STUFF below ...
0096 void DDCompactView::setRoot(const DDLogicalPart& root) { rep_->setRoot(root); }
0097 
0098 void DDCompactView::swap(DDCompactView& repToSwap) { rep_->swap(*(repToSwap.rep_)); }
0099 
0100 DDCompactView::DDCompactView()
0101     : rep_(std::make_unique<DDCompactViewImpl>()),
0102       worldpos_(std::make_unique<DDPosData>(DDTranslation(), DDRotation(), 0)) {}
0103 
0104 void DDCompactView::lockdown() {
0105   // at this point we should have a valid store of DDObjects and we will move these
0106   // to the local storage area using swaps with the existing Singleton<Store...>'s
0107   DDMaterial::StoreT::instance().swap(matStore_);
0108   DDSolid::StoreT::instance().swap(solidStore_);
0109   DDLogicalPart::StoreT::instance().swap(lpStore_);
0110   DDSpecifics::StoreT::instance().swap(specStore_);
0111   DDRotation::StoreT::instance().swap(rotStore_);
0112 
0113   //Deal with DDVectors
0114   DDVector::iterator<DDVector> vit;
0115   DDVector::iterator<DDVector> ved(DDVector::end());
0116 
0117   for (; vit != ved; ++vit) {
0118     if (vit->isDefined().second) {
0119       DDName vname(vit->name());
0120       vectors_.emplace(vname.name(), vit->values());
0121     }
0122   }
0123   // NOTE: would be good to clear DDVector's container at this time
0124   // to avoid mixing with other DDCompactViews. Unclear if that is
0125   // safe to do.
0126 
0127   // FIXME: lock the global stores.
0128   DDMaterial::StoreT::instance().setReadOnly(false);
0129   DDSolid::StoreT::instance().setReadOnly(false);
0130   DDLogicalPart::StoreT::instance().setReadOnly(false);
0131   DDSpecifics::StoreT::instance().setReadOnly(false);
0132   DDRotation::StoreT::instance().setReadOnly(false);
0133 }