DD4hep  1.31.0
Detector Description Toolkit for High Energy Physics
DetectorHelperTest.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 
14 // Framework include files
15 #include <DD4hep/Detector.h>
16 #include <DD4hep/Printout.h>
17 #include <DD4hep/Factories.h>
18 #include <DD4hep/DetectorHelper.h>
19 
20 // C/C++ include files
21 #include <stdexcept>
22 #include <algorithm>
23 
24 using namespace dd4hep;
25 
26 namespace {
27 
43  struct DetectorHelperTest {
45  DetectorHelperTest(Detector& description, int argc, char** argv) {
46  DetectorHelper h(&description);
47  const char* nam = argc>1 ? argv[1]+1 : "SiVertexEndcap";
48  printSD(h,nam);
49  walkSD(h,description.detector(nam));
50  }
52  virtual ~DetectorHelperTest() {}
53 
54  void walkSD(DetectorHelper h, DetElement de) const {
55  printSD(h,de);
56  for(DetElement::Children::const_iterator i=de.children().begin(); i!=de.children().end(); ++i) {
57  DetElement child = (*i).second;
58  printSD(h,child);
59  if ( child.children().size() > 0 ) walkSD(h,child);
60  }
61  }
62  void printSD(DetectorHelper h, DetElement de) const {
64  printout(INFO,"DetectorHelperTest","Sensitive detector[%s]: %p --> %s",de.path().c_str(),(void*)sd.ptr(),
65  sd.ptr() ? sd.name() : "????");
66 
67  }
68  void printSD(DetectorHelper h, const char* nam) const {
70  printout(INFO,"DetectorHelperTest","Sensitive detector[%s]: %p --> %s",nam,(void*)sd.ptr(),
71  sd.ptr() ? sd.name() : "????");
72 
73  }
75  static long run(Detector& description,int argc,char** argv) {
76  DetectorHelperTest test(description,argc,argv);
77  return 1;
78  }
79  };
80 }
81 
82 namespace dd4hep {
83  using ::DetectorHelperTest;
84 }
85 DECLARE_APPLY(CLICSiD_DetectorHelperTest,DetectorHelperTest::run)
dd4hep::DetElement::children
const Children & children() const
Access to the list of children.
Definition: DetElement.cpp:207
dd4hep::DetElement::path
const std::string & path() const
Path of the detector element (not necessarily identical to placement path!)
Definition: DetElement.cpp:158
dd4hep::Detector::detector
virtual DetElement detector(const std::string &name) const =0
Retrieve a subdetector element by its name from the detector description.
dd4hep::SensitiveDetector
Handle class to hold the information of a sensitive detector.
Definition: DetElement.h:44
Detector.h
DECLARE_APPLY
#define DECLARE_APPLY(name, func)
Definition: Factories.h:281
DetectorHelper.h
Factories.h
dd4hep::Handle::name
const char * name() const
Access the object name (or "" if not supported by the object)
dd4hep::DetElement
Handle class describing a detector element.
Definition: DetElement.h:188
dd4hep::DetectorHelper
DetectorHelper: class to shortcut certain questions to the dd4hep detector description interface.
Definition: DetectorHelper.h:32
dd4hep::DetectorHelper::sensitiveDetector
SensitiveDetector sensitiveDetector(const std::string &detector) const
Access the sensitive detector of a given subdetector (if the sub-detector is sensitive!...
Definition: DetectorHelper.cpp:23
dd4hep::Handle::ptr
T * ptr() const
Access to the held object.
Definition: Handle.h:153
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::Detector
The main interface to the dd4hep detector description package.
Definition: Detector.h:90
Printout.h