Skip to content
Snippets Groups Projects
Commit 90bd8f08 authored by Felix Weiglhofer's avatar Felix Weiglhofer
Browse files

algo::Archive: Implement %n wildcard in filenames to store TS id in filename.

parent 4bfcc332
No related branches found
No related tags found
1 merge request!1192cbmreco: Add support to store results to file
...@@ -5,11 +5,14 @@ ...@@ -5,11 +5,14 @@
#include "CbmStsDigi.h" #include "CbmStsDigi.h"
#include <boost/algorithm/string.hpp>
#include <boost/archive/binary_iarchive.hpp> #include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/binary_oarchive.hpp> #include <boost/archive/binary_oarchive.hpp>
#include <boost/serialization/vector.hpp> #include <boost/serialization/vector.hpp>
#include <fstream> #include <fstream>
#include <iomanip>
#include <sstream>
#include "log.hpp" #include "log.hpp"
...@@ -25,10 +28,28 @@ Archive::Archive(fs::path file) ...@@ -25,10 +28,28 @@ Archive::Archive(fs::path file)
ia >> *this; ia >> *this;
} }
void Archive::Store(fs::path file) const void Archive::Store(fs::path file, std::optional<size_t> tsId) const
{ {
file = makeFileName(file, tsId);
L_(info) << "Writing archive to " << file; L_(info) << "Writing archive to " << file;
std::ofstream ofs(file.string(), std::ios::binary); std::ofstream ofs(file.string(), std::ios::binary);
ba::binary_oarchive oa(ofs); ba::binary_oarchive oa(ofs);
oa << *this; oa << *this;
} }
fs::path Archive::makeFileName(fs::path file, std::optional<size_t> tsId) const
{
if (!tsId) return file;
// Shamelessly copied from fles::OutputArchiveSequence
if (file.string().find("%n") == std::string::npos) {
L_(warning)
<< "Archive file name does not contain %n wildcard (timeslice number). Appending id to file name instead.";
file += "_%n";
}
std::ostringstream number;
number << std::setw(4) << std::setfill('0') << *tsId;
return boost::replace_all_copy(file.string(), "%n", number.str());
}
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <boost/serialization/access.hpp> #include <boost/serialization/access.hpp>
#include <boost/serialization/version.hpp> #include <boost/serialization/version.hpp>
#include <optional>
#include <vector> #include <vector>
#include "RecoIO.h" #include "RecoIO.h"
...@@ -32,7 +33,7 @@ namespace cbm::algo ...@@ -32,7 +33,7 @@ namespace cbm::algo
/** /**
* @brief Store Archive object to file. * @brief Store Archive object to file.
*/ */
void Store(fs::path file) const; void Store(fs::path file, std::optional<size_t> tsId = {}) const;
const std::vector<fles::SubsystemIdentifier>& Detectors() const { return fDetectors; } const std::vector<fles::SubsystemIdentifier>& Detectors() const { return fDetectors; }
...@@ -41,7 +42,6 @@ namespace cbm::algo ...@@ -41,7 +42,6 @@ namespace cbm::algo
private: private:
std::vector<fles::SubsystemIdentifier> fDetectors; std::vector<fles::SubsystemIdentifier> fDetectors;
std::vector<RecoIO> fTimesliceResults; std::vector<RecoIO> fTimesliceResults;
friend class boost::serialization::access; friend class boost::serialization::access;
...@@ -51,6 +51,8 @@ namespace cbm::algo ...@@ -51,6 +51,8 @@ namespace cbm::algo
ar& fDetectors; ar& fDetectors;
ar& fTimesliceResults; ar& fTimesliceResults;
} }
fs::path makeFileName(fs::path file, std::optional<size_t> tsId) const;
}; };
} // namespace cbm::algo } // namespace cbm::algo
......
...@@ -25,10 +25,10 @@ namespace cbm::algo ...@@ -25,10 +25,10 @@ namespace cbm::algo
Reco(); Reco();
~Reco(); ~Reco();
Reco(const Reco&) = delete; Reco(const Reco&) = delete;
Reco& operator=(const Reco&) = delete; Reco& operator=(const Reco&) = delete;
Reco(Reco&&) = delete; Reco(Reco&&) = delete;
Reco& operator=(Reco&&) = delete; Reco& operator=(Reco&&) = delete;
void Init(const Options&); void Init(const Options&);
RecoIO Run(const fles::Timeslice&); RecoIO Run(const fles::Timeslice&);
......
...@@ -58,19 +58,20 @@ int main(int argc, char** argv) ...@@ -58,19 +58,20 @@ int main(int argc, char** argv)
} }
auto result = reco.Run(*ts); auto result = reco.Run(*ts);
if (opts.WritePerTimeslice() && !opts.OutputFile().empty()) { if (opts.SplitOutputPerTS() && !opts.OutputFile().empty()) {
Archive tsResults({fles::SubsystemIdentifier::STS}); // TODO: use opts.Detector() once detector flag is merged Archive tsResults({fles::SubsystemIdentifier::STS}); // TODO: use opts.Detector() once detector flag is merged
tsResults.TimesliceResults().push_back(result); tsResults.TimesliceResults().emplace_back(std::move(result));
// TODO: handle file endings tsResults.Store(opts.OutputFile(), ts->index());
tsResults.Store(fmt::format("{}_{}", opts.OutputFile().string(), ts->index())); }
else {
archive.TimesliceResults().emplace_back(std::move(result));
} }
archive.TimesliceResults().push_back(result); // TODO: result should be moved not copied
tsIdx++; tsIdx++;
if (num_ts > 0 && tsIdx >= num_ts) { break; } if (num_ts > 0 && tsIdx >= num_ts) { break; }
} }
if (!opts.WritePerTimeslice() && !opts.OutputFile().empty()) archive.Store(opts.OutputFile()); if (!opts.SplitOutputPerTS() && !opts.OutputFile().empty()) archive.Store(opts.OutputFile());
reco.Finalize(); reco.Finalize();
return 0; return 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment