From ef9ff32cf7c2e4763560279ec5a497e76eebdcf6 Mon Sep 17 00:00:00 2001 From: Markus Frank <Markus.Frank@cern.ch> Date: Tue, 11 Oct 2022 20:18:41 +0200 Subject: [PATCH] Fix python style errors --- DDCore/python/dd4hep_base.py | 6 ++ DDDigi/python/dddigi.py | 17 +++- DDDigi/python/digitize.py | 36 ++------- DDG4/python/DDG4.py | 7 +- examples/DDDigi/scripts/DigiTest.py | 45 +++++++---- examples/DDDigi/scripts/TestFramework.py | 1 + examples/DDDigi/scripts/TestInput.py | 17 +++- .../DDDigi/scripts/TestMultiInteractions.py | 46 +++++------ .../DDDigi/scripts/TestSegmentationSplit.py | 26 +++---- examples/DDDigi/scripts/TestSpillover.py | 78 ++++++++++--------- 10 files changed, 154 insertions(+), 125 deletions(-) diff --git a/DDCore/python/dd4hep_base.py b/DDCore/python/dd4hep_base.py index d2d8aaa75..fac7caf26 100644 --- a/DDCore/python/dd4hep_base.py +++ b/DDCore/python/dd4hep_base.py @@ -72,6 +72,7 @@ def import_namespace_item(ns, nam): def import_root(nam): setattr(name_space, nam, getattr(ROOT, nam)) + # --------------------------------------------------------------------------- # try: @@ -96,6 +97,7 @@ class _Levels: self.FATAL = 6 self.ALWAYS = 7 + # --------------------------------------------------------------------------- def unicode_2_string(value): """Turn any unicode literal into str, needed when passing to c++. @@ -120,6 +122,7 @@ def unicode_2_string(value): value = tempDict return str(value) + OutputLevel = _Levels() # ------------------------Generic STL stuff can be accessed using std: ----- # @@ -157,6 +160,7 @@ import_namespace_item('detail', 'eval') def import_detail(): import_namespace_item('detail', 'DD4hepUI') + # --------------------------------------------------------------------------- def import_geometry(): import_namespace_item('core', 'setPrintLevel') @@ -243,6 +247,7 @@ def import_geometry(): import_namespace_item('core', 'UnionSolid') import_namespace_item('core', 'IntersectionSolid') + # --------------------------------------------------------------------------- def import_tgeo(): import_root('TGeoManager') @@ -342,6 +347,7 @@ class Logger: "Call dd4hep exception function" dd4hep.exception(self.name, msg) + dd4hep_logger = Logger # --------------------------------------------------------------------------- diff --git a/DDDigi/python/dddigi.py b/DDDigi/python/dddigi.py index f5d111c7a..a6f3cc97d 100644 --- a/DDDigi/python/dddigi.py +++ b/DDDigi/python/dddigi.py @@ -10,9 +10,11 @@ # ========================================================================== from __future__ import absolute_import, unicode_literals from dd4hep_base import * # noqa: F403 +import dd4hep_base.dd4hep_logger as dd4hep_logger logger = dd4hep_logger('dddigi') + def loadDDDigi(): import ROOT from ROOT import gSystem @@ -41,6 +43,7 @@ def loadDDDigi(): from ROOT import dd4hep as module return module + # We are nearly there .... current = __import__(__name__) @@ -48,6 +51,7 @@ def _import_class(ns, nam): scope = getattr(current, ns) setattr(current, nam, getattr(scope, nam)) + # --------------------------------------------------------------------------- # try: @@ -64,12 +68,11 @@ digi = dd4hep.digi Kernel = digi.KernelHandle Interface = digi.DigiActionCreation Detector = core.Detector -# -# # --------------------------------------------------------------------------- def _constant(self, name): return self.constantAsString(name) + Detector.globalVal = _constant # --------------------------------------------------------------------------- @@ -120,6 +123,7 @@ def importConstants(description, namespace=None, debug=False): if cnt < 100: logger.info('+++ Imported %d global values to namespace:%s', num, ns.__name__,) + # --------------------------------------------------------------------------- def _getKernelProperty(self, name): ret = Interface.getPropertyKernel(self.get(), name) @@ -132,6 +136,7 @@ def _getKernelProperty(self, name): msg = 'DigiKernel::GetProperty [Unhandled]: Cannot access Kernel.' + name raise KeyError(msg) + # --------------------------------------------------------------------------- def _setKernelProperty(self, name, value): if Interface.setPropertyKernel(self.get(), str(name), str(value)): @@ -139,6 +144,7 @@ def _setKernelProperty(self, name, value): msg = 'DigiKernel::SetProperty [Unhandled]: Cannot set Kernel.' + name + ' = ' + str(value) raise KeyError(msg) + # --------------------------------------------------------------------------- def _kernel_terminate(self): return self.get().terminate() @@ -155,9 +161,9 @@ def Action(kernel, nam, parallel=False): obj = Interface.createAction(kernel, str(nam)) obj.parallel = parallel return obj -# --------------------------------------------------------------------------- +# --------------------------------------------------------------------------- def EventAction(kernel, nam, parallel=False): obj = Interface.createEventAction(kernel, str(nam)) obj.parallel = parallel @@ -197,6 +203,7 @@ def _setup(obj): # setattr(cls,'add',_adopt) return cls + def _get(self, name): a = Interface.toAction(self) ret = Interface.getProperty(a, name) @@ -209,6 +216,7 @@ def _get(self, name): msg = 'DDDigiAction::GetProperty [Unhandled]: Cannot access property ' + a.name() + '.' + name raise KeyError(msg) + def _set(self, name, value): """This function is called when properties are passed to the c++ objects.""" a = Interface.toAction(self) @@ -228,6 +236,7 @@ def _props(obj, **extensions): cls.__setattr__ = _set return cls + _setup('DigiActionSequence') _setup('DigiSynchronize') @@ -243,6 +252,7 @@ _props('InputActionHandle') _props('ActionSequenceHandle') _props('SynchronizeHandle') + def adopt_sequence_action(self, name, **options): kernel = Interface.createKernel(Interface.toAction(self)) action = EventAction(kernel, name) @@ -251,6 +261,7 @@ def adopt_sequence_action(self, name, **options): self.adopt(action) return action + _props('DigiSynchronize') _props('DigiActionSequence', adopt_action = adopt_sequence_action) _props('DigiParallelActionSequence', adopt_action = adopt_sequence_action) diff --git a/DDDigi/python/digitize.py b/DDDigi/python/digitize.py index 72c485aad..5c63b7eee 100644 --- a/DDDigi/python/digitize.py +++ b/DDDigi/python/digitize.py @@ -12,7 +12,9 @@ from __future__ import absolute_import import dd4hep import dddigi -""" + +class Digitize(dd4hep.Logger): + """ Helper object to perform stuff, which occurs very often. I am sick of typing the same over and over again. Hence, I grouped often used python fragments to this small @@ -27,8 +29,7 @@ import dddigi #import pdb #pdb.set_trace() -""" -class Digitize(dd4hep.Logger): + """ def __init__(self, kernel=None): dd4hep.Logger.__init__(self, 'dddigi') self._kernel = kernel @@ -122,8 +123,6 @@ class Digitize(dd4hep.Logger): """ return self.kernel().events_processing() - - """ Execute the Geant 4 program with all steps. @@ -147,31 +146,10 @@ class Digitize(dd4hep.Logger): return detectors def printDetectors(self): - logger.info('+++ List of sensitive detectors:') + self.info('+++ List of sensitive detectors:') dets = self.activeDetectors() for d in dets: - logger.info('+++ %-32s ---> type:%-12s', d['name'], d['type']) - - def setupDetector(self, name, collections=None, modules=None): - seq = ActionSequence(self.kernel(), 'DigiActionSequence/' + name) - actions = [] - if isinstance(modules, tuple) or isinstance(modules, list): - for m in modules: - if isinstance(m, str): - a = Action(self.kernel(), m) - actions.append(a) - elif isinstance(m, tuple) or isinstance(m, list): - a = Action(self.kernel(), m[0]) - actions.append(a) - if len(m) > 1: - params = m[1] - for k, v in params.items(): - setattr(a, k, v) - else: - actions.append(m) - for a in actions: - seq.adopt(a) - return (seq, actions) + self.info('+++ %-32s ---> type:%-12s', d['name'], d['type']) """ Configure ROOT output for the event digitization @@ -179,7 +157,7 @@ class Digitize(dd4hep.Logger): \author M.Frank """ def setupROOTOutput(self, name, output, mc_truth=True): - evt_root = EventAction(self.kernel(), 'DigiOutput2ROOT/' + name, True) # noqa: F405 + evt_root = dddigi.EventAction(self.kernel(), 'DigiOutput2ROOT/' + name, True) # noqa: F405 evt_root.HandleMCTruth = mc_truth evt_root.Control = True if not output.endswith('.root'): diff --git a/DDG4/python/DDG4.py b/DDG4/python/DDG4.py index 6e4edad15..6df487951 100644 --- a/DDG4/python/DDG4.py +++ b/DDG4/python/DDG4.py @@ -279,6 +279,7 @@ _import_class('Sim', 'Geant4Random') _import_class('CLHEP', 'HepRandom') _import_class('CLHEP', 'HepRandomEngine') + def _get(self, name): a = Interface.toAction(self) ret = Interface.getProperty(a, name) @@ -291,22 +292,26 @@ def _get(self, name): msg = 'Geant4Action::GetProperty [Unhandled]: Cannot access property ' + a.name() + '.' + name raise KeyError(msg) + def _set(self, name, value): """This function is called when properties are passed to the c++ objects.""" + from dd4hep_base import unicode_2_string a = Interface.toAction(self) - name = unicode_2_string(name) + name = unicode_2_string(name) value = unicode_2_string(value) if Interface.setProperty(a, name, value): return msg = 'Geant4Action::SetProperty [Unhandled]: Cannot set ' + a.name() + '.' + name + ' = ' + value raise KeyError(msg) + def _props(obj): _import_class('Sim', obj) cl = getattr(current, obj) cl.__getattr__ = _get cl.__setattr__ = _set + _props('FilterHandle') _props('ActionHandle') _props('PhaseActionHandle') diff --git a/examples/DDDigi/scripts/DigiTest.py b/examples/DDDigi/scripts/DigiTest.py index 393e6029f..e2ddf6d28 100644 --- a/examples/DDDigi/scripts/DigiTest.py +++ b/examples/DDDigi/scripts/DigiTest.py @@ -19,7 +19,7 @@ logger = logging.getLogger(__name__) """ 00C7A3C1 SiVertexEndcapHits : map<long long, EnergyDeposit> 00D16F45 EcalBarrelHits : map<long long, EnergyDeposit> - 0D3C3803 MCParticles : vector<shared_ptr<dd4hep::sim::Geant4Particle>, allocator<shared_ptr<dd4hep::sim::Geant4Particle> > > + 0D3C3803 MCParticles : 2E9082A9 HcalPlugHits : map<long long, EnergyDeposit> 3A89E02E HcalEndcapHits : map<long long, EnergyDeposit> 569C1C49 HcalBarrelHits : map<long long, EnergyDeposit> @@ -34,20 +34,20 @@ logger = logging.getLogger(__name__) F4183035 SiTrackerEndcapHits : map<long long, EnergyDeposit> """ -attenuation = { 'SiVertexEndcapHits': 15 * ns, - 'SiVertexBarrelHits': 15 * ns, - 'SiTrackerForwardHits': 15 * ns, - 'SiTrackerEndcapHits': 15 * ns, - 'SiTrackerBarrelHits': 15 * ns, - 'HcalPlugHits': 15 * ns, - 'HcalEndcapHits': 15 * ns, - 'HcalBarrelHits': 15 * ns, - 'EcalEndcapHits': 15 * ns, - 'MuonEndcapHits': 15 * ns, - 'MuonBarrelHits': 15 * ns, - 'BeamCalHits': 15 * ns, - 'LumiCalHits': 15 * ns, -} +attenuation = {'SiVertexEndcapHits': 15 * ns, + 'SiVertexBarrelHits': 15 * ns, + 'SiTrackerForwardHits': 15 * ns, + 'SiTrackerEndcapHits': 15 * ns, + 'SiTrackerBarrelHits': 15 * ns, + 'HcalPlugHits': 15 * ns, + 'HcalEndcapHits': 15 * ns, + 'HcalBarrelHits': 15 * ns, + 'EcalEndcapHits': 15 * ns, + 'MuonEndcapHits': 15 * ns, + 'MuonBarrelHits': 15 * ns, + 'BeamCalHits': 15 * ns, + 'LumiCalHits': 15 * ns, + } class Test(dddigi.Digitize): @@ -70,6 +70,11 @@ class Test(dddigi.Digitize): ] self.used_inputs = [] + def check_creation(self, objs): + for o in objs: + if o is None: + self.error('FAILED Failed to create object') + def declare_input(self, name, input, parallel=True): if not self.input: self.input = dddigi.Synchronize(self.kernel(), 'DigiParallelActionSequence/READER') @@ -81,3 +86,13 @@ class Test(dddigi.Digitize): next = self.inputs[len(self.used_inputs)] self.used_inputs.append(next) return next + + def run_checked(self, num_events=5, num_threads=5, parallel=3): + evt_todo = num_events + evt_done = digi.run(num_events=evt_todo, num_threads=num_threads, parallel=parallel) + if evt_done == evt_todo: + result = "PASSED" + else: + result = "FAILED" + self.always('%s Test finished after processing %d events.'%(result, digi.events_done(),)) + self.always('Test done. Exiting') diff --git a/examples/DDDigi/scripts/TestFramework.py b/examples/DDDigi/scripts/TestFramework.py index 1ff0a061f..0173d3795 100644 --- a/examples/DDDigi/scripts/TestFramework.py +++ b/examples/DDDigi/scripts/TestFramework.py @@ -12,6 +12,7 @@ from __future__ import absolute_import, unicode_literals import dddigi import os + def make_input(kernel): input_1 = dddigi.TestAction(kernel, 'input_01', 100) input_2 = dddigi.TestAction(kernel, 'input_02', 200) diff --git a/examples/DDDigi/scripts/TestInput.py b/examples/DDDigi/scripts/TestInput.py index e071947b5..175ced536 100644 --- a/examples/DDDigi/scripts/TestInput.py +++ b/examples/DDDigi/scripts/TestInput.py @@ -10,12 +10,23 @@ # ========================================================================== from __future__ import absolute_import + def run(): import DigiTest - digi = DigiTest.Test(geometry=None) + digi = DigiTest.Test(geometry=None) reader = digi.input_action('DigiROOTInput/SignalReader', mask=0x1, input=['CLICSiD_2022-10-05_13-21.root']) - dump = digi.event_action('DigiStoreDump/StoreDump') - digi.run(num_events = 5, num_threads = 5, parallel = 3) + dump = digi.event_action('DigiStoreDump/StoreDump') + + if reader is None: digi.error('FAILED create DigiROOTInput') + if dump is None: digi.error('FAILED create DigiStoreDump') + + evt_todo = 5 + evt_done = digi.run(num_events=evt_todo, num_threads=5, parallel=3) + if evt_done == evt_todo: result = "PASSED" + else: result = "FAILED" + digi.always('%s Test finished after processing %d events.'%(result, digi.events_done(),)) + digi.always('Test done. Exiting') + if __name__ == '__main__': run() diff --git a/examples/DDDigi/scripts/TestMultiInteractions.py b/examples/DDDigi/scripts/TestMultiInteractions.py index b7cdc2cf1..836a3a80d 100644 --- a/examples/DDDigi/scripts/TestMultiInteractions.py +++ b/examples/DDDigi/scripts/TestMultiInteractions.py @@ -10,46 +10,48 @@ # ========================================================================== from __future__ import absolute_import + def run(): import DigiTest digi = DigiTest.Test(geometry=None) attenuation = digi.attenuation - input = digi.input_action('DigiParallelActionSequence/READER') - #======================================================================================================== + input = digi.input_action('DigiParallelActionSequence/READER') + # ======================================================================================================== digi.info('Created SIGNAL input') - signal = input.adopt_action('DigiROOTInput/SignalReader', mask=0x0, input = [digi.next_input()]) - #======================================================================================================== + signal = input.adopt_action('DigiROOTInput/SignalReader', mask=0x0, input=[digi.next_input()]) + digi.check_creation([signal]) + # ======================================================================================================== digi.info('Creating collision overlays....') - #======================================================================================================== + # ======================================================================================================== overlay = input.adopt_action('DigiSequentialActionSequence/Overlay-1') - evtreader = overlay.adopt_action('DigiROOTInput/Reader-1', mask=0x1, input = [digi.next_input()]) - hist_drop = overlay.adopt_action('DigiHitHistoryDrop/Drop-1', masks = [evtreader.mask]) + evtreader = overlay.adopt_action('DigiROOTInput/Reader-1', mask=0x1, input=[digi.next_input()]) + hist_drop = overlay.adopt_action('DigiHitHistoryDrop/Drop-1', masks=[evtreader.mask]) + digi.check_creation([overlay, evtreader, hist_drop]) digi.info('Created input.overlay25') - #======================================================================================================== + # ======================================================================================================== overlay = input.adopt_action('DigiSequentialActionSequence/Overlay-2') - evtreader = overlay.adopt_action('DigiROOTInput/Reader-2', mask=0x2, input = [digi.next_input()]) - hist_drop = overlay.adopt_action('DigiHitHistoryDrop/Drop-2', masks = [evtreader.mask]) + evtreader = overlay.adopt_action('DigiROOTInput/Reader-2', mask=0x2, input=[digi.next_input()]) + hist_drop = overlay.adopt_action('DigiHitHistoryDrop/Drop-2', masks=[evtreader.mask]) + digi.check_creation([overlay, evtreader, hist_drop]) digi.info('Created input.overlay50') - #======================================================================================================== + # ======================================================================================================== overlay = input.adopt_action('DigiSequentialActionSequence/Overlay-3') - evtreader = overlay.adopt_action('DigiROOTInput/Reader-3', mask=0x3, input = [digi.next_input()]) - hist_drop = overlay.adopt_action('DigiHitHistoryDrop/Drop-3', masks = [evtreader.mask]) + evtreader = overlay.adopt_action('DigiROOTInput/Reader-3', mask=0x3, input=[digi.next_input()]) + hist_drop = overlay.adopt_action('DigiHitHistoryDrop/Drop-3', masks=[evtreader.mask]) + digi.check_creation([overlay, evtreader, hist_drop]) digi.info('Created input.overlay75') - #======================================================================================================== - + # ======================================================================================================== event = digi.event_action('DigiSequentialActionSequence/EventAction') combine = event.adopt_action('DigiContainerCombine/Combine', masks=[0x0, 0x1, 0x2, 0x3], deposit_mask=0xFEED) combine.erase_combined = True # Not thread-safe! only do in SequentialActionSequence dump = event.adopt_action('DigiStoreDump/StoreDump') + digi.check_creation([combine, dump]) digi.info('Created event.dump') - #======================================================================================================== - evt_todo = 5 - evt_done = digi.run(num_events = evt_todo, num_threads = 5, parallel = 3) - if evt_done == evt_todo: result = "PASSED" - else: result = "FAILED" - digi.always('%s Test finished after processing %d events.'%(result, digi.events_done(),)) - digi.always('Test done. Exiting') + + # ======================================================================================================== + digi.run_checked(num_events=5, num_threads=5, parallel=3) + if __name__ == '__main__': run() diff --git a/examples/DDDigi/scripts/TestSegmentationSplit.py b/examples/DDDigi/scripts/TestSegmentationSplit.py index d908de66e..22e349b54 100644 --- a/examples/DDDigi/scripts/TestSegmentationSplit.py +++ b/examples/DDDigi/scripts/TestSegmentationSplit.py @@ -10,34 +10,30 @@ # ========================================================================== from __future__ import absolute_import + def run(): import DigiTest digi = DigiTest.Test(geometry=None) - attenuation = digi.attenuation - input = digi.input_action('DigiParallelActionSequence/READER') - #======================================================================================================== + input = digi.input_action('DigiParallelActionSequence/READER') + # ======================================================================================================== digi.info('Created SIGNAL input') - signal = input.adopt_action('DigiROOTInput/SignalReader', mask=0x0, input = [digi.next_input()]) - #======================================================================================================== + signal = input.adopt_action('DigiROOTInput/SignalReader', mask=0x0, input=[digi.next_input()]) + digi.check_creation([signal]) + # ======================================================================================================== event = digi.event_action('DigiSequentialActionSequence/EventAction') combine = event.adopt_action('DigiContainerCombine/Combine', masks=[0x0, 0x1, 0x2, 0x3], deposit_mask=0xFEED) combine.erase_combined = True # Not thread-safe! only do in SequentialActionSequence - dump = event.adopt_action('DigiStoreDump/StoreDump') - splitter = event.adopt_action('DigiSegmentationSplitter/Splitter', input='deposits', masks=[0xFEED], detector='SiTrackerBarrel'); - + dump = event.adopt_action('DigiStoreDump/StoreDump') + digi.check_creation([combine, dump, splitter]) digi.info('Created event.dump') - #======================================================================================================== - evt_todo = 5 - evt_done = digi.run(num_events = evt_todo, num_threads = 5, parallel = 3) - if evt_done == evt_todo: result = "PASSED" - else: result = "FAILED" - digi.always('%s Test finished after processing %d events.'%(result, digi.events_done(),)) - digi.always('Test done. Exiting') + # ======================================================================================================== + digi.run_checked(num_events=5, num_threads=5, parallel=3) + if __name__ == '__main__': run() diff --git a/examples/DDDigi/scripts/TestSpillover.py b/examples/DDDigi/scripts/TestSpillover.py index f5000dc41..41dd1df00 100644 --- a/examples/DDDigi/scripts/TestSpillover.py +++ b/examples/DDDigi/scripts/TestSpillover.py @@ -16,69 +16,73 @@ def run(): digi = DigiTest.Test(geometry=None) attenuation = digi.attenuation - input = digi.input_action('DigiParallelActionSequence/READER') - #======================================================================================================== - signal = input.adopt_action('DigiROOTInput/SignalReader', mask=0x0, input = [digi.next_input()]) + input = digi.input_action('DigiParallelActionSequence/READER') + # ======================================================================================================== + signal = input.adopt_action('DigiROOTInput/SignalReader', mask=0x0, input=[digi.next_input()]) + digi.check_creation([signal]) digi.info('Created input.signal') - #======================================================================================================== + # ======================================================================================================== digi.info('Creating spillover sequence for EARLIER bunch crossings.....') - #======================================================================================================== + # ======================================================================================================== spillover = input.adopt_action('DigiSequentialActionSequence/Spillover-25') - evtreader = spillover.adopt_action('DigiROOTInput/Reader-25ns', mask=0x1, input = [digi.next_input()]) + evtreader = spillover.adopt_action('DigiROOTInput/Reader-25ns', mask=0x1, input=[digi.next_input()]) attenuate = spillover.adopt_action('DigiHitAttenuatorExp/Attenuator-25ns', - t0 = -25 * ns, masks = [evtreader.mask], containers = attenuation) - hist_drop = spillover.adopt_action('DigiHitHistoryDrop/Drop-25ns', masks = [evtreader.mask]) + t0=-25 * ns, masks=[evtreader.mask], containers=attenuation) + hist_drop = spillover.adopt_action('DigiHitHistoryDrop/Drop-25ns', masks=[evtreader.mask]) + digi.check_creation([spillover, evtreader, attenuate, hist_drop]) digi.info('Created input.spillover25') - #======================================================================================================== + # ======================================================================================================== spillover = input.adopt_action('DigiSequentialActionSequence/Spillover-50') - evtreader = spillover.adopt_action('DigiROOTInput/Reader-50ns', mask=0x2, input = [digi.next_input()]) + evtreader = spillover.adopt_action('DigiROOTInput/Reader-50ns', mask=0x2, input=[digi.next_input()]) attenuate = spillover.adopt_action('DigiHitAttenuatorExp/Attenuator-50ns', - t0 = -50 * ns, masks = [evtreader.mask], containers = attenuation) - hist_drop = spillover.adopt_action('DigiHitHistoryDrop/Drop-50ns', masks = [evtreader.mask]) + t0=-50 * ns, masks=[evtreader.mask], containers=attenuation) + hist_drop = spillover.adopt_action('DigiHitHistoryDrop/Drop-50ns', masks=[evtreader.mask]) + digi.check_creation([spillover, evtreader, attenuate, hist_drop]) digi.info('Created input.spillover50') - #======================================================================================================== + # ======================================================================================================== spillover = input.adopt_action('DigiSequentialActionSequence/Spillover-75') - evtreader = spillover.adopt_action('DigiROOTInput/Reader-75ns', mask=0x3, input = [digi.next_input()]) + evtreader = spillover.adopt_action('DigiROOTInput/Reader-75ns', mask=0x3, input=[digi.next_input()]) attenuate = spillover.adopt_action('DigiHitAttenuatorExp/Attenuator-75ns', - t0 = -75 * ns, masks = [evtreader.mask], containers = attenuation) - hist_drop = spillover.adopt_action('DigiHitHistoryDrop/Drop-75ns', masks = [evtreader.mask]) + t0=-75 * ns, masks=[evtreader.mask], containers=attenuation) + hist_drop = spillover.adopt_action('DigiHitHistoryDrop/Drop-75ns', masks=[evtreader.mask]) + digi.check_creation([spillover, evtreader, attenuate, hist_drop]) digi.info('Created input.spillover75') - #======================================================================================================== + # ======================================================================================================== digi.info('Creating spillover sequence for LATER bunch crossings.....') - #======================================================================================================== + # ======================================================================================================== spillover = input.adopt_action('DigiSequentialActionSequence/Spillover+25') - evtreader = spillover.adopt_action('DigiROOTInput/Reader+25ns', mask=0x4, input = [digi.next_input()]) + evtreader = spillover.adopt_action('DigiROOTInput/Reader+25ns', mask=0x4, input=[digi.next_input()]) attenuate = spillover.adopt_action('DigiHitAttenuatorExp/Attenuator+25ns', - t0 = 25 * ns, masks = [evtreader.mask], containers = attenuation) - hist_drop = spillover.adopt_action('DigiHitHistoryDrop/Drop+25ns', masks = [evtreader.mask]) + t0=25 * ns, masks=[evtreader.mask], containers=attenuation) + hist_drop = spillover.adopt_action('DigiHitHistoryDrop/Drop+25ns', masks=[evtreader.mask]) + digi.check_creation([spillover, evtreader, attenuate, hist_drop]) digi.info('Created input.spillover25') - #======================================================================================================== + # ======================================================================================================== spillover = input.adopt_action('DigiSequentialActionSequence/Spillover+50') - evtreader = spillover.adopt_action('DigiROOTInput/Reader+50ns', mask=0x5, input = [digi.next_input()]) + evtreader = spillover.adopt_action('DigiROOTInput/Reader+50ns', mask=0x5, input=[digi.next_input()]) attenuate = spillover.adopt_action('DigiHitAttenuatorExp/Attenuator+50ns', - t0 = 50 * ns, masks = [evtreader.mask], containers = attenuation) - hist_drop = spillover.adopt_action('DigiHitHistoryDrop/Drop_50ns', masks = [evtreader.mask]) + t0=50 * ns, masks=[evtreader.mask], containers=attenuation) + hist_drop = spillover.adopt_action('DigiHitHistoryDrop/Drop_50ns', masks=[evtreader.mask]) + digi.check_creation([spillover, evtreader, attenuate, hist_drop]) digi.info('Created input.spillover50') - #======================================================================================================== + # ======================================================================================================== spillover = input.adopt_action('DigiSequentialActionSequence/Spillover+75') - evtreader = spillover.adopt_action('DigiROOTInput/Reader+75ns', mask=0x6, input = [digi.next_input()]) + evtreader = spillover.adopt_action('DigiROOTInput/Reader+75ns', mask=0x6, input=[digi.next_input()]) attenuate = spillover.adopt_action('DigiHitAttenuatorExp/Attenuator+75ns', - t0 = 75 * ns, masks = [evtreader.mask], containers = attenuation) - hist_drop = spillover.adopt_action('DigiHitHistoryDrop/Drop+75ns', masks = [evtreader.mask]) + t0=75 * ns, masks=[evtreader.mask], containers=attenuation) + hist_drop = spillover.adopt_action('DigiHitHistoryDrop/Drop+75ns', masks=[evtreader.mask]) + digi.check_creation([spillover, evtreader, attenuate, hist_drop]) digi.info('Created input.spillover75') - #======================================================================================================== + # ======================================================================================================== event = digi.event_action('DigiSequentialActionSequence/EventAction') combine = event.adopt_action('DigiContainerCombine/Combine', masks=[0x0, 0x1, 0x2, 0x3], deposit_mask=0xFEED) combine.erase_combined = True # Not thread-safe! only do in SequentialActionSequence evtdump = event.adopt_action('DigiStoreDump/StoreDump') + digi.check_creation([combine, evtdump]) digi.info('Created event.dump') - #======================================================================================================== - evt_todo = 5 - evt_done = digi.run(num_events = evt_todo, num_threads = 5, parallel = 3) - if evt_done == evt_todo: result = "PASSED" - else: result = "FAILED" - digi.always('%s Test finished after processing %d events.'%(result, digi.events_done(),)) - digi.always('Test done. Exiting') + # ======================================================================================================== + digi.run_checked(num_events=5, num_threads=5, parallel=3) + if __name__ == '__main__': run() -- GitLab