Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:16:47

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author     : M.Frank
0011 //
0012 //==========================================================================
0013 
0014 // Framework include files
0015 #include <DD4hep/Detector.h>
0016 #include <DD4hep/Printout.h>
0017 #include <DD4hep/Factories.h>
0018 #include <DD4hep/IDDescriptor.h>
0019 #include <DD4hep/VolumeManager.h>
0020 #include <DD4hep/DetectorTools.h>
0021 
0022 // C/C++ include files
0023 #include <stdexcept>
0024 #include <algorithm>
0025 
0026 using namespace dd4hep;
0027 
0028 using ElementPath = detail::tools::ElementPath;
0029 using PlacementPath = detail::tools::PlacementPath;
0030 
0031 namespace  {
0032 
0033   /** @class GeometryWalk
0034    *
0035    *  Test the volume manager by scanning the sensitive
0036    *  volumes of one or several subdetectors.
0037    *
0038    *  @author  M.Frank
0039    *  @version 1.0
0040    */
0041   struct GeometryWalk  {
0042     /// Helper to scan volume ids
0043     struct FND {
0044       const std::string& test;
0045       FND(const std::string& c) : test(c) {}
0046       bool operator()(const PlacedVolume::VolIDs::value_type& c) const { return c.first == test; }
0047     };
0048     VolumeManager m_mgr;
0049     DetElement    m_det;
0050 
0051     /// Initializing constructor
0052     GeometryWalk(Detector& description, DetElement sdet);
0053     /// Default destructor
0054     virtual ~GeometryWalk() {}
0055     /// Walk through tree of detector elements
0056     void walk(DetElement de, PlacedVolume::VolIDs ids)  const;
0057     /// Printout volume information
0058     void print(DetElement e, PlacedVolume pv, const PlacedVolume::VolIDs& child_ids)  const;
0059     /// Action routine to execute the test
0060     static long run(Detector& description,int argc,char** argv);
0061   };
0062 }
0063 
0064 typedef DetElement::Children _C;
0065 
0066 /// Initializing constructor
0067 GeometryWalk::GeometryWalk(Detector& description, DetElement sdet) : m_det(sdet) {
0068   m_mgr = description.volumeManager();
0069   if ( !m_det.isValid() )   {
0070     std::stringstream err;
0071     err << "The subdetector " << m_det.name() << " is not known to the geometry.";
0072     printout(INFO,"GeometryWalk",err.str().c_str());
0073     throw std::runtime_error(err.str());
0074   }
0075   walk(m_det,PlacedVolume::VolIDs());
0076 }
0077 
0078 /// Printout volume information
0079 void GeometryWalk::print(DetElement e, PlacedVolume pv, const PlacedVolume::VolIDs& /* child_ids */)  const {
0080   std::stringstream log;
0081   PlacementPath all_nodes;
0082   ElementPath   det_elts;
0083   detail::tools::elementPath(e,det_elts);
0084   detail::tools::placementPath(e,all_nodes);
0085   std::string elt_path  = detail::tools::elementPath(det_elts);
0086   std::string node_path = detail::tools::placementPath(all_nodes);
0087   log << "Lookup " << std::left << std::setw(32) << pv.name() << " Detector[" << det_elts.size() << "]: " << elt_path;
0088   printout(INFO,m_det.name(),log.str());
0089   log.str("");
0090   log << "       " << std::left << std::setw(32) << "       " << " Places[" <<  all_nodes.size()  << "]:   " << node_path;
0091   printout(INFO,m_det.name(),log.str());
0092   log.str("");
0093   log << "       " << std::left << std::setw(32) << "       " << " detail::matrix[" <<  all_nodes.size()  << "]: ";
0094   for(PlacementPath::const_iterator i=all_nodes.begin(); i!=all_nodes.end(); ++i)  {
0095     log << (void*)((*i)->GetMatrix()) << "  ";
0096     if ( i+1 == all_nodes.end() ) log << "( -> " << (*i)->GetName() << ")";
0097   }
0098   printout(INFO, m_det.name(), log.str());
0099 }
0100 
0101 /// Walk through tree of volume placements
0102 void GeometryWalk::walk(DetElement e, PlacedVolume::VolIDs ids)  const   {
0103   const _C& children = e.children();
0104   PlacedVolume pv = e.placement();
0105   PlacedVolume::VolIDs child_ids(ids);
0106   print(e,pv,ids);
0107   child_ids.insert(child_ids.end(),pv.volIDs().begin(),pv.volIDs().end());
0108   for (_C::const_iterator i=children.begin(); i!=children.end(); ++i)  {
0109     walk((*i).second,child_ids);
0110   }
0111 }
0112 
0113 /// Action routine to execute the test
0114 long GeometryWalk::run(Detector& description,int argc,char** argv)    {
0115   std::cout << "++ Processing plugin....GeometryWalker.." << std::endl;
0116   DetElement world = description.world();
0117   for(int in=1; in < argc; ++in)  {
0118     std::string name = argv[in]+1;
0119     if ( name == "all" || name == "All" || name == "ALL" )  {
0120       const _C& children = world.children();
0121       for (_C::const_iterator i=children.begin(); i!=children.end(); ++i)  {
0122         DetElement sdet = (*i).second;
0123         std::cout << "++ Processing subdetector: " << sdet.name() << std::endl;
0124         GeometryWalk test(description, sdet);
0125       }
0126       return 1;
0127     }
0128     std::cout << "++ Processing subdetector: " << name << std::endl;
0129     GeometryWalk test(description, description.detector(name));
0130   }
0131   return 1;
0132 }
0133 
0134 
0135 namespace dd4hep {
0136   namespace detail {
0137     using ::GeometryWalk;
0138   }
0139 }
0140 DECLARE_APPLY(GeometryWalker,GeometryWalk::run)