Skip to content

Commit d1ac3b9

Browse files
committed
add enum EventType
1 parent 4651f9a commit d1ac3b9

27 files changed

+108
-94
lines changed

Intern/rayx-core/src/Beamline/Objects/CircleSource.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ std::vector<Ray> CircleSource::getRays([[maybe_unused]] int thread_count) const
5959

6060
const auto field = stokesToElectricField(m_stokes, direction);
6161

62-
Ray r = {position, ETYPE_UNINIT, direction, en, field, 0.0, 0.0, -1.0, -1.0};
62+
Ray r = {position, EventType::Uninit, direction, en, field, 0.0, 0.0, -1.0, -1.0};
6363

6464
rayList.push_back(r);
6565
}

Intern/rayx-core/src/Beamline/Objects/DipoleSource.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ std::vector<Ray> DipoleSource::getRays(int thread_count) const {
133133

134134
const auto field = stokesToElectricField(psiandstokes.stokes, direction);
135135

136-
Ray r = {position, ETYPE_UNINIT, direction, en, field, 0.0, 0.0, -1.0, -1.0};
136+
Ray r = {position, EventType::Uninit, direction, en, field, 0.0, 0.0, -1.0, -1.0};
137137
#if defined(DIPOLE_OMP)
138138
#pragma omp critical // thread-safety for writing rayList
139139
{ rayList.push_back(r); }

Intern/rayx-core/src/Beamline/Objects/MatrixSource.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ std::vector<Ray> MatrixSource::getRays([[maybe_unused]] int thread_count) const
6161

6262
const auto field = stokesToElectricField(m_pol, direction);
6363

64-
Ray r = {position, ETYPE_UNINIT, direction, en, field, 0.0, 0.0, -1.0, -1.0};
64+
Ray r = {position, EventType::Uninit, direction, en, field, 0.0, 0.0, -1.0, -1.0};
6565

6666
returnList.push_back(r);
6767
}

Intern/rayx-core/src/Beamline/Objects/PixelSource.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ std::vector<Ray> PixelSource::getRays([[maybe_unused]] int thread_count) const {
7676
const auto rotation = glm::dmat3(m_orientation);
7777
const auto field = stokesToElectricField(m_pol, rotation);
7878

79-
Ray r = {position, ETYPE_UNINIT, direction, en, field, 0.0, 0.0, -1.0, -1.0};
79+
Ray r = {position, EventType::Uninit, direction, en, field, 0.0, 0.0, -1.0, -1.0};
8080

8181
rayList.push_back(r);
8282
}

