BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
region.h
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) BDSIM Collaboration, 2001 - 2026.
3
4This file is part of BDSIM.
5
6BDSIM is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published
8by the Free Software Foundation version 3 of the License.
9
10BDSIM is distributed in the hope that it will be useful, but
11WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
17*/
18#ifndef REGION_H
19#define REGION_H
20
21#include <iomanip>
22#include <iostream>
23#include <string>
24
25#include "published.h"
26
27namespace GMAD
28{
34 class Region: public Published<Region>
35 {
36 public:
37 std::string name;
38
39 double defaultRangeCut;
40 double prodCutPhotons;
41 double prodCutElectrons;
42 double prodCutPositrons;
43 double prodCutProtons;
44
46 Region();
48 void clear();
50 void print()const;
52 template <typename T>
53 void set_value(std::string property, T value, bool bExit = true);
54
55 private:
57 void PublishMembers();
58 };
59
60 template <typename T>
61 void Region::set_value(std::string property, T value, bool bExit)
62 {
63#ifdef BDSDEBUG
64 std::cout << "region> Setting value " << std::setw(25) << std::left << property << value << std::endl;
65#endif
66 // member method can throw runtime_error, catch and exit gracefully
67 try
68 {set(this,property,value);}
69 catch(const std::runtime_error&)
70 {
71 std::cerr << "Error: region> unknown option \"" << property << "\" with value \"" << value << "\"" << std::endl;
72 if (bExit)
73 {exit(1);}
74 else
75 {std::rethrow_exception(std::current_exception());} // to be caught by python
76 }
77 }
78}
79
80#endif
Class that provides introspection to its members.
Definition published.h:48
void set(Region *instance, const std::string &name, double value)
Definition published.h:100
Region class for parser.
Definition region.h:35
void clear()
reset
Definition region.cc:28
std::string name
name
Definition region.h:37
void print() const
print some properties
Definition region.cc:50
void PublishMembers()
publish members
Definition region.cc:40
Region()
constructor
Definition region.cc:22
void set_value(std::string property, T value, bool bExit=true)
set methods by property name and value
Definition region.h:61
Parser namespace for GMAD language. Combination of Geant4 and MAD.