|
| 1 | +# |
| 2 | +# Copyright (c) 2014-2024 Key4hep-Project. |
| 3 | +# |
| 4 | +# This file is part of Key4hep. |
| 5 | +# See https://key4hep.github.io/key4hep-doc/ for further info. |
| 6 | +# |
| 7 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +# you may not use this file except in compliance with the License. |
| 9 | +# You may obtain a copy of the License at |
| 10 | +# |
| 11 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +# |
| 13 | +# Unless required by applicable law or agreed to in writing, software |
| 14 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +# See the License for the specific language governing permissions and |
| 17 | +# limitations under the License. |
| 18 | +# |
| 19 | + |
| 20 | +# This is an example using two producers that create histograms and persist them to a ROOT file |
| 21 | + |
| 22 | +from Gaudi.Configuration import INFO |
| 23 | +from Configurables import ExampleFunctionalProducerHist |
| 24 | +from k4FWCore import ApplicationMgr |
| 25 | +from Configurables import RootHistSvc |
| 26 | +from Configurables import Gaudi__Histograming__Sink__Root as RootHistoSink |
| 27 | +from Configurables import HiveWhiteBoard, HiveSlimEventLoopMgr, AvalancheSchedulerSvc |
| 28 | + |
| 29 | +# Multithreaded also works fine with histograms |
| 30 | +multithreaded = True |
| 31 | +threads = 2 |
| 32 | +slots = 3 |
| 33 | +if multithreaded: |
| 34 | + whiteboard = HiveWhiteBoard( |
| 35 | + "EventDataSvc", |
| 36 | + EventSlots=slots, |
| 37 | + ForceLeaves=True, |
| 38 | + ) |
| 39 | + slimeventloopmgr = HiveSlimEventLoopMgr( |
| 40 | + "HiveSlimEventLoopMgr", SchedulerName="AvalancheSchedulerSvc", OutputLevel=INFO |
| 41 | + ) |
| 42 | + |
| 43 | + scheduler = AvalancheSchedulerSvc(ThreadPoolSize=threads, OutputLevel=INFO) |
| 44 | + scheduler.ShowDataDependencies = True |
| 45 | + scheduler.ShowDataFlow = True |
| 46 | + scheduler.ShowControlFlow = True |
| 47 | + |
| 48 | + |
| 49 | +producer1 = ExampleFunctionalProducerHist( |
| 50 | + "ExampleFunctionalProducer1", OutputCollection=["dummy1"] |
| 51 | +) |
| 52 | +producer2 = ExampleFunctionalProducerHist( |
| 53 | + "ExampleFunctionalProducer2", OutputCollection=["dummy2"] |
| 54 | +) |
| 55 | + |
| 56 | +hist = RootHistSvc("HistogramPersistencySvc") |
| 57 | +root_hist_svc = RootHistoSink("RootHistoSink") |
| 58 | +root_hist_svc.FileName = "functional_producer_hist.root" |
| 59 | + |
| 60 | + |
| 61 | +if not multithreaded: |
| 62 | + app = ApplicationMgr( |
| 63 | + TopAlg=[producer1, producer2], |
| 64 | + EvtSel="NONE", |
| 65 | + EvtMax=10, |
| 66 | + ExtSvc=[root_hist_svc] + ([whiteboard] if multithreaded else []), |
| 67 | + OutputLevel=INFO, |
| 68 | + HistogramPersistency="ROOT", |
| 69 | + ) |
| 70 | +else: |
| 71 | + app = ApplicationMgr( |
| 72 | + TopAlg=[producer1, producer2], |
| 73 | + EvtSel="NONE", |
| 74 | + EvtMax=10, |
| 75 | + ExtSvc=[root_hist_svc] + ([whiteboard] if multithreaded else []), |
| 76 | + OutputLevel=INFO, |
| 77 | + HistogramPersistency="ROOT", |
| 78 | + EventLoop=slimeventloopmgr, |
| 79 | + ) |
0 commit comments