@@ -98,6 +98,7 @@ OperationWindow::OperationWindow(std::shared_ptr<StatisticsIO>& IOmanager, const
98
98
lastFlush_{eckit::Date{0 }, eckit::Time{0 }},
99
99
timeStepInSeconds_{0 },
100
100
count_{0 },
101
+ counts_{},
101
102
type_{0 } {
102
103
load (IOmanager, opt);
103
104
return ;
@@ -115,25 +116,43 @@ OperationWindow::OperationWindow(const eckit::DateTime& epochPoint, const eckit:
115
116
lastFlush_{epochPoint},
116
117
timeStepInSeconds_{timeStepInSeconds},
117
118
count_{0 },
119
+ counts_{},
118
120
type_{windowType} {}
119
121
120
122
121
123
long OperationWindow::count () const {
122
124
return count_;
123
125
}
124
126
127
+ const std::vector<long >& OperationWindow::counts () const {
128
+ return counts_;
129
+ }
130
+
131
+ template <typename T>
132
+ void OperationWindow::updateCounts (const T* values, size_t size, double missingValue) const {
133
+ initCountsLazy (size);
134
+ std::transform (counts_.begin (), counts_.end (), values, counts_.begin (),
135
+ [missingValue](long c, T v) { return v == missingValue ? c : c + 1 ; });
136
+ return ;
137
+ }
138
+ template void OperationWindow::updateCounts (const float * values, size_t size, double missingValue) const ;
139
+ template void OperationWindow::updateCounts (const double * values, size_t size, double missingValue) const ;
140
+
125
141
void OperationWindow::dump (std::shared_ptr<StatisticsIO>& IOmanager, const StatisticsOptions& opt) const {
126
- IOBuffer restartState{IOmanager->getBuffer (restartSize ())};
142
+ const size_t writeSize = restartSize ();
143
+ IOBuffer restartState{IOmanager->getBuffer (writeSize)};
127
144
restartState.zero ();
128
145
serialize (restartState, IOmanager->getCurrentDir () + " /operationWindow_dump.txt" , opt);
129
- IOmanager->write (" operationWindow" , static_cast < size_t >( 16 ), restartSize () );
146
+ IOmanager->write (" operationWindow" , writeSize, writeSize );
130
147
IOmanager->flush ();
131
148
return ;
132
149
}
133
150
134
151
void OperationWindow::load (std::shared_ptr<StatisticsIO>& IOmanager, const StatisticsOptions& opt) {
135
- IOBuffer restartState{IOmanager->getBuffer (restartSize ())};
136
- IOmanager->read (" operationWindow" , restartSize ());
152
+ size_t readSize;
153
+ IOmanager->readSize (" operationWindow" , readSize);
154
+ IOBuffer restartState{IOmanager->getBuffer (readSize)};
155
+ IOmanager->read (" operationWindow" , readSize);
137
156
deserialize (restartState, IOmanager->getCurrentDir () + " /operationWindow_load.txt" , opt);
138
157
restartState.zero ();
139
158
return ;
@@ -157,6 +176,7 @@ void OperationWindow::updateWindow(const eckit::DateTime& startPoint, const ecki
157
176
prevPoint_ = startPoint;
158
177
endPoint_ = endPoint;
159
178
count_ = 0 ;
179
+ counts_.clear ();
160
180
return ;
161
181
}
162
182
@@ -434,6 +454,20 @@ long OperationWindow::lastFlushInSteps() const {
434
454
return (lastFlush_ - epochPoint_) / timeStepInSeconds_;
435
455
}
436
456
457
+ void OperationWindow::initCountsLazy (size_t size) const {
458
+ if (counts_.size () == size) {
459
+ return ;
460
+ }
461
+ if (counts_.size () == 0 ) {
462
+ counts_.resize (size, 0 );
463
+ return ;
464
+ }
465
+
466
+ std::ostringstream os;
467
+ os << *this << " : counts array is already initialized with a different size" << std::endl;
468
+ throw eckit::SeriousBug (os.str (), Here ());
469
+ }
470
+
437
471
void OperationWindow::serialize (IOBuffer& currState, const std::string& fname, const StatisticsOptions& opt) const {
438
472
439
473
if (opt.debugRestart ()) {
@@ -447,6 +481,7 @@ void OperationWindow::serialize(IOBuffer& currState, const std::string& fname, c
447
481
outFile << " lastFlush_ :: " << lastFlush_ << std::endl;
448
482
outFile << " timeStepInSeconds_ :: " << timeStepInSeconds_ << std::endl;
449
483
outFile << " count_ :: " << count_ << std::endl;
484
+ outFile << " counts_.size() :: " << counts_.size () << std::endl;
450
485
outFile << " type_ :: " << type_ << std::endl;
451
486
outFile.close ();
452
487
}
@@ -476,6 +511,12 @@ void OperationWindow::serialize(IOBuffer& currState, const std::string& fname, c
476
511
currState[15 ] = static_cast <std::uint64_t >(count_);
477
512
currState[16 ] = static_cast <std::uint64_t >(type_);
478
513
514
+ const size_t countsSize = counts_.size ();
515
+ currState[17 ] = static_cast <std::uint64_t >(countsSize);
516
+ for (size_t i = 0 ; i < countsSize; ++i) {
517
+ currState[i+18 ] = static_cast <std::uint64_t >(counts_[i]);
518
+ }
519
+
479
520
currState.computeChecksum ();
480
521
481
522
return ;
@@ -495,6 +536,12 @@ void OperationWindow::deserialize(const IOBuffer& currState, const std::string&
495
536
count_ = static_cast <long >(currState[15 ]);
496
537
type_ = static_cast <long >(currState[16 ]);
497
538
539
+ const auto countsSize = static_cast <size_t >(currState[17 ]);
540
+ counts_.resize (countsSize);
541
+ for (size_t i = 0 ; i < countsSize; ++i) {
542
+ counts_[i] = static_cast <long >(currState[i+18 ]);
543
+ }
544
+
498
545
if (opt.debugRestart ()) {
499
546
std::ofstream outFile (fname);
500
547
outFile << " epochPoint_ :: " << epochPoint_ << std::endl;
@@ -506,6 +553,7 @@ void OperationWindow::deserialize(const IOBuffer& currState, const std::string&
506
553
outFile << " lastFlush_ :: " << lastFlush_ << std::endl;
507
554
outFile << " timeStepInSeconds_ :: " << timeStepInSeconds_ << std::endl;
508
555
outFile << " count_ :: " << count_ << std::endl;
556
+ outFile << " counts_.size() :: " << counts_.size () << std::endl;
509
557
outFile << " type_ :: " << type_ << std::endl;
510
558
outFile.close ();
511
559
}
@@ -514,7 +562,7 @@ void OperationWindow::deserialize(const IOBuffer& currState, const std::string&
514
562
}
515
563
516
564
size_t OperationWindow::restartSize () const {
517
- return static_cast < size_t >( 18 );
565
+ return 18 + counts_. size () + 1 ; // values + counts + checksum
518
566
}
519
567
520
568
void OperationWindow::print (std::ostream& os) const {
0 commit comments