Commit 8997fb4e authored by kraus's avatar kraus

replace all pointers to ElementBase with shared and weak pointers resp.

parent d7d4f1f1
......@@ -20,6 +20,8 @@
#include "AbstractObjects/Element.h"
#include <memory>
class Beamline;
......@@ -48,7 +50,7 @@ public:
/// Return the embedded CLASSIC beam line.
// The result it the ideal line.
virtual Beamline *fetchLine() const = 0;
virtual std::shared_ptr<Beamline> fetchLine() const = 0;
protected:
......@@ -68,4 +70,4 @@ private:
void operator=(const BeamSequence &);
};
#endif // OPAL_BeamSequence_HH
#endif // OPAL_BeamSequence_HH
\ No newline at end of file
......@@ -20,7 +20,9 @@
#include "AbstractObjects/Object.h"
#include "AbstractObjects/Expressions.h"
#include <vector>
#include <memory>
class Attribute;
class Beamline;
......@@ -113,7 +115,7 @@ public:
/// Return embedded CLASSIC beamline.
// Returns the CLASSIC beamline representing the table.
// The data of the table are attached to each position in the line.
virtual const Beamline *getLine() const = 0;
virtual std::shared_ptr<const Beamline> getLine() const = 0;
/// Return a table row.
// Returns the values stored in the row specified by the first argument,
......@@ -165,4 +167,4 @@ private:
void operator=(const Table &);
};
#endif // OPAL_Table_HH
#endif // OPAL_Table_HH
\ No newline at end of file
......@@ -605,7 +605,7 @@ void ParallelTTracker::computeExternalFields(OrbitThreader &oth) {
void ParallelTTracker::computeWakefield(IndexMap::value_t &elements) {
bool hasWake = false;
WakeFunction *wfInstance;
std::shared_ptr<WakeFunction> wfInstance;
Inform msg("ParallelTTracker ", *gmsg);
......@@ -640,7 +640,7 @@ void ParallelTTracker::computeWakefield(IndexMap::value_t &elements) {
if (!wakeStatus_m) {
msg << level2 << "============== START WAKE CALCULATION =============" << endl;
wfInstance->initialize((*it).get());
wfInstance->initialize(*it);
wakeStatus_m = true;
}
......@@ -677,7 +677,7 @@ void ParallelTTracker::computeWakefield(IndexMap::value_t &elements) {
void ParallelTTracker::computeParticleMatterInteraction(IndexMap::value_t elements, OrbitThreader &oth) {
Inform msg("ParallelTTracker ", *gmsg);
std::set<IndexMap::value_t::value_type> elementsWithParticleMatterInteraction;
std::set<ParticleMatterInteractionHandler*> particleMatterinteractionHandlers;
std::set<ParticleMatterInteractionHandler::SP> particleMatterinteractionHandlers;
std::pair<double, double> currentRange(0.0, 0.0);
while (elements.size() > 0) {
......@@ -698,8 +698,8 @@ void ParallelTTracker::computeParticleMatterInteraction(IndexMap::value_t elemen
}
if (elementsWithParticleMatterInteraction.size() > 0) {
std::set<ParticleMatterInteractionHandler*> oldSPHandlers;
std::vector<ParticleMatterInteractionHandler*> leftBehindSPHandlers, newSPHandlers;
std::set<ParticleMatterInteractionHandler::SP> oldSPHandlers;
std::vector<ParticleMatterInteractionHandler::SP> leftBehindSPHandlers, newSPHandlers;
for (auto it: activeParticleMatterInteractionHandlers_m) {
oldSPHandlers.insert(it);
}
......@@ -738,7 +738,7 @@ void ParallelTTracker::computeParticleMatterInteraction(IndexMap::value_t elemen
do {
///all particles in material if max per node is 2 and other degraders have 0 particles
//check if more than one degrader has particles
ParticleMatterInteractionHandler* onlyDegraderWithParticles = NULL;
ParticleMatterInteractionHandler::SP onlyDegraderWithParticles = NULL;
int degradersWithParticlesCount = 0;
for (auto it: activeParticleMatterInteractionHandlers_m) {
it->setFlagAllParticlesIn(false);
......@@ -979,7 +979,7 @@ void ParallelTTracker::writePhaseSpace(const long long /*step*/, bool psDump, bo
FieldList collimators = itsOpalBeamline_m.getElementByType(ElementBase::CCOLLIMATOR);
if (collimators.size() != 0) {
for (FieldList::iterator it = collimators.begin(); it != collimators.end(); ++ it) {
FlexibleCollimator* coll = static_cast<FlexibleCollimator*>(it->getElement().get());
std::shared_ptr<FlexibleCollimator> coll = std::static_pointer_cast<FlexibleCollimator>(it->getElement());
std::string name = coll->getName();
unsigned int losses = coll->getLosses();
collimatorLosses.push_back(std::make_pair(name, losses));
......@@ -1216,7 +1216,7 @@ void ParallelTTracker::autophaseCavities(const BorisPusher &pusher) {
auto elementSet = itsOpalBeamline_m.getElements(nextR);
for (auto element: elementSet) {
if (element->getType() == ElementBase::TRAVELINGWAVE) {
const TravelingWave *TWelement = static_cast<const TravelingWave *>(element.get());
std::shared_ptr<const TravelingWave> TWelement = std::static_pointer_cast<const TravelingWave>(element);
if (!TWelement->getAutophaseVeto()) {
CavityAutophaser ap(itsReference, element);
ap.getPhaseAtMaxEnergy(itsOpalBeamline_m.transformToLocalCS(element, itsBunch_m->RefPartR_m),
......@@ -1225,7 +1225,7 @@ void ParallelTTracker::autophaseCavities(const BorisPusher &pusher) {
}
} else if (element->getType() == ElementBase::RFCAVITY) {
const RFCavity *RFelement = static_cast<const RFCavity *>(element.get());
std::shared_ptr<const RFCavity> RFelement = std::static_pointer_cast<const RFCavity>(element);
if (!RFelement->getAutophaseVeto()) {
CavityAutophaser ap(itsReference, element);
ap.getPhaseAtMaxEnergy(itsOpalBeamline_m.transformToLocalCS(element, itsBunch_m->RefPartR_m),
......
......@@ -63,6 +63,7 @@
#include <list>
#include <vector>
#include <memory>
class ParticleMatterInteractionHandler;
......@@ -205,7 +206,7 @@ private:
bool deletedParticles_m;
WakeFunction* wakeFunction_m;
std::shared_ptr<WakeFunction> wakeFunction_m;
double pathLength_m;
......@@ -242,7 +243,7 @@ private:
IpplTimings::TimerRef BinRepartTimer_m;
IpplTimings::TimerRef WakeFieldTimer_m;
std::set<ParticleMatterInteractionHandler*> activeParticleMatterInteractionHandlers_m;
std::set<std::shared_ptr<ParticleMatterInteractionHandler>> activeParticleMatterInteractionHandlers_m;
bool particleMatterStatus_m;
unsigned long totalParticlesInSimulation_m;
......
......@@ -69,7 +69,7 @@ BeamStripping::BeamStripping(const BeamStripping &right):
maxr_m(right.maxr_m),
minz_m(right.minz_m),
maxz_m(right.maxz_m),
parmatint_m(NULL) {
parmatint_m(nullptr) {
}
BeamStripping::BeamStripping(const std::string &name):
......@@ -84,7 +84,7 @@ BeamStripping::BeamStripping(const std::string &name):
maxr_m(0.0),
minz_m(0.0),
maxz_m(0.0),
parmatint_m(NULL) {
parmatint_m(nullptr) {
}
......@@ -166,7 +166,7 @@ bool BeamStripping::getStop() const {
}
bool BeamStripping::checkBeamStripping(PartBunchBase<double, 3> *bunch, std::shared_ptr<Cyclotron> cycl,
bool BeamStripping::checkBeamStripping(PartBunchBase<double, 3> *bunch, std::shared_ptr<Cyclotron> const& cycl,
const int /*turnnumber*/, const double /*t*/, const double /*tstep*/) {
bool flagNeedUpdate = false;
......@@ -190,7 +190,7 @@ bool BeamStripping::checkBeamStripping(PartBunchBase<double, 3> *bunch, std::sha
}
reduce(&flagNeedUpdate, &flagNeedUpdate + 1, &flagNeedUpdate, OpBitwiseOrAssign());
if (flagNeedUpdate && parmatint_m) {
dynamic_cast<BeamStrippingPhysics*>(parmatint_m)->setCyclotron(cycl);
std::dynamic_pointer_cast<BeamStrippingPhysics>(parmatint_m)->setCyclotron(cycl);
parmatint_m->apply(bunch, boundingSphere);
}
return flagNeedUpdate;
......
......@@ -27,9 +27,11 @@
#include <string>
#include <vector>
#include <memory>
class BeamlineVisitor;
class Cyclotron;
class ParticleMatterInteractionHandler;
struct PFieldData {
std::string filename;
......@@ -77,7 +79,7 @@ public:
/// Apply visitor to BeamStripping.
virtual void accept(BeamlineVisitor &) const;
virtual bool checkBeamStripping(PartBunchBase<double, 3> *bunch, std::shared_ptr<Cyclotron> cycl, const int turnnumber, const double t, const double tstep);
virtual bool checkBeamStripping(PartBunchBase<double, 3> *bunch, std::shared_ptr<Cyclotron> const& cycl, const int turnnumber, const double t, const double tstep);
virtual void initialise(PartBunchBase<double, 3> *bunch, double &startField, double &endField);
......@@ -145,7 +147,7 @@ private:
double maxz_m; /// mm
///@}
ParticleMatterInteractionHandler *parmatint_m;
std::shared_ptr<ParticleMatterInteractionHandler> parmatint_m;
protected:
// object of Matrices including pressure field map and its derivates
......
......@@ -20,6 +20,8 @@
#include "AbsBeamline/PluginElement.h"
#include <memory>
class ParticleMatterInteractionHandler;
class CCollimator: public PluginElement {
......@@ -83,7 +85,7 @@ private:
///@}
double rmax_m; ///< maximum extend in r
ParticleMatterInteractionHandler *parmatint_m = nullptr;
std::shared_ptr<ParticleMatterInteractionHandler> parmatint_m = nullptr;
};
inline
......@@ -100,4 +102,4 @@ inline
double CCollimator::getWidth() {
return width_m;
}
#endif // CLASSIC_CCollimator_HH
#endif // CLASSIC_CCollimator_HH
\ No newline at end of file
......@@ -151,7 +151,7 @@ Channel *ElementBase::getChannel(const std::string &aKey, bool create) {
const ConstChannel *ElementBase::getConstChannel(const std::string &aKey) const {
// Use const_cast to allow calling the non-const method GetChannel().
// The const return value of this method will nevertheless inhibit set().
return const_cast<ElementBase *>(this)->getChannel(aKey);
return const_cast<ElementBase * >(this)->getChannel(aKey);
}
......@@ -310,15 +310,15 @@ bool ElementBase::update(const AttributeSet &set) {
return true;
}
void ElementBase::setWake(WakeFunction *wk) {
wake_m = wk;//->clone(getName() + std::string("_wake")); }
void ElementBase::setWake(std::shared_ptr<WakeFunction> const& wf) {
wake_m = wf;
}
void ElementBase::setBoundaryGeometry(BoundaryGeometry *geo) {
bgeometry_m = geo;//->clone(getName() + std::string("_wake")); }
}
void ElementBase::setParticleMatterInteraction(ParticleMatterInteractionHandler *parmatint) {
void ElementBase::setParticleMatterInteraction(std::shared_ptr<ParticleMatterInteractionHandler> const& parmatint) {
parmatint_m = parmatint;
}
......
......@@ -399,16 +399,16 @@ public:
/// attach a wake field to the element
virtual void setWake(WakeFunction *wf);
virtual void setWake(std::shared_ptr<WakeFunction> const& wf);
/// return the attached wake object if there is any
virtual WakeFunction *getWake() const;
virtual std::shared_ptr<WakeFunction> getWake() const;
virtual bool hasWake() const;
virtual void setParticleMatterInteraction(ParticleMatterInteractionHandler *spys);
virtual void setParticleMatterInteraction(std::shared_ptr<ParticleMatterInteractionHandler> const& spys);
virtual ParticleMatterInteractionHandler *getParticleMatterInteraction() const;
virtual std::shared_ptr<ParticleMatterInteractionHandler> getParticleMatterInteraction() const;
virtual bool hasParticleMatterInteraction() const;
......@@ -466,11 +466,11 @@ private:
// The user-defined set of attributes.
AttributeSet userAttribs;
WakeFunction *wake_m;
std::shared_ptr<WakeFunction> wake_m;
BoundaryGeometry *bgeometry_m;
ParticleMatterInteractionHandler *parmatint_m;
std::shared_ptr<ParticleMatterInteractionHandler> parmatint_m;
bool positionIsFixed;
///@{ ELEMEDGE attribute
......@@ -541,12 +541,12 @@ bool ElementBase::isSharable() const
{ return shareFlag; }
inline
WakeFunction *ElementBase::getWake() const
std::shared_ptr<WakeFunction> ElementBase::getWake() const
{ return wake_m; }
inline
bool ElementBase::hasWake() const
{ return wake_m != NULL; }
{ return wake_m != nullptr; }
inline
BoundaryGeometry *ElementBase::getBoundaryGeometry() const
......@@ -557,12 +557,12 @@ bool ElementBase::hasBoundaryGeometry() const
{ return bgeometry_m != NULL; }
inline
ParticleMatterInteractionHandler *ElementBase::getParticleMatterInteraction() const
std::shared_ptr<ParticleMatterInteractionHandler> ElementBase::getParticleMatterInteraction() const
{ return parmatint_m; }
inline
bool ElementBase::hasParticleMatterInteraction() const
{ return parmatint_m != NULL; }
{ return parmatint_m != nullptr; }
inline
void ElementBase::setCSTrafoGlobal2Local(const CoordinateSystemTrafo &trafo)
......
......@@ -80,7 +80,7 @@ private:
unsigned int losses_m;
std::unique_ptr<LossDataSink> lossDs_m;
ParticleMatterInteractionHandler *parmatint_m;
std::shared_ptr<ParticleMatterInteractionHandler> parmatint_m;
};
inline
......@@ -108,4 +108,4 @@ std::string FlexibleCollimator::getDescription() const {
return description_m;
}
#endif // CLASSIC_FlexibleCollimator_HH
#endif // CLASSIC_FlexibleCollimator_HH
\ No newline at end of file
......@@ -25,7 +25,7 @@
// Class Integrator
// ------------------------------------------------------------------------
Integrator::Integrator(ElementBase *elem):
Integrator::Integrator(ElementBase::SP const& elem):
ElementBase(elem->getName()), itsElement(elem)
{}
......@@ -42,4 +42,4 @@ Integrator::~Integrator()
void Integrator::makeSharable() {
shareFlag = true;
itsElement->makeSharable();
}
}
\ No newline at end of file
......@@ -42,12 +42,12 @@ class Integrator: public ElementBase {
public:
explicit Integrator(ElementBase *);
explicit Integrator(ElementBase::SP const& );
Integrator(const Integrator &rhs);
virtual ~Integrator();
/// Return the embedded element.
inline ElementBase *getElement() const;
inline ElementBase::SP getElement() const;
/// Set sharable flag.
// The whole structure depending on [b]this[/b] is marked as sharable.
......@@ -81,7 +81,7 @@ public:
protected:
/// Pointer to the replaced element.
Pointer<ElementBase> itsElement;
ElementBase::SP itsElement;
private:
......@@ -94,8 +94,8 @@ private:
// Implementation.
// ------------------------------------------------------------------------
inline ElementBase *Integrator::getElement() const {
return &*itsElement;
inline ElementBase::SP Integrator::getElement() const {
return itsElement;
}
#endif // CLASSIC_Integrator_HH
#endif // CLASSIC_Integrator_HH
\ No newline at end of file
......@@ -33,7 +33,7 @@ ElmPtr::ElmPtr(const ElmPtr &rhs):
{}
ElmPtr::ElmPtr(ElementBase *elem):
ElmPtr::ElmPtr(ElementBase::SP const& elem):
itsElement(elem)
{}
......@@ -44,4 +44,4 @@ ElmPtr::~ElmPtr()
void ElmPtr::accept(BeamlineVisitor &visitor) const {
itsElement->accept(visitor);
}
}
\ No newline at end of file
......@@ -35,7 +35,7 @@ public:
ElmPtr();
ElmPtr(const ElmPtr &);
ElmPtr(ElementBase *);
ElmPtr(ElementBase::SP const& );
virtual ~ElmPtr();
/// Apply visitor.
......
......@@ -20,10 +20,11 @@
//
// ------------------------------------------------------------------------
#include "AbsBeamline/Definition.h"
#include <string>
#include <memory>
class ElementBase;
class AttributeSet;
......@@ -42,7 +43,7 @@ public:
// The element [b]newElement[/b] is linked to the repository.
// If an element with the same name exists already, replacement is
// rejected, and [b]newElement[/b] is deleted.
virtual bool define(ElementBase *newElement) = 0;
virtual bool define(ElementBaseSP const& newElement) = 0;
/// Erase element by name.
// If there is no element with the given [b]name[/b],
......
......@@ -13,8 +13,8 @@
#include <fstream>
#include <cmath>
CSRIGFWakeFunction::CSRIGFWakeFunction(const std::string &name, ElementBase *element, std::vector<Filter *> filters, const unsigned int &N):
WakeFunction(name, element, N),
CSRIGFWakeFunction::CSRIGFWakeFunction(const std::string &name, std::vector<Filter *> filters, const unsigned int &N):
WakeFunction(name, N),
filters_m(filters.begin(), filters.end()),
lineDensity_m(),
dlineDensitydz_m(),
......@@ -106,11 +106,11 @@ void CSRIGFWakeFunction::apply(PartBunchBase<double, 3> *bunch) {
}
}
void CSRIGFWakeFunction::initialize(const ElementBase *ref) {
void CSRIGFWakeFunction::initialize(ElementBase::ConstSP const& ref) {
if (ref->getType() == ElementBase::RBEND ||
ref->getType() == ElementBase::SBEND) {
const Bend2D *bend = static_cast<const Bend2D *>(ref);
std::shared_ptr<const Bend2D> bend = std::static_pointer_cast<const Bend2D>(ref);
double End;
bendRadius_m = bend->getBendRadius();
......
......@@ -2,21 +2,21 @@
#define CSRIGFWAKEFUNCTION_HH
#include "Solvers/WakeFunction.hh"
#include "AbsBeamline/Definition.h"
#include <memory>
#include <vector>
#include <string>
class Filter;
class ElementBase;
class CSRIGFWakeFunction: public WakeFunction {
public:
CSRIGFWakeFunction(const std::string &name, ElementBase *element, std::vector<Filter *> filters, const unsigned int &N);
CSRIGFWakeFunction(const std::string &name, std::vector<Filter *> filters, const unsigned int &N);
void apply(PartBunchBase<double, 3> *bunch);
void initialize(const ElementBase * ref);
void initialize(ElementBaseConstSP const& ref);
virtual const std::string getType() const;
......
......@@ -15,8 +15,8 @@
#include <cmath>
CSRWakeFunction::CSRWakeFunction(const std::string &name, ElementBase *element, std::vector<Filter *> filters, const unsigned int &N):
WakeFunction(name, element, N),
CSRWakeFunction::CSRWakeFunction(const std::string &name, std::vector<Filter *> filters, const unsigned int &N):
WakeFunction(name, N),
filters_m(filters.begin(), filters.end()),
lineDensity_m(),
dlineDensitydz_m(),
......@@ -112,11 +112,11 @@ void CSRWakeFunction::apply(PartBunchBase<double, 3> *bunch) {
}
}
void CSRWakeFunction::initialize(const ElementBase *ref) {
void CSRWakeFunction::initialize(ElementBase::ConstSP const& ref) {
if (ref->getType() == ElementBase::RBEND ||
ref->getType() == ElementBase::SBEND) {
const Bend2D *bend = static_cast<const Bend2D *>(ref);
std::shared_ptr<const Bend2D> bend = std::static_pointer_cast<const Bend2D>(ref);
double End;
bendRadius_m = bend->getBendRadius();
......
......@@ -2,21 +2,21 @@
#define CSRWAKEFUNCTION_HH
#include "Solvers/WakeFunction.hh"
#include "AbsBeamline/Definition.h"
#include <memory>
#include <vector>
#include <string>
class Filter;
class ElementBase;
class CSRWakeFunction: public WakeFunction {
public:
CSRWakeFunction(const std::string &name, ElementBase *element, std::vector<Filter *> filters, const unsigned int &N);
CSRWakeFunction(const std::string &name, std::vector<Filter *> filters, const unsigned int &N);
void apply(PartBunchBase<double, 3> *bunch);
void initialize(const ElementBase * ref);
void initialize(ElementBaseConstSP const& ref);
virtual const std::string getType() const;
......
......@@ -31,43 +31,48 @@
#include <algorithm>
namespace {
bool myCompF(PART x, PART y) {
return x.label > y.label;
}
struct DegraderInsideTester: public InsideTester {
explicit DegraderInsideTester(ElementBase * el) {
deg_m = static_cast<Degrader*>(el);
explicit DegraderInsideTester(ElementBase::WP const& el) {
deg_m = std::static_pointer_cast<Degrader>(el.lock());
}
virtual
bool checkHit(const Vector_t &R, const Vector_t &/*P*/, double /*dt*/) override {
return deg_m->isInMaterial(R(2));
return deg_m.lock()->isInMaterial(R(2));
}
private:
Degrader *deg_m;
std::weak_ptr<Degrader> deg_m;
};
struct CollimatorInsideTester: public InsideTester {
explicit CollimatorInsideTester(ElementBase * el) {
col_m = static_cast<CCollimator*>(el);
explicit CollimatorInsideTester(ElementBase::WP const& el) {
col_m = std::static_pointer_cast<CCollimator>(el.lock());
}
virtual
bool checkHit(const Vector_t &R, const Vector_t &/*P*/, double /*dt*/) override {
return col_m->checkPoint(R(0), R(1));
return col_m.lock()->checkPoint(R(0), R(1));
}
private:
CCollimator *col_m;
std::weak_ptr<CCollimator> col_m;
};
struct FlexCollimatorInsideTester: public InsideTester {
explicit FlexCollimatorInsideTester(ElementBase * el) {
col_m = static_cast<FlexibleCollimator*>(el);
explicit FlexCollimatorInsideTester(ElementBase::WP const& el) {
col_m = std::static_pointer_cast<FlexibleCollimator>(el.lock());
}
virtual
bool checkHit(const Vector_t &R, const Vector_t &P, double dt) override {
return col_m->isStopped(R, P, Physics::c * dt / sqrt(1.0 + dot(P, P)));
return col_m.lock()->isStopped(R, P, Physics::c * dt / sqrt(1.0 + dot(P, P)));
}
private:
FlexibleCollimator *col_m;
std::weak_ptr<FlexibleCollimator> col_m;
};
}
......@@ -117,13 +122,13 @@ CollimatorPhysics::CollimatorPhysics(const std::string &name,
collshape_m = element_ref_m.lock()->getType();
switch (collshape_m) {
case ElementBase::DEGRADER:
hitTester_m.reset(new DegraderInsideTester(element_ref_m));
hitTester_m.reset(new DegraderInsideTester(element_ref_m.lock()));
break;
case ElementBase::CCOLLIMATOR:
hitTester_m.reset(new CollimatorInsideTester(element_ref_m));
hitTester_m.reset(new CollimatorInsideTester(element_ref_m.lock()));
break;
case ElementBase::FLEXIBLECOLLIMATOR:
hitTester_m.reset(new FlexCollimatorInsideTester(element_ref_m));
hitTester_m.reset(new FlexCollimatorInsideTester(element_ref_m.lock()));
break;
default:
throw OpalException("CollimatorPhysics::CollimatorPhysics",
......@@ -565,7 +570,7 @@ bool CollimatorPhysics::stillAlive(PartBunchBase<double, 3> *bunch) {
//free GPU memory in case element is degrader, it is empty and bunch has moved past it
if (collshape_m == ElementBase::DEGRADER && totalPartsInMat_m == 0) {
Degrader *deg = static_cast<Degrader *>(element_ref_m);
std::shared_ptr<Degrader> deg = std::static_pointer_cast<Degrader>(element_ref_m.lock());
//get the size of the degrader
double zBegin, zEnd;
......@@ -584,12 +589,6 @@ bool CollimatorPhysics::stillAlive(PartBunchBase<double, 3> *bunch) {
}
namespace {
bool myCompF(PART x, PART y) {
return x.label > y.label;
}