From 1dcf0355cfda62f35750bd596fedcf3a3fa33dc4 Mon Sep 17 00:00:00 2001 From: Markus Frank <Markus.Frank@cern.ch> Date: Thu, 16 Mar 2017 20:20:33 +0100 Subject: [PATCH] Improve JSON interpreter --- DDCore/CMakeLists.txt | 2 +- DDCore/include/JSON/Detector.h | 33 + DDCore/include/JSON/Dimension.h | 31 + DDCore/include/JSON/Dimension.inl | 24 + DDCore/include/JSON/Elements.h | 124 +-- DDCore/include/JSON/Tags.h | 26 + DDCore/include/JSON/config.h | 6 +- DDCore/include/XML/UnicodeValues.h | 1008 ++++++++++----------- DDCore/include/XML/XMLDetector.h | 72 +- DDCore/include/XML/XMLDimension.h | 559 +----------- DDCore/include/XML/XMLDimension.inl | 35 +- DDCore/include/XML/XMLTags.h | 20 +- DDCore/include/XML/detail/Detector.h | 94 ++ DDCore/include/XML/detail/Detector.imp | 104 +++ DDCore/include/XML/detail/Dimension.h | 568 ++++++++++++ DDCore/include/XML/detail/Dimension.imp | 221 +++++ DDCore/include/XML/detail/Dimension.inl | 55 ++ DDCore/src/JSON/Detector.cpp | 19 + DDCore/src/JSON/Dimension.cpp | 17 + DDCore/src/XML/XMLDetector.cpp | 90 +- DDCore/src/XML/XMLDimension.cpp | 208 +---- DDCore/src/XML/XMLTags.cpp | 7 + examples/ClientTests/compact/MiniTel.json | 36 + examples/ClientTests/src/JsonTest.cpp | 58 ++ 24 files changed, 1865 insertions(+), 1552 deletions(-) create mode 100644 DDCore/include/JSON/Detector.h create mode 100644 DDCore/include/JSON/Dimension.h create mode 100644 DDCore/include/JSON/Dimension.inl create mode 100644 DDCore/include/JSON/Tags.h create mode 100644 DDCore/include/XML/detail/Detector.h create mode 100644 DDCore/include/XML/detail/Detector.imp create mode 100644 DDCore/include/XML/detail/Dimension.h create mode 100644 DDCore/include/XML/detail/Dimension.imp create mode 100644 DDCore/include/XML/detail/Dimension.inl create mode 100644 DDCore/src/JSON/Detector.cpp create mode 100644 DDCore/src/JSON/Dimension.cpp create mode 100644 examples/ClientTests/compact/MiniTel.json create mode 100644 examples/ClientTests/src/JsonTest.cpp diff --git a/DDCore/CMakeLists.txt b/DDCore/CMakeLists.txt index e8bc4a493..e97409d67 100644 --- a/DDCore/CMakeLists.txt +++ b/DDCore/CMakeLists.txt @@ -14,7 +14,7 @@ dd4hep_package( DDCore DDSegmentation OPTIONAL XERCESC INCLUDE_DIRS include - INSTALL_INCLUDES include/DD4hep include/XML) + INSTALL_INCLUDES include/DD4hep include/XML include/JSON) #---Generate ROOT dictionary------------------------------------------------------ dd4hep_add_dictionary( G__DD4hep diff --git a/DDCore/include/JSON/Detector.h b/DDCore/include/JSON/Detector.h new file mode 100644 index 000000000..19f35c299 --- /dev/null +++ b/DDCore/include/JSON/Detector.h @@ -0,0 +1,33 @@ +//========================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : M.Frank +// +//========================================================================== +#ifndef DD4HEP_JSON_DETECTOR_H +#define DD4HEP_JSON_DETECTOR_H + +// Framework include files +#include "JSON/Dimension.h" + +/// Namespace for the AIDA detector description toolkit +namespace DD4hep { + + // Forward declarations + class NamedObject; + + /// Namespace for the AIDA detector description toolkit supporting JSON utilities + namespace JSON { + + /// Include the implementation in the proper namespace +#include "XML/detail/Detector.h" + + } /* End namespace JSON */ +} /* End namespace DD4hep */ +#endif /* DD4HEP_JSON_DETECTOR_H */ diff --git a/DDCore/include/JSON/Dimension.h b/DDCore/include/JSON/Dimension.h new file mode 100644 index 000000000..c8e369618 --- /dev/null +++ b/DDCore/include/JSON/Dimension.h @@ -0,0 +1,31 @@ +//========================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : M.Frank +// +//========================================================================== +#ifndef DD4HEP_JSON_DIMENSION_H +#define DD4HEP_JSON_DIMENSION_H + +// Framework include files +#include "JSON/Elements.h" +#include "JSON/Tags.h" + +/// Namespace for the AIDA detector description toolkit +namespace DD4hep { + + /// Namespace for the AIDA detector description toolkit supporting JSON utilities + namespace JSON { + + /// Re-use the defined interface for the XML data access +#include "XML/detail/Dimension.h" + + } /* End namespace JSON */ +} /* End namespace DD4hep */ +#endif /* DD4HEP_JSON_DIMENSION_H */ diff --git a/DDCore/include/JSON/Dimension.inl b/DDCore/include/JSON/Dimension.inl new file mode 100644 index 000000000..74f13ccf9 --- /dev/null +++ b/DDCore/include/JSON/Dimension.inl @@ -0,0 +1,24 @@ +//========================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : M.Frank +// +//========================================================================== + +#ifndef DD4HEP_JSONDIMENSION_INL +#define DD4HEP_JSONDIMENSION_INL + +// Configuration definitions +#define DIMENSION_NS JSON + +// Framework include files +#include "JSON/Dimension.h" +#include "XML/detail/Dimension.inl" + +#endif /* DD4HEP_JSONDIMENSION_INL */ diff --git a/DDCore/include/JSON/Elements.h b/DDCore/include/JSON/Elements.h index 74c0a91e2..383b4cd4d 100644 --- a/DDCore/include/JSON/Elements.h +++ b/DDCore/include/JSON/Elements.h @@ -37,11 +37,6 @@ namespace DD4hep { typedef const JsonAttr* Attribute; - typedef const std::string& CSTR; - - /// Dump DOM tree of a document - void dumpTree(JsonDocument* doc); - /// Convert json attribute to STL string \ingroup DD4HEP_JSON std::string _toString(const Attribute attr); /// Convert json string to STL string \ingroup DD4HEP_JSON @@ -69,13 +64,12 @@ namespace DD4hep { { return _ptrToString((void*)p,fmt); } /// Helper function to populate the evaluator dictionary \ingroup DD4HEP_JSON - void _toDictionary(const char* name, const char* value); + template <typename T> void _toDictionary(const char* name, T value); /// Helper function to populate the evaluator dictionary \ingroup DD4HEP_JSON - void _toDictionary(const std::string& name, const char* value) - { _toDictionary(name, value); } + void _toDictionary(const char* name, const char* value); /// Helper function to populate the evaluator dictionary \ingroup DD4HEP_JSON - template <typename T> void _toDictionary(const char* name, T value); - + inline void _toDictionary(const std::string& name, const char* value) + { _toDictionary(name.c_str(), value); } /// Helper function to populate the evaluator dictionary \ingroup DD4HEP_JSON void _toDictionary(const char* name, float value); /// Helper function to populate the evaluator dictionary \ingroup DD4HEP_JSON @@ -84,13 +78,13 @@ namespace DD4hep { std::string getEnviron(const std::string& env); /// Conversion function from raw unicode string to bool \ingroup DD4HEP_JSON - bool _toBool(const char* value); + bool _toBool(const char* value); /// Conversion function from raw unicode string to int \ingroup DD4HEP_JSON - int _toInt(const char* value); + int _toInt(const char* value); /// Conversion function from raw unicode string to long \ingroup DD4HEP_JSON - long _toLong(const char* value); + long _toLong(const char* value); /// Conversion function from raw unicode string to float \ingroup DD4HEP_JSON - float _toFloat(const char* value); + float _toFloat(const char* value); /// Conversion function from raw unicode string to double \ingroup DD4HEP_JSON double _toDouble(const char* value); @@ -154,7 +148,7 @@ namespace DD4hep { operator Elt_t() const { return m_node; } /// Direct access to the JsonElement by function Elt_t ptr() const { return m_node; } - /// Unicode text access to the element's tag. Tis must be wrong .... + /// Unicode text access to the element's tag. const char* rawTag() const; /// Unicode text access to the element's text const char* rawText() const; @@ -371,19 +365,7 @@ namespace DD4hep { Element(const Handle_t& e) : m_element(e) { } /// Constructor from JsonElement handle Element(const Element& e) : m_element(e.m_element) { } - /// Constructor from DOM document entity - //Element(const Document& document, const char* type); - /// Access the hosting document handle of this DOM element - //Document document() const; - /// operator bool: check handle validity - operator bool() const { - return 0 != m_element.ptr(); - } - /// operator NOT: check handle validity - bool operator!() const { - return 0 == m_element.ptr(); - } /// Assignment operator Element& operator=(const Element& c) { m_element = c.m_element; @@ -394,89 +376,51 @@ namespace DD4hep { m_element = handle; return *this; } + /// operator bool: check handle validity + operator bool() const { return 0 != m_element.ptr(); } + /// operator NOT: check handle validity + bool operator!() const { return 0 == m_element.ptr(); } /// Automatic conversion to DOM element handle - operator Handle_t() const { - return m_element; - } + operator Handle_t() const { return m_element; } /// Automatic conversion to JsonElement pointer - operator Elt_t() const { - return m_element; - } + operator Elt_t() const { return m_element; } /// Access to JsonElement pointer - Elt_t ptr() const { - return m_element; - } -#if 0 - /// Access the JsonElements parent - Handle_t parent() const { - return m_element.parent(); - } - /// Access the JsonElements parent - Elt_t parentElement() const; -#endif + Elt_t ptr() const { return m_element; } /// Access the tag name of this element - std::string tag() const { - return m_element.tag(); - } + std::string tag() const { return m_element.tag(); } /// Access the tag name of this element - const char* tagName() const { - return m_element.rawTag(); - } + const char* tagName() const { return m_element.rawTag(); } /// Access the tag name of this element - std::string text() const { - return m_element.text(); - } + std::string text() const { return m_element.text(); } /// Check for the existence of a named attribute - bool hasAttr(const char* name) const { - return m_element.hasAttr(name); - } + bool hasAttr(const char* name) const {return m_element.hasAttr(name); } /// Access attribute with implicit return type conversion - template <class T> T attr(const char* tag_value) const { - return m_element.attr<T>(tag_value); - } + template <class T> T attr(const char* tag_value) const + { return m_element.attr<T>(tag_value); } /// Access attribute name (throws exception if not present) - const char* attr_name(const Attribute a) const { - return m_element.attr_name(a); - } + const char* attr_name(const Attribute a) const + { return m_element.attr_name(a); } /// Access attribute value by the attribute (throws exception if not present) - const char* attr_value(const Attribute a) const { - return m_element.attr_value(a); - } + const char* attr_value(const Attribute a) const + { return m_element.attr_value(a); } /// Access the number of children of this element with a given tag name - size_t numChildren(const char* tag_value, bool exc = true) const { - return m_element.numChildren(tag_value, exc); - } + size_t numChildren(const char* tag_value, bool exc = true) const + { return m_element.numChildren(tag_value, exc); } /// Retrieve a collection of all attributes of this element - std::vector<Attribute> attributes() const { - return m_element.attributes(); - } + std::vector<Attribute> attributes() const + { return m_element.attributes(); } /// Access single attribute by it's name Attribute getAttr(const char* name) const; /// Access child by tag name. Thow an exception if required in case the child is not present - Handle_t child(const char* tag_value, bool except = true) const { - return m_element.child(tag_value, except); - } + Handle_t child(const char* tag_value, bool except = true) const + { return m_element.child(tag_value, except); } /// Check the existence of a child with a given tag name - bool hasChild(const char* tag_value) const { - return m_element.hasChild(tag_value); - } + bool hasChild(const char* tag_value) const + { return m_element.hasChild(tag_value); } }; - #undef INLINE - /// Forward declarations - class DocumentHandler; - - /// Dump partial or full JSON trees to stdout - void dump_tree(Handle_t elt); - /// Dump partial or full JSON trees - void dump_tree(Handle_t elt, std::ostream& os); - /// Dump partial or full JSON documents to stdout - void dump_tree(Document doc); - /// Dump partial or full JSON documents - void dump_tree(Document doc, std::ostream& os); - } /* End namespace XML */ } /* End namespace DD4hep */ #endif /* DDCORE_DD4HEP_JSON_ELEMENTS_H */ diff --git a/DDCore/include/JSON/Tags.h b/DDCore/include/JSON/Tags.h new file mode 100644 index 000000000..307e1331b --- /dev/null +++ b/DDCore/include/JSON/Tags.h @@ -0,0 +1,26 @@ +//========================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : M.Frank +// +//========================================================================== +#ifndef DD4HEP_JSON_TAGS_H +#define DD4HEP_JSON_TAGS_H + +#define DECLARE_UNICODE_TAG(x) + +// Framework include files +#include "JSON/Elements.h" + +// Helpers to access tags and attributes quickly without specifying explicitly namespaces +#define _DD4hep_Unicode_Item(a) #a +#define _U(a) #a +#define _Unicode(a) #a + +#endif // DD4HEP_JSON_TAGS_H diff --git a/DDCore/include/JSON/config.h b/DDCore/include/JSON/config.h index b0327306e..4c3895e75 100644 --- a/DDCore/include/JSON/config.h +++ b/DDCore/include/JSON/config.h @@ -23,11 +23,13 @@ namespace DD4hep { /// Namespace for the AIDA detector description toolkit supporting JSON utilities namespace JSON { + + typedef char XmlChar; typedef boost::property_tree::ptree ptree; typedef boost::property_tree::ptree JsonDocument; typedef boost::property_tree::ptree::value_type JsonAttr; typedef boost::property_tree::ptree::value_type JsonElement; + } /* End namespace JSON */ } /* End namespace DD4hep */ - -#endif /* DD4HEP_DDCORE_JSON_CONFIG_H */ +#endif /* DD4HEP_DDCORE_JSON_CONFIG_H */ diff --git a/DDCore/include/XML/UnicodeValues.h b/DDCore/include/XML/UnicodeValues.h index 33d5633f7..c1f009083 100644 --- a/DDCore/include/XML/UnicodeValues.h +++ b/DDCore/include/XML/UnicodeValues.h @@ -11,512 +11,502 @@ // //========================================================================== - -/// Namespace for the AIDA detector description toolkit -namespace DD4hep { - - /// Namespace for the AIDA detector description toolkit supporting XML utilities - namespace XML { - - extern const Tag_t Unicode_NULL; - extern const Tag_t Unicode_empty; - extern const Tag_t Unicode_star; - extern const Tag_t Unicode_PI; - extern const Tag_t Unicode_TWOPI; - - UNICODE(0); - UNICODE(1); - UNICODE(2); - UNICODE(3); - UNICODE(4); - UNICODE(5); - UNICODE(6); - UNICODE(7); - UNICODE(8); - UNICODE(9); - - UNICODE (a); - UNICODE (A); - UNICODE (Air); - UNICODE (angle); - UNICODE (alignment); - UNICODE (alignments); - UNICODE (alpha); - UNICODE (alpha1); - UNICODE (alpha2); - UNICODE (alpha3); - UNICODE (alpha4); - UNICODE (arb8); - UNICODE (arg); - UNICODE (argument); - UNICODE (assembly); - UNICODE (atom); - UNICODE (attributes); - UNICODE (aunit); - UNICODE (author); - - UNICODE (b); - UNICODE (B); - UNICODE (barrel); - UNICODE (barrel_envelope); - UNICODE (beampipe); - UNICODE (beta); - UNICODE (box); - - UNICODE (c); - UNICODE (distance); - UNICODE (C); - UNICODE (calorimeter); - UNICODE (cartesian_grid_xy); - UNICODE (chamber); - UNICODE (chambers); - UNICODE (check); - UNICODE (checksum); - UNICODE (close); - UNICODE (cm); - UNICODE (coefficient); - UNICODE (coefficients); - UNICODE (color); - UNICODE (collections); - UNICODE (collection); - UNICODE (combine_hits); - UNICODE (combineHits); - UNICODE (comment); - UNICODE (component); - UNICODE (composite); - UNICODE (cone); - UNICODE (cons); - UNICODE (constant); - UNICODE (crossing_angle); - UNICODE (cut); - - UNICODE (d); - UNICODE (D); - UNICODE (daughter); - UNICODE (define); - UNICODE (delta); - UNICODE (deltaphi); - UNICODE (deltatheta); - UNICODE (depth); - UNICODE (density); - UNICODE (detector); - UNICODE (detectors); - UNICODE (dim_r); - UNICODE (dim_x); - UNICODE (dim_y); - UNICODE (dim_z); - UNICODE (dimensions); - UNICODE (dipole_coeff); - UNICODE (disk); - UNICODE (disks); - UNICODE (display); - UNICODE (dr); - UNICODE (drawing_style); - UNICODE (drawingStyle); - UNICODE (dx); - UNICODE (dy); - UNICODE (dz); - - UNICODE (e); - UNICODE (E); - UNICODE (ecut); - UNICODE (element); - UNICODE (eltube); - UNICODE (end); - UNICODE (end_module); - UNICODE (end_modules); - UNICODE (endcap); - UNICODE (endphi); - UNICODE (epsilon); - UNICODE (eunit); - UNICODE (end_x); - UNICODE (end_y); - UNICODE (end_z); - - UNICODE (f); - UNICODE (F); - UNICODE(false); - UNICODE (field); - UNICODE (fields); - UNICODE (field_name); - UNICODE (file); - UNICODE (first); - UNICODE (firstposition); - UNICODE (firstrotation); - UNICODE (formula); - UNICODE (fraction); - UNICODE (funit); - - UNICODE (g); - UNICODE (G); - UNICODE (gamma); - UNICODE (gap); - UNICODE (gas); - UNICODE (generator); - UNICODE (gdml); - UNICODE (gdmlFile); - UNICODE (geometry); - UNICODE (glass); - UNICODE (global); - UNICODE (global_grid_xy); - UNICODE (grid_size_x); - UNICODE (grid_size_y); - UNICODE (grid_size_z); - UNICODE (grid_size_phi); - UNICODE (grid_xyz); - UNICODE (gridSizePhi); - UNICODE (gridSizeX); - UNICODE (gridSizeY); - UNICODE (gridSizeZ); - - UNICODE (h); - UNICODE (H); - UNICODE (half_x); - UNICODE (half_y); - UNICODE (half_z); - UNICODE (header); - UNICODE (height); - UNICODE (hits_collections); - UNICODE (hits_collection); - UNICODE (hype); - - UNICODE (i); - UNICODE (I); - UNICODE (id); - UNICODE (iddict); - UNICODE (identity_rot); - UNICODE (identity_pos); - UNICODE (idfield); - UNICODE (idspec); - UNICODE (idspecref); - UNICODE (include); - UNICODE (includes); - UNICODE (incoming_r); - UNICODE (info); - UNICODE (inner); - UNICODE (inner_field); - UNICODE (inner_r); - UNICODE (inner_radius); - UNICODE (inner_stereo); - UNICODE (inner_z); - UNICODE (insideTrackingVolume); - UNICODE (intersection); - UNICODE (InvisibleNoDaughters); - UNICODE (InvisibleWithDaughters); - UNICODE (isotope); - UNICODE (item); - - UNICODE (j); - UNICODE (J); - - UNICODE (k); - UNICODE (key); - UNICODE (key_min); - UNICODE (key_max); - UNICODE (key_val); - UNICODE (key_value); - UNICODE (K); - - UNICODE (l); - UNICODE (L); - UNICODE (label); - UNICODE (ladder); - UNICODE (layer); - UNICODE (layers); - UNICODE (lcdd); - UNICODE (lccdd); - UNICODE (length); - UNICODE (limit); - UNICODE (limits); - UNICODE (limitset); - UNICODE (limitsetref); - UNICODE (line_style); - UNICODE (lineStyle); - UNICODE (local); - UNICODE (logvol); - UNICODE (lunit); - - UNICODE (m); - UNICODE (M); - UNICODE (material); - UNICODE (materialref); - UNICODE (materials); - UNICODE (member); - UNICODE (MeV); - UNICODE (mm); - UNICODE (module); - UNICODE (modules); - UNICODE (module_component); - UNICODE (module_envelope); - UNICODE (moduleHeight); - UNICODE (modulePitch); - UNICODE (modulePosX); - UNICODE (modulePosY); - UNICODE (moduleWidth); - UNICODE (mother); - - UNICODE (n); - UNICODE (N); - UNICODE (NIL); - UNICODE (name); - UNICODE (nmodules); - UNICODE (nModules); - UNICODE (normal); - UNICODE (nonprojective_cylinder); - UNICODE (nPads); - UNICODE (nphi); - UNICODE (ntheta); - UNICODE (number); - UNICODE (numsides); - UNICODE (nsides); - UNICODE (nsides_inner); - UNICODE (nsides_outer); - UNICODE (nz); - - UNICODE (o); - UNICODE (O); - UNICODE (offset); - UNICODE (open); - UNICODE (overlap); - UNICODE (outer); - UNICODE (outer_field); - UNICODE (outer_r); - UNICODE (outer_radius); - UNICODE (outer_stereo); - UNICODE (outer_z); - UNICODE (outgoing_r); - UNICODE (outst); - - UNICODE (p); - UNICODE (P); - UNICODE (padPitch); - UNICODE (pads); - UNICODE (para); - UNICODE (paraboloid); - UNICODE (param); - UNICODE (parameter); - UNICODE (params); - UNICODE (parent); - UNICODE (particles); - UNICODE (path); - UNICODE (phi); - UNICODE (phi0); - UNICODE (phi0_offset); - UNICODE (phi1); - UNICODE (phi_tilt); - UNICODE (phiBins); - UNICODE (phi_size_max); - UNICODE (physvol); - UNICODE (physvolid); - UNICODE (pivot); - UNICODE (pivot_point); - UNICODE (plugin); - UNICODE (plugins); - UNICODE (point); - UNICODE (polyhedra); - UNICODE (polycone); - UNICODE (position); - UNICODE (positionref); - UNICODE (pressure); - UNICODE (projective_cylinder); - UNICODE (projective_zplane); - UNICODE (properties); - UNICODE (psi); - - UNICODE (q); - UNICODE (Q); - - UNICODE (r); - UNICODE (R); - UNICODE (r_size); - UNICODE (r0); - UNICODE (rad); - UNICODE (radian); - UNICODE (radius); - UNICODE (radiator); - UNICODE (rbg); - UNICODE (rc); - UNICODE (readout); - UNICODE (readouts); - UNICODE (ref); - UNICODE (reflect); - UNICODE (reflect_rot); - UNICODE (region); - UNICODE (regions); - UNICODE (regionref); - UNICODE (repeat); - UNICODE (rhi); - UNICODE (ring); - UNICODE (rlo); - UNICODE (rmax); - UNICODE (rmax1); - UNICODE (rmax2); - UNICODE (rmin); - UNICODE (rmin1); - UNICODE (rmin2); - UNICODE (RL); - UNICODE (row); - UNICODE (rpc); - UNICODE (RowID); - UNICODE (rowHeight); - UNICODE (rowPitch); - UNICODE (rphi_layout); - UNICODE (rotation); - UNICODE (rotationref); - UNICODE (rtor); - - UNICODE (s); - UNICODE (S); - UNICODE (scintillator); - UNICODE (sd); - UNICODE (sdref); - UNICODE (second); - UNICODE (segmentation); - UNICODE (sensitive); - UNICODE (sensitive_detector); - UNICODE (sensitive_detectors); - UNICODE (sensor); - UNICODE (sequence); - UNICODE (setup); - UNICODE (shape); - UNICODE (show_daughters); - UNICODE (showDaughters); - UNICODE (size); - UNICODE(signed); - UNICODE (skew); - UNICODE (slice); - UNICODE (slices); - UNICODE (solid); - UNICODE (solids); - UNICODE (solidref); - UNICODE (spacer); - UNICODE (sphere); - UNICODE (status); - UNICODE (start); - UNICODE (start_x); - UNICODE (start_y); - UNICODE (start_z); - UNICODE (startphi); - UNICODE (starttheta); - UNICODE (state); - UNICODE (stave); - UNICODE (staves); - UNICODE (store_secondaries); - UNICODE (strength); - UNICODE (structure); - UNICODE (subtraction); - UNICODE (support); - UNICODE (system); - UNICODE (symbol); - - UNICODE (t); - UNICODE (T); - UNICODE (temperature); - UNICODE (theta); - UNICODE (thetaBins); - UNICODE (thickness); - UNICODE (threshold); - UNICODE (title); - UNICODE (tube); - UNICODE (tubes); - UNICODE (torus); - UNICODE (tracker); - UNICODE (tracking_cylinder); - UNICODE (tracking_volume); - UNICODE (trap); - UNICODE (trd); - UNICODE (true); - UNICODE (tubs); - UNICODE (type); - - UNICODE (u); - UNICODE (U); - UNICODE (union); - UNICODE (unit); - UNICODE (useForHitPosition); - UNICODE (url); - - UNICODE (v); - UNICODE (V); - UNICODE (v1x); - UNICODE (v1y); - UNICODE (v2x); - UNICODE (v2y); - UNICODE (v3x); - UNICODE (v3y); - UNICODE (v4x); - UNICODE (v4y); - UNICODE (v5x); - UNICODE (v5y); - UNICODE (v6x); - UNICODE (v6y); - UNICODE (v7x); - UNICODE (v7y); - UNICODE (v8x); - UNICODE (v8y); - UNICODE (Vacuum); - UNICODE (value); - UNICODE (verbose); - UNICODE (version); - UNICODE (vis); - UNICODE (visible); - UNICODE (visref); - UNICODE (volume); - UNICODE (volumeref); - - UNICODE (w); - UNICODE (W); - UNICODE (wedge); - UNICODE (width); - UNICODE (world); - UNICODE (world_box); - UNICODE (world_volume); - - UNICODE (x); - UNICODE (X); - UNICODE (x_offset); - UNICODE (x0); - UNICODE (x1); - UNICODE (X1); - UNICODE (x2); - UNICODE (X2); - UNICODE (x3); - UNICODE (x4); - UNICODE (xhalf); - UNICODE (xmax); - UNICODE (xmin); - UNICODE (xml); - - UNICODE (y); - UNICODE (Y); - UNICODE (y0); - UNICODE (y1); - UNICODE (Y1); - UNICODE (y2); - UNICODE (Y2); - UNICODE (y3); - UNICODE (y4); - UNICODE (yhalf); - UNICODE (ymin); - UNICODE (ymax); - UNICODE (y_offset); - - UNICODE (z); - UNICODE (Z); - UNICODE (z_layout); - UNICODE (z_length); - UNICODE (z_offset); - UNICODE (z0); - UNICODE (z1); - UNICODE (z2); - UNICODE (z3); - UNICODE (z4); - UNICODE (Zeff); - UNICODE (zhalf); - UNICODE (zmin); - UNICODE (zmax); - UNICODE (zplane); - UNICODE (zstart); - - } -} +extern const Tag_t Unicode_NULL; +extern const Tag_t Unicode_empty; +extern const Tag_t Unicode_star; +extern const Tag_t Unicode_PI; +extern const Tag_t Unicode_TWOPI; + +UNICODE(0); +UNICODE(1); +UNICODE(2); +UNICODE(3); +UNICODE(4); +UNICODE(5); +UNICODE(6); +UNICODE(7); +UNICODE(8); +UNICODE(9); + +UNICODE (a); +UNICODE (A); +UNICODE (Air); +UNICODE (angle); +UNICODE (alignment); +UNICODE (alignments); +UNICODE (alpha); +UNICODE (alpha1); +UNICODE (alpha2); +UNICODE (alpha3); +UNICODE (alpha4); +UNICODE (arb8); +UNICODE (arg); +UNICODE (argument); +UNICODE (assembly); +UNICODE (atom); +UNICODE (attributes); +UNICODE (aunit); +UNICODE (author); + +UNICODE (b); +UNICODE (B); +UNICODE (barrel); +UNICODE (barrel_envelope); +UNICODE (beampipe); +UNICODE (beta); +UNICODE (box); + +UNICODE (c); +UNICODE (distance); +UNICODE (C); +UNICODE (calorimeter); +UNICODE (cartesian_grid_xy); +UNICODE (chamber); +UNICODE (chambers); +UNICODE (check); +UNICODE (checksum); +UNICODE (close); +UNICODE (cm); +UNICODE (coefficient); +UNICODE (coefficients); +UNICODE (color); +UNICODE (collections); +UNICODE (collection); +UNICODE (combine_hits); +UNICODE (combineHits); +UNICODE (comment); +UNICODE (component); +UNICODE (composite); +UNICODE (cone); +UNICODE (cons); +UNICODE (constant); +UNICODE (crossing_angle); +UNICODE (cut); + +UNICODE (d); +UNICODE (D); +UNICODE (daughter); +UNICODE (define); +UNICODE (delta); +UNICODE (deltaphi); +UNICODE (deltatheta); +UNICODE (depth); +UNICODE (density); +UNICODE (detector); +UNICODE (detectors); +UNICODE (dim_r); +UNICODE (dim_x); +UNICODE (dim_y); +UNICODE (dim_z); +UNICODE (dimensions); +UNICODE (dipole_coeff); +UNICODE (disk); +UNICODE (disks); +UNICODE (display); +UNICODE (dr); +UNICODE (drawing_style); +UNICODE (drawingStyle); +UNICODE (dx); +UNICODE (dy); +UNICODE (dz); + +UNICODE (e); +UNICODE (E); +UNICODE (ecut); +UNICODE (element); +UNICODE (eltube); +UNICODE (end); +UNICODE (end_module); +UNICODE (end_modules); +UNICODE (endcap); +UNICODE (endphi); +UNICODE (epsilon); +UNICODE (eunit); +UNICODE (end_x); +UNICODE (end_y); +UNICODE (end_z); + +UNICODE (f); +UNICODE (F); +UNICODE(false); +UNICODE (field); +UNICODE (fields); +UNICODE (field_name); +UNICODE (file); +UNICODE (first); +UNICODE (firstposition); +UNICODE (firstrotation); +UNICODE (formula); +UNICODE (fraction); +UNICODE (funit); + +UNICODE (g); +UNICODE (G); +UNICODE (gamma); +UNICODE (gap); +UNICODE (gas); +UNICODE (generator); +UNICODE (gdml); +UNICODE (gdmlFile); +UNICODE (geometry); +UNICODE (glass); +UNICODE (global); +UNICODE (global_grid_xy); +UNICODE (grid_size_x); +UNICODE (grid_size_y); +UNICODE (grid_size_z); +UNICODE (grid_size_phi); +UNICODE (grid_xyz); +UNICODE (gridSizePhi); +UNICODE (gridSizeX); +UNICODE (gridSizeY); +UNICODE (gridSizeZ); + +UNICODE (h); +UNICODE (H); +UNICODE (half_x); +UNICODE (half_y); +UNICODE (half_z); +UNICODE (header); +UNICODE (height); +UNICODE (hits_collections); +UNICODE (hits_collection); +UNICODE (hype); + +UNICODE (i); +UNICODE (I); +UNICODE (id); +UNICODE (iddict); +UNICODE (identity_rot); +UNICODE (identity_pos); +UNICODE (idfield); +UNICODE (idspec); +UNICODE (idspecref); +UNICODE (include); +UNICODE (includes); +UNICODE (incoming_r); +UNICODE (info); +UNICODE (inner); +UNICODE (inner_field); +UNICODE (inner_r); +UNICODE (inner_radius); +UNICODE (inner_stereo); +UNICODE (inner_z); +UNICODE (insideTrackingVolume); +UNICODE (intersection); +UNICODE (InvisibleNoDaughters); +UNICODE (InvisibleWithDaughters); +UNICODE (isotope); +UNICODE (item); + +UNICODE (j); +UNICODE (J); + +UNICODE (k); +UNICODE (key); +UNICODE (key_min); +UNICODE (key_max); +UNICODE (key_val); +UNICODE (key_value); +UNICODE (K); + +UNICODE (l); +UNICODE (L); +UNICODE (label); +UNICODE (ladder); +UNICODE (layer); +UNICODE (layers); +UNICODE (lcdd); +UNICODE (lccdd); +UNICODE (length); +UNICODE (limit); +UNICODE (limits); +UNICODE (limitset); +UNICODE (limitsetref); +UNICODE (line_style); +UNICODE (lineStyle); +UNICODE (local); +UNICODE (logvol); +UNICODE (lunit); + +UNICODE (m); +UNICODE (M); +UNICODE (material); +UNICODE (materialref); +UNICODE (materials); +UNICODE (member); +UNICODE (MeV); +UNICODE (mm); +UNICODE (module); +UNICODE (modules); +UNICODE (module_component); +UNICODE (module_envelope); +UNICODE (moduleHeight); +UNICODE (modulePitch); +UNICODE (modulePosX); +UNICODE (modulePosY); +UNICODE (moduleWidth); +UNICODE (mother); + +UNICODE (n); +UNICODE (N); +UNICODE (NIL); +UNICODE (name); +UNICODE (nmodules); +UNICODE (nModules); +UNICODE (normal); +UNICODE (nonprojective_cylinder); +UNICODE (nPads); +UNICODE (nphi); +UNICODE (ntheta); +UNICODE (number); +UNICODE (numsides); +UNICODE (nsides); +UNICODE (nsides_inner); +UNICODE (nsides_outer); +UNICODE (nz); + +UNICODE (o); +UNICODE (O); +UNICODE (offset); +UNICODE (open); +UNICODE (overlap); +UNICODE (outer); +UNICODE (outer_field); +UNICODE (outer_r); +UNICODE (outer_radius); +UNICODE (outer_stereo); +UNICODE (outer_z); +UNICODE (outgoing_r); +UNICODE (outst); + +UNICODE (p); +UNICODE (P); +UNICODE (padPitch); +UNICODE (pads); +UNICODE (para); +UNICODE (paraboloid); +UNICODE (param); +UNICODE (parameter); +UNICODE (params); +UNICODE (parent); +UNICODE (particles); +UNICODE (path); +UNICODE (phi); +UNICODE (phi0); +UNICODE (phi0_offset); +UNICODE (phi1); +UNICODE (phi_tilt); +UNICODE (phiBins); +UNICODE (phi_size_max); +UNICODE (physvol); +UNICODE (physvolid); +UNICODE (pivot); +UNICODE (pivot_point); +UNICODE (plugin); +UNICODE (plugins); +UNICODE (point); +UNICODE (polyhedra); +UNICODE (polycone); +UNICODE (position); +UNICODE (positionref); +UNICODE (pressure); +UNICODE (projective_cylinder); +UNICODE (projective_zplane); +UNICODE (properties); +UNICODE (psi); + +UNICODE (q); +UNICODE (Q); + +UNICODE (r); +UNICODE (R); +UNICODE (r_size); +UNICODE (r0); +UNICODE (rad); +UNICODE (radian); +UNICODE (radius); +UNICODE (radiator); +UNICODE (rbg); +UNICODE (rc); +UNICODE (readout); +UNICODE (readouts); +UNICODE (ref); +UNICODE (reflect); +UNICODE (reflect_rot); +UNICODE (region); +UNICODE (regions); +UNICODE (regionref); +UNICODE (repeat); +UNICODE (rhi); +UNICODE (ring); +UNICODE (rlo); +UNICODE (rmax); +UNICODE (rmax1); +UNICODE (rmax2); +UNICODE (rmin); +UNICODE (rmin1); +UNICODE (rmin2); +UNICODE (RL); +UNICODE (row); +UNICODE (rpc); +UNICODE (RowID); +UNICODE (rowHeight); +UNICODE (rowPitch); +UNICODE (rphi_layout); +UNICODE (rotation); +UNICODE (rotationref); +UNICODE (rtor); + +UNICODE (s); +UNICODE (S); +UNICODE (scintillator); +UNICODE (sd); +UNICODE (sdref); +UNICODE (second); +UNICODE (segmentation); +UNICODE (sensitive); +UNICODE (sensitive_detector); +UNICODE (sensitive_detectors); +UNICODE (sensor); +UNICODE (sequence); +UNICODE (setup); +UNICODE (shape); +UNICODE (show_daughters); +UNICODE (showDaughters); +UNICODE (size); +UNICODE(signed); +UNICODE (skew); +UNICODE (slice); +UNICODE (slices); +UNICODE (solid); +UNICODE (solids); +UNICODE (solidref); +UNICODE (spacer); +UNICODE (sphere); +UNICODE (status); +UNICODE (start); +UNICODE (start_x); +UNICODE (start_y); +UNICODE (start_z); +UNICODE (startphi); +UNICODE (starttheta); +UNICODE (state); +UNICODE (stave); +UNICODE (staves); +UNICODE (store_secondaries); +UNICODE (strength); +UNICODE (structure); +UNICODE (subtraction); +UNICODE (support); +UNICODE (system); +UNICODE (symbol); + +UNICODE (t); +UNICODE (T); +UNICODE (temperature); +UNICODE (theta); +UNICODE (thetaBins); +UNICODE (thickness); +UNICODE (threshold); +UNICODE (title); +UNICODE (tube); +UNICODE (tubes); +UNICODE (torus); +UNICODE (tracker); +UNICODE (tracking_cylinder); +UNICODE (tracking_volume); +UNICODE (trap); +UNICODE (trd); +UNICODE (true); +UNICODE (tubs); +UNICODE (type); + +UNICODE (u); +UNICODE (U); +UNICODE (union); +UNICODE (unit); +UNICODE (useForHitPosition); +UNICODE (url); + +UNICODE (v); +UNICODE (V); +UNICODE (v1x); +UNICODE (v1y); +UNICODE (v2x); +UNICODE (v2y); +UNICODE (v3x); +UNICODE (v3y); +UNICODE (v4x); +UNICODE (v4y); +UNICODE (v5x); +UNICODE (v5y); +UNICODE (v6x); +UNICODE (v6y); +UNICODE (v7x); +UNICODE (v7y); +UNICODE (v8x); +UNICODE (v8y); +UNICODE (Vacuum); +UNICODE (value); +UNICODE (verbose); +UNICODE (version); +UNICODE (vis); +UNICODE (visible); +UNICODE (visref); +UNICODE (volume); +UNICODE (volumeref); + +UNICODE (w); +UNICODE (W); +UNICODE (wedge); +UNICODE (width); +UNICODE (world); +UNICODE (world_box); +UNICODE (world_volume); + +UNICODE (x); +UNICODE (X); +UNICODE (x_offset); +UNICODE (x0); +UNICODE (x1); +UNICODE (X1); +UNICODE (x2); +UNICODE (X2); +UNICODE (x3); +UNICODE (x4); +UNICODE (xhalf); +UNICODE (xmax); +UNICODE (xmin); +UNICODE (xml); + +UNICODE (y); +UNICODE (Y); +UNICODE (y0); +UNICODE (y1); +UNICODE (Y1); +UNICODE (y2); +UNICODE (Y2); +UNICODE (y3); +UNICODE (y4); +UNICODE (yhalf); +UNICODE (ymin); +UNICODE (ymax); +UNICODE (y_offset); + +UNICODE (z); +UNICODE (Z); +UNICODE (z_layout); +UNICODE (z_length); +UNICODE (z_offset); +UNICODE (z0); +UNICODE (z1); +UNICODE (z2); +UNICODE (z3); +UNICODE (z4); +UNICODE (Zeff); +UNICODE (zhalf); +UNICODE (zmin); +UNICODE (zmax); +UNICODE (zplane); +UNICODE (zstart); diff --git a/DDCore/include/XML/XMLDetector.h b/DDCore/include/XML/XMLDetector.h index b8264f723..f5c3eb550 100644 --- a/DDCore/include/XML/XMLDetector.h +++ b/DDCore/include/XML/XMLDetector.h @@ -10,7 +10,6 @@ // Author : M.Frank // //========================================================================== - #ifndef DD4HEP_XMLDETECTOR_H #define DD4HEP_XMLDETECTOR_H @@ -26,74 +25,9 @@ namespace DD4hep { /// Namespace for the AIDA detector description toolkit supporting XML utilities namespace XML { - /// XML Handle class extending the XML handle Dimension - /** - * Helper class to access any field in a xml tag. - * Specialized for attributes of a detector sub-element. - * - * \author M.Frank - * \version 1.0 - * \ingroup DD4HEP_XML - */ - struct Component: public Dimension { - /// Constructor from Handle - Component(Handle_t e) - : Dimension(e) { - } - /// Constructor from Element - Component(const Element& e) - : Dimension(e) { - } - /// Access material attribute as STL string - std::string materialStr() const; - /// Check if component is sensitive - bool isSensitive() const; - - /// Check if component is a radiator (absorber) - bool isRadiator() const; - - /// Create a shape using the plugin mechanism from an XML element - NamedObject* createShape() const; - }; - - /// XML Handle class extending the XML handle Dimension - /** - * Helper class to access any field in a xml tag. - * Specialized for some of the attributes of a detector element. - * - * \author M.Frank - * \version 1.0 - * \ingroup DD4HEP_XML - */ - struct DetElement: public Dimension { - /// Constructor from Handle - DetElement(Handle_t e) - : Dimension(e) { - } - /// Access underlying XML handle object - Handle_t handle() const { - return m_element; - } + /// Include the implementation in the proper namespace +#include "XML/detail/Detector.h" - /// Access parameters: id - int id() const; - /// Access material attribute as STL string. If not present empty return empty string - std::string materialStr() const; - /// Check if xml detector element is sensitive - bool isSensitive() const; - /// Check if element describes a tracking detector - bool isTracker() const; - /// Check if element describes a calorimetric detector - bool isCalorimeter() const; - /// Check if element is inside the tracking volume - bool isInsideTrackingVolume() const; - /// Helper to check a condition (for debugging) - void check(bool condition, const std::string& msg) const; - /// Access attribute by type - template <typename T> T attr(const XmlChar* tag_value) const { - return m_element.attr < T > (tag_value); - } - }; } -} /* End namespace DD4hep */ +} /* End namespace DD4hep */ #endif /* DD4HEP_XMLDETECTOR_H */ diff --git a/DDCore/include/XML/XMLDimension.h b/DDCore/include/XML/XMLDimension.h index 74bb491b3..9bbc9d361 100644 --- a/DDCore/include/XML/XMLDimension.h +++ b/DDCore/include/XML/XMLDimension.h @@ -10,11 +10,11 @@ // Author : M.Frank // //========================================================================== - -#ifndef DD4HEP_XMLDIMENSION_H -#define DD4HEP_XMLDIMENSION_H +#ifndef DD4HEP_XML_XMLDIMENSION_H +#define DD4HEP_XML_XMLDIMENSION_H // Framework include files +#include "XML/XMLElements.h" #include "XML/XMLTags.h" /// Namespace for the AIDA detector description toolkit @@ -23,550 +23,9 @@ namespace DD4hep { /// Namespace for the AIDA detector description toolkit supporting XML utilities namespace XML { - /// XML Handle to xml elements with predefined attribute access - /** - * Helper class to access any field in a xml tag in a - * very easy way. - * - You may assign any xml handle to a dimension object - * - Any attribute of this xml element may then be accessed - * by it's natural way. All possible attribute names are - * reflected by the Dimension object's member functions. - * - If an attribute is requested and not present, a exception - * is thrown. - * - Functions, which accept a default value do NOT throw - * an exception if the attribute is not present. These - * rather return the default value. - * - If a often used function is not present - the - * implementation thereof is simple. - * - * Such helper classes may be defined locally by any user - * since XML element handles may easily be transferred. - * Run-time exceptions occur however, if non-exiting attributes - * are accessed. - * - * \author M.Frank - * \version 1.0 - * \ingroup DD4HEP_XML - */ - struct Dimension: public Element { - /// Default constructor - Dimension() - : Element(Handle_t(0)) { - } - /// Constructor from Handle - Dimension(Handle_t e) - : Element(e) { - } - /// Constructor from Element - Dimension(const Element& e) - : Element(e) { - } - - /// Access parameters: id - int id() const; - /// Access parameters: id, if not present returns default - int id(int default_value) const; - - /// Access parameters: type - int type() const; - /// Access rotation constants: combineHits - bool combineHits() const; - - /// Access rotation constants: angle - double angle() const; - /// Access rotation constants: alpha - double alpha() const; - /// Access rotation constants: alpha - double alpha(double default_value) const; - /// Access rotation constants: alpha1 - double alpha1() const; - /// Access rotation constants: alpha1 - double alpha1(double default_value) const; - /// Access rotation constants: alpha2 - double alpha2() const; - /// Access rotation constants: alpha2 - double alpha2(double default_value) const; - /// Access rotation constants: angle - double beta() const; - /// Access rotation constants: angle - double beta(double default_value) const; - /// Access rotation constants: angle - double gamma() const; - /// Access rotation constants: angle - double gamma(double default_value) const; - /// Access rotation constants: angle - double delta() const; - /// Access rotation constants: angle - double delta(double default_value) const; - /// Access rotation constants: angle - double epsilon() const; - /// Access rotation constants: angle - double epsilon(double default_value) const; - /// Access rotation constants: theta - double theta() const; - /// Access rotation constants: theta - double theta(double default_value) const; - /// Access rotation constants: deltatheta - double deltatheta() const; - /// Access rotation constants: deltatheta - double deltatheta(double default_value) const; - /// Access rotation constants: thetaBins - int thetaBins() const; - - /// Access rotation constants: phi - double phi() const; - /// Access rotation constants: phi - double phi(double default_value) const; - /// Access rotation constants: phiBins - int phiBins() const; - /// Access rotation constants: phi0 - double phi0() const; - /// Access parameters: phi0, if not present returns default - double phi0(double default_value) const; - /// Access rotation constants: phi0_offset - double phi0_offset() const; - /// Access parameters: phi0_offset, if not present returns default - double phi0_offset(double default_value) const; - /// Access rotation constants: phi1 - double phi1() const; - /// Access parameters: phi1, if not present returns default - double phi1(double default_value) const; - /// Access rotation constants: psi - double psi() const; - /// Access rotation constants: psi - double psi(double default_value) const; - - /// Access Tube parameters: zhalf - double zhalf() const; - /// Access Tube parameters: deltaphi - double deltaphi() const; - /// Access Tube parameters: deltaphi - double deltaphi(double default_value) const; - /// Access rotation constants: startphi - double startphi() const; - /// Access rotation constants: startphi - double startphi(double default_value) const; - - /// Access parameters: a - double a() const; - /// Access parameters: a - double a(double default_value) const; - /// Access parameters: A - double A() const; - /// Access parameters: A - double A(double default_value) const; - /// Access parameters: b - double b() const; - /// Access parameters: b - double b(double default_value) const; - /// Access parameters: c - double c() const; - /// Access parameters: c - double c(double default_value) const; - ///Access parameters: distance - double distance() const; - ///Access parameters: distance - double distance(double default_value) const; - /// Access parameters: B - double B() const; - /// Access parameters: B - double B(double default_value) const; - /// Access parameters: g - double g() const; - /// Access parameters: g - double g(double default_value) const; - /// Access parameters: G - double G() const; - /// Access parameters: G - double G(double default_value) const; - /// Access parameters: I - double I() const; - /// Access parameters: I - double I(double default_value) const; - - /// Access parameters: r - double r() const; - /// Access parameters: r, if not present returns default - double r(double default_value) const; - /// Access parameters: R - double R() const; - /// Access parameters: R - double R(double default_value) const; - /// Access parameters: dr - double dr() const; - /// Access parameters: dr, if not present returns default - double dr(double default_value) const; - /// Access parameters: r0 - double r0() const; - /// Access parameters: r0 - double r0(double default_value) const; - /// Access min/max parameters: rmin - double rmin() const; - /// Access min/max parameters: rmin - double rmin(double default_val) const; - /// Access min/max parameters: rmax - double rmax() const; - /// Access min/max parameters: rmax - double rmax(double default_val) const; - /// Access min/max parameters: rmin1 - double rmin1() const; - /// Access min/max parameters: rmin1 - double rmin1(double default_val) const; - /// Access min/max parameters: rmax1 - double rmax1() const; - /// Access min/max parameters: rmax1 - double rmax1(double default_val) const; - /// Access min/max parameters: rmin2 - double rmin2() const; - /// Access min/max parameters: rmin2 - double rmin2(double default_val) const; - /// Access min/max parameters: rmax2 - double rmax2() const; - /// Access min/max parameters: rmax2 - double rmax2(double default_val) const; - /// Access parameters: radius - double radius() const; - /// Access parameters: radius - double radius(double default_val) const; - /// Access attribute values: outer_radius - double outer_radius() const; - /// Access attribute values: outer_r - double outer_r() const; - /// Access attribute values: inner_radius - double inner_radius() const; - /// Access attribute values: inner_r - double inner_r() const; - - /// Access parameters: x - double x() const; - /// Access parameters: x, if not present returns default - double x(double default_val) const; - /// Access parameters: X - double X() const; - /// Access parameters: X - double X(double default_val) const; - /// Access parameters: x0 - double x0() const; - /// Access parameters: x0 - double x0(double default_val) const; - /// Access parameters: x1 - double x1() const; - /// Access parameters: x1 - double x1(double default_val) const; - /// Access parameters: x2 - double x2() const; - /// Access parameters: x2 - double x2(double default_val) const; - /// Access parameters: x3 - double x3() const; - /// Access parameters: x3 - double x3(double default_val) const; - /// Access parameters: x4 - double x4() const; - /// Access parameters: x4 - double x4(double default_val) const; - /// Access parameters: dx - double dx() const; - /// Access parameters: dx, if not present returns default - double dx(double default_value) const; - /// Access min/max parameters: xmax - double xmin() const; - /// Access min/max parameters: xmax - double xmin(double default_value) const; - /// Access min/max parameters: xmax - double xmax() const; - /// Access min/max parameters: xmax - double xmax(double default_value) const; - /// Access min/max parameters: x_offset - double x_offset() const; - /// Access min/max parameters: x_offset - double x_offset(double default_value) const; - /// Access min/max parameters: dim_x - double dim_x() const; - /// Access min/max parameters: dim_x - double dim_x(double default_value) const; - - /// Access parameters: y - double y() const; - /// Access parameters: y, if not present returns default - double y(double default_val) const; - /// Access parameters: Y - double Y() const; - /// Access parameters: Y - double Y(double default_val) const; - /// Access parameters: y0 - double y0() const; - /// Access parameters: y0 - double y0(double default_value) const; - /// Access parameters: y1 - double y1() const; - /// Access parameters: y1 - double y1(double default_value) const; - /// Access parameters: y2 - double y2() const; - /// Access parameters: y2 - double y2(double default_value) const; - /// Access parameters: dy - double dy() const; - /// Access parameters: dz, if not present returns default - double dy(double default_value) const; - /// Access min/max parameters: ymax - double ymin() const; - /// Access min/max parameters: ymax - double ymin(double default_value) const; - /// Access min/max parameters: ymax - double ymax() const; - /// Access min/max parameters: ymax - double ymax(double default_value) const; - /// Access min/max parameters: y_offset - double y_offset() const; - /// Access min/max parameters: y_offset - double y_offset(double default_value) const; - /// Access min/max parameters: dim_y - double dim_y() const; - /// Access min/max parameters: dim_y - double dim_y(double default_value) const; - - /// Access parameters: z - double z() const; - /// Access parameters: z, if not present returns default - double z(double default_val) const; - /// Access parameters: Z - double Z() const; - /// Access parameters: Z - double Z(double default_val) const; - /// Access parameters: z0 - double z0() const; - /// Access parameters: z0 - double z0(double default_val) const; - /// Access parameters: z1 - double z1() const; - /// Access parameters: z1 - double z1(double default_val) const; - /// Access parameters: z2 - double z2() const; - /// Access parameters: z2 - double z2(double default_val) const; - /// Access parameters: dz - double dz() const; - /// Access parameters: dz, if not present returns default - double dz(double default_value) const; - /// Access min/max parameters: zmax - double zmin() const; - /// Access min/max parameters: zmax - double zmin(double default_value) const; - /// Access min/max parameters: zmax - double zmax() const; - /// Access min/max parameters: zmax - double zmax(double default_value) const; - /// Access attribute values: outer_z - double outer_z() const; - /// Access attribute values: inner_z - double inner_z() const; - /// Access attribute values: outer_stereo - double outer_stereo() const; - /// Access attribute values: inner_stereo - double inner_stereo() const; - /// Access min/max parameters: z_offset - double z_offset() const; - /// Access min/max parameters: z_offset - double z_offset(double default_value) const; - /// Access min/max parameters: dim_z - double dim_z() const; - /// Access min/max parameters: dim_z - double dim_z(double default_value) const; - - /// Access attribute values: length - double length() const; - /// Access attribute values: width - double width() const; - /// Access attribute values: height - double height() const; - /// Access attribute values: depth - double depth() const; - /// Access attribute values: thickness - double thickness() const; - - /// Access attribute values: z_length - double z_length() const; - /// Access attribute values: gap - double gap() const; - /// Access attribute values: r_size - double r_size() const; - /// Access attribute values: phi_size_max - double phi_size_max() const; - /// Access attribute values: reflect - bool reflect() const; - /// Access attribute values: reflect - bool reflect(bool default_value) const; - /// Access attribute values: crossing_angle - double crossing_angle() const; - /// Access attribute values: repeat - int repeat() const; - - /// Access attribute values: coefficient - double coefficient() const; - /// Access attribute values: coefficient - double coefficient(double default_value) const; - - /// Access attribute values: skew - double skew() const; - /// Access attribute values: skew - double skew(double default_value) const; - - /// Access attribute values: outgoing_r - double outgoing_r() const; - /// Access attribute values: incoming_r - double incoming_r() const; - /// Access attribute values: offset - double offset() const; - /// Access attribute values: offset - double offset(double default_value) const; - /// Access attribute values: number - int number() const; - - /// Access attribute values: nmodules - int nmodules() const; - /// Access attribute values: nModules - int nModules() const; - /// Access attribute values: RowID - int RowID() const; - /// Access attribute values: moduleHeight - double moduleHeight() const; - /// Access attribute values: moduleWidth - double moduleWidth() const; - /// Access attribute values: modulePitch - double modulePitch() const; - /// Access attribute values: modulePosX - double modulePosX() const; - /// Access attribute values: modulePosY - double modulePosY() const; - - /// Access attribute values: nPads - int nPads() const; - /// Access attribute values: rowPitch - double rowPitch() const; - /// Access attribute values: padPitch - double padPitch() const; - /// Access attribute values: rowHeight - double rowHeight() const; - /// Access attribute values: padType - std::string padType() const; - - /// Access attribute values: numsides - int numsides() const; - /// Access attribute values: nsides - int nsides() const; - /// Access attribute values: nsides_inner - int nsides_inner() const; - /// Access attribute values: nsides_outer - int nsides_outer() const; - - - /// Access attribute values: phi_tilt - double phi_tilt() const; - /// Access attribute values: nphi - int nphi() const; - /// Access attribute values: rc - double rc() const; - - /// Access attribute values: zstart - double zstart() const; - /// Access attribute values: nz - int nz() const; - /// Access attribute values: key - int key() const; - /// Access attribute values: key_min - int key_min() const; - /// Access attribute values: key_max - int key_max() const; - /// Access attribute values: key_val - int key_val() const; - /// Access attribute values: key_value - int key_value() const; - - /// Access attribute values: start - double start() const; - /// Access attribute values: start - double start(double default_value) const; - /// Access attribute values: end - double end() const; - /// Access attribute values: end - double end(double default_value) const; - /// Access attribute values: inner_field - double inner_field() const; - /// Access attribute values: outer_field - double outer_field() const; - - /// Access attribute values: visible - bool visible() const; - /// Access attribute values: show_daughters - bool show_daughters() const; - - /// Access min/max parameters: cut - double cut() const; - /// Access min/max parameters: cut - double cut(double default_value) const; - /// Access min/max parameters: threshold - double threshold() const; - /// Access min/max parameters: threshold - double threshold(double default_value) const; - /// Access min/max parameters: eunit - double eunit() const; - /// Access min/max parameters: eunit - double eunit(double default_value) const; - /// Access min/max parameters: lunit - double lunit() const; - /// Access min/max parameters: lunit - double lunit(double default_value) const; - - /// Access rotation constants: temperature - double temperature() const; - /// Access rotation constants: temperature - double temperature(double default_value) const; - /// Access rotation constants: pressure - double pressure() const; - /// Access rotation constants: pressure - double pressure(double default_value) const; - /// Access rotation constants: density - double density() const; - /// Access rotation constants: density - double density(double default_value) const; - - /// Access child element with tag "dimensions" as Dimension object - Dimension dimensions(bool throw_if_not_present = true) const; - /// Child access: position - Dimension position(bool throw_if_not_present = true) const; - /// Child access: rotation - Dimension rotation(bool throw_if_not_present = true) const; - /// Child access: trd - Dimension trd(bool throw_if_not_present = true) const; - /// Child access: tubs - Dimension tubs(bool throw_if_not_present = true) const; - /// Child access: staves - Dimension staves(bool throw_if_not_present = true) const; - /// Child access: beampipe - Dimension beampipe(bool throw_if_not_present = true) const; - - /// Access "name" attribute as STL string - std::string nameStr() const; - /// Access "ref" attribute as a string - std::string refStr() const; - /// Access "type" attribute as STL string - std::string typeStr() const; - /// Access "value" attribute as STL string - std::string valueStr() const; - /// Access "module" attribute as STL string - std::string moduleStr() const; - /// Access "readout" attribute as STL string - std::string readoutStr() const; - /// Access vis attribute as STL string. If not present empty return empty string - std::string visStr() const; - /// Access region attribute as STL string. If not present empty return empty string - std::string regionStr() const; - /// Access limits attribute as STL string. If not present empty return empty string - std::string limitsStr() const; - }; - } /* End namespace XML */ -} /* End namespace DD4hep */ -#endif /* DD4HEP_XMLDIMENSION_H */ + /// Re-use the defined interface for the XML data access +#include "XML/detail/Dimension.h" + + } /* End namespace XML */ +} /* End namespace DD4hep */ +#endif /* DD4HEP_XML_XMLDIMENSION_H */ diff --git a/DDCore/include/XML/XMLDimension.inl b/DDCore/include/XML/XMLDimension.inl index c5deadb24..1a1620a81 100644 --- a/DDCore/include/XML/XMLDimension.inl +++ b/DDCore/include/XML/XMLDimension.inl @@ -14,38 +14,11 @@ #ifndef DD4HEP_XMLDIMENSION_INL #define DD4HEP_XMLDIMENSION_INL -// Framework include files -#include "XML/XMLDimension.h" - -#define XML_ATTR_NS_ACCESSOR(type,ns,name) type ns::name() const { return m_element.attr<type>(Unicode_##name); } - -#define XML_ATTR_NS_ACCESSOR_DEFAULT(type,ns,name,dressing) \ - type ns::name(type default_val) const { \ - const ::DD4hep::XML::XmlChar* val = m_element.attr_value_nothrow(Unicode_##name); \ - return val ? dressing(val) : default_val; } - -#define XML_ATTR_NS_ACCESSOR_DOUBLE(ns,name) \ - XML_ATTR_NS_ACCESSOR(double,ns,name) \ - XML_ATTR_NS_ACCESSOR_DEFAULT(double,ns,name,DD4hep::XML::_toDouble) - -#define XML_ATTR_NS_ACCESSOR_INT(ns,name) \ - XML_ATTR_NS_ACCESSOR(int,ns,name) \ - XML_ATTR_NS_ACCESSOR_DEFAULT(int,ns,name,DD4hep::XML::_toInt) -#define XML_ATTR_NS_ACCESSOR_STRING(ns,name) \ - XML_ATTR_NS_ACCESSOR(std::string,ns,name) \ - XML_ATTR_NS_ACCESSOR_DEFAULT(std::string,ns,name,DD4hep::XML::_toString) +#define DIMENSION_NS XML - -#define XML_ATTR_ACCESSOR(type,name) XML_ATTR_NS_ACCESSOR(type,DD4hep::XML::Dimension,name) -#define XML_ATTR_ACCESSOR_DEFAULT(name,type,dressing) XML_ATTR_NS_ACCESSOR_DEFAULT(type,DD4hep::XML::Dimension,name,dressing) -#define XML_ATTR_ACCESSOR_DOUBLE(name) XML_ATTR_NS_ACCESSOR_DOUBLE(DD4hep::XML::Dimension,name) - -#define XML_ATTR_ACCESSOR_INT(name) XML_ATTR_NS_ACCESSOR_DEFAULT(int,DD4hep::XML::Dimension,name,_toInt) -#define XML_ATTR_ACCESSOR_BOOL(name) XML_ATTR_NS_ACCESSOR_DEFAULT(bool,DD4hep::XML::Dimension,name,_toBool) - -#define XML_CHILD_ACCESSOR_XML_DIM(name) \ - DD4hep::XML::Dimension DD4hep::XML::Dimension::name(bool throw_if_not_present) const { \ - return m_element.child(Unicode_##name,throw_if_not_present); } +// Framework include files +#include "XML/XMLDimension.h" +#include "XML/detail/Dimension.inl" #endif /* DD4HEP_XMLDIMENSION_INL */ diff --git a/DDCore/include/XML/XMLTags.h b/DDCore/include/XML/XMLTags.h index 80b427bc8..c73cac3c4 100644 --- a/DDCore/include/XML/XMLTags.h +++ b/DDCore/include/XML/XMLTags.h @@ -11,19 +11,29 @@ // //========================================================================== -#ifndef DD4hep_XML_TAGS_H -#define DD4hep_XML_TAGS_H +#ifndef DD4HEP_XML_TAGS_H +#define DD4HEP_XML_TAGS_H #define DECLARE_UNICODE_TAG(x) extern const ::DD4hep::XML::Tag_t Unicode_##x (#x) // Framework include files #include "XML/XMLElements.h" #define UNICODE(x) extern const Tag_t Unicode_##x + +/// Namespace for the AIDA detector description toolkit +namespace DD4hep { + + /// Namespace for the AIDA detector description toolkit supporting XML utilities + namespace XML { #include "XML/UnicodeValues.h" + } +} + #undef UNICODE // Helpers to access tags and attributes quickly without specifying explicitly namespaces -#define _U(a) ::DD4hep::XML::Unicode_##a -#define _Unicode(a) ::DD4hep::XML::Strng_t(#a) +#define _DD4hep_Unicode_Item(a) Unicode_##a +#define _U(a) ::DD4hep::XML::Unicode_##a +#define _Unicode(a) ::DD4hep::XML::Strng_t(#a) -#endif // DD4hep_XML_TAGS_H +#endif // DD4HEP_XML_TAGS_H diff --git a/DDCore/include/XML/detail/Detector.h b/DDCore/include/XML/detail/Detector.h new file mode 100644 index 000000000..a420dbd03 --- /dev/null +++ b/DDCore/include/XML/detail/Detector.h @@ -0,0 +1,94 @@ +//========================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : M.Frank +// +//========================================================================== +#ifndef DD4HEP_XML_DETAIL_DETECTOR_H +#define DD4HEP_XML_DETAIL_DETECTOR_H + +/** + * Note: Do NEVER include this file directly! + * + * Include XML/XMLDetector.h or JSON/Detector.h ! + */ + +// Framework includes +#include "XML/detail/Dimension.h" + +/// XML Handle class extending the XML handle Dimension +/** + * Helper class to access any field in a xml tag. + * Specialized for attributes of a detector sub-element. + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_XML + */ +struct Component: public Dimension { + /// Constructor from Handle + Component(Handle_t e) + : Dimension(e) { + } + /// Constructor from Element + Component(const Element& e) + : Dimension(e) { + } + /// Access material attribute as STL string + std::string materialStr() const; + /// Check if component is sensitive + bool isSensitive() const; + + /// Check if component is a radiator (absorber) + bool isRadiator() const; + + /// Create a shape using the plugin mechanism from an XML element + NamedObject* createShape() const; +}; + +/// XML Handle class extending the XML handle Dimension +/** + * Helper class to access any field in a xml tag. + * Specialized for some of the attributes of a detector element. + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_XML + */ +struct DetElement: public Dimension { + /// Constructor from Handle + DetElement(Handle_t e) + : Dimension(e) { + } + /// Access underlying XML handle object + Handle_t handle() const { + return m_element; + } + + /// Access parameters: id + int id() const; + /// Access material attribute as STL string. If not present empty return empty string + std::string materialStr() const; + /// Check if xml detector element is sensitive + bool isSensitive() const; + /// Check if element describes a tracking detector + bool isTracker() const; + /// Check if element describes a calorimetric detector + bool isCalorimeter() const; + /// Check if element is inside the tracking volume + bool isInsideTrackingVolume() const; + /// Helper to check a condition (for debugging) + void check(bool condition, const std::string& msg) const; + /// Access attribute by type + template <typename T> T attr(const XmlChar* tag_value) const { + return m_element.attr < T > (tag_value); + } +}; + +#endif /* DD4HEP_XML_DETAIL_DETECTOR_H */ diff --git a/DDCore/include/XML/detail/Detector.imp b/DDCore/include/XML/detail/Detector.imp new file mode 100644 index 000000000..8418b003c --- /dev/null +++ b/DDCore/include/XML/detail/Detector.imp @@ -0,0 +1,104 @@ +//========================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : M.Frank +// +//========================================================================== + +// Framework include files +#include "DD4hep/Plugins.h" +#include "DD4hep/LCDD.h" + +using namespace std; + +namespace Geometry { class LCDD; } + +string Component::materialStr() const { + return m_element.attr < string > (_U(material)); +} + +bool Component::isSensitive() const { + char val = m_element.hasAttr(_U(sensitive)) ? m_element.attr < string > (_U(sensitive))[0] : 'f'; + val = ::toupper(val); + return val == 'T' || val == 'Y'; +} + +bool Component::isRadiator() const { + char val = m_element.hasAttr(_U(radiator)) ? m_element.attr < string > (_U(radiator))[0] : 'f'; + val = ::toupper(val); + return val == 'T' || val == 'Y'; +} + +DD4hep::NamedObject* Component::createShape() const { + using namespace DD4hep::Geometry; + Dimension child_dim(m_element); + string typ = child_dim.typeStr(); + string fac = typ + "__shape_constructor"; + Handle_t solid_elt = m_element; + LCDD* lcdd = 0; + NamedObject* solid = PluginService::Create<NamedObject*>(fac, lcdd, &solid_elt); + if ( !solid ) { + PluginDebug dbg; + PluginService::Create<NamedObject*>(typ, lcdd, &solid_elt); + throw runtime_error("Failed to create solid of type " + typ + ". " + dbg.missingFactory(typ)); + } + return solid; +} + +int DetElement::id() const { + return m_element.hasAttr(_U(id)) ? m_element.attr<int>(_U(id)) : -1; +} + +bool DetElement::isSensitive() const { + char val = m_element.hasAttr(_U(sensitive)) ? m_element.attr < string > (_U(sensitive))[0] : 'f'; + val = ::toupper(val); + return val == 'T' || val == 'Y'; +} + +string DetElement::materialStr() const { + Handle_t h = m_element.child(_U(material)); + if (h && h.hasAttr(_U(name))) { + return h.attr < string > (_U(name)); + } + return ""; +} + +void DetElement::check(bool condition, const string& msg) const { + if (condition) { + throw runtime_error(msg); + } +} + +bool DetElement::isTracker() const { + if (m_element) { + string typ = attr < string > (_U(type)); + if (typ.find("Tracker") != string::npos && hasAttr(_U(readout))) { + return true; + } + } + return false; +} + +bool DetElement::isCalorimeter() const { + if (m_element) { + string typ = attr < string > (_U(type)); + if (typ.find("Calorimeter") != string::npos && hasAttr(_U(readout))) { + return true; + } + } + return false; +} + +bool DetElement::isInsideTrackingVolume() const { + if (m_element && hasAttr(_U(insideTrackingVolume)) ) + return attr<bool>(_U(insideTrackingVolume)); + else if ( isTracker() ) + return true; + return false; +} diff --git a/DDCore/include/XML/detail/Dimension.h b/DDCore/include/XML/detail/Dimension.h new file mode 100644 index 000000000..d64042f73 --- /dev/null +++ b/DDCore/include/XML/detail/Dimension.h @@ -0,0 +1,568 @@ +//========================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : M.Frank +// +//========================================================================== +#ifndef DD4HEP_XML_DETAIL_DIMENSION_H +#define DD4HEP_XML_DETAIL_DIMENSION_H + +/** + * Note: Do NEVER include this file directly! + * + * Include XML/XMLDimension.h or JSON/Dimension.h ! + */ + + +/// XML Handle to xml elements with predefined attribute access +/** + * Helper class to access any field in a xml tag in a + * very easy way. + * - You may assign any xml handle to a dimension object + * - Any attribute of this xml element may then be accessed + * by it's natural way. All possible attribute names are + * reflected by the Dimension object's member functions. + * - If an attribute is requested and not present, a exception + * is thrown. + * - Functions, which accept a default value do NOT throw + * an exception if the attribute is not present. These + * rather return the default value. + * - If a often used function is not present - the + * implementation thereof is simple. + * + * Such helper classes may be defined locally by any user + * since XML element handles may easily be transferred. + * Run-time exceptions occur however, if non-exiting attributes + * are accessed. + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_XML + */ +struct Dimension: public Element { + /// Default constructor + Dimension() + : Element(Handle_t(0)) { + } + /// Constructor from Handle + Dimension(Handle_t e) + : Element(e) { + } + /// Constructor from Element + Dimension(const Element& e) + : Element(e) { + } + + /// Access parameters: id + int id() const; + /// Access parameters: id, if not present returns default + int id(int default_value) const; + + /// Access parameters: type + int type() const; + /// Access rotation constants: combineHits + bool combineHits() const; + + /// Access rotation constants: angle + double angle() const; + /// Access rotation constants: alpha + double alpha() const; + /// Access rotation constants: alpha + double alpha(double default_value) const; + /// Access rotation constants: alpha1 + double alpha1() const; + /// Access rotation constants: alpha1 + double alpha1(double default_value) const; + /// Access rotation constants: alpha2 + double alpha2() const; + /// Access rotation constants: alpha2 + double alpha2(double default_value) const; + /// Access rotation constants: angle + double beta() const; + /// Access rotation constants: angle + double beta(double default_value) const; + /// Access rotation constants: angle + double gamma() const; + /// Access rotation constants: angle + double gamma(double default_value) const; + /// Access rotation constants: angle + double delta() const; + /// Access rotation constants: angle + double delta(double default_value) const; + /// Access rotation constants: angle + double epsilon() const; + /// Access rotation constants: angle + double epsilon(double default_value) const; + /// Access rotation constants: theta + double theta() const; + /// Access rotation constants: theta + double theta(double default_value) const; + /// Access rotation constants: deltatheta + double deltatheta() const; + /// Access rotation constants: deltatheta + double deltatheta(double default_value) const; + /// Access rotation constants: thetaBins + int thetaBins() const; + + /// Access rotation constants: phi + double phi() const; + /// Access rotation constants: phi + double phi(double default_value) const; + /// Access rotation constants: phiBins + int phiBins() const; + /// Access rotation constants: phi0 + double phi0() const; + /// Access parameters: phi0, if not present returns default + double phi0(double default_value) const; + /// Access rotation constants: phi0_offset + double phi0_offset() const; + /// Access parameters: phi0_offset, if not present returns default + double phi0_offset(double default_value) const; + /// Access rotation constants: phi1 + double phi1() const; + /// Access parameters: phi1, if not present returns default + double phi1(double default_value) const; + /// Access rotation constants: psi + double psi() const; + /// Access rotation constants: psi + double psi(double default_value) const; + + /// Access Tube parameters: zhalf + double zhalf() const; + /// Access Tube parameters: deltaphi + double deltaphi() const; + /// Access Tube parameters: deltaphi + double deltaphi(double default_value) const; + /// Access rotation constants: startphi + double startphi() const; + /// Access rotation constants: startphi + double startphi(double default_value) const; + + /// Access parameters: a + double a() const; + /// Access parameters: a + double a(double default_value) const; + /// Access parameters: A + double A() const; + /// Access parameters: A + double A(double default_value) const; + /// Access parameters: b + double b() const; + /// Access parameters: b + double b(double default_value) const; + /// Access parameters: c + double c() const; + /// Access parameters: c + double c(double default_value) const; + ///Access parameters: distance + double distance() const; + ///Access parameters: distance + double distance(double default_value) const; + /// Access parameters: B + double B() const; + /// Access parameters: B + double B(double default_value) const; + /// Access parameters: g + double g() const; + /// Access parameters: g + double g(double default_value) const; + /// Access parameters: G + double G() const; + /// Access parameters: G + double G(double default_value) const; + /// Access parameters: I + double I() const; + /// Access parameters: I + double I(double default_value) const; + + /// Access parameters: r + double r() const; + /// Access parameters: r, if not present returns default + double r(double default_value) const; + /// Access parameters: R + double R() const; + /// Access parameters: R + double R(double default_value) const; + /// Access parameters: dr + double dr() const; + /// Access parameters: dr, if not present returns default + double dr(double default_value) const; + /// Access parameters: r0 + double r0() const; + /// Access parameters: r0 + double r0(double default_value) const; + /// Access min/max parameters: rmin + double rmin() const; + /// Access min/max parameters: rmin + double rmin(double default_val) const; + /// Access min/max parameters: rmax + double rmax() const; + /// Access min/max parameters: rmax + double rmax(double default_val) const; + /// Access min/max parameters: rmin1 + double rmin1() const; + /// Access min/max parameters: rmin1 + double rmin1(double default_val) const; + /// Access min/max parameters: rmax1 + double rmax1() const; + /// Access min/max parameters: rmax1 + double rmax1(double default_val) const; + /// Access min/max parameters: rmin2 + double rmin2() const; + /// Access min/max parameters: rmin2 + double rmin2(double default_val) const; + /// Access min/max parameters: rmax2 + double rmax2() const; + /// Access min/max parameters: rmax2 + double rmax2(double default_val) const; + /// Access parameters: radius + double radius() const; + /// Access parameters: radius + double radius(double default_val) const; + /// Access attribute values: outer_radius + double outer_radius() const; + /// Access attribute values: outer_r + double outer_r() const; + /// Access attribute values: inner_radius + double inner_radius() const; + /// Access attribute values: inner_r + double inner_r() const; + + /// Access parameters: x + double x() const; + /// Access parameters: x, if not present returns default + double x(double default_val) const; + /// Access parameters: X + double X() const; + /// Access parameters: X + double X(double default_val) const; + /// Access parameters: x0 + double x0() const; + /// Access parameters: x0 + double x0(double default_val) const; + /// Access parameters: x1 + double x1() const; + /// Access parameters: x1 + double x1(double default_val) const; + /// Access parameters: x2 + double x2() const; + /// Access parameters: x2 + double x2(double default_val) const; + /// Access parameters: x3 + double x3() const; + /// Access parameters: x3 + double x3(double default_val) const; + /// Access parameters: x4 + double x4() const; + /// Access parameters: x4 + double x4(double default_val) const; + /// Access parameters: dx + double dx() const; + /// Access parameters: dx, if not present returns default + double dx(double default_value) const; + /// Access min/max parameters: xmax + double xmin() const; + /// Access min/max parameters: xmax + double xmin(double default_value) const; + /// Access min/max parameters: xmax + double xmax() const; + /// Access min/max parameters: xmax + double xmax(double default_value) const; + /// Access min/max parameters: x_offset + double x_offset() const; + /// Access min/max parameters: x_offset + double x_offset(double default_value) const; + /// Access min/max parameters: dim_x + double dim_x() const; + /// Access min/max parameters: dim_x + double dim_x(double default_value) const; + + /// Access parameters: y + double y() const; + /// Access parameters: y, if not present returns default + double y(double default_val) const; + /// Access parameters: Y + double Y() const; + /// Access parameters: Y + double Y(double default_val) const; + /// Access parameters: y0 + double y0() const; + /// Access parameters: y0 + double y0(double default_value) const; + /// Access parameters: y1 + double y1() const; + /// Access parameters: y1 + double y1(double default_value) const; + /// Access parameters: y2 + double y2() const; + /// Access parameters: y2 + double y2(double default_value) const; + /// Access parameters: dy + double dy() const; + /// Access parameters: dz, if not present returns default + double dy(double default_value) const; + /// Access min/max parameters: ymax + double ymin() const; + /// Access min/max parameters: ymax + double ymin(double default_value) const; + /// Access min/max parameters: ymax + double ymax() const; + /// Access min/max parameters: ymax + double ymax(double default_value) const; + /// Access min/max parameters: y_offset + double y_offset() const; + /// Access min/max parameters: y_offset + double y_offset(double default_value) const; + /// Access min/max parameters: dim_y + double dim_y() const; + /// Access min/max parameters: dim_y + double dim_y(double default_value) const; + + /// Access parameters: z + double z() const; + /// Access parameters: z, if not present returns default + double z(double default_val) const; + /// Access parameters: Z + double Z() const; + /// Access parameters: Z + double Z(double default_val) const; + /// Access parameters: z0 + double z0() const; + /// Access parameters: z0 + double z0(double default_val) const; + /// Access parameters: z1 + double z1() const; + /// Access parameters: z1 + double z1(double default_val) const; + /// Access parameters: z2 + double z2() const; + /// Access parameters: z2 + double z2(double default_val) const; + /// Access parameters: dz + double dz() const; + /// Access parameters: dz, if not present returns default + double dz(double default_value) const; + /// Access min/max parameters: zmax + double zmin() const; + /// Access min/max parameters: zmax + double zmin(double default_value) const; + /// Access min/max parameters: zmax + double zmax() const; + /// Access min/max parameters: zmax + double zmax(double default_value) const; + /// Access attribute values: outer_z + double outer_z() const; + /// Access attribute values: inner_z + double inner_z() const; + /// Access attribute values: outer_stereo + double outer_stereo() const; + /// Access attribute values: inner_stereo + double inner_stereo() const; + /// Access min/max parameters: z_offset + double z_offset() const; + /// Access min/max parameters: z_offset + double z_offset(double default_value) const; + /// Access min/max parameters: dim_z + double dim_z() const; + /// Access min/max parameters: dim_z + double dim_z(double default_value) const; + + /// Access attribute values: length + double length() const; + /// Access attribute values: width + double width() const; + /// Access attribute values: height + double height() const; + /// Access attribute values: depth + double depth() const; + /// Access attribute values: thickness + double thickness() const; + + /// Access attribute values: z_length + double z_length() const; + /// Access attribute values: gap + double gap() const; + /// Access attribute values: r_size + double r_size() const; + /// Access attribute values: phi_size_max + double phi_size_max() const; + /// Access attribute values: reflect + bool reflect() const; + /// Access attribute values: reflect + bool reflect(bool default_value) const; + /// Access attribute values: crossing_angle + double crossing_angle() const; + /// Access attribute values: repeat + int repeat() const; + + /// Access attribute values: coefficient + double coefficient() const; + /// Access attribute values: coefficient + double coefficient(double default_value) const; + + /// Access attribute values: skew + double skew() const; + /// Access attribute values: skew + double skew(double default_value) const; + + /// Access attribute values: outgoing_r + double outgoing_r() const; + /// Access attribute values: incoming_r + double incoming_r() const; + /// Access attribute values: offset + double offset() const; + /// Access attribute values: offset + double offset(double default_value) const; + /// Access attribute values: number + int number() const; + + /// Access attribute values: nmodules + int nmodules() const; + /// Access attribute values: nModules + int nModules() const; + /// Access attribute values: RowID + int RowID() const; + /// Access attribute values: moduleHeight + double moduleHeight() const; + /// Access attribute values: moduleWidth + double moduleWidth() const; + /// Access attribute values: modulePitch + double modulePitch() const; + /// Access attribute values: modulePosX + double modulePosX() const; + /// Access attribute values: modulePosY + double modulePosY() const; + + /// Access attribute values: nPads + int nPads() const; + /// Access attribute values: rowPitch + double rowPitch() const; + /// Access attribute values: padPitch + double padPitch() const; + /// Access attribute values: rowHeight + double rowHeight() const; + /// Access attribute values: padType + std::string padType() const; + + /// Access attribute values: numsides + int numsides() const; + /// Access attribute values: nsides + int nsides() const; + /// Access attribute values: nsides_inner + int nsides_inner() const; + /// Access attribute values: nsides_outer + int nsides_outer() const; + + + /// Access attribute values: phi_tilt + double phi_tilt() const; + /// Access attribute values: nphi + int nphi() const; + /// Access attribute values: rc + double rc() const; + + /// Access attribute values: zstart + double zstart() const; + /// Access attribute values: nz + int nz() const; + /// Access attribute values: key + int key() const; + /// Access attribute values: key_min + int key_min() const; + /// Access attribute values: key_max + int key_max() const; + /// Access attribute values: key_val + int key_val() const; + /// Access attribute values: key_value + int key_value() const; + + /// Access attribute values: start + double start() const; + /// Access attribute values: start + double start(double default_value) const; + /// Access attribute values: end + double end() const; + /// Access attribute values: end + double end(double default_value) const; + /// Access attribute values: inner_field + double inner_field() const; + /// Access attribute values: outer_field + double outer_field() const; + + /// Access attribute values: visible + bool visible() const; + /// Access attribute values: show_daughters + bool show_daughters() const; + + /// Access min/max parameters: cut + double cut() const; + /// Access min/max parameters: cut + double cut(double default_value) const; + /// Access min/max parameters: threshold + double threshold() const; + /// Access min/max parameters: threshold + double threshold(double default_value) const; + /// Access min/max parameters: eunit + double eunit() const; + /// Access min/max parameters: eunit + double eunit(double default_value) const; + /// Access min/max parameters: lunit + double lunit() const; + /// Access min/max parameters: lunit + double lunit(double default_value) const; + + /// Access rotation constants: temperature + double temperature() const; + /// Access rotation constants: temperature + double temperature(double default_value) const; + /// Access rotation constants: pressure + double pressure() const; + /// Access rotation constants: pressure + double pressure(double default_value) const; + /// Access rotation constants: density + double density() const; + /// Access rotation constants: density + double density(double default_value) const; + + /// Access child element with tag "dimensions" as Dimension object + Dimension dimensions(bool throw_if_not_present = true) const; + /// Child access: position + Dimension position(bool throw_if_not_present = true) const; + /// Child access: rotation + Dimension rotation(bool throw_if_not_present = true) const; + /// Child access: trd + Dimension trd(bool throw_if_not_present = true) const; + /// Child access: tubs + Dimension tubs(bool throw_if_not_present = true) const; + /// Child access: staves + Dimension staves(bool throw_if_not_present = true) const; + /// Child access: beampipe + Dimension beampipe(bool throw_if_not_present = true) const; + + /// Access "name" attribute as STL string + std::string nameStr() const; + /// Access "ref" attribute as a string + std::string refStr() const; + /// Access "type" attribute as STL string + std::string typeStr() const; + /// Access "value" attribute as STL string + std::string valueStr() const; + /// Access "module" attribute as STL string + std::string moduleStr() const; + /// Access "readout" attribute as STL string + std::string readoutStr() const; + /// Access vis attribute as STL string. If not present empty return empty string + std::string visStr() const; + /// Access region attribute as STL string. If not present empty return empty string + std::string regionStr() const; + /// Access limits attribute as STL string. If not present empty return empty string + std::string limitsStr() const; +}; + +#endif /* DD4HEP_XML_DETAIL_DIMENSION_H */ diff --git a/DDCore/include/XML/detail/Dimension.imp b/DDCore/include/XML/detail/Dimension.imp new file mode 100644 index 000000000..9d7b7d705 --- /dev/null +++ b/DDCore/include/XML/detail/Dimension.imp @@ -0,0 +1,221 @@ +//========================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : M.Frank +// +//========================================================================== + +#include "XML/detail/Dimension.inl" + +XML_ATTR_ACCESSOR(int, id) +XML_ATTR_ACCESSOR_INT(id) +XML_ATTR_ACCESSOR(bool, combineHits) + +XML_ATTR_ACCESSOR_DOUBLE(x) +XML_ATTR_ACCESSOR_DOUBLE(X) +XML_ATTR_ACCESSOR_DOUBLE(dx) + +XML_ATTR_ACCESSOR_DOUBLE(x0) +XML_ATTR_ACCESSOR_DOUBLE(x1) +XML_ATTR_ACCESSOR_DOUBLE(x2) +XML_ATTR_ACCESSOR_DOUBLE(x3) +XML_ATTR_ACCESSOR_DOUBLE(x4) +XML_ATTR_ACCESSOR_DOUBLE(xmin) +XML_ATTR_ACCESSOR_DOUBLE(xmax) +XML_ATTR_ACCESSOR_DOUBLE(x_offset) +XML_ATTR_ACCESSOR_DOUBLE(dim_x) + +XML_ATTR_ACCESSOR_DOUBLE(y) +XML_ATTR_ACCESSOR_DOUBLE(Y) +XML_ATTR_ACCESSOR_DOUBLE(dy) +XML_ATTR_ACCESSOR_DOUBLE(y0) +XML_ATTR_ACCESSOR_DOUBLE(y1) +XML_ATTR_ACCESSOR_DOUBLE(y2) +XML_ATTR_ACCESSOR_DOUBLE(ymin) +XML_ATTR_ACCESSOR_DOUBLE(ymax) +XML_ATTR_ACCESSOR_DOUBLE(y_offset) +XML_ATTR_ACCESSOR_DOUBLE(dim_y) + +XML_ATTR_ACCESSOR_DOUBLE(z) +XML_ATTR_ACCESSOR_DOUBLE(Z) +XML_ATTR_ACCESSOR_DOUBLE(dz) +XML_ATTR_ACCESSOR_DOUBLE(z0) +XML_ATTR_ACCESSOR_DOUBLE(z1) +XML_ATTR_ACCESSOR_DOUBLE(z2) +XML_ATTR_ACCESSOR_DOUBLE(zmin) +XML_ATTR_ACCESSOR_DOUBLE(zmax) +XML_ATTR_ACCESSOR_DOUBLE(z_offset) +XML_ATTR_ACCESSOR_DOUBLE(dim_z) +XML_ATTR_ACCESSOR(double, outer_z) +XML_ATTR_ACCESSOR(double, inner_z) + +XML_ATTR_ACCESSOR_DOUBLE(a) +XML_ATTR_ACCESSOR_DOUBLE(b) +XML_ATTR_ACCESSOR_DOUBLE(c) +XML_ATTR_ACCESSOR_DOUBLE(distance) +XML_ATTR_ACCESSOR_DOUBLE(g) +XML_ATTR_ACCESSOR_DOUBLE(A) +XML_ATTR_ACCESSOR_DOUBLE(B) +XML_ATTR_ACCESSOR_DOUBLE(G) +XML_ATTR_ACCESSOR_DOUBLE(I) + +XML_ATTR_ACCESSOR_DOUBLE(r) +XML_ATTR_ACCESSOR_DOUBLE(R) +XML_ATTR_ACCESSOR_DOUBLE(dr) + +XML_ATTR_ACCESSOR_DOUBLE(rmin) +XML_ATTR_ACCESSOR_DOUBLE(rmax) +XML_ATTR_ACCESSOR_DOUBLE(rmin1) +XML_ATTR_ACCESSOR_DOUBLE(rmax1) +XML_ATTR_ACCESSOR_DOUBLE(rmin2) +XML_ATTR_ACCESSOR_DOUBLE(rmax2) +XML_ATTR_ACCESSOR_DOUBLE(radius) +XML_ATTR_ACCESSOR(double, outer_r) +XML_ATTR_ACCESSOR(double, outer_radius) +XML_ATTR_ACCESSOR(double, inner_r) +XML_ATTR_ACCESSOR(double, inner_radius) + +XML_ATTR_ACCESSOR(double, angle) +XML_ATTR_ACCESSOR_DOUBLE(alpha) +XML_ATTR_ACCESSOR_DOUBLE(alpha1) +XML_ATTR_ACCESSOR_DOUBLE(alpha2) +XML_ATTR_ACCESSOR_DOUBLE(beta) +XML_ATTR_ACCESSOR_DOUBLE(gamma) +XML_ATTR_ACCESSOR_DOUBLE(delta) +XML_ATTR_ACCESSOR_DOUBLE(epsilon) +XML_ATTR_ACCESSOR_DOUBLE(theta) +XML_ATTR_ACCESSOR_DOUBLE(deltatheta) +XML_ATTR_ACCESSOR(int, thetaBins) +XML_ATTR_ACCESSOR_DOUBLE(psi) +XML_ATTR_ACCESSOR_DOUBLE(phi) +XML_ATTR_ACCESSOR(int, phiBins) +XML_ATTR_ACCESSOR_DOUBLE(phi0) +XML_ATTR_ACCESSOR_DOUBLE(phi0_offset) +XML_ATTR_ACCESSOR_DOUBLE(phi1) +XML_ATTR_ACCESSOR_DOUBLE(deltaphi) +XML_ATTR_ACCESSOR_DOUBLE(startphi) + +XML_ATTR_ACCESSOR(double, length) +XML_ATTR_ACCESSOR(double, width) +XML_ATTR_ACCESSOR(double, height) +XML_ATTR_ACCESSOR(double, depth) +XML_ATTR_ACCESSOR_DOUBLE(offset) +XML_ATTR_ACCESSOR(double, crossing_angle) +XML_ATTR_ACCESSOR(double, incoming_r) +XML_ATTR_ACCESSOR(double, outgoing_r) +XML_ATTR_ACCESSOR(double, phi_size_max) +XML_ATTR_ACCESSOR(double, r_size) + +XML_ATTR_ACCESSOR_DOUBLE(skew) +XML_ATTR_ACCESSOR_DOUBLE(coefficient) + +XML_ATTR_ACCESSOR(double, gap) +XML_ATTR_ACCESSOR(double, z_length) +XML_ATTR_ACCESSOR(double, zhalf) +XML_ATTR_ACCESSOR(double, phi_tilt) +XML_ATTR_ACCESSOR(int, nphi) +XML_ATTR_ACCESSOR(double, rc) +XML_ATTR_ACCESSOR(int, nz) +XML_ATTR_ACCESSOR(int, key) +XML_ATTR_ACCESSOR(int, key_min) +XML_ATTR_ACCESSOR(int, key_max) +XML_ATTR_ACCESSOR(int, key_val) +XML_ATTR_ACCESSOR(int, key_value) +XML_ATTR_ACCESSOR(double, zstart) +XML_ATTR_ACCESSOR_DOUBLE(start) +XML_ATTR_ACCESSOR_DOUBLE(end) +XML_ATTR_ACCESSOR(double, thickness) +XML_ATTR_ACCESSOR(double, inner_stereo) +XML_ATTR_ACCESSOR(double, outer_stereo) +XML_ATTR_ACCESSOR(int, numsides) +XML_ATTR_ACCESSOR(int, nsides) +XML_ATTR_ACCESSOR(int, nsides_inner) +XML_ATTR_ACCESSOR(int, nsides_outer) +XML_ATTR_ACCESSOR(int, number) +XML_ATTR_ACCESSOR(int, repeat) +XML_ATTR_ACCESSOR(bool, reflect) +XML_ATTR_ACCESSOR_BOOL(reflect) + +XML_ATTR_ACCESSOR(int, nmodules) +XML_ATTR_ACCESSOR(int, nModules) +XML_ATTR_ACCESSOR(int, RowID) +XML_ATTR_ACCESSOR(int, nPads) +XML_ATTR_ACCESSOR(double, moduleHeight) +XML_ATTR_ACCESSOR(double, moduleWidth) +XML_ATTR_ACCESSOR(double, modulePosX) +XML_ATTR_ACCESSOR(double, modulePosY) +XML_ATTR_ACCESSOR(double, modulePitch) +XML_ATTR_ACCESSOR(double, rowPitch) +XML_ATTR_ACCESSOR(double, padPitch) +XML_ATTR_ACCESSOR(double, rowHeight) +XML_ATTR_ACCESSOR(double, inner_field) +XML_ATTR_ACCESSOR(double, outer_field) +XML_ATTR_ACCESSOR(int, type) + +XML_ATTR_ACCESSOR(bool, visible) +XML_ATTR_ACCESSOR(bool, show_daughters) + +XML_ATTR_ACCESSOR_DOUBLE(cut) +XML_ATTR_ACCESSOR_DOUBLE(threshold) +XML_ATTR_ACCESSOR_DOUBLE(lunit) +XML_ATTR_ACCESSOR_DOUBLE(eunit) + +XML_ATTR_ACCESSOR_DOUBLE(density) +XML_ATTR_ACCESSOR_DOUBLE(pressure) +XML_ATTR_ACCESSOR_DOUBLE(temperature) + + +XML_CHILD_ACCESSOR_XML_DIM(dimensions) +XML_CHILD_ACCESSOR_XML_DIM(position) +XML_CHILD_ACCESSOR_XML_DIM(rotation) +XML_CHILD_ACCESSOR_XML_DIM(trd) +XML_CHILD_ACCESSOR_XML_DIM(tubs) +XML_CHILD_ACCESSOR_XML_DIM(staves) +XML_CHILD_ACCESSOR_XML_DIM(beampipe) + +std::string DD4hep::DIMENSION_NS::Dimension::padType() const { + return m_element.attr < std::string > (_U(pads)); +} + +std::string DD4hep::DIMENSION_NS::Dimension::nameStr() const { + return m_element.attr < std::string > (_U(name)); +} + +std::string DD4hep::DIMENSION_NS::Dimension::refStr() const { + return m_element.attr < std::string > (_U(ref)); +} + +std::string DD4hep::DIMENSION_NS::Dimension::typeStr() const { + return m_element.attr < std::string > (_U(type)); +} + +/// Access "value" attribute as STL std::string +std::string DD4hep::DIMENSION_NS::Dimension::valueStr() const { + return m_element.attr < std::string > (_U(value)); +} + +std::string DD4hep::DIMENSION_NS::Dimension::regionStr() const { + return m_element.hasAttr(_U(region)) ? m_element.attr < std::string > (_U(region)) : std::string(); +} + +std::string DD4hep::DIMENSION_NS::Dimension::limitsStr() const { + return m_element.hasAttr(_U(limits)) ? m_element.attr < std::string > (_U(limits)) : std::string(); +} + +std::string DD4hep::DIMENSION_NS::Dimension::visStr() const { + return m_element.hasAttr(_U(vis)) ? m_element.attr < std::string > (_U(vis)) : std::string(); +} + +std::string DD4hep::DIMENSION_NS::Dimension::readoutStr() const { + return m_element.hasAttr(_U(readout)) ? m_element.attr < std::string > (_U(readout)) : std::string(); +} + +std::string DD4hep::DIMENSION_NS::Dimension::moduleStr() const { + return m_element.hasAttr(_U(module)) ? m_element.attr < std::string > (_U(module)) : std::string(); +} diff --git a/DDCore/include/XML/detail/Dimension.inl b/DDCore/include/XML/detail/Dimension.inl new file mode 100644 index 000000000..aeb2fc662 --- /dev/null +++ b/DDCore/include/XML/detail/Dimension.inl @@ -0,0 +1,55 @@ +//========================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : M.Frank +// +//========================================================================== + +#ifndef DD4HEP_XML_DETAIL_DIMENSION_INL +#define DD4HEP_XML_DETAIL_DIMENSION_INL + +/** + * Note: Do NEVER include this file directly! + * + * Include XML/XMLDimension.h or JSON/Dimension.h ! + */ + + +#define XML_ATTR_NS_ACCESSOR(type,ns,name) type ns::name() const { return m_element.attr<type>(_DD4hep_Unicode_Item(name)); } + +#define XML_ATTR_NS_ACCESSOR_DEFAULT(type,ns,name,dressing) \ + type ns::name(type default_val) const { \ + const XmlChar* val = m_element.attr_value_nothrow(_DD4hep_Unicode_Item(name)); \ + return val ? dressing(val) : default_val; } + +#define XML_ATTR_NS_ACCESSOR_DOUBLE(ns,name) \ + XML_ATTR_NS_ACCESSOR(double,ns,name) \ + XML_ATTR_NS_ACCESSOR_DEFAULT(double,ns,name,DD4hep::DIMENSION_NS::_toDouble) + +#define XML_ATTR_NS_ACCESSOR_INT(ns,name) \ + XML_ATTR_NS_ACCESSOR(int,ns,name) \ + XML_ATTR_NS_ACCESSOR_DEFAULT(int,ns,name,DD4hep::DIMENSION_NS::_toInt) + +#define XML_ATTR_NS_ACCESSOR_STRING(ns,name) \ + XML_ATTR_NS_ACCESSOR(std::string,ns,name) \ + XML_ATTR_NS_ACCESSOR_DEFAULT(std::string,ns,name,DD4hep::DIMENSION_NS::_toString) + + +#define XML_ATTR_ACCESSOR(type,name) XML_ATTR_NS_ACCESSOR(type,DD4hep::DIMENSION_NS::Dimension,name) +#define XML_ATTR_ACCESSOR_DEFAULT(name,type,dressing) XML_ATTR_NS_ACCESSOR_DEFAULT(type,DD4hep::DIMENSION_NS::Dimension,name,dressing) +#define XML_ATTR_ACCESSOR_DOUBLE(name) XML_ATTR_NS_ACCESSOR_DOUBLE(DD4hep::DIMENSION_NS::Dimension,name) + +#define XML_ATTR_ACCESSOR_INT(name) XML_ATTR_NS_ACCESSOR_DEFAULT(int,DD4hep::DIMENSION_NS::Dimension,name,_toInt) +#define XML_ATTR_ACCESSOR_BOOL(name) XML_ATTR_NS_ACCESSOR_DEFAULT(bool,DD4hep::DIMENSION_NS::Dimension,name,_toBool) + +#define XML_CHILD_ACCESSOR_XML_DIM(name) \ + DD4hep::DIMENSION_NS::Dimension DD4hep::DIMENSION_NS::Dimension::name(bool throw_if_not_present) const { \ + return m_element.child(_DD4hep_Unicode_Item(name),throw_if_not_present); } + +#endif /* DD4HEP_XML_DETAIL_DIMENSION_INL */ diff --git a/DDCore/src/JSON/Detector.cpp b/DDCore/src/JSON/Detector.cpp new file mode 100644 index 000000000..8216e7b7e --- /dev/null +++ b/DDCore/src/JSON/Detector.cpp @@ -0,0 +1,19 @@ +//========================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : M.Frank +// +//========================================================================== + +// Framework include files +#include "JSON/Detector.h" + +using namespace DD4hep::JSON; +#include "XML/detail/Detector.imp" + diff --git a/DDCore/src/JSON/Dimension.cpp b/DDCore/src/JSON/Dimension.cpp new file mode 100644 index 000000000..356f1277c --- /dev/null +++ b/DDCore/src/JSON/Dimension.cpp @@ -0,0 +1,17 @@ +//========================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : M.Frank +// +//========================================================================== + +// Framework include files +#include "JSON/Dimension.inl" +// Instantiate here the concrete implementations +#include "XML/detail/Dimension.imp" diff --git a/DDCore/src/XML/XMLDetector.cpp b/DDCore/src/XML/XMLDetector.cpp index 29b928486..339b624ae 100644 --- a/DDCore/src/XML/XMLDetector.cpp +++ b/DDCore/src/XML/XMLDetector.cpp @@ -13,94 +13,6 @@ // Framework include files #include "XML/XMLDetector.h" -#include "DD4hep/Plugins.h" -#include "DD4hep/LCDD.h" -using namespace std; using namespace DD4hep::XML; - -namespace Geometry { class LCDD; } - -string Component::materialStr() const { - return m_element.attr < string > (_U(material)); -} - -bool Component::isSensitive() const { - char val = m_element.hasAttr(_U(sensitive)) ? m_element.attr < string > (_U(sensitive))[0] : 'f'; - val = ::toupper(val); - return val == 'T' || val == 'Y'; -} - -bool Component::isRadiator() const { - char val = m_element.hasAttr(_U(radiator)) ? m_element.attr < string > (_U(radiator))[0] : 'f'; - val = ::toupper(val); - return val == 'T' || val == 'Y'; -} - -DD4hep::NamedObject* Component::createShape() const { - using namespace DD4hep::Geometry; - Dimension child_dim(m_element); - string typ = child_dim.typeStr(); - string fac = typ + "__shape_constructor"; - Handle_t solid_elt = m_element; - LCDD* lcdd = 0; - NamedObject* solid = PluginService::Create<NamedObject*>(fac, lcdd, &solid_elt); - if ( !solid ) { - PluginDebug dbg; - PluginService::Create<NamedObject*>(typ, lcdd, &solid_elt); - throw runtime_error("Failed to create solid of type " + typ + ". " + dbg.missingFactory(typ)); - } - return solid; -} - -int DetElement::id() const { - return m_element.hasAttr(_U(id)) ? m_element.attr<int>(_U(id)) : -1; -} - -bool DetElement::isSensitive() const { - char val = m_element.hasAttr(_U(sensitive)) ? m_element.attr < string > (_U(sensitive))[0] : 'f'; - val = ::toupper(val); - return val == 'T' || val == 'Y'; -} - -string DetElement::materialStr() const { - Handle_t h = m_element.child(_U(material)); - if (h && h.hasAttr(_U(name))) { - return h.attr < string > (_U(name)); - } - return ""; -} - -void DetElement::check(bool condition, const string& msg) const { - if (condition) { - throw runtime_error(msg); - } -} - -bool DetElement::isTracker() const { - if (m_element) { - string typ = attr < string > (_U(type)); - if (typ.find("Tracker") != string::npos && hasAttr(_U(readout))) { - return true; - } - } - return false; -} - -bool DetElement::isCalorimeter() const { - if (m_element) { - string typ = attr < string > (_U(type)); - if (typ.find("Calorimeter") != string::npos && hasAttr(_U(readout))) { - return true; - } - } - return false; -} - -bool DetElement::isInsideTrackingVolume() const { - if (m_element && hasAttr(_U(insideTrackingVolume)) ) - return attr<bool>(_U(insideTrackingVolume)); - else if ( isTracker() ) - return true; - return false; -} +#include "XML/detail/Detector.imp" diff --git a/DDCore/src/XML/XMLDimension.cpp b/DDCore/src/XML/XMLDimension.cpp index a38b340b6..c02dfd9f8 100644 --- a/DDCore/src/XML/XMLDimension.cpp +++ b/DDCore/src/XML/XMLDimension.cpp @@ -14,209 +14,5 @@ // Framework include files #include "XML/XMLDimension.inl" -XML_ATTR_ACCESSOR(int, id) -XML_ATTR_ACCESSOR_INT(id) -XML_ATTR_ACCESSOR(bool, combineHits) - -XML_ATTR_ACCESSOR_DOUBLE(x) -XML_ATTR_ACCESSOR_DOUBLE(X) -XML_ATTR_ACCESSOR_DOUBLE(dx) - -XML_ATTR_ACCESSOR_DOUBLE(x0) -XML_ATTR_ACCESSOR_DOUBLE(x1) -XML_ATTR_ACCESSOR_DOUBLE(x2) -XML_ATTR_ACCESSOR_DOUBLE(x3) -XML_ATTR_ACCESSOR_DOUBLE(x4) -XML_ATTR_ACCESSOR_DOUBLE(xmin) -XML_ATTR_ACCESSOR_DOUBLE(xmax) -XML_ATTR_ACCESSOR_DOUBLE(x_offset) -XML_ATTR_ACCESSOR_DOUBLE(dim_x) - -XML_ATTR_ACCESSOR_DOUBLE(y) -XML_ATTR_ACCESSOR_DOUBLE(Y) -XML_ATTR_ACCESSOR_DOUBLE(dy) -XML_ATTR_ACCESSOR_DOUBLE(y0) -XML_ATTR_ACCESSOR_DOUBLE(y1) -XML_ATTR_ACCESSOR_DOUBLE(y2) -XML_ATTR_ACCESSOR_DOUBLE(ymin) -XML_ATTR_ACCESSOR_DOUBLE(ymax) -XML_ATTR_ACCESSOR_DOUBLE(y_offset) -XML_ATTR_ACCESSOR_DOUBLE(dim_y) - -XML_ATTR_ACCESSOR_DOUBLE(z) -XML_ATTR_ACCESSOR_DOUBLE(Z) -XML_ATTR_ACCESSOR_DOUBLE(dz) -XML_ATTR_ACCESSOR_DOUBLE(z0) -XML_ATTR_ACCESSOR_DOUBLE(z1) -XML_ATTR_ACCESSOR_DOUBLE(z2) -XML_ATTR_ACCESSOR_DOUBLE(zmin) -XML_ATTR_ACCESSOR_DOUBLE(zmax) -XML_ATTR_ACCESSOR_DOUBLE(z_offset) -XML_ATTR_ACCESSOR_DOUBLE(dim_z) -XML_ATTR_ACCESSOR(double, outer_z) -XML_ATTR_ACCESSOR(double, inner_z) - -XML_ATTR_ACCESSOR_DOUBLE(a) -XML_ATTR_ACCESSOR_DOUBLE(b) -XML_ATTR_ACCESSOR_DOUBLE(c) -XML_ATTR_ACCESSOR_DOUBLE(distance) -XML_ATTR_ACCESSOR_DOUBLE(g) -XML_ATTR_ACCESSOR_DOUBLE(A) -XML_ATTR_ACCESSOR_DOUBLE(B) -XML_ATTR_ACCESSOR_DOUBLE(G) -XML_ATTR_ACCESSOR_DOUBLE(I) - -XML_ATTR_ACCESSOR_DOUBLE(r) -XML_ATTR_ACCESSOR_DOUBLE(R) -XML_ATTR_ACCESSOR_DOUBLE(dr) - -XML_ATTR_ACCESSOR_DOUBLE(rmin) -XML_ATTR_ACCESSOR_DOUBLE(rmax) -XML_ATTR_ACCESSOR_DOUBLE(rmin1) -XML_ATTR_ACCESSOR_DOUBLE(rmax1) -XML_ATTR_ACCESSOR_DOUBLE(rmin2) -XML_ATTR_ACCESSOR_DOUBLE(rmax2) -XML_ATTR_ACCESSOR_DOUBLE(radius) -XML_ATTR_ACCESSOR(double, outer_r) -XML_ATTR_ACCESSOR(double, outer_radius) -XML_ATTR_ACCESSOR(double, inner_r) -XML_ATTR_ACCESSOR(double, inner_radius) - -XML_ATTR_ACCESSOR(double, angle) -XML_ATTR_ACCESSOR_DOUBLE(alpha) -XML_ATTR_ACCESSOR_DOUBLE(alpha1) -XML_ATTR_ACCESSOR_DOUBLE(alpha2) -XML_ATTR_ACCESSOR_DOUBLE(beta) -XML_ATTR_ACCESSOR_DOUBLE(gamma) -XML_ATTR_ACCESSOR_DOUBLE(delta) -XML_ATTR_ACCESSOR_DOUBLE(epsilon) -XML_ATTR_ACCESSOR_DOUBLE(theta) -XML_ATTR_ACCESSOR_DOUBLE(deltatheta) -XML_ATTR_ACCESSOR(int, thetaBins) -XML_ATTR_ACCESSOR_DOUBLE(psi) -XML_ATTR_ACCESSOR_DOUBLE(phi) -XML_ATTR_ACCESSOR(int, phiBins) -XML_ATTR_ACCESSOR_DOUBLE(phi0) -XML_ATTR_ACCESSOR_DOUBLE(phi0_offset) -XML_ATTR_ACCESSOR_DOUBLE(phi1) -XML_ATTR_ACCESSOR_DOUBLE(deltaphi) -XML_ATTR_ACCESSOR_DOUBLE(startphi) - -XML_ATTR_ACCESSOR(double, length) -XML_ATTR_ACCESSOR(double, width) -XML_ATTR_ACCESSOR(double, height) -XML_ATTR_ACCESSOR(double, depth) -XML_ATTR_ACCESSOR_DOUBLE(offset) -XML_ATTR_ACCESSOR(double, crossing_angle) -XML_ATTR_ACCESSOR(double, incoming_r) -XML_ATTR_ACCESSOR(double, outgoing_r) -XML_ATTR_ACCESSOR(double, phi_size_max) -XML_ATTR_ACCESSOR(double, r_size) - -XML_ATTR_ACCESSOR_DOUBLE(skew) -XML_ATTR_ACCESSOR_DOUBLE(coefficient) - -XML_ATTR_ACCESSOR(double, gap) -XML_ATTR_ACCESSOR(double, z_length) -XML_ATTR_ACCESSOR(double, zhalf) -XML_ATTR_ACCESSOR(double, phi_tilt) -XML_ATTR_ACCESSOR(int, nphi) -XML_ATTR_ACCESSOR(double, rc) -XML_ATTR_ACCESSOR(int, nz) -XML_ATTR_ACCESSOR(int, key) -XML_ATTR_ACCESSOR(int, key_min) -XML_ATTR_ACCESSOR(int, key_max) -XML_ATTR_ACCESSOR(int, key_val) -XML_ATTR_ACCESSOR(int, key_value) -XML_ATTR_ACCESSOR(double, zstart) -XML_ATTR_ACCESSOR_DOUBLE(start) -XML_ATTR_ACCESSOR_DOUBLE(end) -XML_ATTR_ACCESSOR(double, thickness) -XML_ATTR_ACCESSOR(double, inner_stereo) -XML_ATTR_ACCESSOR(double, outer_stereo) -XML_ATTR_ACCESSOR(int, numsides) -XML_ATTR_ACCESSOR(int, nsides) -XML_ATTR_ACCESSOR(int, nsides_inner) -XML_ATTR_ACCESSOR(int, nsides_outer) -XML_ATTR_ACCESSOR(int, number) -XML_ATTR_ACCESSOR(int, repeat) -XML_ATTR_ACCESSOR(bool, reflect) -XML_ATTR_ACCESSOR_BOOL(reflect) - -XML_ATTR_ACCESSOR(int, nmodules) -XML_ATTR_ACCESSOR(int, nModules) -XML_ATTR_ACCESSOR(int, RowID) -XML_ATTR_ACCESSOR(int, nPads) -XML_ATTR_ACCESSOR(double, moduleHeight) -XML_ATTR_ACCESSOR(double, moduleWidth) -XML_ATTR_ACCESSOR(double, modulePosX) -XML_ATTR_ACCESSOR(double, modulePosY) -XML_ATTR_ACCESSOR(double, modulePitch) -XML_ATTR_ACCESSOR(double, rowPitch) -XML_ATTR_ACCESSOR(double, padPitch) -XML_ATTR_ACCESSOR(double, rowHeight) -XML_ATTR_ACCESSOR(double, inner_field) -XML_ATTR_ACCESSOR(double, outer_field) -XML_ATTR_ACCESSOR(int, type) - -XML_ATTR_ACCESSOR(bool, visible) -XML_ATTR_ACCESSOR(bool, show_daughters) - -XML_ATTR_ACCESSOR_DOUBLE(cut) -XML_ATTR_ACCESSOR_DOUBLE(threshold) -XML_ATTR_ACCESSOR_DOUBLE(lunit) -XML_ATTR_ACCESSOR_DOUBLE(eunit) - -XML_ATTR_ACCESSOR_DOUBLE(density) -XML_ATTR_ACCESSOR_DOUBLE(pressure) -XML_ATTR_ACCESSOR_DOUBLE(temperature) - - -XML_CHILD_ACCESSOR_XML_DIM(dimensions) -XML_CHILD_ACCESSOR_XML_DIM(position) -XML_CHILD_ACCESSOR_XML_DIM(rotation) -XML_CHILD_ACCESSOR_XML_DIM(trd) -XML_CHILD_ACCESSOR_XML_DIM(tubs) -XML_CHILD_ACCESSOR_XML_DIM(staves) -XML_CHILD_ACCESSOR_XML_DIM(beampipe) - -std::string DD4hep::XML::Dimension::padType() const { - return m_element.attr < std::string > (_U(pads)); -} - -std::string DD4hep::XML::Dimension::nameStr() const { - return m_element.attr < std::string > (_U(name)); -} - -std::string DD4hep::XML::Dimension::refStr() const { - return m_element.attr < std::string > (_U(ref)); -} - -std::string DD4hep::XML::Dimension::typeStr() const { - return m_element.attr < std::string > (_U(type)); -} - -/// Access "value" attribute as STL std::string -std::string DD4hep::XML::Dimension::valueStr() const { - return m_element.attr < std::string > (_U(value)); -} - -std::string DD4hep::XML::Dimension::regionStr() const { - return m_element.hasAttr(_U(region)) ? m_element.attr < std::string > (_U(region)) : std::string(); -} - -std::string DD4hep::XML::Dimension::limitsStr() const { - return m_element.hasAttr(_U(limits)) ? m_element.attr < std::string > (_U(limits)) : std::string(); -} - -std::string DD4hep::XML::Dimension::visStr() const { - return m_element.hasAttr(_U(vis)) ? m_element.attr < std::string > (_U(vis)) : std::string(); -} - -std::string DD4hep::XML::Dimension::readoutStr() const { - return m_element.hasAttr(_U(readout)) ? m_element.attr < std::string > (_U(readout)) : std::string(); -} - -std::string DD4hep::XML::Dimension::moduleStr() const { - return m_element.hasAttr(_U(module)) ? m_element.attr < std::string > (_U(module)) : std::string(); -} +// Instantiate here the concrete implementations +#include "XML/detail/Dimension.imp" diff --git a/DDCore/src/XML/XMLTags.cpp b/DDCore/src/XML/XMLTags.cpp index a1378c34c..ea04bb4f8 100644 --- a/DDCore/src/XML/XMLTags.cpp +++ b/DDCore/src/XML/XMLTags.cpp @@ -61,7 +61,14 @@ namespace { } #define UNICODE(x) extern const Tag_t Unicode_##x (#x, #x, __Init::register_tag) +/// Namespace for the AIDA detector description toolkit +namespace DD4hep { + + /// Namespace for the AIDA detector description toolkit supporting XML utilities + namespace XML { #include "XML/UnicodeValues.h" + } +} namespace DD4hep { namespace XML { diff --git a/examples/ClientTests/compact/MiniTel.json b/examples/ClientTests/compact/MiniTel.json new file mode 100644 index 000000000..e2d474c6e --- /dev/null +++ b/examples/ClientTests/compact/MiniTel.json @@ -0,0 +1,36 @@ +//========================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : M.Frank +// +//========================================================================== +{ + "detectors": { + "detector1": { + "id": 1, + "type": "MiniTelPixel", + "material": "Silicon", + "vis": "DetVis", + "readout": "MyLHCBdetector1Hits", + "dimensions": { "z": "1*mm", "y": "10*cm", "x": "10*cm" }, + "module": { + "name": "pixel", + "type:": "MiniTelPixel", + "material": "Silicon", + "x": "6*mm", + "y": "6*mm", + "z": "1*mm", + "vis": "ModVis", + "alpha": "-2.*radian", + "beta": "-2.*radian", + "gamma": "-0.*radian" + } + } + } +} diff --git a/examples/ClientTests/src/JsonTest.cpp b/examples/ClientTests/src/JsonTest.cpp new file mode 100644 index 000000000..880570f2b --- /dev/null +++ b/examples/ClientTests/src/JsonTest.cpp @@ -0,0 +1,58 @@ +//========================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : M.Frank +// +//========================================================================== +#ifdef DD4HEP_USE_BOOST + +// Framework include files +#include "JSON/Elements.h" +#include "DD4hep/Factories.h" + + +using namespace std; +using namespace DD4hep; +using namespace DD4hep::JSON; +using namespace DD4hep::Geometry; + +static long json_dump(LCDD& lcdd, int argc, char** argv) { + if ( argc < 1 ) { + return 0; + } + boost::property_tree::ptree pt; + boost::property_tree::read_json(argv[0], pt); + + for( boost::property_tree::ptree::value_type const& rowPair : pt.get_child( "" ) ) + { + cout << "1--" << rowPair.first << ": " << endl; + cout << rowPair.second.get_value<string>() << " " << endl; + + for( boost::property_tree::ptree::value_type const& itemPair : rowPair.second ) + { + cout << "\t2--" << itemPair.first << " " << endl; + + for( boost::property_tree::ptree::value_type const& node : itemPair.second ) + { + cout << "\t\t3--" << node.first << "=" << node.second.get_value<string>() << endl; + } + + cout << endl; + + } + + cout << endl; + } + + return 1; +} + +DECLARE_APPLY(DD4hep_JsonDumper,json_dump) + +#endif -- GitLab