-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlogger.cpp
193 lines (139 loc) · 5.38 KB
/
logger.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
//
// logger.cpp
// Xcode
//
// Created by jacob on 7/18/11.
// Copyright 2011 BMPI. All rights reserved.
//
#include "vector3D.h"
#include "photon.h"
#include "logger.h"
Logger * Logger::pInstance = 0;
Logger::Logger()
{
//cout << "logger dying";
}
Logger::~Logger()
{
exit_data_stream.close();
absorber_data_stream.close();
meta_data_stream.close();
}
Logger * Logger::getInstance(void)
{
if (!pInstance)
{
pInstance = new Logger();
}
return pInstance;
}
void Logger::openExitFile(std::string filename)
{
// Ensure file stream is not already open.
if (exit_data_stream.is_open())
exit_data_stream.close();
exit_data_stream.open(filename.c_str());
}
void Logger::openAbsorberFile(std::string filename)
{
// Ensure file stream is not already open.
if (absorber_data_stream.is_open())
absorber_data_stream.close();
absorber_data_stream.open(filename.c_str());
}
void Logger::openMetaData(std::string filename)
{
meta_data_stream.open(filename.c_str());
}
void Logger::write(double val)
{
// Grab the lock to ensure that the logger doesn't get interrupted by a thread
// in the middle of a write, causing the output to be corrupted.
boost::mutex::scoped_lock lock(m_mutex);
exit_data_stream << "val = " << val << endl;
}
void Logger::writeMetaData(const double absorberRadius, const double detectorRadius,
const int Nphotons, const double detectorPlane, const Vector3d &absorberLocation)
{
meta_data_stream << "Absorber radius: " << absorberRadius
<< "Detector radius: " << detectorRadius
<< "Number of photons: " << Nphotons
<< "Detector position: " << detectorPlane
<< "Absorber location: " << absorberLocation;
meta_data_stream.flush();
}
void Logger::writeExitData(const boost::shared_ptr<Vector3d> photonVector)
{
// Grab the lock to ensure that the logger doesn't get interrupted by a thread
// in the middle of a write, causing the output to be corrupted.
boost::mutex::scoped_lock lock(m_mutex);
exit_data_stream << photonVector;
exit_data_stream.flush();
}
void Logger::writeExitData(const boost::shared_ptr<Vector3d> photonVector,
const double weight,
bool tagged)
{
// Grab the lock to ensure that the logger doesn't get interrupted by a thread
// in the middle of a write, causing the output to be corrupted.
boost::mutex::scoped_lock lock(m_mutex);
// Write out the location (x,y,z), exit angle (theta), weight of photon, and whether it was
// tagged.
exit_data_stream << tagged << ","
<< weight << ","
<< photonVector->getDirZ() << ","
<< photonVector << "\n";
exit_data_stream.flush();
}
void Logger::writeExitData(const boost::shared_ptr<Vector3d> photonVector,
const double weight)
{
// Grab the lock to ensure that the logger doesn't get interrupted by a thread
// in the middle of a write, causing the output to be corrupted.
boost::mutex::scoped_lock lock(m_mutex);
// Write out the location (x,y,z), exit angle (theta), weight of photon, and whether it was
// tagged.
exit_data_stream << weight << ","
<< photonVector->getDirZ() << ","
<< photonVector << "\n";
}
void Logger::writeExitData(const boost::shared_ptr<Vector3d> photonVector,
const double weight,
const double transmissionAngle)
{
// Grab the lock to ensure that the logger doesn't get interrupted by a thread
// in the middle of a write, causing the output to be corrupted.
boost::mutex::scoped_lock lock(m_mutex);
// Write out the location (x,y,z), transmission angle (theta), weight of photon
exit_data_stream << weight << ","
<< transmissionAngle << ","
<< photonVector << "\n";
exit_data_stream.flush();
}
void Logger::writeWeightAngleLengthCoords(const double exitWeight,
const double transmissionAngle,
const double modulatedPathLength,
const boost::shared_ptr<Vector3d> photonVector)
{
// Grab the lock to ensure that the logger doesn't get interrupted by a thread
// in the middle of a write, causing the output to be corrupted.
boost::mutex::scoped_lock lock(m_mutex);
// Write out the location (x,y,z), transmission angle (theta), weight of photon
exit_data_stream << exitWeight << ","
<< transmissionAngle << ","
<< modulatedPathLength << ","
<< photonVector << "\n";
exit_data_stream.flush();
}
void Logger::writePhoton(Photon *p)
{
// Grab the lock to ensure that the logger doesn't get interrupted by a thread
// in the middle of a write, causing the output to be corrupted.
boost::mutex::scoped_lock lock(m_mutex);
cout << "Logger::writePhoton() stub\n";
}
void Logger::writeAbsorberData(const double absorbedWeight)
{
absorber_data_stream << absorbedWeight << "\n";
absorber_data_stream.flush();
}