Skip to content

Commit 5b46597

Browse files
Python config update (#62)
* patch admonish syntax * first few sections of usage guide with python rename * notes on design * point out flexibility in how parameters can be set * start rewriting sim area * updates as i'm rereading the sim section * make sure standalone works
1 parent 68f66f4 commit 5b46597

16 files changed

Lines changed: 185 additions & 202 deletions

src/developing/Logging.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ The python class `Process` has the `logger` member that configures how the loggi
88

99
Parameter | Description
1010
---|---
11-
`filePath` | path to logging file. No logging to file is done if this is not set.
12-
`fileLevel` | Logging level (and above) to print to the file
13-
`termLevel` | Logging level (and above) to print to the terminal
11+
`file_path` | path to logging file. No logging to file is done if this is not set.
12+
`file_level` | Logging level (and above) to print to the file
13+
`term_level` | Logging level (and above) to print to the terminal
1414

1515
Besides these parameters you can set directly, the `logger` also has
1616
the ability to customize logging levels depending on the name of the logging
@@ -19,7 +19,7 @@ channel (usually the processor's name).
1919
### Examples
2020
to lower the level for everyone
2121
```python
22-
p.logger.termLevel = 0
22+
p.logger.term_level = 0
2323
```
2424
to debug a specific processor
2525
```python

src/developing/compatibility.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ which uses an older version of ROOT.
144144
The error you see is with using `XYZTVector` which is not present in the `ROOT::Math` namespace
145145
without including a couple more headers.
146146

147-
~~~admonish example title="Example Compile Error Message", collapsible=true
147+
~~~admonish example title="Example Compile Error Message" collapsible=true
148148
I've removed the other errors generated by the compiler, mainly focused on how the `centroid` function
149149
is not defined anymore since its return type is not defined.
150150
```

src/using/analysis/ana-cfg.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from LDMX.Framework import ldmxcfg
22
p = ldmxcfg.Process('ana')
3-
p.sequence = [ ldmxcfg.Analyzer.from_file('MyAnalyzer.cxx', needs=['Ecal_Event']) ]
4-
p.inputFiles = [ 'events.root' ]
5-
p.histogramFile = 'hist.root'
3+
p.sequence = [ ldmxcfg.processor_from_file('MyAnalyzer.cxx', needs=['SimCore_Event', 'Ecal_Event']) ]
4+
p.input_files = [ 'events.root' ]
5+
p.histogram_file = 'hist.root'
6+
p.pause()

src/using/analysis/analyzer-total-rec-energy.cxx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@ class MyAnalyzer : public framework::Analyzer {
1313
};
1414

1515
void MyAnalyzer::onProcessStart() {
16-
/**
17-
* In v4.5.1 ldmx-sw and earlier, forgetting `getHistoDirectory()`
18-
* led to silently not creating any histograms.
19-
* In v4.5.2 ldmx-sw and newer, it can be left out but it does
20-
* no harm if left in.
21-
*/
22-
getHistoDirectory();
2316
histograms_.create(
2417
"total_ecal_rec_energy",
2518
"Total ECal Rec Energy [GeV]", 160, 0.0, 16.0

src/using/analysis/gen.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
from LDMX.Framework import ldmxcfg
22
p = ldmxcfg.Process('test')
33
from LDMX.SimCore import simulator as sim
4-
mySim = sim.simulator( "mySim" )
5-
mySim.setDetector( 'ldmx-det-v14-8gev', True )
4+
mySim = sim.Simulator( "mySim" )
5+
mySim.set_detector( 'ldmx-det-v15-8gev', True )
66
from LDMX.SimCore import generators as gen
77
mySim.generators = [ gen.single_8gev_e_upstream_tagger() ]
8-
mySim.beamSpotSmear = [20.,80.,0.]
98
mySim.description = 'Basic test Simulation'
109
p.sequence = [ mySim ]
1110
p.run = 1
12-
p.maxEvents = 10000
13-
p.outputFiles = [ 'events.root' ]
11+
p.max_events = 10000
12+
p.output_files = [ 'events.root' ]
1413

15-
import LDMX.Ecal.EcalGeometry
14+
import LDMX.Ecal.ecal_geometry
1615
import LDMX.Ecal.ecal_hardcoded_conditions
17-
import LDMX.Hcal.HcalGeometry
16+
import LDMX.Hcal.hcal_geometry
1817
import LDMX.Ecal.digi as ecal_digi
1918

2019
p.sequence = [

src/using/analysis/ldmx-sw.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,15 @@ made within the function definitions.
135135
Look at the [documentation of the HistogramPool](https://ldmx-software.github.io/ldmx-sw/classframework_1_1HistogramPool.html)
136136
to see more examples of how to `create` and `fill` histograms.
137137
138+
~~~admonish note title="Missing Histograms" collapsible=true
139+
If the output histogram file you are writing to does not receive any histograms despite
140+
you following the above procedure, you are probably working with an older version of
141+
ldmx-sw. In v4.5.1 ldmx-sw and earlier, you needed to include `getHistoDirectory()`
142+
at the beginning of your `onProcessStart` function.
143+
~~~
144+
138145
In order to run this code on the data, we need to compile and run the program.
139-
The special `from_file` function within the config script handles this in
146+
The special `processor_from_file` function within the config script handles this in
140147
most situations for us.
141148
Below, you'll see that the analyzer is re-compiled into the library while
142149
`fire` is loading the configuration and then the analyzer is used during event processing.

src/using/config/config-basics.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,27 @@ Additional notes:
1717
python module so that the C++ class name, the module name, and any other parameters can be properly spelled once and used everywhere.
1818

1919
## Minimal Production Config
20-
In Production Mode, there won't be a `p.inputFiles` line but there will be a line setting `p.run` to some value.
20+
In Production Mode, there won't be a `p.input_files` line but there will be a line setting `p.run` to some value.
2121

2222
```python
2323
from LDMX.Framework import ldmxcfg
2424
p = ldmxcfg.Process('mypass')
25-
p.outputFiles = ['output_events.root']
25+
p.output_files = ['output_events.root']
2626
p.run = 1
2727
p.sequence = [
28-
ldmxcfg.Producer('my_producer','some::cpp::MyProducer','Module')
28+
ldmxcfg.make_processor('my_producer','some::cpp::MyProducer','Module')
2929
]
3030
```
3131

3232
## Minimal Reconstruction Config
33-
In Reconstruction Mode, there will be a `p.inputFiles` line but since `p.run` will be ignored it is often omitted.
33+
In Reconstruction Mode, there will be a `p.input_files` line but since `p.run` will be ignored it is often omitted.
3434

3535
```python
3636
from LDMX.Framework import ldmxcfg
3737
p = ldmxcfg.Process('myreco')
38-
p.inputFiles = ['input_events.root']
39-
p.outputFiles = ['rereco_input_events.root']
38+
p.input_files = ['input_events.root']
39+
p.output_files = ['rereco_input_events.root']
4040
p.sequence = [
41-
ldmxcfg.Producer('my_reco', 'some::cpp::MyReco', 'Module')
41+
ldmxcfg.make_processor('my_reco', 'some::cpp::MyReco', 'Module')
4242
]
4343
```

src/using/config/config-tips.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ args = parser.parse_args()
1717
from LDMX.Framework import ldmxcfg
1818
p = ldmxcfg.Process('example')
1919
p.run = args.run_number
20-
p.outputFile = [
20+
p.output_file = [
2121
str(args.out_dir / f'my_special_simulation_run_{p.run:04d}.root')
2222
]
2323
@@ -33,12 +33,12 @@ Python's [pathlib](https://docs.python.org/3/library/pathlib.html) library is he
3333
3434
For example, if `input_dir` is a `pathlib.Path` for an input directory of ROOT files.
3535
```python
36-
p.inputFiles = [ str(f) for f in input_dir.iterdir() if f.suffix == '.root' ]
36+
p.input_files = [ str(f) for f in input_dir.iterdir() if f.suffix == '.root' ]
3737
```
3838
3939
We can also use an input file `input_file` to get an output file name and an output directory `output_dir`
4040
to place this file in the directory we want.
4141
```python
42-
p.outputFiles = [ str(output_dir / (input_file.stem + '_with_my_analyzer.root')) ]
42+
p.output_files = [ str(output_dir / (input_file.stem + '_with_my_analyzer.root')) ]
4343
```
4444
~~~

src/using/config/event-skimming.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ what the default decision is in the case of no hints or a tie in voting.
3939

4040
### Listening Rules
4141
The format of the string representing a listening rule is a bit complicated, so it is best
42-
to just use the `p.skimConsider` function when defining which processors you wish to "listen"
42+
to just use the `p.skim_consider` function when defining which processors you wish to "listen"
4343
to (or "consider") when making a skimming decision. Most commonly, a user just has one processor
4444
that they want to make the skimming decision and in this case you can just provide the processors
4545
name.
4646
```python
47-
p.skimConsider(my_processor.instanceName)
47+
p.skim_consider(my_processor.instanceName)
4848
```
4949
Technically, the listening rules use regular expressions for both the processor name and the
5050
purpose, so one could get quite fancy about which processors (and purposes) are selected.
@@ -57,15 +57,15 @@ processors at all, the default configuration of the default decision is to keep
5757
any config changes, we keep all events that are processed. Without changing this,
5858
you could have a processor that explicity "drops" events and update the config to consider
5959
this processor in order to run over events and drop the "uninteresting" ones
60-
(using `p.skimConsider` like above).
60+
(using `p.skim_consider` like above).
6161

6262
On the other hand, we could set the default decision to drop all the events and instead
6363
have a processor specifically "keep" events that are interesting. In this case, you would
6464
want to add the following to your config.
6565
```python
66-
p.skimDefaultIsDrop()
66+
p.skim_default_is_drop()
6767
```
68-
**along with a `p.skimConsider`** so that something ends up in your output event file.
68+
**along with a `p.skim_consider`** so that something ends up in your output event file.
6969

7070
~~~admonish warning title="Another Form of Event Dropping"
7171
This style of event dropping is geared more towards readout, reconstruction, and analysis

src/using/config/intro.md

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ There are two processing modes that `fire` can run in which are defined by the p
3333
If there are no input data files, then `fire` is in _Production Mode_ while if there are input data files, then
3434
`fire` is in _Reconstruction Mode_. The names of these two modes originate from how `fire` is used in LDMX research.
3535

36-
[^1]: In this context, an "input data file" is a data file previously produced by `fire`. There can be other types of data that are "input" into `fire` but unless `fire` is actually treating those input files as a reference, `fire` is considered to be in "Production Mode". See the `inputFiles` configuration parameter below.
36+
[^1]: In this context, an "input data file" is a data file previously produced by `fire`. There can be other types of data that are "input" into `fire` but unless `fire` is actually treating those input files as a reference, `fire` is considered to be in "Production Mode". See the `input_files` configuration parameter below.
3737

3838
## The Process Object
3939

@@ -44,31 +44,44 @@ As an example, the pass name is `practice`, so the line which constructs the Pro
4444
p = ldmxcfg.Process("practice")
4545
```
4646

47+
~~~admonish warning title="Parameter Renames"
48+
As part of our drive to have better organized Python configuratin modules, we applied common
49+
Python linting and formatting rules to ldmx-sw. This led to many parameters being changed
50+
from `camelCase` to `snake_case` marked by the release of v4.6.0 of ldmx-sw.
51+
52+
If you are using a version of ldmx-sw prior to v4.6.0, then you will likely need to change
53+
any `snake_case` parameter name in this example to `camelCase` although that is not true
54+
in all cases.
55+
56+
The documentation written here does not necessarily fix this rename in all places.
57+
Please contribute if you find a place that needs to be updated!
58+
~~~
59+
4760
Here is a list of some of the most important process options and what they control.
4861
It is encouraged to browse the python modules themselves for all the details,
4962
but you can also call `help(ldmxcfg.Process)` in `python` to see the documentation.
5063

51-
- `passName` (string)
64+
- `pass_name` (string)
5265
- **required** Given in the constructor, tag for the process as a whole.
5366
- For example: `"10MeVSignal"` for a simulation of a 10MeV A'
5467
- `run` (integer)
5568
- Unique number identifying the run
5669
- For example: `9001`
5770
- Default is `0`
58-
- `maxEvents` (integer)
71+
- `max_events` (integer)
5972
- Maximum number of events to run for
6073
- Required for Production Mode (no input files)
6174
- In Reconstruction Mode, the number of events that are run is the number of events in the input files unless this parameter is positive and less than the input number.
6275
- For example: `9000`
63-
- `outputFiles` (list of strings)
76+
- `output_files` (list of strings)
6477
- List of files to output events to
6578
- Required to be exactly one for Production Mode, and either exactly one or exactly the number of input files in Reconstruction Mode.
6679
- For example: `[ "output.root" ]`
67-
- `inputFiles` (list of strings)
80+
- `input_files` (list of strings)
6881
- List of files to read events in from
6982
- Required if no output files are given
7083
- For example: `[ "input.root" ]`
71-
- `histogramFile` (string)
84+
- `histogram_file` (string)
7285
- Name of file to put histograms and ntuples in
7386
- For example: `"myHistograms.root"`
7487
- `sequence` (list of event processors)
@@ -79,19 +92,22 @@ but you can also call `help(ldmxcfg.Process)` in `python` to see the documentati
7992
- List of drop/keep rules to help ldmx-sw know which collections to put into output file(s)
8093
- Slightly complicated, see the [documentation of EventFile](https://ldmx-software.github.io/ldmx-sw/classframework_1_1EventFile.html)
8194
- For example: `[ "drop .*SimHits.*" , "keep Ecal.*" ]`
82-
- `skimDefaultIsKeep` (bool)
95+
- `skim_default_is_keep` (bool)
8396
- Should the process keep events unless told to drop by a processor?
8497
- Default is `True`: events will be kept unless processors use `setStorageHint`.
85-
- Use `skimDefaultIsDrop()` or `skimDefaultIsSave()` to modify
86-
- `skimRules` (list of strings)
98+
- Use `skim_default_is_drop()` or `skim_default_is_save()` to modify
99+
- `skim_rules` (list of strings)
87100
- List of processors to use to decide whether an event should be stored in the output file (along with the default given above).
88-
- Has a very specific format, use `skimConsider( processorName )` to modify
89-
- `processorName` is the _instance name_ and not the class name
101+
- Has a very specific format, use `skim_consider( processorName )` to modify
102+
- `processor_name` is the _instance name_ and not the class name
90103
- For example, the Ecal veto chooses whether an event should be kept or not depending on a lot of physics stuff. If you only want the events passing the veto to be saved, you would:
91104
```python
92-
p.skimDefaultIsDrop() #process should drop events unless specified otherwise
93-
p.skimConsider('ecalVeto') #process should listen to storage hints from ecalVeto
105+
p.skim_default_is_drop() #process should drop events unless specified otherwise
106+
p.skim_consider('ecalVeto') #process should listen to storage hints from ecalVeto
94107
```
95-
- `logFrequency` (int)
108+
- `log_frequency` (int)
96109
- How frequently should the processor tell you what event number it is on?
97110
- Default is `-1` which is never.
111+
- `logger.term_level` (int)
112+
- how severe messages should be before they are printed to the terminal
113+
- default is `2` which is warnings and above, the event number printing is at level `1` (info)

0 commit comments

Comments
 (0)