Iguana 0.0.0
Implementation Guardian of Analysis Algorithms
Loading...
Searching...
No Matches
iguana_ex_python_00_run_functions.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2
3"""!
4@begin_doc_example{python}
5@file iguana_ex_python_00_run_functions.py
6@brief Python version of `iguana_ex_cpp_00_run_functions.cc` (for more details, see this `.cc` file)
7@end_doc_example
8@doxygen_off
9"""
10
11import pyiguana
12import sys
13
14# include the header files that you need
15pyiguana.include('hipo4/reader.h', 'iguana/algorithms/AlgorithmSequence.h')
16# then import the bound namespaces (must be after including the headers)
17from cppyy.gbl import hipo, iguana
18# from here the syntax is analogous to the C++ example
19
20inFile = sys.argv[1] if len(sys.argv)>1 else 'data.hipo'
21numEvents = int(sys.argv[2]) if len(sys.argv)>2 else 3
22
23reader = hipo.reader(inFile)
24banks = reader.getBanks([
25 "RUN::config",
26 "REC::Particle",
27 "REC::Calorimeter",
28 "REC::Track",
29 "REC::Scintillator"])
30
31seq = iguana.AlgorithmSequence('pyiguana')
32seq.Add('clas12::EventBuilderFilter')
33seq.Add('clas12::SectorFinder')
34seq.Add('clas12::MomentumCorrection')
35seq.PrintSequence()
36
37seq.SetOption('clas12::EventBuilderFilter', 'log', 'debug')
38seq.SetOption('clas12::MomentumCorrection', 'log', 'debug')
39
40seq.SetOption('clas12::EventBuilderFilter', 'pids', [11, 211, -211])
41
42def prettyPrint(message, bank):
43 print(f'{"="*30} {message} {"="*30}')
44 bank.show()
45
46iEvent = 0
47seq.Start(banks)
48while(reader.next(banks) and (numEvents==0 or iEvent < numEvents)):
49 iEvent += 1
50 prettyPrint("BEFORE", banks[1])
51 seq.Run(banks)
52 prettyPrint("AFTER", banks[1])
53
54seq.Stop()
55
56"""!@doxygen_on"""
User-level class for running a sequence of algorithms.
void prettyPrint(std::string header, hipo::bank &bank)
show a bank along with a header