Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:18:03

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 // DDDB is a detector description convention developed by the LHCb experiment.
0015 // For further information concerning the DTD, please see:
0016 // http://lhcb-comp.web.cern.ch/lhcb-comp/Frameworks/DetDesc/Documents/lhcbDtd.pdf
0017 //
0018 //==========================================================================
0019 
0020 // Framework includes
0021 #include "DDDB/DDDBHelper.h"
0022 #include "DDDB/DDDBConversion.h"
0023 
0024 using namespace std;
0025 using namespace dd4hep;
0026 using namespace dd4hep::DDDB;
0027 
0028 namespace {
0029   struct ByName {
0030     const string& n;
0031     ByName(const string& s) : n(s) {}
0032     bool operator() (const pair<string, VisAttr>& o) const  {
0033       return o.first == n;
0034     }
0035   };
0036 }
0037 
0038 /// Standard constructor
0039 DDDBHelper::DDDBHelper(Detector& dsc) 
0040  : m_description(dsc), m_xmlReader(0), m_detDesc(0)
0041 {
0042 }
0043 
0044 /// Default destructor
0045 DDDBHelper::~DDDBHelper()    {
0046   detail::deletePtr(m_detDesc);
0047   m_visAttrs.clear();
0048 }
0049 
0050 /// Attach detectorDescription information
0051 void DDDBHelper::setDetectorDescription(dddb* geo)   {
0052   detail::deletePtr(m_detDesc);
0053   m_detDesc = geo;
0054 }
0055 
0056 /// Access visualization attribute for a given volume by path
0057 VisAttr DDDBHelper::visAttr(const std::string& path)  const   {
0058   VisAttrs::const_iterator i = std::find_if(m_visAttrs.begin(), m_visAttrs.end(), ByName(path));
0059   if ( i == m_visAttrs.end() )  {
0060     for( i=m_visAttrs.begin(); i != m_visAttrs.end(); ++i)  {
0061       size_t idx = path.find((*i).first);
0062       if ( idx == 0 )  {
0063         return (*i).second;
0064       }
0065     }
0066     return VisAttr();
0067   }
0068   return (*i).second;
0069 }
0070 
0071 /// Add visualization attribute
0072 void DDDBHelper::addVisAttr(const std::string& path, const std::string attr_name)    {
0073   VisAttr attr = m_description.visAttributes(attr_name);
0074   if ( attr.isValid() )   {
0075     addVisAttr(path, attr);
0076   }
0077 }
0078 
0079 /// Add visualization attribute
0080 void DDDBHelper::addVisAttr(const std::string& path, VisAttr attr)    {
0081   if ( attr.isValid() )   {
0082     VisAttrs::const_iterator i = std::find_if(m_visAttrs.begin(), m_visAttrs.end(), ByName(path));
0083     if ( i == m_visAttrs.end() )  {
0084       m_visAttrs.push_back(make_pair(path, attr));
0085     }
0086   }
0087 }
0088 
0089 /// Add new conditions entry
0090 bool DDDBHelper::addConditionEntry(const std::string& key, DetElement det, const std::string& item)    {
0091   return m_detCond.insert(make_pair(key,make_pair(det,item))).second;
0092 }
0093 
0094 /// Access conditions entry
0095 std::pair<DetElement,std::string> DDDBHelper::getConditionEntry(const std::string& key)  const    {
0096   auto i = m_detCond.find(key);
0097   if ( i != m_detCond.end() )
0098     return (*i).second;
0099   return make_pair(DetElement(),"");
0100 }
0101