1717*/
1818
1919#include < ored/report/inmemoryreport.hpp>
20+ #include < ored/utilities/serializationdate.hpp>
21+ #include < ored/utilities/serializationperiod.hpp>
2022
2123#include < boost/algorithm/string/join.hpp>
24+ #include < boost/serialization/serialization.hpp>
25+ #include < boost/serialization/vector.hpp>
26+ #include < boost/serialization/variant.hpp>
27+ #include < boost/archive/binary_oarchive.hpp>
28+ #include < boost/archive/binary_iarchive.hpp>
29+
30+ #include < fstream>
2231
2332namespace ore {
2433namespace data {
@@ -27,15 +36,26 @@ Report& InMemoryReport::addColumn(const string& name, const ReportType& rt, Size
2736 headers_.push_back (name);
2837 columnTypes_.push_back (rt);
2938 columnPrecision_.push_back (precision);
30- data_.push_back (vector<ReportType>()); // Initialise vector for
39+ data_.push_back (vector<ReportType>()); // Initialise vector for column
3140 i_++;
3241 return *this ;
3342}
3443
3544Report& InMemoryReport::next () {
36- QL_REQUIRE (i_ == headers_.size (), " Cannot go to next line, only " << i_ << " entires filled, report headers are: "
45+ QL_REQUIRE (i_ == headers_.size (), " Cannot go to next line, only " << i_ << " entries filled, report headers are: "
3746 << boost::join (headers_, " ," ));
3847 i_ = 0 ;
48+ if (bufferSize_ && data_[0 ].size () == bufferSize_ && !headers_.empty ()) {
49+ std::string s = std::tmpnam (nullptr );
50+ std::ofstream os (s.c_str (), std::ios::binary);
51+ boost::archive::binary_oarchive oa (os, boost::archive::no_header);
52+ for (Size i = 0 ; i < headers_.size (); i++) {
53+ oa << data_[i];
54+ data_[i].clear ();
55+ }
56+ os.close ();
57+ files_.push_back (s);
58+ }
3959 return *this ;
4060}
4161
@@ -85,6 +105,8 @@ void InMemoryReport::end() {
85105}
86106
87107const vector<Report::ReportType>& InMemoryReport::data (Size i) const {
108+ QL_REQUIRE (files_.empty (), " Member function InMemoryReport::data() is not supported "
109+ " when buffering is active" );
88110 QL_REQUIRE (data_[i].size () == rows (), " internal error: report column "
89111 << i << " (" << header (i) << " ) contains " << data_[i].size ()
90112 << " rows, expected are " << rows ()
@@ -103,6 +125,24 @@ void InMemoryReport::toFile(const string& filename, const char sep, const bool c
103125
104126 auto numColumns = columns ();
105127 if (numColumns > 0 ) {
128+
129+ for (auto &f : files_) {
130+ vector<vector<ReportType>> data (numColumns);
131+ std::ifstream is (f.c_str (), std::ios::binary);
132+ boost::archive::binary_iarchive ia (is, boost::archive::no_header);
133+ for (Size i = 0 ; i < numColumns; i++) {
134+ ia >> data[i];
135+ }
136+ is.close ();
137+
138+ for (Size i = 0 ; i < data[0 ].size (); i++) {
139+ cReport.next ();
140+ for (Size j = 0 ; j < numColumns; j++) {
141+ cReport.add (data[j][i]);
142+ }
143+ }
144+ }
145+
106146 auto numRows = data_[0 ].size ();
107147
108148 for (Size i = 0 ; i < numRows; i++) {
0 commit comments