59 monitorId_ = monitorId;
63 grpMonLastUpdated_ = 0;
65 persistentData_ =
false;
67 needToWriteFileHeader_ =
true;
68 groupFileSignature_ = 206661989;
69 groupFileVersion_ = 0.2f;
75 void GroupMonitorCore::init() {
89 if (groupFileId_ != NULL) {
113 timeVector_.push_back(time);
114 dataVector_.push_back(data);
126 std::vector<int> peakTimeVector;
128 int size = dataVector_.size() - 1;
129 for (
int i = 1; i < size; i++) {
130 if (dataVector_[i-1] < dataVector_[i] && dataVector_[i] > dataVector_[i+1])
131 peakTimeVector.push_back(timeVector_[i]);
134 return peakTimeVector;
138 std::vector<int> sortedPeakTimeVector;
140 int size = dataVector_.size() - 1;
141 for (
int i = 1; i < size; i++) {
142 if (dataVector_[i-1] < dataVector_[i] && dataVector_[i] > dataVector_[i+1])
143 sortedPeakTimeVector.push_back(timeVector_[i]);
146 std::sort(sortedPeakTimeVector.begin(), sortedPeakTimeVector.end());
147 std::reverse(sortedPeakTimeVector.begin(), sortedPeakTimeVector.end());
149 return sortedPeakTimeVector;
153 std::vector<float> peakValueVector;
155 int size = dataVector_.size() - 1;
156 for (
int i = 1; i < size; i++) {
157 if (dataVector_[i-1] < dataVector_[i] && dataVector_[i] > dataVector_[i+1])
158 peakValueVector.push_back(dataVector_[i]);
161 return peakValueVector;
165 std::vector<float> sortedPeakValueVector;
167 int size = dataVector_.size() - 1;
168 for (
int i = 1; i < size; i++) {
169 if (dataVector_[i-1] < dataVector_[i] && dataVector_[i] > dataVector_[i+1])
170 sortedPeakValueVector.push_back(dataVector_[i]);
173 std::sort(sortedPeakValueVector.begin(), sortedPeakValueVector.end());
174 std::reverse(sortedPeakValueVector.begin(), sortedPeakValueVector.end());
176 return sortedPeakValueVector;
180 if (!persistentData_) {
192 if (persistentData_) {
195 startTime_ = (startTime_<0) ? currentTime : startTime_;
196 startTimeLast_ = currentTime;
197 accumTime_ = (totalTime_>0) ? totalTime_ : 0;
200 startTime_ = currentTime;
201 startTimeLast_ = currentTime;
208 assert(startTime_>-1 && startTimeLast_>-1 && accumTime_>-1);
218 totalTime_ = stopTime_-startTimeLast_ + accumTime_;
219 assert(totalTime_>=0);
226 if (groupFileId_ != NULL)
227 KERNEL_ERROR(
"GroupMonitorCore: setGroupFileId() has already been called.");
229 groupFileId_ = groupFileId;
231 if (groupFileId_ == NULL)
232 needToWriteFileHeader_ =
false;
235 needToWriteFileHeader_ =
true;
236 writeGroupFileHeader();
242 void GroupMonitorCore::writeGroupFileHeader() {
243 if (!needToWriteFileHeader_)
247 if (!fwrite(&groupFileSignature_,
sizeof(
int), 1, groupFileId_))
248 KERNEL_ERROR(
"GroupMonitorCore: writeSpikeFileHeader has fwrite error");
251 if (!fwrite(&groupFileVersion_,
sizeof(
float), 1, groupFileId_))
252 KERNEL_ERROR(
"GroupMonitorCore: writeGroupFileHeader has fwrite error");
256 int tmpInt = grid.
numX;
257 if (!fwrite(&tmpInt,
sizeof(
int), 1, groupFileId_))
258 KERNEL_ERROR(
"GroupMonitorCore: writeGroupFileHeader has fwrite error");
261 if (!fwrite(&tmpInt,
sizeof(
int),1,groupFileId_))
262 KERNEL_ERROR(
"GroupMonitorCore: writeGroupFileHeader has fwrite error");
265 if (!fwrite(&tmpInt,
sizeof(
int),1,groupFileId_))
266 KERNEL_ERROR(
"GroupMonitorCore: writeGroupFileHeader has fwrite error");
269 needToWriteFileHeader_ =
false;