From dc73db66584a0cbd23e8a6ce523e03accd2de994 Mon Sep 17 00:00:00 2001 From: Markus Frank Date: Mon, 21 Oct 2024 16:33:04 +0200 Subject: [PATCH] Add test using signal DDCore handler --- .../ClientTests/compact/InterruptTrigger.xml | 104 ++++++++++++++++++ examples/ClientTests/src/InterruptTrigger.cpp | 50 +++++++++ 2 files changed, 154 insertions(+) create mode 100644 examples/ClientTests/compact/InterruptTrigger.xml create mode 100644 examples/ClientTests/src/InterruptTrigger.cpp diff --git a/examples/ClientTests/compact/InterruptTrigger.xml b/examples/ClientTests/compact/InterruptTrigger.xml new file mode 100644 index 000000000..3cc6512b6 --- /dev/null +++ b/examples/ClientTests/compact/InterruptTrigger.xml @@ -0,0 +1,104 @@ + + + + + + Alignment test with 2 simple boxes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + system:8,x:24:-12,y:-12 + + + + system:8,x:24:-12,y:-12 + + + + + + + + + diff --git a/examples/ClientTests/src/InterruptTrigger.cpp b/examples/ClientTests/src/InterruptTrigger.cpp new file mode 100644 index 000000000..43b664cec --- /dev/null +++ b/examples/ClientTests/src/InterruptTrigger.cpp @@ -0,0 +1,50 @@ +//========================================================================== +// AIDA Detector description implementation +//-------------------------------------------------------------------------- +// 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 includes +#include "DD4hep/DetFactoryHelper.h" +#include "DD4hep/SignalHandler.h" +#include "DD4hep/Printout.h" + +// C/C++ include files +#include +#include +#include + +using namespace dd4hep; + +static bool signal_handler(void* user_context, int signal) { + printout(ALWAYS,"SignalHandler", + "+++ Caught signal: %d context: %p. exit process.", + signal, user_context); + ::fflush(stdout); + ::exit(EINVAL); + return true; +} + +static Ref_t create_detector(Detector& , xml_h e, SensitiveDetector ) { + // XML detector object: DDCore/XML/XMLDetector.h + xml_dim_t x_det = e; + //Create the DetElement for dd4hep + DetElement d_det(x_det.nameStr(),x_det.id()); + + SignalHandler handler; + handler.registerHandler(SIGINT, (void*)0xFEEDBABE, signal_handler); + + printout(ALWAYS,"SignalTrigger","+++ Sending interrupt signal to self..."); + ::kill(::getpid(), SIGINT); + + return d_det; +} + +DECLARE_DETELEMENT(InterruptTrigger,create_detector)