Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-03-13 08:19:58

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/DetectorLoad.h>
0017 #include <DD4hep/Printout.h>
0018 #include <XML/Conversions.h>
0019 #include <XML/XMLElements.h>
0020 #include <XML/DocumentHandler.h>
0021 #include <DD4hep/DetFactoryHelper.h>
0022 
0023 #include <DDEve/Display.h>
0024 #include <DDEve/DisplayConfiguration.h>
0025 
0026 // C/C++ include files
0027 #include <stdexcept>
0028 
0029 using namespace dd4hep;
0030 
0031 namespace dd4hep  {  namespace   {
0032     /// Some utility class to specialize the convetrers:
0033     class ddeve;
0034     class view;
0035     class panel;
0036     class calodata;
0037     class calodata_configs;
0038     class detelement;
0039     class include;
0040     class display;
0041     class collection;
0042     class collection_configs;
0043   }
0044 
0045   typedef DisplayConfiguration::Configurations Configurations;
0046   typedef DisplayConfiguration::ViewConfigurations ViewConfigurations;
0047 
0048   /// Forward declarations for all specialized converters
0049   template <> void Converter<ddeve>::operator()(xml_h seq)  const;
0050   template <> void Converter<display>::operator()(xml_h seq)  const;
0051   template <> void Converter<view>::operator()(xml_h seq)  const;
0052   template <> void Converter<panel>::operator()(xml_h seq)  const;
0053   template <> void Converter<include>::operator()(xml_h seq)  const;
0054   template <> void Converter<calodata>::operator()(xml_h e)  const;
0055   template <> void Converter<calodata_configs>::operator()(xml_h e)  const;
0056   template <> void Converter<collection>::operator()(xml_h e)  const;
0057   template <> void Converter<collection_configs>::operator()(xml_h e)  const;
0058   template <> void Converter<detelement>::operator()(xml_h seq)  const;
0059 }
0060 
0061 #define DECL_TAG(x) xml::Strng_t u_##x(#x)
0062 namespace {
0063   DECL_TAG(clone);
0064   DECL_TAG(load_geo);
0065   DECL_TAG(show_evt);
0066   DECL_TAG(use);
0067   DECL_TAG(emax);
0068   DECL_TAG(hits);
0069   DECL_TAG(n_eta);
0070   DECL_TAG(eta_min);
0071   DECL_TAG(eta_max);
0072   DECL_TAG(n_phi);
0073   DECL_TAG(phi_min);
0074   DECL_TAG(phi_max);
0075   DECL_TAG(calodata);
0076   DECL_TAG(towerH);
0077   DECL_TAG(visLevel);
0078   DECL_TAG(loadLevel);
0079 }
0080 
0081 static void extract(DisplayConfiguration::Config& c, xml_h e, int typ)   {
0082   c.name  = e.attr<std::string>(_U(name));
0083   c.type = typ;
0084   c.data.defaults.show_evt  = e.hasAttr(u_show_evt) ? e.attr<int>(u_show_evt)  :  1;
0085   c.data.defaults.load_geo  = e.hasAttr(u_load_geo) ? e.attr<int>(u_load_geo)  : -1;
0086   c.data.defaults.color     = e.hasAttr(_U(color))  ? e.attr<int>(_U(color))   : 0xBBBBBB;
0087   c.data.defaults.alpha     = e.hasAttr(_U(alpha))  ? e.attr<float>(_U(alpha)) : -1.0;
0088   c.data.calo3d.emax        = e.hasAttr(u_emax)     ? e.attr<float>(u_emax)    : 25.0;
0089   c.data.calo3d.towerH      = e.hasAttr(u_towerH)   ? e.attr<float>(u_towerH)  : 25.0;
0090   if ( e.hasAttr(_U(dz))   ) c.data.calo3d.dz   = e.attr<float>(_U(dz));
0091   if ( e.hasAttr(_U(rmin)) ) c.data.calo3d.rmin = e.attr<float>(_U(rmin));
0092   if ( e.hasAttr(u_use)    ) c.use  = e.attr<std::string>(u_use);
0093   if ( e.hasAttr(u_hits)   ) c.hits = e.attr<std::string>(u_hits);
0094   if ( e.hasAttr(_U(threshold)) ) c.data.calo3d.threshold = e.attr<float>(_U(threshold));
0095 }
0096 
0097 /** Convert display configuration objects of  tag type ddeve/detelement
0098  *
0099  *  <detelement name="TPC" load="1" ... />
0100  *
0101  *  @author  M.Frank
0102  *  @version 1.0
0103  *  @date    01/06/2014
0104  */
0105 template <> void Converter<detelement>::operator()(xml_h e)  const  {
0106   Configurations* configs = (Configurations*)param;
0107   DisplayConfiguration::Config c;
0108   extract(c,e,DisplayConfiguration::DETELEMENT);
0109   configs->push_back(c);
0110 }
0111 template <> void Converter<panel>::operator()(xml_h e)  const  {
0112   Configurations* configs = (Configurations*)param;
0113   DisplayConfiguration::Config c;
0114   extract(c,e,DisplayConfiguration::PANEL);
0115   configs->push_back(c);
0116 }
0117 template <> void Converter<calodata_configs>::operator()(xml_h e)  const  {
0118   Configurations* configs = (Configurations*)param;
0119   DisplayConfiguration::Config c;
0120   extract(c,e,DisplayConfiguration::CALODATA);
0121   configs->push_back(c);
0122 }
0123 
0124 template <> void Converter<collection_configs>::operator()(xml_h e)  const  {
0125   Configurations* configs = (Configurations*)param;
0126   DisplayConfiguration::Config c;
0127   c.name = e.attr<std::string>(_U(name));
0128   c.type = DisplayConfiguration::COLLECTION;
0129   c.data.hits.color     = e.hasAttr(_U(color)) ? e.attr<int>(_U(color))   : 0xBBBBBB;
0130   c.data.hits.alpha     = e.hasAttr(_U(alpha)) ? e.attr<float>(_U(alpha)) : -1.0;
0131   c.data.hits.emax      = e.hasAttr(u_emax)    ? e.attr<float>(u_emax)    : 25.0;
0132   c.data.hits.towerH    = e.hasAttr(u_towerH)  ? e.attr<float>(u_towerH)  : 25.0;
0133   c.data.hits.threshold = e.hasAttr(_U(threshold)) ? e.attr<float>(_U(threshold)) : 0.0;
0134   if ( e.hasAttr(u_hits)   ) c.hits = e.attr<std::string>(u_hits);
0135   if ( e.hasAttr(u_use)    ) c.use = e.attr<std::string>(u_use);
0136   configs->push_back(c);
0137 }
0138 
0139 /** Convert display configuration elements of tag type ddeve/view
0140  *
0141  *    <view>
0142  *      <detelement name="TPC" ... />
0143  *        ...
0144  *    </ddeve>
0145  *
0146  *  @author  M.Frank
0147  *  @version 1.0
0148  *  @date    01/06/2014
0149  */
0150 template <> void Converter<view>::operator()(xml_h e)  const  {
0151   ViewConfigurations* configs = (ViewConfigurations*)param;
0152   DisplayConfiguration::ViewConfig c;
0153   extract(c,e,DisplayConfiguration::VIEW);
0154   c.name  = e.attr<std::string>(_U(name));
0155   c.type  = e.attr<std::string>(_U(type));
0156   c.show_structure = e.hasAttr(_U(structure)) ? e.attr<bool>(_U(structure)) : true;
0157   c.show_sensitive = e.hasAttr(_U(sensitive)) ? e.attr<bool>(_U(sensitive)) : true;
0158   printout(INFO,"DisplayConfiguration","+++ View: %s sensitive:%d structure:%d.",
0159            c.name.c_str(), c.show_sensitive, c.show_structure);
0160   xml_coll_t(e,_Unicode(panel)).for_each(Converter<panel>(description,&c.subdetectors));
0161   xml_coll_t(e,_Unicode(detelement)).for_each(Converter<detelement>(description,&c.subdetectors));
0162   xml_coll_t(e,_Unicode(calodata)).for_each(Converter<calodata_configs>(description,&c.subdetectors));
0163   xml_coll_t(e,_Unicode(collection)).for_each(Converter<collection_configs>(description,&c.subdetectors));
0164   configs->push_back(c);
0165 }
0166 
0167 /** Convert display configuration elements of tag type ddeve/calodata
0168  *
0169  *    <view>
0170  *      <calodata name="TPC" n_eta="5" ..../>
0171  *        ...
0172  *    </ddeve>
0173  *
0174  *  @author  M.Frank
0175  *  @version 1.0
0176  *  @date    01/06/2014
0177  */
0178 template <> void Converter<calodata>::operator()(xml_h e)  const  {
0179   Configurations* configs = (Configurations*)param;
0180   DisplayConfiguration::Config c;
0181   c.name = e.attr<std::string>(_U(name));
0182   c.type = DisplayConfiguration::CALODATA;
0183   if ( e.hasAttr(u_use)    )   {
0184     c.use  = e.attr<std::string>(u_use);
0185     c.hits = e.attr<std::string>(u_hits);
0186   }
0187   else  {
0188     c.hits = e.attr<std::string>(u_hits);
0189     c.data.calodata.n_eta   = e.attr<int>(u_n_eta);
0190     c.data.calodata.eta_min = e.attr<float>(u_eta_min);
0191     c.data.calodata.eta_max = e.attr<float>(u_eta_max);
0192     c.data.calodata.n_phi   = e.attr<int>(u_n_phi);
0193     c.data.calodata.phi_min = e.attr<float>(u_phi_min);
0194     c.data.calodata.phi_max = e.attr<float>(u_phi_max);
0195     c.data.calodata.dz      = e.attr<float>(_U(dz));
0196     c.data.calodata.rmin    = e.attr<float>(_U(rmin));
0197     c.data.calodata.color   = e.attr<int>(_U(color));
0198     c.data.calodata.alpha   = e.attr<float>(_U(alpha));
0199     c.data.calodata.emax    = e.hasAttr(u_emax) ? e.attr<float>(u_emax) : 25.0;
0200     if ( e.hasAttr(u_towerH) ) c.data.calodata.towerH = e.attr<float>(u_towerH);
0201     if ( e.hasAttr(_U(threshold)) ) c.data.calodata.threshold = e.attr<float>(_U(threshold));
0202   }
0203   configs->push_back(c);
0204 }
0205 
0206 /** Convert display configuration elements of tag type ddeve/hits
0207  *
0208  *    <view>
0209  *      <calodata name="TPC" n_eta="5" ..../>
0210  *        ...
0211  *    </ddeve>
0212  *
0213  *  @author  M.Frank
0214  *  @version 1.0
0215  *  @date    01/06/2014
0216  */
0217 template <> void Converter<collection>::operator()(xml_h e)  const  {
0218   Configurations* configs = (Configurations*)param;
0219   DisplayConfiguration::Config c;
0220   c.name = e.attr<std::string>(_U(name));
0221   c.hits = e.attr<std::string>(u_hits);
0222   c.type = DisplayConfiguration::COLLECTION;
0223   c.use  = e.hasAttr(u_use) ? e.attr<std::string>(u_use) : std::string();
0224   c.data.hits.size  = e.attr<float>(_U(size));
0225   c.data.hits.type  = e.attr<float>(_U(type));
0226   c.data.hits.color = e.hasAttr(_U(color))  ? e.attr<int>(_U(color)) : kRed;
0227   c.data.hits.alpha = e.hasAttr(_U(alpha))  ? e.attr<float>(_U(alpha)) : 1.0;
0228   c.data.hits.width = e.hasAttr(_U(width))  ? e.attr<float>(_U(width)) : 1.0;
0229   c.data.hits.emax    = e.hasAttr(u_emax)   ? e.attr<float>(u_emax)    : 25.0;
0230   c.data.hits.towerH  = e.hasAttr(u_towerH) ? e.attr<float>(u_towerH)  : 25.0;
0231   c.data.hits.threshold = e.hasAttr(_U(threshold)) ? e.attr<float>(_U(threshold)) : 0;
0232   configs->push_back(c);
0233 }
0234 
0235 /** Convert display configuration elements of tag type ddeve/include
0236  *
0237  *    <ddeve>
0238  *      <view>   ...   </view>
0239  *        ...
0240  *    </ddeve>
0241  *
0242  *  @author  M.Frank
0243  *  @version 1.0
0244  *  @date    01/06/2014
0245  */
0246 template <> void Converter<include>::operator()(xml_h e)  const  {
0247   if ( e )  {
0248     DetectorLoad* load = dynamic_cast<DetectorLoad*>(&this->description);
0249     if ( load )   {
0250       load->processXML(e, e.attr<std::string>(_U(ref)));
0251       return;
0252     }
0253     except("DisplayConfiguration","++ Invalid DetectorLoad instance in XML converter <include>");
0254   }
0255   except("DisplayConfiguration","++ Attempt to parse invalid include statement [Invalid XML element]");
0256 }
0257 
0258 /** Convert display configuration elements of tag type ddeve/include
0259  *
0260  *    <ddeve>
0261  *      <include ref="..."/>
0262  *        ...
0263  *    </ddeve>
0264  *
0265  *  @author  M.Frank
0266  *  @version 1.0
0267  *  @date    01/06/2014
0268  */
0269 template <> void Converter<display>::operator()(xml_h e)  const  {
0270   Display* d = (Display*)param;
0271   if ( e.hasAttr(_Unicode(visLevel))     ) d->setVisLevel(e.attr<int>(_Unicode(visLevel)));
0272   if ( e.hasAttr(_Unicode(eventHandler)) ) d->setEventHandlerName(e.attr<std::string>(_Unicode(eventHandler)));
0273   if ( e.hasAttr(_Unicode(loadLevel))    ) d->setLoadLevel(e.attr<int>(_Unicode(loadLevel)));
0274 }
0275 
0276 /** Convert display configuration elements of tag type ddeve
0277  *
0278  *    <ddeve>
0279  *      <view>   ...   </view>
0280  *        ...
0281  *    </ddeve>
0282  *
0283  *  @author  M.Frank
0284  *  @version 1.0
0285  *  @date    01/06/2014
0286  */
0287 template <> void Converter<ddeve>::operator()(xml_h e)  const  {
0288   Display* disp = (Display*)param;
0289   DisplayConfiguration cfg(disp);
0290   /// Now we process all allowed elements within this tag
0291   xml_coll_t(e,_Unicode(display)).for_each(Converter<display>(description,disp));
0292   xml_coll_t(e,_Unicode(include)).for_each(Converter<include>(description,disp));
0293   xml_coll_t(e,_Unicode(calodata)).for_each(Converter<calodata>(description,&cfg.calodata));
0294   xml_coll_t(e,_Unicode(collection)).for_each(Converter<collection>(description,&cfg.collections));
0295   xml_coll_t(e,_Unicode(view)).for_each(Converter<view>(description,&cfg.views));
0296   disp->ImportConfiguration(cfg);
0297 }
0298 
0299 #include <TEveProjections.h>
0300 /** Basic entry point to read display configuration files
0301  *
0302  *  @author  M.Frank
0303  *  @version 1.0
0304  *  @date    01/06/2014
0305  */
0306 static long setup_DDEve(Detector& description, const xml_h& e) {
0307   Display* display = description.extension<Display>();
0308   static bool first = true;
0309   if ( first )   {
0310     first = false;
0311 #define add_root_enum(x) xml::_toDictionary(xml::Strng_t(#x),int(x))
0312     add_root_enum(kBlack);
0313     add_root_enum(kWhite);
0314     add_root_enum(kOrange);
0315     add_root_enum(kBlue);
0316     add_root_enum(kAzure);
0317     add_root_enum(kRed);
0318     add_root_enum(kCyan);
0319     add_root_enum(kPink);
0320     add_root_enum(kGreen);
0321     add_root_enum(kViolet);
0322     add_root_enum(kYellow);
0323     add_root_enum(kTeal);
0324     add_root_enum(kMagenta);
0325     add_root_enum(kSpring);
0326     add_root_enum(kTeal);
0327 
0328     add_root_enum(kDot);
0329     add_root_enum(kPlus);
0330     add_root_enum(kStar);
0331     add_root_enum(kCircle);
0332     add_root_enum(kMultiply);
0333     add_root_enum(kFullDotSmall);
0334     add_root_enum(kFullDotMedium);
0335     add_root_enum(kFullDotLarge);
0336     add_root_enum(kFullCircle);
0337     add_root_enum(kFullSquare);
0338     add_root_enum(kFullTriangleUp);
0339     add_root_enum(kFullTriangleDown);
0340     add_root_enum(kOpenCircle);
0341     add_root_enum(kOpenSquare);
0342     add_root_enum(kOpenTriangleUp);
0343     add_root_enum(kOpenDiamond);
0344     add_root_enum(kOpenCross);
0345     add_root_enum(kFullStar);
0346     add_root_enum(kOpenStar);
0347     add_root_enum(kOpenTriangleDown);
0348     add_root_enum(kFullDiamond);
0349     add_root_enum(kFullCross);
0350     add_root_enum(TEveProjection::kPT_RPhi);
0351     add_root_enum(TEveProjection::kPT_RhoZ);
0352     add_root_enum(TEveProjection::kPT_3D);
0353     add_root_enum(TEveProjection::kPP_Plane);
0354     add_root_enum(TEveProjection::kPP_Distort);
0355     add_root_enum(TEveProjection::kPP_Full);
0356     add_root_enum(TEveProjection::kGM_Polygons);
0357     add_root_enum(TEveProjection::kGM_Segments);
0358   }
0359   (dd4hep::Converter<dd4hep::ddeve>(description,display))(e);
0360   return 1;
0361 }
0362 DECLARE_XML_DOC_READER(ddeve,setup_DDEve)