Code indexing in gitaly is broken and leads to code not being visible to the user. We work on the issue with highest priority.

Skip to content
Snippets Groups Projects
Commit f2ad55a4 authored by frey_m's avatar frey_m
Browse files

Proper inheritance + more like C++11.

parent ec22b6cd
No related branches found
No related tags found
1 merge request!33Master
...@@ -15,12 +15,16 @@ PartBins::PartBins(int bins, int sbins) : ...@@ -15,12 +15,16 @@ PartBins::PartBins(int bins, int sbins) :
hBin_m(0.0), hBin_m(0.0),
nemittedBins_m(0), nemittedBins_m(0),
nemittedSBins_m(0) { nemittedSBins_m(0) {
nBin_m = new size_t[bins_m]; // number of particles in the bins on the local node
xbinmin_m = new double[bins_m]; nBin_m = std::unique_ptr<size_t[]>(new size_t[bins_m]);
xbinmax_m = new double[bins_m]; xbinmin_m = std::unique_ptr<double[]>(new double[bins_m]);
binsEmitted_m = new bool[bins_m]; xbinmax_m = std::unique_ptr<double[]>(new double[bins_m]);
nDelBin_m = new size_t[bins_m];
// flag whether the bin contain particles or not
binsEmitted_m = std::unique_ptr<bool[]>(new bool[bins_m]);
nDelBin_m = std::unique_ptr<size_t[]>(new size_t[bins_m]);
for(int i = 0; i < bins_m; i++) { for(int i = 0; i < bins_m; i++) {
nDelBin_m[i] = nBin_m[i] = 0; nDelBin_m[i] = nBin_m[i] = 0;
...@@ -124,16 +128,8 @@ void PartBins::resetPartInBin_cyc(size_t newPartNum[], int maxbinIndex) { ...@@ -124,16 +128,8 @@ void PartBins::resetPartInBin_cyc(size_t newPartNum[], int maxbinIndex) {
PartBins::~PartBins() { PartBins::~PartBins() {
if(nBin_m) {
delete [] nBin_m;
delete [] xbinmax_m;
delete [] xbinmin_m;
delete [] binsEmitted_m;
}
tmppart_m.clear(); tmppart_m.clear();
isEmitted_m.clear(); isEmitted_m.clear();
} }
...@@ -228,7 +224,7 @@ Inform &PartBins::print(Inform &os) { ...@@ -228,7 +224,7 @@ Inform &PartBins::print(Inform &os) {
for(int i = 0; i < bins_m; i++) { for(int i = 0; i < bins_m; i++) {
size_t msum = 0; size_t msum = 0;
for(int j = 0; j < sBins_m; j++) for(int j = 0; j < sBins_m; j++)
msum += gsl_histogram_get(h_m, i * sBins_m + j); msum += gsl_histogram_get(h_m.get(), i * sBins_m + j);
os << "Bin # " << i << " val " << msum << endl; os << "Bin # " << i << " val " << msum << endl;
} }
......
...@@ -132,7 +132,7 @@ public: ...@@ -132,7 +132,7 @@ public:
void setGamma(double gamma) { gamma_m = gamma;} void setGamma(double gamma) { gamma_m = gamma;}
double getGamma() {return gamma_m;} double getGamma() {return gamma_m;}
private: protected:
double gamma_m; double gamma_m;
/** /**
...@@ -149,8 +149,8 @@ private: ...@@ -149,8 +149,8 @@ private:
double xmax_m; double xmax_m;
/** extremal particle position within the bins */ /** extremal particle position within the bins */
double *xbinmin_m; std::unique_ptr<double[]> xbinmin_m;
double *xbinmax_m; std::unique_ptr<double[]> xbinmax_m;
/** bin size */ /** bin size */
double hBin_m; double hBin_m;
...@@ -160,7 +160,7 @@ private: ...@@ -160,7 +160,7 @@ private:
std::vector< bool > isEmitted_m; std::vector< bool > isEmitted_m;
/** holds information whether all particles of a bin are emitted */ /** holds information whether all particles of a bin are emitted */
// std::vector< bool > binsEmitted_m; // std::vector< bool > binsEmitted_m;
bool *binsEmitted_m; std::unique_ptr<bool[]> binsEmitted_m;
/** /**
Here comes the new stuff, t-binning Here comes the new stuff, t-binning
...@@ -173,10 +173,10 @@ public: ...@@ -173,10 +173,10 @@ public:
int getSBins() { return sBins_m; }; int getSBins() { return sBins_m; };
/** get the number of used bin */ /** get the number of used bin */
virtual int getNBins() {return gsl_histogram_bins(h_m) / sBins_m; } virtual int getNBins() {return gsl_histogram_bins(h_m.get()) / sBins_m; }
/** Get the total number of sampled bins */ /** Get the total number of sampled bins */
virtual int getNSBins() {return gsl_histogram_bins(h_m); } virtual int getNSBins() {return gsl_histogram_bins(h_m.get()); }
int getBinToEmit() { int getBinToEmit() {
int save; int save;
...@@ -206,23 +206,21 @@ public: ...@@ -206,23 +206,21 @@ public:
/** \brief If the bunch object rebins we need to call resetBins() */ /** \brief If the bunch object rebins we need to call resetBins() */
void resetBins() { void resetBins() {
if(h_m) h_m.reset(nullptr);
delete h_m;
h_m = NULL;
} }
virtual bool weHaveBins() { virtual bool weHaveBins() {
return h_m != NULL; return h_m != nullptr;
} }
/** sort the vector of particles according to the bin number */ /** sort the vector of particles according to the bin number */
void sortArrayT(); void sortArrayT();
inline void setHistogram(gsl_histogram *h) { h_m = h;} inline void setHistogram(gsl_histogram *h) { h_m.reset(h);}
/** \brief How many particles are on one bin */ /** \brief How many particles are on one bin */
virtual inline size_t getGlobalBinCount(int bin) { virtual inline size_t getGlobalBinCount(int bin) {
size_t a = gsl_histogram_get(h_m, bin); size_t a = gsl_histogram_get(h_m.get(), bin);
reduce(a, a, OpAddAssign()); reduce(a, a, OpAddAssign());
return a; return a;
} }
...@@ -231,13 +229,13 @@ public: ...@@ -231,13 +229,13 @@ public:
inline size_t getLocalBinCount(int bin) { inline size_t getLocalBinCount(int bin) {
size_t ret = 0; size_t ret = 0;
for(int i = sBins_m * bin; i < sBins_m * (bin + 1); i++) { for(int i = sBins_m * bin; i < sBins_m * (bin + 1); i++) {
ret += gsl_histogram_get(h_m, i); ret += gsl_histogram_get(h_m.get(), i);
} }
return ret; return ret;
} }
/** \brief How many particles are in one sampling bin */ /** \brief How many particles are in one sampling bin */
inline size_t getLocalSBinCount(int bin) { return gsl_histogram_get(h_m, bin);} inline size_t getLocalSBinCount(int bin) { return gsl_histogram_get(h_m.get(), bin);}
/** \brief How many particles are in all the bins */ /** \brief How many particles are in all the bins */
...@@ -247,7 +245,7 @@ public: ...@@ -247,7 +245,7 @@ public:
size_t getTotalNumPerBin(int b); size_t getTotalNumPerBin(int b);
private: protected:
/** number of emitted bins */ /** number of emitted bins */
int nemittedBins_m; int nemittedBins_m;
...@@ -256,12 +254,12 @@ private: ...@@ -256,12 +254,12 @@ private:
int nemittedSBins_m; int nemittedSBins_m;
/** number of particles in the bins, the sum of all the nodes */ /** number of particles in the bins, the sum of all the nodes */
size_t *nBin_m; std::unique_ptr<size_t[]> nBin_m;
/** number of deleted particles in the bins */ /** number of deleted particles in the bins */
size_t *nDelBin_m; std::unique_ptr<size_t[]> nDelBin_m;
gsl_histogram *h_m; std::unique_ptr<gsl_histogram> h_m;
}; };
......
...@@ -6,56 +6,27 @@ extern Inform *gmsg; ...@@ -6,56 +6,27 @@ extern Inform *gmsg;
// constructer function for cyclotron // constructer function for cyclotron
PartBinsCyc::PartBinsCyc(int specifiedNumBins, int bins, size_t partInBin[]) PartBinsCyc::PartBinsCyc(int specifiedNumBins, int bins, size_t partInBin[])
: PartBins::PartBins(specifiedNumBins, 0) { : PartBins(specifiedNumBins, 0) {
bins_m = specifiedNumBins; // max bin number bins_m = specifiedNumBins; // max bin number
nemittedBins_m = bins; // the bin number with particles nemittedBins_m = bins; // the bin number with particles
binsEmitted_m = new bool[bins_m]; // flag whether the bin contain particles or not
nBin_m = new size_t[bins_m]; // number of particles in the bins on the local node
for(int i = 0; i < bins_m; i++) {
nBin_m[i] = 0;
binsEmitted_m[i] = false;
}
for(int i = 0; i < nemittedBins_m; i++) { for(int i = 0; i < nemittedBins_m; i++) {
nBin_m[i] = partInBin[i]; nBin_m[i] = partInBin[i];
*gmsg << "Read in: Bin=" << i << " Particles Num=" << getTotalNumPerBin(i) << endl; *gmsg << "Read in: Bin=" << i << " Particles Num=" << getTotalNumPerBin(i) << endl;
binsEmitted_m[i] = true; binsEmitted_m[i] = true;
} }
} }
// constructer function for cyclotron for restart run. // constructer function for cyclotron for restart run.
PartBinsCyc::PartBinsCyc(int specifiedNumBins, int bins) PartBinsCyc::PartBinsCyc(int specifiedNumBins, int bins)
: PartBins::PartBins(specifiedNumBins, 0) { : PartBins(specifiedNumBins, 0) {
bins_m = specifiedNumBins; // max bin number bins_m = specifiedNumBins; // max bin number
nemittedBins_m = bins; // the bin number with particles nemittedBins_m = bins; // the bin number with particles
binsEmitted_m = new bool[bins_m]; // flag whether the bin contain particles or not
nBin_m = new size_t[bins_m]; // number of particles in the bins on the local node
for(int i = 0; i < bins_m; i++) {
nBin_m[i] = 0;
binsEmitted_m[i] = false;
}
for(int i = 0; i < nemittedBins_m; i++) { for(int i = 0; i < nemittedBins_m; i++) {
binsEmitted_m[i] = true; binsEmitted_m[i] = true;
} }
} }
PartBinsCyc::~PartBinsCyc() {
if(nBin_m) {
delete nBin_m;
delete xbinmax_m;
delete xbinmin_m;
delete binsEmitted_m;
}
tmppart_m.clear();
isEmitted_m.clear();
if(h_m)
delete h_m;
}
...@@ -30,41 +30,12 @@ ...@@ -30,41 +30,12 @@
class PartBinsCyc: public PartBins { class PartBinsCyc: public PartBins {
private:
double gamma_m;
int getBin(double x);
int bins_m;
/** extremal particle positions */
double xmin_m;
double xmax_m;
/** extremal particle position within the bins */
double *xbinmin_m;
double *xbinmax_m;
/** bin size */
double hBin_m;
/** holds the particles not yet in the bunch */
std::vector< std::vector<double> > tmppart_m;
std::vector< bool > isEmitted_m;
/** holds information whether all particles of a bin are emitted */
// std::vector< bool > binsEmitted_m;
bool *binsEmitted_m;
public: public:
/** constructer function for cyclotron*/ /** constructer function for cyclotron*/
PartBinsCyc(int bunches, int bins, size_t partInBin[]); PartBinsCyc(int bunches, int bins, size_t partInBin[]);
PartBinsCyc(int specifiedNumBins, int bins); PartBinsCyc(int specifiedNumBins, int bins);
~PartBinsCyc();
/** get the number of used bin */ /** get the number of used bin */
int getNBins() {return bins_m; } int getNBins() {return bins_m; }
...@@ -79,20 +50,6 @@ public: ...@@ -79,20 +50,6 @@ public:
bool weHaveBins() { bool weHaveBins() {
return ( nemittedBins_m > 0 ); return ( nemittedBins_m > 0 );
} }
private:
/** number of emitted bins */
int nemittedBins_m;
/** number of particles in the bins, the sum of all the nodes */
size_t *nBin_m;
/** number of deleted particles in the bins */
size_t *nDelBin_m;
gsl_histogram *h_m;
}; };
#endif // OPAL_BinsCyc_HH #endif // OPAL_BinsCyc_HH
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment