IAP GITLAB

Skip to content
Snippets Groups Projects
Commit 13460451 authored by ralfulrich's avatar ralfulrich
Browse files

run ./do-clang-format.sh

parent ce459bfe
No related branches found
No related tags found
No related merge requests found
Showing
with 184 additions and 197 deletions
#include <corsika/logging/Logger.h>
#include <boost/format.hpp>
#include <string>
#include <iostream>
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
using namespace corsika::logging;
int
main()
{
int main() {
{
cout << "writing to \"another.log\"" << endl;
ofstream logfile("another.log");
......@@ -18,28 +15,32 @@ main()
sink::BufferedSinkStream sink(logfile, sink::StdBuffer(10000));
Logger<MessageOn, sink::BufferedSinkStream> info("\033[32m", "info", sink);
Logger<MessageOn, sink::BufferedSinkStream> err("\033[31m", "error", sink);
//logger<ostream,messageconst,StdBuffer> info(std::cout, StdBuffer(10000));
// logger<ostream,messageconst,StdBuffer> info(std::cout, StdBuffer(10000));
/*
Logging& logs = Logging::GetInstance();
logs.AddLogger<>("info", info);
auto& log_1 = logs.GetLogger("info"); // no so useful, since type of log_1 is std::any
auto& log_1 = logs.GetLogger("info"); // no so useful, since type of log_1 is
std::any
*/
for (int i=0; i<100000; ++i) {
LOG(info, "irgendwas"," ", string("and more")," ", boost::format("error: %i message: %s. done."), i, "stupido");
for (int i = 0; i < 100000; ++i) {
LOG(info, "irgendwas", " ", string("and more"), " ",
boost::format("error: %i message: %s. done."), i, "stupido");
LOG(err, "Fehler");
}
}
{
sink::NoSink off;
Logger<MessageOff> info("", "", off);
for (int i=0; i<100000; ++i) {
LOG(info, "irgendwas", string("and more"), boost::format("error: %i message: %s. done."), i, "stupido", "a-number:", 8.99, "ENDE" );
for (int i = 0; i < 100000; ++i) {
LOG(info, "irgendwas", string("and more"),
boost::format("error: %i message: %s. done."), i, "stupido", "a-number:", 8.99,
"ENDE");
}
}
return 0;
}
#include <corsika/stack/super_stupid/SuperStupidStack.h>
#include <corsika/particles/ParticleProperties.h>
#include <corsika/stack/super_stupid/SuperStupidStack.h>
#include <iomanip>
#include <iostream>
......@@ -10,7 +10,6 @@ using namespace std;
using namespace corsika::units;
using namespace corsika::stack;
void fill(corsika::stack::super_stupid::SuperStupidStack& s) {
for (int i = 0; i < 11; ++i) {
auto p = s.NewParticle();
......
......@@ -2,27 +2,20 @@
namespace cascade;
template<typename Sequence, typename Trajectory>
void
Cascade::Cascade() {
template <typename Sequence, typename Trajectory>
void Cascade::Cascade() {
kkk;
kk;
}
template<typename Sequence, typename Trajectory>
void
Cascade::Init()
{
template <typename Sequence, typename Trajectory>
void Cascade::Init() {
fStack.Init();
fProcesseList.Init();
}
template<typename Sequence, typename Trajectory>
void
Cascade::Run()
{
template <typename Sequence, typename Trajectory>
void Cascade::Run() {
if (!fStack.IsEmpty()) {
if (!fStack.IsEmpty()) {
Particle& p = fStack.GetNextParticle();
......@@ -34,14 +27,10 @@ Cascade::Run()
}
}
template<typename Sequence, typename Trajectory>
void
Cascade::Step(Particle& particle)
{
template <typename Sequence, typename Trajectory>
void Cascade::Step(Particle& particle) {
double nextStep = fProcesseList.MinStepLength(particle);
Trajectory trajectory = fProcesseList.Transport(particle, nextStep);
sequence.DoContinuous(particle, trajectory);
sequence.DoDiscrete(particle);
}
......@@ -3,9 +3,9 @@
namespace cascade {
template<typename Processes, typename Trajectory, typename Stack>
template <typename Processes, typename Trajectory, typename Stack>
class Cascade {
public:
Cascade();
......@@ -16,9 +16,8 @@ namespace cascade {
private:
Stack fStack;
Processes fProcesseList;
};
}
} // namespace cascade
#endif
......@@ -2,13 +2,9 @@
namespace cascade;
void
Cascade::Step(auto& sequence, Particle& particle)
{
void Cascade::Step(auto& sequence, Particle& particle) {
double nextStep = sequence.MinStepLength(particle);
Trajectory trajectory = sequence.Transport(particle, nextStep);
sequence.DoContinuous(particle, trajectory);
sequence.DoDiscrete(particle);
}
......@@ -11,7 +11,7 @@ typedef Eigen::Translation<double, 3> EigenTranslation;
namespace corsika::geometry {
using corsika::units::length_d;
class CoordinateSystem {
CoordinateSystem const* reference = nullptr;
EigenTransform transf;
......@@ -59,6 +59,6 @@ namespace corsika::geometry {
auto const& GetTransform() const { return transf; }
};
} // namespace corsika
} // namespace corsika::geometry
#endif
......@@ -8,12 +8,12 @@
namespace corsika::geometry {
using corsika::units::SpeedType;
using corsika::units::TimeType;
using corsika::units::frequency_d;
using corsika::units::FrequencyType;
using corsika::units::quantity;
using corsika::units::frequency_d;
using corsika::units::SpeedType;
using corsika::units::TimeType;
class Helix // TODO: inherit from to-be-implemented "Trajectory"
{
using SpeedVec = Vector<SpeedType::dimension_type>;
......@@ -26,8 +26,8 @@ namespace corsika::geometry {
LengthType const radius;
public:
Helix(Point const& pR0, quantity<frequency_d> pOmegaC,
SpeedVec const& pvPar, SpeedVec const& pvPerp)
Helix(Point const& pR0, quantity<frequency_d> pOmegaC, SpeedVec const& pvPar,
SpeedVec const& pvPerp)
: r0(pR0)
, omegaC(pOmegaC)
, vPar(pvPar)
......@@ -43,6 +43,6 @@ namespace corsika::geometry {
auto GetRadius() const { return radius; }
};
} // namespace corsika
} // namespace corsika::geometry
#endif
#ifndef _include_LINETRAJECTORY_H
#define _include_LINETRAJECTORY_H
#include <Units/PhysicalUnits.h>
#include <corsika/Point.h>
#include <corsika/Vector.h>
#include <Units/PhysicalUnits.h>
namesapce corsika {
class LineTrajectory // TODO: inherit from Trajectory
{
class LineTrajectory // TODO: inherit from Trajectory
{
using SpeedVec = Vector<Speed::dimension_type>;
Point const r0;
SpeedVec const v0;
LineTrajectory(Point const& pR0, SpeedVec const& pV0) :
r0(r0), v0(pV0)
{
}
auto GetPosition(Time t) const
{
return r0 + v0 * t;
}
};
LineTrajectory(Point const& pR0, SpeedVec const& pV0)
: r0(r0)
, v0(pV0) {}
auto GetPosition(Time t) const { return r0 + v0 * t; }
};
} // end namesapce
......
......@@ -8,9 +8,9 @@
namespace corsika::geometry {
using corsika::units::LengthType;
using corsika::units::length_d;
using corsika::units::LengthType;
/*!
* A Point represents a point in position space. It is defined by its
* coordinates with respect to some CoordinateSystem.
......@@ -60,6 +60,6 @@ namespace corsika::geometry {
}
};
} // namespace corsika
} // namespace corsika::geometry
#endif
......@@ -172,6 +172,6 @@ namespace corsika::geometry {
}
};
} // namespace corsika
} // namespace corsika::geometry
#endif
......@@ -4,7 +4,6 @@
namespace corsika::logging {
namespace sink {
/**
Output buffer template. NoBuffer does nothingk.
......@@ -19,47 +18,53 @@ namespace corsika::logging {
*/
/**
Output buffer template. StdBuffer records fSize characters in
local memeory before passing it on to further output stages.
local memeory before passing it on to further output stages.
*/
struct StdBuffer {
StdBuffer(const int size) : fSize(size) {}
inline bool Test(const std::string& s) { return int(fBuffer.tellp())+s.length() < fSize; }
StdBuffer(const int size)
: fSize(size) {}
inline bool Test(const std::string& s) {
return int(fBuffer.tellp()) + s.length() < fSize;
}
inline std::string GetString() const { return fBuffer.str(); }
inline void Clear() { fBuffer.str(""); }
inline void Add(const std::string& s) { fBuffer << s; }
private:
int fSize;
std::ostringstream fBuffer;
};
/**
Definition of Sink for log output.
*/
template<typename TStream, typename TBuffer=StdBuffer>
Definition of Sink for log output.
*/
template <typename TStream, typename TBuffer = StdBuffer>
class BufferedSink {
public:
BufferedSink(TStream& out, TBuffer buffer = {} ) : fOutput(out), fBuffer(std::move(buffer)) {}
void operator<<(const std::string& msg) {
if (!fBuffer.Test(msg)) {
fOutput << fBuffer.GetString();
fBuffer.Clear();
BufferedSink(TStream& out, TBuffer buffer = {})
: fOutput(out)
, fBuffer(std::move(buffer)) {}
void operator<<(const std::string& msg) {
if (!fBuffer.Test(msg)) {
fOutput << fBuffer.GetString();
fBuffer.Clear();
}
if (!fBuffer.Test(msg))
fOutput << msg;
else
fBuffer.Add(msg);
}
if (!fBuffer.Test(msg))
fOutput << msg;
else
fBuffer.Add(msg);
}
void Close() { fOutput << fBuffer.GetString(); }
void Close() { fOutput << fBuffer.GetString(); }
private:
TStream& fOutput;
TBuffer fBuffer;
TStream& fOutput;
TBuffer fBuffer;
};
typedef BufferedSink<std::ostream, StdBuffer> BufferedSinkStream;
}// end namespace
} // end namespace
} // namespace sink
} // namespace corsika::logging
#endif
......@@ -8,25 +8,22 @@
#define _include_logger_h_
#include <iosfwd>
#include <string>
#include <sstream>
#include <string>
#include <typeinfo>
#include <boost/format.hpp>
#include <corsika/logging/MessageOn.h>
#include <corsika/logging/BufferedSink.h>
#include <corsika/logging/MessageOff.h>
#include <corsika/logging/Sink.h>
#include <corsika/logging/MessageOn.h>
#include <corsika/logging/NoSink.h>
#include <corsika/logging/BufferedSink.h>
#include <corsika/logging/Sink.h>
using namespace std;
using namespace boost;
namespace corsika::logging {
/**
@class Logger
......@@ -36,50 +33,51 @@ namespace corsika::logging {
compile-time into message strings. The helper class MessageOff,
will just do nothing and will be optimized away at compile time.
*/
template<typename MSG=MessageOn, typename TSink=sink::NoSink>
template <typename MSG = MessageOn, typename TSink = sink::NoSink>
class Logger : private MSG {
using MSG::Message;
public:
// Logger() : fName("") {}
Logger(const std::string color, const std::string name, TSink& sink) : fSink(sink), fName(color+"["+name+"]\033[39m ") {}
~Logger() { fSink.Close(); }
Logger(const std::string color, const std::string name, TSink& sink)
: fSink(sink)
, fName(color + "[" + name + "]\033[39m ") {}
~Logger() { fSink.Close(); }
// Logger(const Logger&) = delete;
/**
Function to add string-concatenation of all inputs to output
sink.
*/
template<typename ... Strings>
template <typename... Strings>
void Log(const Strings&... inputs) {
fSink << MSG::Message(inputs...);
}
const std::string& GetName() const { return fName; }
private:
TSink& fSink;
std::string fName;
};
} // end namesapce
} // namespace corsika::logging
/**
* @def LOG(...)
*
*
* This is the main interface to the logging facilities. If Logger
* object are defined (e.g. log1) use as
* @example LOG(log1, "var1=", variable1int, "var2=", variabl2double)
* object are defined (e.g. log1) use as
* @example LOG(log1, "var1=", variable1int, "var2=", variabl2double)
* for arbitrary long sequence
* of arguments. This may also include boost::format objects the
* output is concatenated, if log1 is switched off at compile time,
* the whole LOG command is optimized away by the compiler.
*/
#define LOG(__LOGGER,...) \
__LOGGER.Log(__LOGGER.GetName(), __FILE__,":", __LINE__, " (", __func__, ") -> ", ##__VA_ARGS__);
#define LOG(__LOGGER, ...) \
__LOGGER.Log(__LOGGER.GetName(), __FILE__, ":", __LINE__, " (", __func__, ") -> ", \
##__VA_ARGS__);
#endif
......@@ -9,11 +9,12 @@ namespace corsika::logging {
*/
class MessageOff {
protected:
template<typename First, typename ... Strings> std::string Message(const First& arg, const Strings&... rest) {
template <typename First, typename... Strings>
std::string Message(const First& arg, const Strings&... rest) {
return "";
}
};
} // end namespace
} // namespace corsika::logging
#endif
#ifndef _include_MessageOn_h_
#define _include_MessageOn_h_
namespace corsika::logging {
/**
......@@ -11,44 +10,51 @@ namespace corsika::logging {
class MessageOn {
protected:
std::string Message() { return "\n"; }
template<typename First, typename ... Strings> std::string Message(const First& arg, const Strings&... rest) {
template <typename First, typename... Strings>
std::string Message(const First& arg, const Strings&... rest) {
std::ostringstream ss;
ss << arg << Message(rest...);
return ss.str();
}
template<typename ... Strings> std::string Message(const int& arg, const Strings&... rest) {
template <typename... Strings>
std::string Message(const int& arg, const Strings&... rest) {
return std::to_string(arg) + Message(rest...);
}
template<typename ... Strings> std::string Message(const double& arg, const Strings&... rest) {
template <typename... Strings>
std::string Message(const double& arg, const Strings&... rest) {
return std::to_string(arg) + Message(rest...);
}
template<typename ... Strings> std::string Message(char const * arg, const Strings&... rest) {
template <typename... Strings>
std::string Message(char const* arg, const Strings&... rest) {
return std::string(arg) + Message(rest...);
}
template<typename ... Strings> std::string Message(const std::string& arg, const Strings&... rest) {
template <typename... Strings>
std::string Message(const std::string& arg, const Strings&... rest) {
return arg + Message(rest...);
}
// ----------------------
// boost format
template<typename ... Strings> std::string Message(const boost::format& fmt, const Strings&... rest) {
template <typename... Strings>
std::string Message(const boost::format& fmt, const Strings&... rest) {
boost::format FMT(fmt);
return bformat(FMT, rest...);
}
template<typename Arg, typename ... Strings> std::string bformat(boost::format& fmt, const Arg& arg, const Strings&... rest) {
template <typename Arg, typename... Strings>
std::string bformat(boost::format& fmt, const Arg& arg, const Strings&... rest) {
fmt % arg;
return bformat(fmt, rest...);
}
std::string bformat(boost::format& fmt) { return fmt.str() + "\n"; }
};
}// end namesapce
} // namespace corsika::logging
#endif
......@@ -10,7 +10,7 @@ namespace corsika::logging {
inline void Close() {}
};
}// end namespace
} // end namespace
} // namespace sink
} // namespace corsika::logging
#endif
......@@ -5,33 +5,33 @@ namespace corsika::logging {
/**
a sink for the logger must implement the two functions
operator<<(const std::string&)
operator<<(const std::string&)
and
Close()
See example: NoSink
*/
namespace sink {
/**
Definition of Sink for log output.
*/
template<typename TStream>
Definition of Sink for log output.
*/
template <typename TStream>
class Sink {
public:
Sink(TStream& out) : fOutput(out) {}
void operator<<(const std::string& msg) {
fOutput << msg;
}
void Close() {}
Sink(TStream& out)
: fOutput(out) {}
void operator<<(const std::string& msg) { fOutput << msg; }
void Close() {}
private:
TStream& fOutput;
TStream& fOutput;
};
typedef Sink<std::ostream> SinkStream;
}// end namespace
} // end namespace
} // namespace sink
} // namespace corsika::logging
#endif
#include <corsika/units/PhysicalUnits.h>
#include <corsika/particles/ParticleProperties.h>
#include <corsika/units/PhysicalUnits.h>
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one
// cpp file
......@@ -18,8 +18,7 @@ TEST_CASE("Particles", "[Particles]") {
REQUIRE(Electron::GetMass() / GetMass(Code::Electron) == Approx(1));
REQUIRE(Electron::GetCharge() / constants::e == Approx(-1));
REQUIRE(Positron::GetCharge() / constants::e == Approx(+1));
REQUIRE(GetElectricCharge(Positron::GetAntiParticle()) / constants::e ==
Approx(-1));
REQUIRE(GetElectricCharge(Positron::GetAntiParticle()) / constants::e == Approx(-1));
REQUIRE(Electron::GetName() == "e-");
}
}
......@@ -111,6 +111,6 @@ namespace corsika::stack {
}
};
} // end namespace stack
} // namespace corsika::stack
#endif
......@@ -27,37 +27,34 @@
#include <phys/units/quantity.hpp>
namespace corsika::units::constants {
using namespace phys::units;
// acceleration of free-fall, standard
constexpr phys::units::quantity<phys::units::acceleration_d> g_sub_n{phys::units::Rep(9.80665L) * phys::units::meter / phys::units::square(phys::units::second)};
// Avogadro constant
constexpr quantity<dimensions<0, 0, 0, 0, 0, -1> > N_sub_A{Rep(6.02214199e+23L) /
mole};
// electronvolt
constexpr quantity<energy_d> eV{Rep(1.60217733e-19L) * joule};
// acceleration of free-fall, standard
constexpr phys::units::quantity<phys::units::acceleration_d> g_sub_n{
phys::units::Rep(9.80665L) * phys::units::meter /
phys::units::square(phys::units::second)};
// elementary charge
constexpr quantity<electric_charge_d> e{Rep(1.602176462e-19L) * coulomb};
// Avogadro constant
constexpr quantity<dimensions<0, 0, 0, 0, 0, -1> > N_sub_A{Rep(6.02214199e+23L) / mole};
// electronvolt
constexpr quantity<energy_d> eV{Rep(1.60217733e-19L) * joule};
// Planck constant
constexpr quantity<dimensions<2, 1, -1> > h{Rep(6.62606876e-34L) * joule * second};
// elementary charge
constexpr quantity<electric_charge_d> e{Rep(1.602176462e-19L) * coulomb};
// speed of light in a vacuum
constexpr quantity<speed_d> c{Rep(299792458L) * meter / second};
// Planck constant
constexpr quantity<dimensions<2, 1, -1> > h{Rep(6.62606876e-34L) * joule * second};
// unified atomic mass unit
constexpr quantity<mass_d> u{Rep(1.6605402e-27L) * kilogram};
// speed of light in a vacuum
constexpr quantity<speed_d> c{Rep(299792458L) * meter / second};
// etc.
// unified atomic mass unit
constexpr quantity<mass_d> u{Rep(1.6605402e-27L) * kilogram};
} // namespace corsika
// etc.
#endif // PHYS_UNITS_PHYSICAL_CONSTANTS_HPP_INCLUDED
} // namespace corsika::units::constants
#endif // PHYS_UNITS_PHYSICAL_CONSTANTS_HPP_INCLUDED
......@@ -15,23 +15,24 @@
namespace phys {
namespace units {
namespace literals {
QUANTITY_DEFINE_SCALING_LITERALS(eV, energy_d, magnitude(corsika::units::constants::eV))
QUANTITY_DEFINE_SCALING_LITERALS(eV, energy_d,
magnitude(corsika::units::constants::eV))
}
} // namespace units
} // namespace phys
namespace corsika::units {
using namespace phys::units;
using namespace phys::units::literals;
//namespace literals = phys::units::literals;
// namespace literals = phys::units::literals;
using LengthType = phys::units::quantity<phys::units::length_d, double>;
using TimeType = phys::units::quantity<phys::units::time_interval_d, double>;
using SpeedType = phys::units::quantity<phys::units::speed_d, double>;
using FrequencyType = phys::units::quantity<phys::units::frequency_d, double>;
using ElectricChargeType = phys::units::quantity<phys::units::electric_charge_d, double>;
using ElectricChargeType =
phys::units::quantity<phys::units::electric_charge_d, double>;
using EnergyType = phys::units::quantity<phys::units::energy_d, double>;
} // end namespace corsika::units
......
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