Commit 632549c9 authored by ext-calvo_p's avatar ext-calvo_p

Merge branch '657-element-output-files-must-not-be-overwritten' into 'master'

Resolve "Element output files must not be overwritten"

Closes #657

See merge request !503
parents 759529cb c6f4883c
This diff is collapsed.
#ifndef OPAL_OpalData_HH
#define OPAL_OpalData_HH
// ------------------------------------------------------------------------
// $RCSfile: OpalData.h,v $
// ------------------------------------------------------------------------
// $Revision: 1.1.1.1.4.2 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
//
// Class: OpalData
// Class OpalData
// The global OPAL structure.
// The OPAL object holds all global data required for a OPAL execution.
// In particular it contains the main Directory, which allows retrieval
// of command objects by their name. For other data refer to the
// implementation file.
//
// ------------------------------------------------------------------------
// Copyright (c) 200x - 2021, Paul Scherrer Institut, Villigen PSI, Switzerland
// All rights reserved
//
// $Date: 2004/11/12 20:10:11 $
// $Author: adelmann $
// This file is part of OPAL.
//
// ------------------------------------------------------------------------
// OPAL is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// You should have received a copy of the GNU General Public License
// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
//
#ifndef OPAL_OpalData_HH
#define OPAL_OpalData_HH
#include "AbstractObjects/ObjectFunction.h"
#include <iosfwd>
......@@ -39,14 +44,8 @@ class BoundaryGeometry;
typedef std::pair<std::string, double > MaxPhasesT;
typedef std::map<double, double> energyEvolution_t;
// Class OpalData
// ------------------------------------------------------------------------
/// The global OPAL structure.
// The OPAL object holds all global data required for an OPAL execution.
// In particular it contains the main Directory, which allows retrieval
// of command objects by their name. For other data refer to the
// implementation file.
/// The global OPAL structure.
class OpalData {
public:
......@@ -191,6 +190,9 @@ public:
/// store opals input filename
void storeInputFn(const std::string &fn);
/// checks the output file names of all items to avoid duplicates
void checkAndAddOutputFileName(const std::string &outfn);
/// get opals restart h5 format filename
std::string getRestartFileName();
......@@ -241,7 +243,6 @@ public:
///
BoundaryGeometry *getGlobalGeometry();
bool hasGlobalGeometry();
void setMaxPhase(std::string elName, double phi);
......
......@@ -136,6 +136,20 @@ void ElementBase::setName(const std::string &name) {
}
void ElementBase::setOutputFN(const std::string fn) {
outputfn_m = fn;
}
std::string ElementBase::getOutputFN() const {
if (outputfn_m.empty()) {
return getName();
} else {
return outputfn_m.substr(0, outputfn_m.rfind("."));
}
}
double ElementBase::getAttribute(const std::string &aKey) const {
const ConstChannel *aChannel = getConstChannel(aKey);
......
......@@ -621,18 +621,4 @@ int ElementBase::getRequiredNumberOfTimeSteps() const {
return 10;
}
inline
void ElementBase::setOutputFN(const std::string fn) {
outputfn_m = fn;
}
inline
std::string ElementBase::getOutputFN() const {
if (outputfn_m.empty()) {
return getName();
} else {
return outputfn_m.substr(0, outputfn_m.rfind("."));
}
}
#endif // CLASSIC_ElementBase_HH
......@@ -17,9 +17,7 @@
//
#include "Structure/LossDataSink.h"
#include <boost/filesystem.hpp>
#include <cmath>
#include "AbstractObjects/OpalData.h"
#include "Algorithms/DistributionMoments.h"
#include "Message/GlobalComm.h"
#include "OPALconfig.h"
......@@ -28,6 +26,10 @@
#include "Utilities/Util.h"
#include "Utility/IpplInfo.h"
#include <boost/filesystem.hpp>
#include <cmath>
extern Inform* gmsg;
#define WRITE_FILEATTRIB_STRING( attribute, value ) { \
......@@ -176,6 +178,15 @@ LossDataSink::LossDataSink(std::string outfn, bool hdf5Save, CollectionType coll
particles_m.clear();
turnNumber_m.clear();
bunchNumber_m.clear();
if (h5hut_mode_m && !Options::enableHDF5) {
throw GeneralClassicException(
"LossDataSink::LossDataSink",
"You must select an OPTION to save Loss data files\n"
"Please, choose 'ENABLEHDF5=TRUE' or 'ASCIIDUMP=TRUE'");
}
OpalData::getInstance()->checkAndAddOutputFileName(outputName_m);
}
LossDataSink::LossDataSink(const LossDataSink &rhs):
......@@ -309,7 +320,6 @@ void LossDataSink::save(unsigned int numSets, OpalData::OPENMODE openMode) {
namespace fs = boost::filesystem;
if (h5hut_mode_m) {
if (!Options::enableHDF5) return;
fn_m = outputName_m + std::string(".h5");
*gmsg << level2 << "Save " << fn_m << endl;
......
#include "PeakFinder.h"
#include <algorithm>
#include <cmath>
#include <iterator>
//
// Class PeakFinder
// Find peaks of radial profile.
// It computes a histogram based on the radial distribution of the particle
// bunch. After that all peaks of the histogram are searched.
// The radii are written in ASCII format to a file.
// This class is used for the cyclotron probe element.
//
// Copyright (c) 2017 - 2021, Matthias Frey, Jochem Snuverink, Paul Scherrer Institut, Villigen PSI, Switzerland
// All rights reserved
//
// This file is part of OPAL.
//
// OPAL is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// You should have received a copy of the GNU General Public License
// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
//
#include "Structure/PeakFinder.h"
#include "AbstractObjects/OpalData.h"
#include "Message/GlobalComm.h"
#include "Utility/IpplInfo.h"
PeakFinder::PeakFinder(std::string elem, double min,
#include <algorithm>
#include <cmath>
#include <iterator>
extern Inform* gmsg;
PeakFinder::PeakFinder(std::string outfn, double min,
double max, double binWidth, bool singlemode)
: element_m(elem)
: outputName_m(outfn)
, binWidth_m(binWidth)
, min_m(min)
, max_m(max)
......@@ -82,10 +105,13 @@ void PeakFinder::save() {
if ( !peaks_m.empty() ) {
// only rank 0 will go in here
fn_m = element_m + std::string(".peaks");
hist_m = element_m + std::string(".hist");
fn_m = outputName_m + std::string(".peaks");
OpalData::getInstance()->checkAndAddOutputFileName(fn_m);
INFOMSG("Save " << fn_m << " and " << hist_m << endl);
hist_m = outputName_m + std::string(".hist");
OpalData::getInstance()->checkAndAddOutputFileName(hist_m);
*gmsg << level2 << "Save " << fn_m << " and " << hist_m << endl;
if(OpalData::getInstance()->inRestartRun())
this->append_m();
......@@ -93,9 +119,7 @@ void PeakFinder::save() {
this->open_m();
this->saveASCII_m();
this->close_m();
}
radius_m.clear();
......
//
// Class PeakFinder
// Find peaks of radial profile.
// It computes a histogram based on the radial distribution of the particle
// bunch. After that all peaks of the histogram are searched.
// The radii are written in ASCII format to a file.
// This class is used for the cyclotron probe element.
//
// Copyright (c) 2017 - 2021, Matthias Frey, Jochem Snuverink, Paul Scherrer Institut, Villigen PSI, Switzerland
// All rights reserved
//
// This file is part of OPAL.
//
// OPAL is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// You should have received a copy of the GNU General Public License
// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
//
#ifndef PEAKFINDER_H
#define PEAKFINDER_H
/*!
* @file PeakFinder.h
* @author Matthias Frey,
* Jochem Snuverink
* @date 22. - 26. May 2017
* @brief Find peaks of radial profile
* @details It computes a histogram based on the radial
* distribution of the particle bunch. After that all
* peaks of the histogram are searched. The radii are
* written in ASCII format to a file. This class is
* used for the cyclotron probe element.
*/
#include "Algorithms/Vektor.h"
#include <fstream>
......@@ -82,7 +90,7 @@ private:
std::ofstream hos_m;
/// Element/probe name, for name output file
std::string element_m;
std::string outputName_m;
// Histogram details
/// Number of bins
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment