OpalProbe.cpp 3.68 KB
Newer Older
gsell's avatar
gsell committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
// ------------------------------------------------------------------------
// $RCSfile: OpalProbe.cpp,v $
// ------------------------------------------------------------------------
// $Revision: 1.1.1.1 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
//
// Class: OpalProbe
//   The class of OPAL Probes.
//
// ------------------------------------------------------------------------
//
// $Date: 2009/10/07 10:06:06 $
// $Author: bi $
//
// ------------------------------------------------------------------------

#include "Elements/OpalProbe.h"
#include "AbstractObjects/Attribute.h"
#include "Attributes/Attributes.h"
#include "BeamlineCore/ProbeRep.h"
#include "Structure/OpalWake.h"
#include "Physics/Physics.h"


// Class OpalProbe
// ------------------------------------------------------------------------

OpalProbe::OpalProbe():
    OpalElement(SIZE, "PROBE",
                "The \"PROBE\" element defines a Probe."),
33
    owk_m(nullptr) {
gsell's avatar
gsell committed
34 35

    itsAttr[XSTART] = Attributes::makeReal
36
                      ("XSTART", " Start of x coordinate [mm]");
gsell's avatar
gsell committed
37
    itsAttr[XEND] = Attributes::makeReal
38
                    ("XEND", " End of x coordinate [mm]");
gsell's avatar
gsell committed
39
    itsAttr[YSTART] = Attributes::makeReal
40
                      ("YSTART", "Start of y coordinate [mm]");
gsell's avatar
gsell committed
41 42 43
    itsAttr[YEND1] = Attributes::makeReal
                     ("YEND1", "Not used now");
    itsAttr[YEND] = Attributes::makeReal
44
                    ("YEND", "End of y coordinate [mm]");
gsell's avatar
gsell committed
45
    itsAttr[WIDTH] = Attributes::makeReal
46 47 48
                     ("WIDTH", "Width of the probe, not used.");
    itsAttr[STEP] = Attributes::makeReal
                     ("STEP", "Step size of the probe [mm]", 1.0);
gsell's avatar
gsell committed
49 50 51 52 53 54 55

    registerRealAttribute("XSTART");
    registerRealAttribute("XEND");
    registerRealAttribute("YSTART");
    registerRealAttribute("YEND1");
    registerRealAttribute("YEND");
    registerRealAttribute("WIDTH");
56
    registerRealAttribute("STEP");
gsell's avatar
gsell committed
57

58 59
    registerOwnership();

gsell's avatar
gsell committed
60 61 62 63
    setElement((new ProbeRep("PROBE"))->makeAlignWrapper());
}


64
OpalProbe::OpalProbe(const std::string &name, OpalProbe *parent):
gsell's avatar
gsell committed
65
    OpalElement(name, parent),
66
    owk_m(nullptr) {
gsell's avatar
gsell committed
67 68 69 70 71
    setElement((new ProbeRep(name))->makeAlignWrapper());
}


OpalProbe::~OpalProbe() {
72
    delete owk_m;
gsell's avatar
gsell committed
73 74 75
}


76
OpalProbe *OpalProbe::clone(const std::string &name) {
gsell's avatar
gsell committed
77 78 79 80 81 82 83 84 85 86 87
    return new OpalProbe(name, this);
}


void OpalProbe::fillRegisteredAttributes(const ElementBase &base, ValueFlag flag) {
    OpalElement::fillRegisteredAttributes(base, flag);

}


void OpalProbe::update() {
88 89
    OpalElement::update();

gsell's avatar
gsell committed
90 91 92 93
    ProbeRep *prob =
        dynamic_cast<ProbeRep *>(getElement()->removeWrappers());
    double length = Attributes::getReal(itsAttr[LENGTH]);
    double xstart = Attributes::getReal(itsAttr[XSTART]);
94
    double xend   = Attributes::getReal(itsAttr[XEND]);
gsell's avatar
gsell committed
95
    double ystart = Attributes::getReal(itsAttr[YSTART]);
96 97 98 99
    double yend1  = Attributes::getReal(itsAttr[YEND1]);
    double yend   = Attributes::getReal(itsAttr[YEND]);
    double width  = Attributes::getReal(itsAttr[WIDTH]);
    double step   = Attributes::getReal(itsAttr[STEP]);
gsell's avatar
gsell committed
100

101
    if(itsAttr[WAKEF] && owk_m == nullptr) {
102
        owk_m = (OpalWake::find(Attributes::getString(itsAttr[WAKEF])))->clone(getOpalName() + std::string("_wake"));
gsell's avatar
gsell committed
103 104 105 106 107 108 109 110 111 112
        owk_m->initWakefunction(*prob);
        prob->setWake(owk_m->wf_m);
    }
    prob->setElementLength(length);
    prob->setXstart(xstart);
    prob->setXend(xend);
    prob->setYstart(ystart);
    prob->setYend(yend1);
    prob->setYend(yend);
    prob->setWidth(width);
113
    prob->setStep(step);
gsell's avatar
gsell committed
114 115 116

    // Transmit "unknown" attributes.
    OpalElement::updateUnknown(prob);
117
}