Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-26 08:22:19

0001 /** TRACCC library, part of the ACTS project (R&D line)
0002  *
0003  * (c) 2024-2025 CERN for the benefit of the ACTS project
0004  *
0005  * Mozilla Public License Version 2.0
0006  */
0007 
0008 // Local include(s).
0009 #include "write_cells.hpp"
0010 
0011 // System include(s).
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   // Make sure that a valid detector description would've been given to the
0023   // function.
0024   if (dd_view.capacity() == 0u || cd_view.capacity() == 0u) {
0025     throw std::invalid_argument("Valid detector description must be provided");
0026   }
0027 
0028   // Open the file for writing.
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   // Create device objects.
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   // Write the header.
0040   ofile << "geometry_id,measurement_id,channel0,channel1,timestamp,value\n";
0041 
0042   // Write out each cell.
0043   for (edm::silicon_cell_collection::const_device::size_type i = 0;
0044        i < cells.size(); ++i) {
0045     // Get the cell.
0046     const edm::silicon_cell cell = cells.at(i);
0047 
0048     // Write the cell info to the file.
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 }  // namespace traccc::io::csv