File indexing completed on 2026-07-26 08:22:19
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "write_cells.hpp"
0010
0011
0012 #include <fstream>
0013 #include <stdexcept>
0014
0015 namespace traccc::io::csv {
0016
0017 void write_cells(std::string_view filename,
0018 traccc::edm::silicon_cell_collection::const_view cells_view,
0019 traccc::detector_design_description::const_view dd_view,
0020 traccc::detector_conditions_description::const_view cd_view,
0021 bool use_acts_geometry_id) {
0022
0023
0024 if (dd_view.capacity() == 0u || cd_view.capacity() == 0u) {
0025 throw std::invalid_argument("Valid detector description must be provided");
0026 }
0027
0028
0029 std::ofstream ofile(filename.data());
0030 if (!ofile.is_open()) {
0031 throw std::runtime_error("Could not open file " + std::string(filename));
0032 }
0033
0034
0035 const edm::silicon_cell_collection::const_device cells(cells_view);
0036 const detector_design_description::const_device det_desc(dd_view);
0037 const detector_conditions_description::const_device det_cond{cd_view};
0038
0039
0040 ofile << "geometry_id,measurement_id,channel0,channel1,timestamp,value\n";
0041
0042
0043 for (edm::silicon_cell_collection::const_device::size_type i = 0;
0044 i < cells.size(); ++i) {
0045
0046 const edm::silicon_cell cell = cells.at(i);
0047
0048
0049 ofile << (use_acts_geometry_id
0050 ? det_cond.acts_geometry_id().at(cell.module_index())
0051 : det_cond.geometry_id().at(cell.module_index()).value())
0052 << ",0," << cell.channel0() << ',' << cell.channel1() << ','
0053 << cell.time() << ',' << cell.activation() << '\n';
0054 }
0055 }
0056
0057 }