Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:17:46

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 includes
0015 #include "DD4hep/DetFactoryHelper.h"
0016 #include "DD4hep/Printout.h"
0017 #include "DD4hep/Detector.h"
0018 #include "DD4hep/Objects.h"
0019 #include "DD4hep/World.h"
0020 
0021 using namespace dd4hep;
0022 using namespace dd4hep::detail;
0023 
0024 namespace {
0025   typedef std::pair<int,int> Result;
0026   std::pair<int,int>& operator += (std::pair<int,int>& left, const std::pair<int,int>& right)  {
0027     left.first  += right.first;
0028     left.second += right.second;
0029     return left;
0030   }
0031   template <typename T, typename Q> Result test_handle(T& from)  {
0032     Result r(0,0);
0033     /// Test handle copy constructors
0034     try  {
0035       Q to(from);
0036       if ( to.ptr() && from.ptr() )  {
0037         printout(INFO,"Check_Handles","PASSED: Handle Construction from %s to %s.",
0038                  typeName(typeid(T)).c_str(),typeName(typeid(Q)).c_str());
0039         ++r.first;
0040         T ffrom(to);
0041         if ( to.ptr() && ffrom.ptr() )  {
0042           printout(INFO,"Check_Handles","PASSED: Handle Construction from %s to %s.",
0043                    typeName(typeid(Q)).c_str(),typeName(typeid(T)).c_str());
0044           ++r.first;
0045         }
0046       }
0047       else if ( !to.ptr() && from.ptr() )   {
0048         printout(INFO,"Check_Handles","FAILED: Handle Construction from %s to %s.",
0049                  typeName(typeid(T)).c_str(),typeName(typeid(Q)).c_str());
0050         ++r.second;
0051       }
0052     }
0053     catch(const std::exception& e)   {
0054       printout(INFO,"Check_Handles",  "FAILED: Handle Construction from %s to %s. [Exception]",
0055                typeName(typeid(T)).c_str(),typeName(typeid(Q)).c_str());
0056       ++r.second;
0057     }
0058     /// Test handle assignments
0059     try  {
0060       Q to = from;
0061       if ( to.ptr() && from.ptr() )  {
0062         printout(INFO,"Check_Handles","PASSED: Handle Assignment   from %s to %s.",
0063                  typeName(typeid(T)).c_str(),typeName(typeid(Q)).c_str());
0064         ++r.first;
0065         T ffrom = to;
0066         if ( to.ptr() && ffrom.ptr() )  {
0067           printout(INFO,"Check_Handles","PASSED: Handle Construction from %s to %s.",
0068                    typeName(typeid(Q)).c_str(),typeName(typeid(T)).c_str());
0069           ++r.first;
0070         }
0071       }
0072       else if ( !to.ptr() && from.ptr() )   {
0073         printout(INFO,"Check_Handles","FAILED: Handle Assignment   from %s to %s.",
0074                  typeName(typeid(T)).c_str(),typeName(typeid(Q)).c_str());
0075         ++r.second;
0076       }
0077     }
0078     catch(const std::exception& e)   {
0079       printout(INFO,"Check_Handles","FAILED: Handle Assignment     from %s to %s. [Exception]",
0080                typeName(typeid(T)).c_str(),typeName(typeid(Q)).c_str());
0081       ++r.second;
0082     }
0083     return r;
0084   }
0085   template <typename T> Result check_handle(T& h)  {
0086     Result r(0,0);
0087     r += test_handle<T, T>(h);
0088     r += test_handle<T, Handle<typename T::Object> >(h);
0089     r += test_handle<T, Handle<NamedObject> >(h);
0090     r += test_handle<T, Handle<TObject> >(h);
0091     r += test_handle<T, Handle<TNamed> >(h);
0092     return r;
0093   }
0094   Result check_handle(Solid& h)  {
0095     Result r(0,0);
0096     r += test_handle<Solid, Solid>(h);
0097     r += test_handle<Solid, Box>(h);
0098     r += test_handle<Solid, HalfSpace>(h);
0099     r += test_handle<Solid, Polycone>(h);
0100     r += test_handle<Solid, ConeSegment>(h);
0101     r += test_handle<Solid, Tube>(h);
0102     r += test_handle<Solid, EllipticalTube>(h);
0103     r += test_handle<Solid, Cone>(h);
0104     r += test_handle<Solid, Trap>(h);
0105     r += test_handle<Solid, Trapezoid>(h);
0106     r += test_handle<Solid, Paraboloid>(h);
0107     r += test_handle<Solid, Hyperboloid>(h);
0108     r += test_handle<Solid, PolyhedraRegular>(h);
0109     r += test_handle<Solid, Torus>(h);
0110     r += test_handle<Solid, Sphere>(h);
0111     r += test_handle<Solid, EightPointSolid>(h);
0112     r += test_handle<Solid, SubtractionSolid>(h);
0113     r += test_handle<Solid, UnionSolid>(h);
0114     r += test_handle<Solid, IntersectionSolid>(h);
0115     r += test_handle<Solid, Handle<TGeoShape> >(h);
0116     r += test_handle<Solid, Handle<TGeoBBox> >(h);
0117     r += test_handle<Solid, Handle<TGeoCone> >(h);
0118     r += test_handle<Solid, Handle<TGeoArb8> >(h);
0119     r += test_handle<Solid, Handle<TGeoConeSeg> >(h);
0120     r += test_handle<Solid, Handle<TGeoParaboloid> >(h);
0121     r += test_handle<Solid, Handle<TGeoPcon> >(h);
0122     r += test_handle<Solid, Handle<TGeoHype> >(h);
0123     r += test_handle<Solid, Handle<TGeoPgon> >(h);
0124     r += test_handle<Solid, Handle<TGeoTube> >(h);
0125     r += test_handle<Solid, Handle<TGeoEltu> >(h);
0126     r += test_handle<Solid, Handle<TGeoTubeSeg> >(h);
0127     r += test_handle<Solid, Handle<TGeoTrap> >(h);
0128     r += test_handle<Solid, Handle<TGeoTrd1> >(h);
0129     r += test_handle<Solid, Handle<TGeoTrd2> >(h);
0130     r += test_handle<Solid, Handle<TGeoSphere> >(h);
0131     r += test_handle<Solid, Handle<TGeoTorus> >(h);
0132     r += test_handle<Solid, Handle<TGeoHalfSpace> >(h);
0133     r += test_handle<Solid, Handle<TGeoShapeAssembly> >(h);
0134     r += test_handle<Solid, Handle<TGeoCompositeShape> >(h);
0135     return r;
0136   }
0137   Result check_handle(Volume& h)  {
0138     Result r(0,0);
0139     r += test_handle<Volume, Volume>(h);
0140     r += test_handle<Volume, Assembly>(h);
0141     r += test_handle<Volume, Handle<TGeoAtt> >(h);
0142     r += test_handle<Volume, Handle<NamedObject> >(h);
0143     r += test_handle<Volume, Handle<TObject> >(h);
0144     r += test_handle<Volume, Handle<TNamed> >(h);
0145     r += test_handle<Volume, Handle<TGeoAtt> >(h);
0146     r += test_handle<Volume, Handle<TAttLine> >(h);
0147     r += test_handle<Volume, Handle<TAtt3D> >(h);
0148     return r;
0149   }
0150   Result check_handle(Assembly& h)  {
0151     Result r(0,0);
0152     r += test_handle<Assembly, Assembly>(h);
0153     r += test_handle<Assembly, Volume>(h);
0154     r += test_handle<Assembly, Handle<TGeoAtt> >(h);
0155     r += test_handle<Assembly, Handle<NamedObject> >(h);
0156     r += test_handle<Assembly, Handle<TObject> >(h);
0157     r += test_handle<Assembly, Handle<TNamed> >(h);
0158     r += test_handle<Assembly, Handle<TGeoAtt> >(h);
0159     r += test_handle<Assembly, Handle<TAttLine> >(h);
0160     r += test_handle<Assembly, Handle<TAtt3D> >(h);
0161     return r;
0162   }
0163   Result check_handle(PlacedVolume& h)  {
0164     Result r(0,0);
0165     r += test_handle<PlacedVolume, PlacedVolume>(h);
0166     r += test_handle<PlacedVolume, Handle<NamedObject> >(h);
0167     r += test_handle<PlacedVolume, Handle<TObject> >(h);
0168     r += test_handle<PlacedVolume, Handle<TNamed> >(h);
0169     return r;
0170   }
0171 }
0172 
0173 static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector sens)  {
0174   // XML detector object: DDCore/XML/XMLDetector.h
0175   xml_dim_t  x_det = e;  
0176   xml_dim_t  x_det_dim(x_det.dimensions());
0177   DetElement d_det(x_det.nameStr(),x_det.id());
0178   Assembly   calo_vol(x_det.nameStr()+"_envelope");
0179   VisAttr    vis = description.visAttributes(x_det.visStr());
0180   Region     reg = description.region(x_det.regionStr());
0181   LimitSet   lim = description.limitSet(x_det.limitsStr());
0182   
0183   // Declare this sensitive detector as a calorimeter
0184   Tube tub(x_det_dim.rmin(), x_det_dim.rmax(), x_det_dim.z()/2.0,0.0,2*M_PI);
0185   Volume tub_vol(x_det.nameStr()+"_tube",tub,description.material("Iron"));
0186   calo_vol.placeVolume(tub_vol).addPhysVolID("module",1);
0187   sens.setType("calorimeter");
0188   tub_vol.setSensitiveDetector(sens);
0189 
0190   // Place the calo inside the world
0191   PlacedVolume  calo_plv = description.pickMotherVolume(d_det).placeVolume(calo_vol);
0192   calo_plv.addPhysVolID("system",x_det.id());
0193   calo_plv.addPhysVolID("barrel",0);
0194   d_det.setPlacement(calo_plv);
0195   Result result(0,0);
0196   Solid  sol = tub;
0197   result += check_handle(calo_plv);
0198   result += check_handle(tub_vol);
0199   result += check_handle(sol);
0200   result += check_handle(calo_vol);
0201   result += check_handle(d_det);
0202   result += check_handle(sens);
0203   result += check_handle(vis);
0204   result += check_handle(lim);
0205   result += check_handle(reg);
0206 
0207   //result += test_handle<Assembly,Region>(calo_vol);
0208   printout(INFO,"Check_Handles","+-----------------------------------------------------------------+");
0209   printout(INFO,"Check_Handles","|   %-4d casts PASSED   %4d casts FAILED                         |",
0210            result.first, result.second);
0211   printout(INFO,"Check_Handles","+-----------------------------------------------------------------+");
0212   return d_det;
0213 }
0214 DECLARE_DETELEMENT(DD4hep_Check_Handles,create_detector)