Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test using signal handler from DDCore #1341

Merged
merged 2 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions examples/ClientTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,15 @@ dd4hep_add_test_reg( box_shape_build_type
REGEX_FAIL "Exception;EXCEPTION;ERROR"
)
#
# Test interrupt handling in the middle of the geometry construction
dd4hep_add_test_reg( ClientTests_interrupt_geometry_construction
COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_ClientTests.sh"
EXEC_ARGS geoDisplay -compact ${ClientTestsEx_INSTALL}/compact/InterruptTrigger.xml
-load -print INFO
REGEX_PASS "\\+\\+\\+ Caught signal: 2 context: 0xfeedbabe. exit process."
REGEX_FAIL "Exception;EXCEPTION;ERROR"
)
#
# EXEC_ARGS test_with_root.sh ${script}
#
if (DD4HEP_USE_GEANT4)
Expand Down
104 changes: 104 additions & 0 deletions examples/ClientTests/compact/InterruptTrigger.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?xml version="1.0" encoding="UTF-8"?>
<lccdd>
<!-- #==========================================================================
# 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.
#
#==========================================================================
-->

<info name="SiliconBlock"
title="Test with 2 simple silicon boxes"
author="Markus Frank"
url="http://www.cern.ch/lhcb"
status="development"
version="$Id: compact.xml 513 2013-04-05 14:31:53Z gaede $">
<comment>Alignment test with 2 simple boxes</comment>
</info>

<includes>
<gdmlFile ref="${DD4hepINSTALL}/DDDetectors/compact/elements.xml"/>
<gdmlFile ref="${DD4hepINSTALL}/DDDetectors/compact/materials.xml"/>
</includes>

<materials>
<material name="G4_PbWO4">
<D type="density" unit="g/cm3" value="8.28"/>
<composite n="4" ref="O"/>
<composite n="1" ref="Pb"/>
<composite n="1" ref="W"/>
</material>
</materials>

<define>
<constant name="world_size" value="30*m"/>
<constant name="world_x" value="world_size"/>
<constant name="world_y" value="world_size"/>
<constant name="world_z" value="world_size"/>
</define>

<display>
<vis name="Invisible" showDaughters="false" visible="false"/>
<vis name="InvisibleWithChildren" showDaughters="true" visible="false"/>
<vis name="VisibleRed" r="1.0" g="0.0" b="0.0" showDaughters="true" visible="true"/>
<vis name="VisibleBlue" r="0.0" g="0.0" b="1.0" showDaughters="false" visible="true"/>
<vis name="VisibleGreen" alpha="1.0" r="0.0" g="1.0" b="0.0" drawingStyle="solid" lineStyle="solid" showDaughters="true" visible="true"/>
</display>

<limits>
<limitset name="SiRegionLimitSet">
<limit name="step_length_max" particles="*" value="5.0" unit="mm" />
<limit name="track_length_max" particles="*" value="1.0" unit="mm" />
</limitset>
</limits>

<regions>
<region name="SiRegion" eunit="MeV" lunit="mm" cut="0.001" threshold="0.001">
<limitsetref name="SiRegionLimitSet"/>
</region>
</regions>

<detectors>
<detector id="1" name="SiliconBlockUpper" type="DD4hep_BoxSegment" readout="SiliconUpperHits" vis="VisibleGreen" sensitive="true" region="SiRegion" limits="SiRegionLimitSet">
<material name="Silicon"/>
<sensitive type="tracker"/>
<box x="30*mm" y="100*cm" z="100*cm"/>
<position x="4*cm" y="0" z="0"/>
<rotation x="0" y="0" z="0"/>
</detector>
<detector id="2" name="InterruptTrigger" type="InterruptTrigger"/>
<detector id="3" name="SiliconBlockDown" type="DD4hep_BoxSegment" readout="SiliconDownHits" vis="VisibleRed" sensitive="true" region="SiRegion" limits="SiRegionLimitSet">
<material name="Silicon"/>
<sensitive type="tracker"/>
<box x="30*mm" y="100*cm" z="100*cm"/>
<position x="-4*cm" y="0" z="0"/>
<rotation x="0" y="0" z="0"/>
</detector>
</detectors>

<readouts>
<readout name="SiliconUpperHits">
<segmentation type="CartesianGridXY" grid_size_x="5*mm" grid_size_y="5*mm"/>
<id>system:8,x:24:-12,y:-12</id>
</readout>
<readout name="SiliconDownHits">
<segmentation type="CartesianGridXY" grid_size_x="5*mm" grid_size_y="5*mm"/>
<id>system:8,x:24:-12,y:-12</id>
</readout>
</readouts>

<fields>
<field name="GlobalSolenoid" type="solenoid"
inner_field="5.0*tesla"
outer_field="-1.5*tesla"
zmax="2*m"
outer_radius="3*m">
</field>
</fields>

</lccdd>
50 changes: 50 additions & 0 deletions examples/ClientTests/src/InterruptTrigger.cpp
Original file line number Diff line number Diff line change
@@ -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 <cstdio>
#include <csignal>
#include <unistd.h>

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)
Loading