Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /DD4hep/DDCore/src/plugins/DetectorHelperTest.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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