15 #include "eckit/filesystem/PathName.h"
16 #include "eckit/io/Length.h"
17 #include "eckit/io/Offset.h"
18 #include "eckit/io/PartFileHandle.h"
24 using namespace eckit;
31 for (
size_t i (0);
i < p.size(); ++
i)
41 for (
size_t i(0);
i < size(); ++
i)
46 ss << fileNamePrefix <<
".pool_" <<
i;
47 PathName partitionFileName (ss.str());
49 Log::info() <<
"" <<
" ##### Writing partition " <<
i <<
" to file " << partitionFileName << endl;
51 p.
write(partitionFileName);
53 r.push_back(partitionFileName);
58 void Partitions::save(
const PathName& partitionFile)
60 Log::info() <<
"Saving partitions info to " << partitionFile << endl;
63 f.exceptions(ofstream::badbit | ofstream::failbit);
64 f.open(
string(partitionFile).c_str());
82 Partition& currentPartition (parts.back());
84 if (! (currentPartition.
numberOfRows() + nRows <= rowsPerPartition)) {
87 if (! currentPartition.
blocks().empty()) {
88 const Block& lastBlock (currentPartition.
blocks().back());
96 newPartition.
add(
Block(fileName, blockStart, blockStart + blockLength, firstRow, firstRow + nRows));
102 if (currentPartition.
blocks().empty()) {
103 currentPartition.
add(
Block(fileName, blockStart, blockStart + blockLength, 0, nRows));
108 Block& currentBlock (currentPartition.
blocks().back());
110 if (currentBlock.
fileName != fileName) {
111 currentPartition.
add(
Block(fileName, blockStart, blockStart + blockLength, 0, nRows));
117 if (currentBlock.
end < Offset(blockStart + blockLength))
118 currentBlock.
end = blockStart + blockLength;
std::vector< Block > & blocks()
ullong write(const eckit::PathName &fileName) const
ullong rowsOnLastBlock() const
ullong numberOfRows() const
ullong startOfLastBlock()
unsigned long long ullong
std::ostream & operator<<(std::ostream &o, const Partitions &p)
subroutine write(self, filename_in)