Intern/rayx-core/src/Beamline/Objects/PointSource.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ std::vector<Ray> PointSource::getRays(int thread_count) const {
9494

9595
const auto field = stokesToElectricField(m_pol, direction);
9696

97-
Ray r = {position, ETYPE_UNINIT, direction, en, field, 0.0, 0.0, -1.0, -1.0};
97+
Ray r = {position, EventType::Uninit, direction, en, field, 0.0, 0.0, -1.0, -1.0};
9898
#if defined(DIPOLE_OMP)
9999
#pragma omp critical
100100
{ rayList.push_back(r); }

Intern/rayx-core/src/Beamline/Objects/SimpleUndulatorSource.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ std::vector<Ray> SimpleUndulatorSource::getRays([[maybe_unused]] int thread_coun
7474

7575
const auto field = stokesToElectricField(m_pol, direction);
7676

77-
Ray r = {position, ETYPE_UNINIT, direction, en, field, 0.0, 0.0, -1.0, -1.0};
77+
Ray r = {position, EventType::Uninit, direction, en, field, 0.0, 0.0, -1.0, -1.0};
7878

7979
rayList.push_back(r);
8080
}

Intern/rayx-core/src/Debug/Debug.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,9 @@ inline std::vector<double> formatAsVec(double arg) { return {arg}; }
166166
inline std::vector<double> formatAsVec(complex::Complex comp) { return {comp.real(), comp.imag()}; }
167167

168168
inline std::vector<double> formatAsVec(const Ray arg) {
169+
const auto eventType = static_cast<double>(arg.m_eventType);
169170
return {
170-
arg.m_position.x, arg.m_position.y, arg.m_position.z, arg.m_eventType, arg.m_direction.x, arg.m_direction.y,
171+
arg.m_position.x, arg.m_position.y, arg.m_position.z, eventType, arg.m_direction.x, arg.m_direction.y,
171172
arg.m_direction.z, arg.m_energy, arg.m_field.x.real(), arg.m_field.x.imag(), arg.m_field.y.real(), arg.m_field.y.imag(),
172173
arg.m_field.z.real(), arg.m_field.z.imag(), arg.m_pathLength, arg.m_order, arg.m_lastElement, arg.m_sourceID,
173174
};

Intern/rayx-core/src/Shader/Behave.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Ray behaveSlit(Ray r, int id, [[maybe_unused]] Collision col, InvState& inv) {
2727
bool withinBeamstop = inCutout(beamstopCutout, r.m_position.x, r.m_position.z);
2828

2929
if (!withinOpening || withinBeamstop) {
30-
recordFinalEvent(r, ETYPE_ABSORBED, inv);
30+
recordFinalEvent(r, EventType::Absorbed, inv);
3131
return r;
3232
}
3333

Intern/rayx-core/src/Shader/Behave.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace RAYX {
1515
/// The `behave*` functions, will
1616
/// - change the rays direction, typically by reflecting using the normal
1717
/// - change the rays stokes vector
18-
/// - potentially absorb the ray (by calling `recordFinalEvent(_, ETYPE_ABSORBED)`)
18+
/// - potentially absorb the ray (by calling `recordFinalEvent(_, EventType::Absorbed)`)
1919

2020
RAYX_FN_ACC Ray behaveSlit(Ray r, int id, Collision col, InvState& inv);
2121
RAYX_FN_ACC Ray behaveRZP(Ray r, int id, Collision col, InvState& inv);

Intern/rayx-core/src/Shader/DynamicElements.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ void dynamicElements(int gid, InvState& inv) {
6464
break;
6565
}
6666

67-
recordEvent(ray, ETYPE_JUST_HIT_ELEM, inv);
67+
recordEvent(ray, EventType::HitElement, inv);
6868

6969
// transform back to WORLD coordinates
7070
ray = rayMatrixMult(ray, nextElement.m_outTrans);

Intern/rayx-core/src/Shader/EventType.h

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,37 @@
44

55
namespace RAYX {
66

7-
// The meaning of the `m_eventType` field of a `Ray`:
8-
////////////////////////////////////////////////////
9-
10-
// This Ray has just hit `m_lastElement`.
11-
// And will continue tracing afterwards.
12-
// Ray is in element coordinates of the hit element.
13-
constexpr double ETYPE_JUST_HIT_ELEM = 1;
14-
15-
// If the storage space for the events is insufficient for the amount of events that were recorded in a shader call.
16-
constexpr double ETYPE_TOO_MANY_EVENTS = 2;
17-
18-
// This Ray was absorbed by `m_lastElement`.
19-
// Ray is in element coordinates, relative to `m_lastElement`.
20-
constexpr double ETYPE_ABSORBED = 3;
21-
22-
// This is a yet uninitialized ray from outputData.
23-
// This is the initial weight within outputData, and if less events than `maxEvents` are taken,
24-
// the remaining weights in outputData will stay ETYPE_UNINIT even when returned to the CPU.
25-
constexpr double ETYPE_UNINIT = 4;
26-
27-
// This is an error code.
28-
// Functions like refrac2D can error due to "ray beyond horizon", see Utils.h.
29-
// In that case this is returned as final event.
30-
constexpr double ETYPE_BEYOND_HORIZON = 5;
31-
32-
// This is a general error code that means some assertion failed in the shader.
33-
// This error code is typically generated using `_throw`.
34-
constexpr double ETYPE_FATAL_ERROR = 6;
35-
36-
// These rays have just been emitted and not had any other events
37-
// If there are no other elements the ray has this eventtype
38-
constexpr double ETYPE_EMITTED = 7;
7+
// The meaning of the `m_eventType` field of a `Ray`
8+
enum class EventType {
9+
// This is a yet uninitialized ray from outputData.
10+
// This is the initial weight within outputData, and if less events than `maxEvents` are taken,
11+
// the remaining weights in outputData will stay EventType::Uninit even when returned to the CPU.
12+
Uninit = 0,
13+
14+
// This Ray has just hit `m_lastElement`.
15+
// And will continue tracing afterwards.
16+
// Ray is in element coordinates of the hit element.
17+
HitElement = 1,
18+
19+
// If the storage space for the events is insufficient for the amount of events that were recorded in a shader call.
20+
TooManyEvents = 2,
21+
22+
// This Ray was absorbed by `m_lastElement`.
23+
// Ray is in element coordinates, relative to `m_lastElement`.
24+
Absorbed = 3,
25+
26+
// This is an error code.
27+
// Functions like refrac2D can error due to "ray beyond horizon", see Utils.h.
28+
// In that case this is returned as final event.
29+
BeyondHorizon = 5,
30+
31+
// This is a general error code that means some assertion failed in the shader.
32+
// This error code is typically generated using `_throw`.
33+
FatalError = 6,
34+
35+
// These rays have just been emitted and not had any other events
36+
// If there are no other elements the ray has this eventtype
37+
Emitted = 7,
38+
};
3939

4040
} // namespace RAYX

Intern/rayx-core/src/Shader/Helper.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ void init(InvState& inv) {
1010
inv.finalized = false;
1111

1212
// TODO(Sven): dont waste time with initializing
13-
// sets all output rays controlled by this shader call to ETYPE_UNINIT.
13+
// sets all output rays controlled by this shader call to EventType::Uninit.
1414
for (uint32_t i = uint32_t(0); i < inv.pushConstants.maxEvents; i++) {
15-
inv.outputRays[output_index(i, inv)].m_eventType = ETYPE_UNINIT;
15+
inv.outputRays[output_index(i, inv)].m_eventType = EventType::Uninit;
1616
}
1717
inv.nextEventIndex = 0;
1818

@@ -38,13 +38,13 @@ uint32_t output_index(uint32_t i, InvState& inv) {
3838
// record an event and store it in the next free spot in outputRays.
3939
// `r` will typically be ray, or some related ray.
4040
RAYX_FN_ACC
41-
void recordEvent(Ray r, double w, InvState& inv) {
41+
void recordEvent(Ray r, EventType w, InvState& inv) {
4242
if (inv.finalized) {
4343
return;
4444
}
4545

4646
// recording of event type ETYPE_UINIT is forbidden.
47-
if (w == ETYPE_UNINIT) {
47+
if (w == EventType::Uninit) {
4848
_throw("recordEvent failed: weight UNINIT is invalid in recordEvent");
4949

5050
return;
@@ -54,9 +54,9 @@ void recordEvent(Ray r, double w, InvState& inv) {
5454
if (inv.nextEventIndex >= inv.pushConstants.maxEvents) {
5555
inv.finalized = true;
5656

57-
// change the last event to "ETYPE_TOO_MANY_EVENTS".
57+
// change the last event to "EventType::TooManyEvents".
5858
uint32_t idx = output_index(uint32_t(inv.pushConstants.maxEvents - 1), inv);
59-
inv.outputRays[idx].m_eventType = ETYPE_TOO_MANY_EVENTS;
59+
inv.outputRays[idx].m_eventType = EventType::TooManyEvents;
6060

6161
_throw("recordEvent failed: too many events!");
6262

@@ -74,7 +74,7 @@ void recordEvent(Ray r, double w, InvState& inv) {
7474
// Like `recordEvent` above, but it will prevent recording more events after this.
7575
// Is used for events terminating the path of the ray.
7676
RAYX_FN_ACC
77-
void recordFinalEvent(Ray r, double w, InvState& inv) {
77+
void recordFinalEvent(Ray r, EventType w, InvState& inv) {
7878
recordEvent(r, w, inv);
7979
inv.finalized = true;
8080
}

Intern/rayx-core/src/Shader/Helper.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace RAYX {
99
RAYX_FN_ACC void init(InvState& inv);
1010
RAYX_FN_ACC uint64_t rayId(InvState& inv);
1111
RAYX_FN_ACC uint32_t output_index(uint32_t i, InvState& inv);
12-
RAYX_FN_ACC void recordEvent(Ray r, double w, InvState& inv);
13-
RAYX_FN_ACC void recordFinalEvent(Ray r, double w, InvState& inv);
12+
RAYX_FN_ACC void recordEvent(Ray r, EventType w, InvState& inv);
13+
RAYX_FN_ACC void recordFinalEvent(Ray r, EventType w, InvState& inv);
1414

1515
} // namespace RAYX

Intern/rayx-core/src/Shader/Ray.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ struct RAYX_API Ray {
1919
glm::dvec3 m_position;
2020

2121
/// The m_eventType expresses what is currently happening to the ray.
22-
/// During tracing the eventType will be uninitialized (ETYPE_UNINIT).
22+
/// During tracing the eventType will be uninitialized (EventType::Uninit).
2323
/// Only when an event will be recorded, the m_eventType will be set accordingly.
2424
/// See the potential values of `m_eventType` in `EventType.h`.
25-
double m_eventType;
25+
EventType m_eventType;
2626

2727
/// The direction of the ray.
2828
/// The direction is normalized, so its L2 norm (aka length) is one.

Intern/rayx-core/src/Shader/Refrac.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ calculates refracted ray
1111
normal: normal at intersection point of ray and element
1212
az: linedensity in z direction varied spacing for different collision angles is already considered
1313
ax: linedensity in x direction
14-
@returns: refracted ray (position unchanged, direction changed), weight = ETYPE_BEYOND_HORIZON if
14+
@returns: refracted ray (position unchanged, direction changed), weight = EventType::BeyondHorizon if
1515
"ray beyond horizon"
1616
*/
1717
RAYX_FN_ACC
@@ -41,7 +41,7 @@ Ray refrac2D(Ray r, glm::dvec3 normal, double density_z, double density_x, InvSt
4141
r.m_direction.z = z1;
4242
r.m_direction = inv_rot * r.m_direction;
4343
} else { // beyond horizon - when divergence too large
44-
recordFinalEvent(r, ETYPE_BEYOND_HORIZON, inv);
44+
recordFinalEvent(r, EventType::BeyondHorizon, inv);
4545
}
4646
return r;
4747
}

Intern/rayx-core/src/Shader/Refrac.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ calculates refracted ray
1010
@params: r: ray
1111
normal: normal at intersection point of ray and element -> for planes normal is always the same (0,1,0) -> no need to rotate but we do
1212
anyways. az: linedensity in z direction ax: linedensity in x direction
13-
@returns: refracted ray (position unchanged, direction changed), weight = ETYPE_BEYOND_HORIZON if
13+
@returns: refracted ray (position unchanged, direction changed), weight = EventType::BeyondHorizon if
1414
"ray beyond horizon"
1515
*/
1616
RAYX_FN_ACC Ray refrac2D(Ray r, glm::dvec3 normal, double az, double ax, InvState& inv);

Intern/rayx-core/src/Shader/Throw.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
// throws an error, and termiantes the program
66
// TODO(Sven): rethink error handling. just instantly terminate with RAYX_EXIT or use recordFinalEvent?
7-
// #define _throw(string) recordFinalEvent(_ray, ETYPE_FATAL_ERROR)
7+
// #define _throw(string) recordFinalEvent(_ray, EventType::FatalError)
88
// #define _throw(string) RAYX_ERR << string
99
#define _throw(string) \
1010
printf("Error occurred while executing shader: %s\n", string); \

Intern/rayx-core/src/Writer/CSVWriter.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,19 +118,26 @@ RAYX::BundleHistory loadCSV(const std::string& filename) {
118118
RAYX_EXIT << "CSV line has incorrect length: " << d.size();
119119
}
120120

121-
const auto direction = glm::dvec3(d[4], d[5], d[6]);
121+
const auto position = glm::dvec3{d[0], d[1], d[2]};
122+
const auto eventType = static_cast<RAYX::EventType>(d[3]);
123+
const auto direction = glm::dvec3(d[4], d[5], d[6]);
124+
const auto energy = d[7];
122125
const auto field = RAYX::ElectricField({d[8], d[9]}, {d[10], d[11]}, {d[12], d[13]});
126+
const auto pathLength = d[14];
127+
const auto order = d[15];
128+
const auto lastElement = d[16];
129+
const auto sourceID = d[17];
123130

124131
// create the Ray from the loaded doubles from this line.
125-
RAYX::Ray ray = {.m_position = {d[0], d[1], d[2]},
126-
.m_eventType = d[3],
132+
RAYX::Ray ray = {.m_position = position,
133+
.m_eventType = eventType,
127134
.m_direction = direction,
128-
.m_energy = d[7],
135+
.m_energy = energy,
129136
.m_field = field,
130-
.m_pathLength = d[14],
131-
.m_order = d[15],
132-
.m_lastElement = d[16],
133-
.m_sourceID = d[17]};
137+
.m_pathLength = pathLength,
138+
.m_order = order,
139+
.m_lastElement = lastElement,
140+
.m_sourceID = sourceID};
134141
// This checks whether `ray_id` is from a "new ray" that didn't yet come up in the BundleHistory.
135142
// If so, we need to make place for it.
136143
if (out.size() <= ray_id) {

Intern/rayx-core/src/Writer/H5Writer.cpp

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,21 +97,27 @@ RAYX::BundleHistory fromDoubles(const std::vector<double>& doubles, const Format
9797
currentRayID = rayID;
9898
}
9999

100+
const auto* d = rayData + 2;
101+
const auto position = glm::dvec3{d[0], d[1], d[2]};
102+
const auto eventType = static_cast<RAYX::EventType>(d[3]);
103+
const auto direction = glm::dvec3(d[4], d[5], d[6]);
104+
const auto energy = d[7];
105+
const auto field = RAYX::ElectricField({d[8], d[9]}, {d[10], d[11]}, {d[12], d[13]});
106+
const auto pathLength = d[14];
107+
const auto order = d[15];
108+
const auto lastElement = d[16];
109+
const auto sourceID = d[17];
110+
100111
const auto ray = RAYX::Ray{
101-
.m_position = {rayData[2], rayData[3], rayData[4]}, // origin
102-
.m_eventType = rayData[5], // eventType
103-
.m_direction = {rayData[6], rayData[7], rayData[8]}, // direction
104-
.m_energy = rayData[9], // energy
105-
.m_field =
106-
{
107-
{rayData[10], rayData[11]},
108-
{rayData[12], rayData[13]},
109-
{rayData[14], rayData[15]},
110-
},
111-
.m_pathLength = rayData[16], // pathLength
112-
.m_order = rayData[17], // order
113-
.m_lastElement = rayData[18], // lastElement
114-
.m_sourceID = rayData[19] // sourceID
112+
.m_position = position,
113+
.m_eventType = eventType,
114+
.m_direction = direction,
115+
.m_energy = energy,
116+
.m_field = field,
117+
.m_pathLength = pathLength,
118+
.m_order = order,
119+
.m_lastElement = lastElement,
120+
.m_sourceID = sourceID,
115121
};
116122

117123
rayHist.push_back(ray);

Intern/rayx-core/src/Writer/Writer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static Format FULL_FORMAT = {
4949
},
5050
FormatComponent{
5151
.name = "Event-type",
52-
.get_double = [](uint32_t, uint32_t, RAYX::Ray ray) { return ray.m_eventType; },
52+
.get_double = [](uint32_t, uint32_t, RAYX::Ray ray) { return static_cast<double>(ray.m_eventType); },
5353
},
5454
FormatComponent{
5555
.name = "X-direction",

Intern/rayx-core/tests/setupTests.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ RAYX::Ray parseCSVline(std::string line) {
5555

5656
// otherwise uninitialized:
5757
ray.m_sourceID = -1;
58-
ray.m_eventType = -1;
58+
ray.m_eventType = EventType::Uninit;
5959
ray.m_lastElement = -1;
6060
ray.m_order = -1;
6161

@@ -84,13 +84,13 @@ std::vector<RAYX::Ray> extractLastHit(const RAYX::BundleHistory& hist) {
8484
std::vector<RAYX::Ray> outs;
8585
for (auto rr : hist) {
8686
Ray out;
87-
out.m_eventType = ETYPE_UNINIT;
87+
out.m_eventType = EventType::Uninit;
8888
for (auto r : rr) {
89-
if (r.m_eventType == ETYPE_JUST_HIT_ELEM) {
89+
if (r.m_eventType == EventType::HitElement) {
9090
out = r;
9191
}
9292
}
93-
if (out.m_eventType != ETYPE_UNINIT) {
93+
if (out.m_eventType != EventType::Uninit) {
9494
outs.push_back(out);
9595
}
9696
}
@@ -168,7 +168,7 @@ std::optional<RAYX::Ray> lastSequentialHit(RayHistory ray_hist, uint32_t beamlin
168168
if (ray_hist[i].m_lastElement != i) {
169169
return {};
170170
}
171-
if (ray_hist[i].m_eventType != ETYPE_JUST_HIT_ELEM) {
171+
if (ray_hist[i].m_eventType != EventType::HitElement) {
172172
return {};
173173
}
174174
}

Intern/rayx-core/tests/setupTests.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ void writeToOutputCSV(const RAYX::BundleHistory& hist, std::string filename);
185185
/// Returns all traced rays
186186
RAYX::BundleHistory traceRML(std::string filename);
187187

188-
// extracts the last ETYPE_JUST_HIT_ELEM for each ray.
188+
// extracts the last EventType::HitElement for each ray.
189189
std::vector<RAYX::Ray> extractLastHit(const RAYX::BundleHistory&);
190190

191191
/// will look at Tests/input/<filename>.csv

0 commit comments

Comments
 (0)