OPAL (Object Oriented Parallel Accelerator Library) 2024.2
OPAL
OpalFlexibleCollimator.cpp
Go to the documentation of this file.
1//
2// Class OpalFlexibleCollimator
3// The Flexible Collimator element.
4//
5// Copyright (c) 200x - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
6// All rights reserved
7//
8// This file is part of OPAL.
9//
10// OPAL is free software: you can redistribute it and/or modify
11// it under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// You should have received a copy of the GNU General Public License
16// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
17//
19
24
25#include <fstream>
26#include <iterator>
27#include <regex>
28#include <string>
29#include <typeinfo>
30
32 OpalElement(SIZE, "FLEXIBLECOLLIMATOR",
33 "The \"FLEXIBLECOLLIMATOR\" element defines a flexible collimator."),
34 parmatint_m(nullptr) {
36 ("FNAME", "File name containing description of holes");
38 ("DESCRIPTION", "String describing the distribution of holes");
40 ("DUMP", "Save quadtree and holes of collimator", false);
42
43 setElement(new FlexibleCollimatorRep("FLEXIBLECOLLIMATOR"));
44}
45
46
48 OpalElement(name, parent),
49 parmatint_m(nullptr) {
51}
52
53
58
59
63
64
67
69 dynamic_cast<FlexibleCollimatorRep*>(getElement());
70
71 double length = Attributes::getReal(itsAttr[LENGTH]);
72 coll->setElementLength(length);
73
74 std::string fname = Attributes::getString(itsAttr[FNAME]);
75 std::string desc = Attributes::getString(itsAttr[DESC]);
76 if (!fname.empty()) {
77 std::ifstream it(fname);
78 std::string str((std::istreambuf_iterator<char>(it)),
79 std::istreambuf_iterator<char>());
80
81 str = std::regex_replace(str,std::regex("//.*?\\n"), std::string(""), std::regex_constants::match_default |std::regex_constants::format_default);
82 str = std::regex_replace(str,std::regex("\\s"), std::string(""), std::regex_constants::match_default |std::regex_constants::format_default);
83
84 coll->setDescription(str);
85 } else if (!desc.empty()) {
86 desc = std::regex_replace(desc,std::regex("[\\t ]"), std::string(""), std::regex_constants::match_default |std::regex_constants::format_default);
87 coll->setDescription(desc);
88 } else if (getOpalName() != "FLEXIBLECOLLIMATOR") {
89 throw OpalException("OpalFlexibleCollimator::update",
90 "A description for the holes has to be provided, either using DESCRIPTION or FNAME");
91 }
93
95 const std::string matterDescriptor = Attributes::getString(itsAttr[PARTICLEMATTERINTERACTION]);
97 parmatint_m = orig->clone(matterDescriptor);
100 }
101
104 }
105
106 // Transmit "unknown" attributes.
108}
@ SIZE
Definition IndexMap.cpp:174
const std::string name
Attribute makeBool(const std::string &name, const std::string &help)
Make logical attribute.
double getReal(const Attribute &attr)
Return real value.
bool getBool(const Attribute &attr)
Return logical value.
std::string getString(const Attribute &attr)
Get string value.
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
ElementBase * getElement() const
Return the embedded CLASSIC element.
Definition Element.h:120
void setElement(ElementBase *)
Assign new CLASSIC element.
Definition Element.h:125
const std::string & getOpalName() const
Return object name.
Definition Object.cpp:310
std::vector< Attribute > itsAttr
The object attributes.
Definition Object.h:216
virtual void setElementLength(double length)
Set design length.
void setOutputFN(std::string fn)
Set output filename.
virtual void setParticleMatterInteraction(ParticleMatterInteractionHandler *spys)
void setDescription(const std::string &desc)
void writeHolesAndQuadtree(const std::string &baseFilename) const
@ PARTICLEMATTERINTERACTION
Definition OpalElement.h:42
virtual void updateUnknown(ElementBase *)
Transmit the `‘unknown’' (not known to OPAL) attributes to CLASSIC.
virtual void update()
Update the embedded CLASSIC element.
void registerOwnership() const
virtual OpalFlexibleCollimator * clone(const std::string &name)
Make clone.
virtual void update()
Update the embedded CLASSIC collimator.
OpalFlexibleCollimator()
Exemplar constructor.
ParticleMatterInteraction * parmatint_m
virtual ParticleMatterInteraction * clone(const std::string &name)
Make clone.
static ParticleMatterInteraction * find(const std::string &name)
Find named PARTICLEMATTERINTERACTION.
ParticleMatterInteractionHandler * handler_m
void initParticleMatterInteractionHandler(ElementBase &element)
The base class for all OPAL exceptions.