DD4hep  1.28.0
Detector Description Toolkit for High Energy Physics
Factories.h
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 #ifndef DD4HEP_FACTORIES_H
14 #define DD4HEP_FACTORIES_H
15 
16 // Framework include files
17 #include <DD4hep/Plugins.h>
18 #include <DD4hep/DetElement.h>
19 #include <DD4hep/NamedObject.h>
20 
21 // C/C++ include files
22 #include <cstdarg>
23 
25 namespace dd4hep {
26 
27  // Forward declarations
28  class Detector;
29  class NamedObject;
30  class SensitiveDetector;
31  class SegmentationObject;
32  class DetElement;
33 
35  namespace json {
36  class Handle_t;
37  }
39  namespace xml {
40  class Handle_t;
41  class RefElement;
42  }
43 
45  namespace DDSegmentation {
46  class BitFieldCoder;
47  }
48 
49 
51 
57  template <typename T> class SimpleConstructionFactory {
58  public:
59  static void* create();
60  };
61  template <typename T> class ConstructionFactory {
62  public:
63  static void* create(const char* arg);
64  };
65 
67 
73  template <typename T> class DetectorConstructionFactory : public PluginFactoryBase {
74  public:
75  static void* create(Detector& description, int argc, char** argv);
76  };
77 
79 
85  template <typename T> class SegmentationFactory : public PluginFactoryBase {
86  public:
88  };
89 
91 
100  template <typename T> class ApplyFactory : public PluginFactoryBase {
101  public:
102  static long create(Detector& description, int argc, char** argv);
103  };
104 
106 
114  template <typename T> class TranslationFactory : public PluginFactoryBase {
115  public:
116  static Handle<NamedObject> create(Detector& description);
117  };
118 
120 
127  template <typename T> class XMLElementFactory : public PluginFactoryBase {
128  public:
130  };
131 
133 
140  template <typename T> class XMLObjectFactory : public PluginFactoryBase {
141  public:
142  static Handle<TObject> create(Detector& description, xml::Handle_t e);
143  };
144 
146 
153  template <typename T> class XMLDocumentReaderFactory : public PluginFactoryBase {
154  public:
155  static long create(Detector& description, xml::Handle_t e);
156  };
157 
159 
166  template <typename T> class XMLConversionFactory : public PluginFactoryBase {
167  public:
168  static long create(Detector& description, xml::RefElement& handle, xml::Handle_t element);
169  };
170 
172 
179  template <typename T> class XmlDetElementFactory : public PluginFactoryBase {
180  public:
182  };
183 
185 
192  template <typename T> class JsonDetElementFactory : public PluginFactoryBase {
193  public:
195  };
196 }
197 
198 namespace {
199 
201  template <typename P, typename S> class Factory;
202 
204  namespace ns {
205  typedef dd4hep::NamedObject Named;
208  typedef dd4hep::Handle<Named> ref_t;
209  typedef dd4hep::SegmentationObject SegmentationObject;
210  typedef dd4hep::DDSegmentation::BitFieldCoder BitFieldCoder;
211  }
212 
215 
216  DD4HEP_PLUGIN_FACTORY_ARGS_1(void*,const char*)
218 
220  { return dd4hep::TranslationFactory<P>::create(*a0).ptr(); }
221 
222  DD4HEP_PLUGIN_FACTORY_ARGS_1(ns::SegmentationObject*,const ns::BitFieldCoder*)
224 
227 
229  static long ret;
230  long result = dd4hep::ApplyFactory<P>::create(*a0,a1,a2);
231  ret = result;
232  return long(&ret);
233  }
234 
236  { return dd4hep::XMLElementFactory<P>::create(*a0,*a1).ptr(); }
237 
239  { return dd4hep::XMLObjectFactory<P>::create(*a0,*a1).ptr(); }
240 
242  static long ret;
243  long result = dd4hep::XMLDocumentReaderFactory<P>::create(*a0,*a1);
244  ret = result;
245  return long(&ret);
246  }
247 
249  { return dd4hep::XmlDetElementFactory<P>::create(*a0,*a1,*a2).ptr(); }
250 
252  { return dd4hep::JsonDetElementFactory<P>::create(*a0,*a1,*a2).ptr(); }
253 }
254 
255 #define DECLARE_DETELEMENT_FACTORY(x) namespace dd4hep \
256  { DD4HEP_PLUGINSVC_FACTORY(x,x,dd4hep::NamedObject*(dd4hep::Detector*,xml::Handle_t*,Ref_t*),__LINE__) }
257 #define DECLARE_NAMESPACE_DETELEMENT_FACTORY(n,x) namespace dd4hep \
258  { DD4HEP_PLUGINSVC_FACTORY(n::x,x,NamedObject*(dd4hep::Detector*,xml::Handle_t*,Ref_t*),__LINE__) }
259 #define DECLARE_NAMED_APPLY_FACTORY(n,x) namespace dd4hep \
260  { DD4HEP_PLUGINSVC_FACTORY(n::x,x,long(dd4hep::Detector*,int, char**),__LINE__) }
261 #define DECLARE_NAMED_TRANSLATION_FACTORY(n,x) namespace dd4hep \
262  { DD4HEP_PLUGINSVC_FACTORY(n::x,x,dd4hep::NamedObject*(dd4hep::Detector*),__LINE__) }
263 #define DECLARE_NAMED_XMLELEMENT_FACTORY(n,x) namespace dd4hep \
264  { DD4HEP_PLUGINSVC_FACTORY(n::x,x,dd4hep::NamedObject*(dd4hep::Detector*,xml::Handle_t*),__LINE__) }
265 #define DECLARE_NAMED_DETELEMENT_FACTORY(n,x) namespace dd4hep \
266  { DD4HEP_PLUGINSVC_FACTORY(n::x,x,dd4hep::*(),__LINE__) }
267 
268 // Call function of the type [SegmentationObject (*func)(dd4hep::Detector*,DDSegmentation::BitFieldCoder*)]
269 #define DECLARE_SEGMENTATION(name,func) DD4HEP_OPEN_PLUGIN(dd4hep,name) { \
270  template <> SegmentationObject* \
271  SegmentationFactory<name>::create(const DDSegmentation::BitFieldCoder* d) { return func(d); } \
272  DD4HEP_PLUGINSVC_FACTORY(name,segmentation_constructor__##name, \
273  SegmentationObject*(const DDSegmentation::BitFieldCoder*),__LINE__)}
274 
275 // Call function of the type [void* (*func)()]
276 #define DECLARE_CREATE(name,func) DD4HEP_OPEN_PLUGIN(dd4hep,name) { \
277  template <> void* SimpleConstructionFactory<name>::create() { return func(); } \
278  DD4HEP_PLUGINSVC_FACTORY(name,name,void*(),__LINE__)}
279 
280 // Call function of the type [long (*func)(const char* arg)]
281 #define DECLARE_APPLY(name,func) DD4HEP_OPEN_PLUGIN(dd4hep,name) { \
282  template <> long ApplyFactory<name>::create(dd4hep::Detector& l,int n,char** a) {return func(l,n,a);} \
283  DD4HEP_PLUGINSVC_FACTORY(name,name,long(dd4hep::Detector*,int,char**),__LINE__)}
284 
285 // Call function of the type [void* (*func)(const char* arg)]
286 #define DECLARE_CONSTRUCTOR(name,func) DD4HEP_OPEN_PLUGIN(dd4hep,name) { \
287  template <> void* ConstructionFactory<name>::create(const char* n) { return func(n);} \
288  DD4HEP_PLUGINSVC_FACTORY(name,name,void*(const char*),__LINE__) }
289 
290 // Call function of the type [void* (*func)(dd4hep::Detector& description, int argc,char** argv)]
291 #define DECLARE_DD4HEP_CONSTRUCTOR(name,func) DD4HEP_OPEN_PLUGIN(dd4hep,name) { \
292  template <> void* DetectorConstructionFactory<name>::create(dd4hep::Detector& l, int n,char** a) { return func(l,n,a);} \
293  DD4HEP_PLUGINSVC_FACTORY(name,name,void*(dd4hep::Detector*,int,char**),__LINE__) }
294 
295 // Call function of the type [void* (*func)(dd4hep::Detector& description)]
296 #define DECLARE_TRANSLATION(name,func) DD4HEP_OPEN_PLUGIN(dd4hep,name) { \
297  template <> Ref_t TranslationFactory<name>::create(dd4hep::Detector& l) {return func(l);} \
298  DECLARE_NAMED_TRANSLATION_FACTORY(Geometry,name) }
299 
300 // Call function of the type [void* (*func)(dd4hep::Detector& description, xml_h handle)]
301 #define DECLARE_XMLELEMENT(name,func) DD4HEP_OPEN_PLUGIN(dd4hep,xml_element_##name) {\
302  template <> Ref_t XMLElementFactory<xml_element_##name>::create(dd4hep::Detector& l,ns::xml_h e) {return func(l,e);} \
303  DD4HEP_PLUGINSVC_FACTORY(xml_element_##name,name,NamedObject*(dd4hep::Detector*,ns::xml_h*),__LINE__) }
304 
305 // Call function of the type [void* (*func)(dd4hep::Detector& description, xml_h handle)]
306 #define DECLARE_XML_SHAPE(name,func) DD4HEP_OPEN_PLUGIN(dd4hep,xml_element_##name) {\
307  template <> Handle<TObject> XMLObjectFactory<xml_element_##name>::create(dd4hep::Detector& l,ns::xml_h e) {return func(l,e);}\
308  DD4HEP_PLUGINSVC_FACTORY(xml_element_##name,name,TObject*(dd4hep::Detector*,ns::xml_h*),__LINE__) }
309 
310 // Call function of the type [void* (*func)(dd4hep::Detector& description, xml_h handle)]
311 #define DECLARE_XML_VOLUME(name,func) DD4HEP_OPEN_PLUGIN(dd4hep,xml_element_##name) {\
312  template <> Handle<TObject> XMLObjectFactory<xml_element_##name>::create(dd4hep::Detector& l,ns::xml_h e) {return func(l,e);}\
313  DD4HEP_PLUGINSVC_FACTORY(xml_element_##name,name,TObject*(dd4hep::Detector*,ns::xml_h*),__LINE__) }
314 
315 // Call function of the type [long (*func)(dd4hep::Detector& description, xml_h handle)]
316 #define DECLARE_XML_DOC_READER(name,func) DD4HEP_OPEN_PLUGIN(dd4hep,xml_document_##name) { \
317  template <> long XMLDocumentReaderFactory<xml_document_##name>::create(dd4hep::Detector& l,ns::xml_h e) {return func(l,e);} \
318  DD4HEP_PLUGINSVC_FACTORY(xml_document_##name,name##_XML_reader,long(dd4hep::Detector*,ns::xml_h*),__LINE__) }
319 
320 // Call function of the type [long (*func)(dd4hep::Detector& description, xml_h handle)]
321 #define DECLARE_XML_PLUGIN(name,func) DD4HEP_OPEN_PLUGIN(dd4hep,xml_document_##name) { \
322  template <> long XMLDocumentReaderFactory<xml_document_##name>::create(dd4hep::Detector& l,ns::xml_h e) {return func(l,e);} \
323  DD4HEP_PLUGINSVC_FACTORY(xml_document_##name,name,long(dd4hep::Detector*,ns::xml_h*),__LINE__) }
324 
325 // Call function of the type [NamedObject* (*func)(dd4hep::Detector& description, xml_h handle, ref_t reference)]
326 #define DECLARE_XML_PROCESSOR_BASIC(name,func,deprecated) DD4HEP_OPEN_PLUGIN(dd4hep,det_element_##name) {\
327  template <> Ref_t XmlDetElementFactory< det_element_##name >::create(dd4hep::Detector& l,ns::xml_h e,ns::ref_t h) \
328  { if (deprecated) warning_deprecated_xml_factory(#name); return func(l,e,h);} \
329  DD4HEP_PLUGINSVC_FACTORY(det_element_##name,name,NamedObject*(dd4hep::Detector*,ns::xml_h*,Ref_t*),__LINE__) }
330 
331 // Call function of the type [NamedObject* (*func)(dd4hep::Detector& description, json_h handle, ref_t reference)]
332 #define DECLARE_JSON_PROCESSOR_BASIC(name,func) DD4HEP_OPEN_PLUGIN(dd4hep,det_element_##name) { \
333  template <> Ref_t JsonDetElementFactory< det_element_##name >::create(dd4hep::Detector& l,ns::json_h e,ns::ref_t h) \
334  { return func(l,e,h);} \
335  DD4HEP_PLUGINSVC_FACTORY(det_element_##name,name,NamedObject*(dd4hep::Detector*,ns::json_h*,ns::ref_t*),__LINE__) }
336 
337 #define DECLARE_XML_PROCESSOR(name,func) DECLARE_XML_PROCESSOR_BASIC(name,func,0)
338 #define DECLARE_SUBDETECTOR(name,func) DECLARE_XML_PROCESSOR_BASIC(name,func,0)
339 #define DECLARE_DETELEMENT(name,func) DECLARE_XML_PROCESSOR_BASIC(name,func,0)
340 #define DECLARE_DEPRECATED_DETELEMENT(name,func) DECLARE_XML_PROCESSOR_BASIC(name,func,1)
341 
342 #define DECLARE_JSON_DETELEMENT(name,func) DECLARE_JSON_PROCESSOR_BASIC(name,func)
343 
344 #endif // DD4HEP_FACTORIES_H
345 
dd4hep::DetectorConstructionFactory
Template class for a generic dd4hep object constructor.
Definition: Factories.h:73
ns
Helper structure to shortcut type definitions for the factories.
Definition: Factories.h:204
dd4hep::DDSegmentation::BitFieldCoder
Helper class for decoding and encoding a bit field of 64bits for convenient declaration.
Definition: BitFieldCoder.h:114
dd4hep::XMLObjectFactory::create
static Handle< TObject > create(Detector &description, xml::Handle_t e)
dd4hep::XmlDetElementFactory
Standard factory to create Detector elements from an XML representation.
Definition: Factories.h:179
dd4hep::ConstructionFactory::create
static void * create(const char *arg)
DD4HEP_PLUGIN_FACTORY_ARGS_3
#define DD4HEP_PLUGIN_FACTORY_ARGS_3(R, A0, A1, A2)
Definition: Plugins.h:184
dd4hep::Handle< NamedObject >
dd4hep::SegmentationObject
Implementation class supporting generic Segmentation of sensitive detectors.
Definition: SegmentationsInterna.h:46
dd4hep::xml::Handle_t
Class to easily access the properties of single XmlElements.
Definition: XMLElements.h:380
dd4hep::SegmentationFactory::create
static SegmentationObject * create(const DDSegmentation::BitFieldCoder *decoder)
DD4HEP_PLUGIN_FACTORY_ARGS_1
#define DD4HEP_PLUGIN_FACTORY_ARGS_1(R, A0)
Definition: Plugins.h:168
dd4hep::ConstructionFactory
Definition: Factories.h:61
DD4HEP_PLUGIN_FACTORY_ARGS_0
#define DD4HEP_PLUGIN_FACTORY_ARGS_0(R)
Definition: Plugins.h:160
json_h
dd4hep::json::Handle_t json_h
Definition: Helper.h:26
DD4HEP_PLUGIN_FACTORY_ARGS_2
#define DD4HEP_PLUGIN_FACTORY_ARGS_2(R, A0, A1)
Definition: Plugins.h:176
dd4hep::JsonDetElementFactory::create
static Handle< NamedObject > create(Detector &description, json::Handle_t e, Handle< NamedObject > sens)
dd4hep::XMLConversionFactory::create
static long create(Detector &description, xml::RefElement &handle, xml::Handle_t element)
dd4hep::SimpleConstructionFactory
Template class with a generic constructor signature.
Definition: Factories.h:57
dd4hep::XMLElementFactory::create
static Handle< NamedObject > create(Detector &description, xml::Handle_t e)
dd4hep::xml
Namespace for the AIDA detector description toolkit supporting XML utilities.
Definition: ConditionsTags.h:27
dd4hep::PluginFactoryBase
Factory base class implementing some utilities.
Definition: Plugins.h:50
Plugins.h
dd4hep::SegmentationFactory
Template class for a generic segmentation object constructor.
Definition: Factories.h:85
dd4hep::XMLDocumentReaderFactory
Read an arbitrary XML document and analyze its content.
Definition: Factories.h:153
dd4hep::XmlDetElementFactory::create
static Handle< NamedObject > create(Detector &description, xml::Handle_t e, Handle< NamedObject > sens)
NamedObject.h
dd4hep::XMLObjectFactory
Standard factory to create ROOT objects from an XML representation.
Definition: Factories.h:140
dd4hep::JsonDetElementFactory
Standard factory to create Detector elements from the compact XML representation.
Definition: Factories.h:192
dd4hep::XMLConversionFactory
Read an arbitrary XML document and analyze its content.
Definition: Factories.h:166
xml_h
dd4hep::xml::Handle_t xml_h
Definition: ConditionsRepository.cpp:32
dd4hep::xml::RefElement
User abstraction class to manipulate named XML elements (references) within a document.
Definition: XMLElements.h:953
dd4hep::Handle::ptr
T * ptr() const
Access to the held object.
Definition: Handle.h:153
DetElement.h
dd4hep::XMLElementFactory
Create an arbitrary object from its XML representation.
Definition: Factories.h:127
dd4hep::DetectorConstructionFactory::create
static void * create(Detector &description, int argc, char **argv)
dd4hep::ApplyFactory::create
static long create(Detector &description, int argc, char **argv)
TObject
Class of the ROOT toolkit. See http://root.cern.ch/root/htmldoc/ClassIndex.html.
Definition: ROOTClasses.h:41
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::XMLDocumentReaderFactory::create
static long create(Detector &description, xml::Handle_t e)
dd4hep::NamedObject
Implementation of a named object.
Definition: NamedObject.h:30
dd4hep::json::Handle_t
Class to easily access the properties of single JsonElements.
Definition: Elements.h:135
dd4hep::Detector
The main interface to the dd4hep detector description package.
Definition: Detector.h:90
dd4hep::ApplyFactory
Template class with a generic signature to apply Detector plugins.
Definition: Factories.h:100
dd4hep::SimpleConstructionFactory::create
static void * create()
dd4hep::TranslationFactory
Specialized factory to translate objects, which can be retrieved from Detector.
Definition: Factories.h:114
handle
void handle(const O *o, const C &c, F pmf)
Definition: LCDDConverter.cpp:1105
dd4hep::TranslationFactory::create
static Handle< NamedObject > create(Detector &description)