36 template <
typename TYPE,
typename PTR> TYPE*
_action(PTR* in) {
37 return dynamic_cast<TYPE*
>(in);
41 template <
typename T>
static void installMessenger(
const T&
handle) {
42 handle->installMessengers();
46 template <
typename T>
static void _setAttributes(
const T&
handle,
xml_h& e) {
49 std::vector<xml::Attribute> attrs = props.attributes();
50 for(std::vector<xml::Attribute>::iterator i=attrs.begin(); i!=attrs.end(); ++i) {
57 template <
typename T>
static void _setProperties(
const T&
handle,
xml_h& e) {
62 _setAttributes(
handle, props);
64 if ( action.hasAttr(
_Unicode(Control)) ) {
70 static Action _convertSensitive(Detector& description,
xml_h e,
const std::string& detector) {
78 std::string nam = f.attr<std::string>(
_U(name));
83 printout(INFO,
"Geant4Setup",
"+++ Added sensitive element %s of type %s",
89 static Action _convertAction(Detector& description,
xml_h e) {
96 printout(INFO,
"Geant4Setup",
"+++ Added action %s of type %s",tn.
second.c_str(),tn.
first.c_str());
99 if ( action.hasChild(
_Unicode(adopt)) ) {
113 std::string nam = a.
attr<std::string>(
_U(name));
122 action = (what ==
SENSITIVE) ?
Action(_convertSensitive(description, a, seqType))
123 : (what==
ACTION) ? _convertAction(description, a)
124 : (what==
FILTER) ? _convertAction(description, a)
127 except(
"Geant4ActionSequence",
128 "DDG4: The action '%s' cannot be created. [Action-Missing]",nam.c_str());
145 template <>
void Converter<Action>::operator()(
xml_h e)
const {
146 Action a = _convertAction(description, e);
161 template <>
void Converter<Filter>::operator()(
xml_h e)
const {
162 Action a = _convertAction(description, e);
176 template <>
void Converter<Phase>::operator()(
xml_h e)
const {
179 std::string nam = x_phase.attr<std::string>(
_U(type));
183 if ( nam ==
"RunAction/begin" ) {
188 else if ( nam ==
"RunAction/end" ) {
193 else if ( nam ==
"EventAction/begin" ) {
198 else if ( nam ==
"EventAction/end" ) {
203 else if ( nam ==
"TrackingAction/begin" ) {
208 else if ( nam ==
"TrackingAction/end" ) {
213 else if ( nam ==
"StackingAction/newStage" ) {
216 else if ( nam ==
"StackingAction/prepare" ) {
219 else if ( nam ==
"SteppingAction" ) {
224 else if ( nam ==
"GeneratorAction/primaries" ) {
231 DetElement
det = description.detector(tn.
first);
232 if ( !
det.isValid() ) {
233 except(
"Phase",
"DDG4: The phase '%s' of type SensitiveSeq"
234 " cannot be attached to a non-existing detector"
235 " [Detector-Missing]",nam.c_str());
238 SensitiveDetector sd = description.sensitiveDetector(tn.
first);
239 if ( !sd.isValid() ) {
240 except(
"Phase",
"DDG4: The phase '%s' of type SensitiveSeq"
241 " cannot be attached to a non-existing sensitive detector"
242 " [Sensitive-Missing]",nam.c_str());
245 if ( tn.
second ==
"begin" )
246 sdSeq->callAtBegin((p=kernel.
addPhase<G4HCofThisEvent*>(tn.
second)).get(),
247 &PH::call<G4HCofThisEvent*>);
248 else if ( tn.
second ==
"end" )
249 sdSeq->callAtEnd((p=kernel.
addPhase<G4HCofThisEvent*>(tn.
second)).get(),
250 &PH::call<G4HCofThisEvent*>);
251 else if ( tn.
second ==
"clear" )
252 sdSeq->callAtClear((p=kernel.
addPhase<G4HCofThisEvent*>(tn.
second)).get(),
253 &PH::call<G4HCofThisEvent*>);
254 else if ( tn.
second ==
"process" )
255 sdSeq->callAtProcess((p=kernel.
addPhase<G4Step*>(tn.
second)).get(),
256 &PH::call<G4Step*,G4TouchableHistory*>);
258 except(
"Phase",
"DDG4: The phase '%s' of type SensitiveSeq"
259 " cannot be attached to the call '%s'."
260 " [Callback-Missing]",tn.
first.c_str(), tn.
second.c_str());
279 template <>
void Converter<ActionSequence>::operator()(
xml_h e)
const {
287 if ( seq.hasAttr(
_U(sd)) ) {
288 std::string sd_nam = seq.attr<std::string>(
_U(sd));
289 SensitiveDetector sensitive = description.sensitiveDetector(sd_nam);
290 seqNam = seq.attr<std::string>(
_U(type))+
"/"+sd_nam;
291 if ( !sensitive.isValid() ) {
292 printout(ALWAYS,
"Geant4Setup",
"+++ ActionSequence %s is defined, "
293 "but no sensitive detector present.",seqNam.c_str());
294 printout(ALWAYS,
"Geant4Setup",
"+++ ---> Sequence for detector %s IGNORED on popular request!",
303 seqNam = seq.attr<std::string>(
_U(name));
306 printout(INFO,
"Geant4Setup",
"+++ ActionSequence %s of type %s added.",
309 if ( seqType.
second ==
"PhysicsList" ) {
313 _setAttributes(pl,e);
318 std::string nam = a.attr<std::string>(
_U(name));
320 if ( seqType.
second ==
"RunAction" )
322 else if ( seqType.
second ==
"EventAction" )
324 else if ( seqType.
second ==
"GeneratorAction" )
326 else if ( seqType.
second ==
"TrackingAction" )
328 else if ( seqType.
second ==
"StackingAction" )
330 else if ( seqType.
second ==
"SteppingAction" )
332 else if ( seqType.
second ==
"PhysicsList" )
334 else if ( sdSeq.
get() )
335 sdSeq->adopt(_action<Geant4Sensitive>(action.get()));
337 except(
"ActionSequence",
"DDG4: The action '%s'"
338 " cannot be attached to any sequence '%s'."
339 " [Sequence-Missing]",nam.c_str(), seqNam.c_str());
341 printout(INFO,
"Geant4Setup",
"+++ ActionSequence %s added filter object:%s",
342 seqType.
second.c_str(),action->name().c_str());
346 std::string nam = a.attr<std::string>(
_U(name));
348 installMessenger(action);
349 printout(INFO,
"Geant4Setup",
"+++ ActionSequence %s added filter object:%s",
350 seqType.
second.c_str(),action->name().c_str());
352 sdSeq->adopt(_action<Geant4Filter>(action.get()));
354 except(
"ActionSequence",
"DDG4: The action '%s'"
355 " cannot be attached to any sequence '%s'."
356 " [Sequence-Missing]",nam.c_str(), seqNam.c_str());
373 template <>
void Converter<Geant4PhysicsList::ParticleProcesses>::operator()(
xml_h e)
const {
375 std::string part_name = part.nameStr();
377 _object<Geant4PhysicsList>().processes(part_name);
381 p.
name = proc.nameStr();
385 procs.emplace_back(p);
386 printout(INFO,
"Geant4Setup",
"+++ Converter<ParticleProcesses: Particle:%s add process %s %d %d %d",
403 template <>
void Converter<Geant4PhysicsList::ParticleConstructor>::operator()(
xml_h e)
const {
406 std::string n = part.nameStr();
407 parts.emplace_back(n);
408 printout(INFO,
"Geant4Setup",
"+++ ParticleConstructor: Add Geant4 particle constructor '%s'",n.c_str());
420 template <>
void Converter<Geant4PhysicsList::PhysicsConstructor>::operator()(
xml_h e)
const {
423 std::string n = part.nameStr();
424 parts.emplace_back(n);
425 printout(INFO,
"Geant4Setup",
"+++ PhysicsConstructor: Add Geant4 physics constructor '%s'",n.c_str());
435 struct PhysicsListExtension;
436 template <>
void Converter<PhysicsListExtension>::operator()(
xml_h e)
const {
440 printout(INFO,
"Geant4Setup",
"+++ PhysicsListExtension: Set predefined Geant4 physics list to '%s'",ext.c_str());
444 template <>
void Converter<PhysicsList>::operator()(
xml_h e)
const {
445 std::string name = e.
attr<std::string>(
_U(name));
453 kernel.physicsList().adopt(
handle);
457 template <>
void Converter<Kernel>::operator()(
xml_h e)
const {
460 if ( k.hasAttr(
_Unicode(NumEvents)) )
467 template <>
void Converter<XMLSetup>::operator()(
xml_h seq)
const {
470 long result = PluginService::Create<long>(
"geant4_XML_reader",&description,&seq);
472 except(
"PhysicsList",
"dd4hep: Failed to locate plugin to interprete files of type"
473 " \"" + seq.
tag() +
"\" - no factory of type geant4_XML_reader.");
475 result = *(
long*) result;
477 except(
"PhysicsList",
"dd4hep: Failed to parse the XML tag %s with the plugin geant4_XML_reader", seq.
tag().c_str());
491 (dd4hep::Converter<dd4hep::sim::XMLSetup>(description))(element);