Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-02 07:53:04

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/DetectorHelper.h>
0019 
0020 // C/C++ include files
0021 
0022 using namespace dd4hep;
0023 
0024 namespace  {
0025 
0026   /** @class DetectorHelperTest
0027    *
0028    * Test DetectorHelper handle object to easily access the sensitive detector object of a detector
0029    * using either the subdetector name or the detector element (or one of its children).
0030    *
0031    * This helper recusively searches for all children of a subdetector the sensitive detector.
0032    * 
0033    * See: dd4hep/DetectorHelper.h
0034    * Test: geoPluginRun -input file:../DD4hep.trunk/examples/CLICSiD/compact/compact.xml \
0035    *                    -plugin CLICSiD_DetectorHelperTest          \
0036    *         optional:  -<detector-name (default:SiVertexEndcap)>  [Note the '-'!!!]
0037    *
0038    *  @author  M.Frank
0039    *  @version 1.0
0040    */
0041   struct DetectorHelperTest  {
0042     /// Initializing constructor
0043     DetectorHelperTest(Detector& description, int argc, char** argv)   {
0044       DetectorHelper h(&description);
0045       const char* nam = argc>1 ? argv[1]+1 : "SiVertexEndcap";
0046       printSD(h,nam);
0047       walkSD(h,description.detector(nam));
0048     }
0049     /// Default destructor
0050     virtual ~DetectorHelperTest() {}
0051 
0052     void walkSD(DetectorHelper h, DetElement de)  const {
0053       printSD(h,de);
0054       for(DetElement::Children::const_iterator i=de.children().begin(); i!=de.children().end(); ++i)  {
0055         DetElement child = (*i).second;
0056         printSD(h,child);
0057         if ( child.children().size() > 0 ) walkSD(h,child);
0058       }
0059     }
0060     void printSD(DetectorHelper h, DetElement de)  const {
0061       SensitiveDetector sd = h.sensitiveDetector(de);
0062       printout(INFO,"DetectorHelperTest","Sensitive detector[%s]: %p  --> %s",de.path().c_str(),(void*)sd.ptr(),
0063                sd.ptr() ? sd.name() : "????");
0064 
0065     }
0066     void printSD(DetectorHelper h, const char* nam)  const {
0067       SensitiveDetector sd = h.sensitiveDetector(nam);
0068       printout(INFO,"DetectorHelperTest","Sensitive detector[%s]: %p  --> %s",nam,(void*)sd.ptr(),
0069                sd.ptr() ? sd.name() : "????");
0070 
0071     }
0072     /// Action routine to execute the test
0073     static long run(Detector& description,int argc,char** argv)   {
0074       DetectorHelperTest test(description,argc,argv);
0075       return 1;
0076     }
0077   };
0078 }
0079 
0080 namespace dd4hep {
0081   using ::DetectorHelperTest;
0082 }
0083 DECLARE_APPLY(CLICSiD_DetectorHelperTest,DetectorHelperTest::run)