Skip to content
Snippets Groups Projects
Commit fc5d7dbf authored by Xiaocong Ai's avatar Xiaocong Ai
Browse files

Update CsvParticleReader and CsvPlanarClusterReader needed for rebase

parent 7ece879b
No related branches found
No related tags found
1 merge request!127WIP: Resolve "Add Csv Readers for GenericGeometry datasets"
Pipeline #936324 failed
......@@ -6,53 +6,9 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include "ACTFW/GenericDetector/BuildGenericDetector.hpp"
#include "Acts/Detector/TrackingGeometry.hpp"
#include "Acts/Utilities/Logger.hpp"
#include "ACTFW/GenericDetector/GenericDetector.hpp"
#include "detail/CsvExampleBase.hpp"
/// @brief adding some specific options for this geometry type
struct GenericOptions
{
/// @brief operator to be called to add options for the generic detector
///
// @tparam options_t Type of the options object
///@param opt Options object
template <typename options_t>
void
operator()(options_t& opt)
{
}
};
/// @brief geometry getter, the operator() will be called int he example base
struct GenericGeometry
{
/// @brief operator called to construct the tracking geometry
///
/// @tparam variable_map_t Type of the variable map template for parameters
///
/// @param vm the parameter map object
///
/// @return a closed TrackingGeometry object
template <typename variable_map_t>
std::shared_ptr<const Acts::TrackingGeometry>
operator()(variable_map_t& vm)
{
// --------------------------------------------------------------------------------
// set geometry building logging level
Acts::Logging::Level surfaceLogLevel = Acts::Logging::Level(
vm["geo-surface-loglevel"].template as<size_t>());
Acts::Logging::Level layerLogLevel
= Acts::Logging::Level(vm["geo-layer-loglevel"].template as<size_t>());
Acts::Logging::Level volumeLogLevel
= Acts::Logging::Level(vm["geo-volume-loglevel"].template as<size_t>());
/// return the generic detector
return FW::Generic::buildGenericDetector(
surfaceLogLevel, layerLogLevel, volumeLogLevel, 3);
}
};
/// @brief main executable
///
/// @param argc The argument count
......
......@@ -16,59 +16,58 @@
#include "ACTFW/Common/OutputOptions.hpp"
#include "ACTFW/Framework/Sequencer.hpp"
#include "ACTFW/Framework/WhiteBoard.hpp"
#include "ACTFW/Options/CommonOptions.hpp"
#include "ACTFW/Plugins/Csv/CsvParticleReader.hpp"
#include "ACTFW/Plugins/Csv/CsvPlanarClusterReader.hpp"
#include "ACTFW/Plugins/Csv/CsvPlanarClusterWriter.hpp"
#include "ACTFW/Plugins/Csv/CsvReaderOptions.hpp"
#include "ACTFW/Utilities/Options.hpp"
namespace po = boost::program_options;
/// @brief The ReadCsv example
///
/// @tparam geometry_getter_t Type of the geometry getter struct
/// @tparam options_setup_t are the callable example options
/// @tparam geometry_setup_t Type of the geometry getter struct
///
/// @param argc the number of argumetns of the call
/// @param aegv the argument list
template <typename geometry_options_t, typename geometry_getter_t>
/// @param argv the argument list
/// @param optionsSetup is a callable options struct
/// @param geometrySetup is a callable geometry getter
template <typename options_setup_t, typename geometry_setup_t>
int
CsvExample(int argc,
char* argv[],
geometry_options_t geometryOptions,
geometry_getter_t trackingGeometry)
CsvExample(int argc,
char* argv[],
options_setup_t& optionsSetup,
geometry_setup_t& geometrySetup)
{
// Declare the supported program options.
po::options_description desc("Allowed options");
// Create the config object for the sequencer
FW::Sequencer::Config seqConfig;
// Now create the sequencer
FW::Sequencer sequencer(seqConfig);
// Add the Common options
FW::Options::addCommonOptions<po::options_description>(desc);
// Add options for the Csv reading
FW::Options::addCsvReaderOptions<po::options_description>(desc);
// Add the geometry options
FW::Options::addGeometryOptions<po::options_description>(desc);
// Add the output options
FW::Options::addOutputOptions<po::options_description>(desc);
// Add specific options for this geometry
geometryOptions(desc);
// setup and parse options
auto desc = FW::Options::makeDefaultOptions();
FW::Options::addSequencerOptions(desc);
FW::Options::addGeometryOptions(desc);
FW::Options::addCsvReaderOptions(desc);
FW::Options::addOutputOptions(desc);
// Map to store the given program options
po::variables_map vm;
// Get all options from contain line and store it into the map
po::store(po::parse_command_line(argc, argv, desc), vm);
po::notify(vm);
// Print help if requested
if (vm.count("help")) {
std::cout << desc << std::endl;
return 1;
optionsSetup(desc);
auto vm = FW::Options::parse(desc, argc, argv);
if (vm.empty()) {
return EXIT_FAILURE;
}
// Read the common options : number of events and log level
auto nEvents = FW::Options::readNumberOfEvents<po::variables_map>(vm);
auto logLevel = FW::Options::readLogLevel<po::variables_map>(vm);
// Get the tracking geometry
auto tGeometry = trackingGeometry(vm);
FW::Sequencer sequencer(FW::Options::readSequencerConfig(vm));
// Now read the standard options
auto logLevel = FW::Options::readLogLevel(vm);
auto nEvents = FW::Options::readSequencerConfig(vm).events;
auto geometry = geometrySetup(vm);
auto tGeometry = geometry.first;
auto contextDecorators = geometry.second;
// Add it to the sequencer
for (auto cdr : contextDecorators) {
sequencer.addContextDecorator(cdr);
}
// Input directory
std::string inputDir = vm["input-dir"].as<std::string>();
......@@ -86,18 +85,16 @@ CsvExample(int argc,
= vm["output-plCluster-collection"].as<std::string>();
// Read particles as CSV files
std::shared_ptr<FW::Csv::CsvParticleReader> particleCsvReader = nullptr;
if (vm["read-particle-csv"].as<bool>()) {
FW::Csv::CsvParticleReader::Config particleCsvReaderConfig;
particleCsvReaderConfig.inputDir = inputDir;
particleCsvReaderConfig.inputFileName = inputParticlesFile + ".csv";
particleCsvReaderConfig.outputParticleCollection = outputParticleCollection;
particleCsvReader = std::make_shared<FW::Csv::CsvParticleReader>(
particleCsvReaderConfig, logLevel);
sequencer.addReader(std::make_shared<FW::Csv::CsvParticleReader>(
particleCsvReaderConfig, logLevel));
}
// Read clusters as CSV files
std::shared_ptr<FW::Csv::CsvPlanarClusterReader> plCsvReader = nullptr;
if (vm["read-plCluster-csv"].as<bool>()) {
FW::Csv::CsvPlanarClusterReader::Config plCsvReaderConfig;
plCsvReaderConfig.tGeometry = tGeometry;
......@@ -106,30 +103,9 @@ CsvExample(int argc,
plCsvReaderConfig.inputDetailsFileName = inputDetailsFileName + ".csv";
plCsvReaderConfig.inputTruthFileName = inputTruthFileName + ".csv";
plCsvReaderConfig.outputClusterCollection = outputClusterCollection;
plCsvReader = std::make_shared<FW::Csv::CsvPlanarClusterReader>(
plCsvReaderConfig, logLevel);
sequencer.addReader(std::make_shared<FW::Csv::CsvPlanarClusterReader>(
plCsvReaderConfig, logLevel));
}
// Output Csv directory
std::string outputDir = vm["output-dir"].template as<std::string>();
// Write back CsvPlanarClusterReader output as Csv files
std::shared_ptr<FW::Csv::CsvPlanarClusterWriter> plCsvWriter = nullptr;
if (vm["output-csv"].template as<bool>()) {
FW::Csv::CsvPlanarClusterWriter::Config clusterWriterCsvConfig;
clusterWriterCsvConfig.collection = outputClusterCollection;
clusterWriterCsvConfig.outputDir = outputDir;
plCsvWriter = std::make_shared<FW::Csv::CsvPlanarClusterWriter>(
clusterWriterCsvConfig);
}
// Initiate the run
if (particleCsvReader) sequencer.addReaders({particleCsvReader});
if (plCsvReader) sequencer.addReaders({plCsvReader});
if (plCsvWriter) sequencer.addWriters({plCsvWriter});
sequencer.appendEventAlgorithms({});
sequencer.run(nEvents);
// Return 0 for success
return 0;
return sequencer.run();
}
......@@ -56,7 +56,7 @@ namespace Csv {
/// Read out data from the input stream
ProcessCode
read(FW::AlgorithmContext ctx) final override;
read(const FW::AlgorithmContext& ctx) final override;
/// Return the number of events
virtual size_t
......
......@@ -67,7 +67,7 @@ namespace Csv {
/// Read out data from the input stream
ProcessCode
read(FW::AlgorithmContext ctx) final override;
read(const FW::AlgorithmContext& ctx) final override;
/// Return the number of events
virtual size_t
......
......@@ -34,7 +34,7 @@ FW::Csv::CsvParticleReader::skip(size_t nEvents)
}
FW::ProcessCode
FW::Csv::CsvParticleReader::read(FW::AlgorithmContext ctx)
FW::Csv::CsvParticleReader::read(const FW::AlgorithmContext& ctx)
{
std::string pathIs
= perEventFilepath(m_cfg.inputDir, m_cfg.inputFileName, ctx.eventNumber);
......@@ -81,10 +81,7 @@ FW::Csv::CsvParticleReader::read(FW::AlgorithmContext ctx)
}
// write the truth particles to the EventStore
if (ctx.eventStore.add(m_cfg.outputParticleCollection, std::move(particles))
== FW::ProcessCode::ABORT) {
return FW::ProcessCode::ABORT;
}
ctx.eventStore.add(m_cfg.outputParticleCollection, std::move(particles));
return ProcessCode::SUCCESS;
}
......@@ -48,7 +48,7 @@ FW::Csv::CsvPlanarClusterReader::skip(size_t nEvents)
}
FW::ProcessCode
FW::Csv::CsvPlanarClusterReader::read(FW::AlgorithmContext ctx)
FW::Csv::CsvPlanarClusterReader::read(const FW::AlgorithmContext& ctx)
{
// Prepare the output data: Clusters
......@@ -131,7 +131,7 @@ FW::Csv::CsvPlanarClusterReader::read(FW::AlgorithmContext ctx)
std::stof(hitVal[1]), std::stof(hitVal[2]), std::stof(hitVal[3]));
Acts::Vector2D local(0, 0);
Acts::Vector3D mom(1, 1, 1);
hitSurface->globalToLocal(pos, mom, local);
hitSurface->globalToLocal(ctx.geoContext, pos, mom, local);
Acts::ActsSymMatrixD<2> cov;
cov << 0., 0., 0., 0.;
......@@ -218,11 +218,7 @@ FW::Csv::CsvPlanarClusterReader::read(FW::AlgorithmContext ctx)
}
// write the clusters to the EventStore
if (ctx.eventStore.add(m_cfg.outputClusterCollection,
std::move(planarClusters))
== FW::ProcessCode::ABORT) {
return FW::ProcessCode::ABORT;
}
ctx.eventStore.add(m_cfg.outputClusterCollection, std::move(planarClusters));
return FW::ProcessCode::SUCCESS;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment