-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Johannes Junggeburth
committed
Feb 24, 2025
1 parent
56378e1
commit 9ed5ba9
Showing
4 changed files
with
196 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
Examples/Io/Csv/include/ActsExamples/Io/Csv/CsvMuonSpacePointReader.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// This file is part of the ACTS project. | ||
// | ||
// Copyright (C) 2016 CERN for the benefit of the ACTS project | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
#pragma once | ||
#include "ActsExamples/Framework/DataHandle.hpp" | ||
#include "ActsExamples/Framework/IReader.hpp" | ||
#include "ActsExamples/Framework/ProcessCode.hpp" | ||
|
||
#include "ActsExamples/EventData/MuonSpacePoint.hpp" | ||
|
||
namespace ActsExamples { | ||
struct AlgorithmContext; | ||
|
||
// Read in a simhit collection in comma-separated-value format. | ||
/// | ||
/// This reads one files per event in the configured input directory. By default | ||
/// it reads files in the current working directory. Files are assumed to be | ||
/// named using the following schema | ||
/// | ||
/// event000000001-<stem>.csv | ||
/// event000000002-<stem>.csv | ||
/// | ||
/// and each line in the file corresponds to one simhit. | ||
class CsvMuonSpacePointReader final : public IReader { | ||
public: | ||
struct Config { | ||
/// Where to read input files from. | ||
std::string inputDir{}; | ||
/// Input filename stem. | ||
std::string inputStem{}; | ||
/// Output simulated (truth) hits collection. | ||
std::string outputSpacePoints{}; | ||
}; | ||
|
||
/// Construct the simhit reader. | ||
/// | ||
/// @param config is the configuration object | ||
/// @param level is the logging level | ||
CsvMuonSpacePointReader(const Config& config, Acts::Logging::Level level); | ||
|
||
std::string name() const override; | ||
|
||
/// Return the available events range. | ||
std::pair<std::size_t, std::size_t> availableEvents() const override; | ||
|
||
/// Read out data from the input stream. | ||
ProcessCode read(const ActsExamples::AlgorithmContext& ctx) override; | ||
|
||
/// Readonly access to the config | ||
const Config& config() const { return m_cfg; } | ||
|
||
private: | ||
Config m_cfg{}; | ||
std::pair<std::size_t, std::size_t> m_eventsRange{}; | ||
std::unique_ptr<const Acts::Logger> m_logger{}; | ||
|
||
WriteDataHandle<Acts::SpacePointContainer> m_outputSpacePoints{this, "OutputMuonSpacePoints"}; | ||
|
||
const Acts::Logger& logger() const { return *m_logger; } | ||
}; | ||
|
||
} // namespace ActsExamples | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
|
||
// This file is part of the ACTS project. | ||
// | ||
// Copyright (C) 2016 CERN for the benefit of the ACTS project | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
#include "ActsExamples/Io/Csv/CsvMuonSpacePointReader.hpp" | ||
|
||
|
||
#include "Acts/Definitions/Units.hpp" | ||
#include "Acts/Geometry/GeometryIdentifier.hpp" | ||
#include "ActsExamples/EventData/MuonSpacePoint.hpp" | ||
#include "ActsExamples/Framework/AlgorithmContext.hpp" | ||
#include "ActsExamples/Io/Csv/CsvInputOutput.hpp" | ||
#include "ActsExamples/Utilities/Paths.hpp" | ||
#include "ActsFatras/EventData/Barcode.hpp" | ||
#include "ActsFatras/EventData/Hit.hpp" | ||
|
||
#include <array> | ||
#include <stdexcept> | ||
|
||
#include "CsvOutputData.hpp" | ||
|
||
|
||
|
||
namespace ActsExamples{ | ||
CsvMuonSpacePointReader::CsvMuonSpacePointReader(const Config& config, | ||
Acts::Logging::Level level): | ||
m_cfg{config}, | ||
// TODO check that all files (hits,cells,truth) exists | ||
m_eventsRange{determineEventFilesRange(m_cfg.inputDir, m_cfg.inputStem + ".csv")}, | ||
m_logger{Acts::getDefaultLogger("CsvMuonSpacePointReader", level)} { | ||
|
||
if (m_cfg.inputStem.empty()) { | ||
throw std::invalid_argument("Missing input filename stem"); | ||
} | ||
if (m_cfg.outputSpacePoints.empty()) { | ||
throw std::invalid_argument("Missing space point output collection"); | ||
} | ||
|
||
m_outputSpacePoints.initialize(m_cfg.outputSpacePoints); | ||
} | ||
|
||
std::string CsvMuonSpacePointReader::CsvMuonSpacePointReader::name() const { | ||
return "CsvMuonSpacePointReader"; | ||
} | ||
|
||
std::pair<std::size_t, std::size_t> | ||
CsvMuonSpacePointReader::availableEvents() const { | ||
return m_eventsRange; | ||
} | ||
|
||
ProcessCode CsvMuonSpacePointReader::read(const AlgorithmContext& ctx) { | ||
auto path = perEventFilepath(m_cfg.inputDir, m_cfg.inputStem + ".csv", | ||
ctx.eventNumber); | ||
|
||
NamedTupleCsvReader<MuonSpacePointData> reader(path); | ||
|
||
MuonSpacePointData data; | ||
|
||
// SimHitContainer::sequence_type unordered; | ||
Acts::SpacePointContainer spacePoints{}; | ||
|
||
while (reader.read(data)) { | ||
// unordered.push_back(SimHit(compressId(f), data.pdgId, pos, mom, mom, -1)); | ||
} | ||
// simHits.insert(unordered.begin(), unordered.end()); | ||
|
||
// write the ordered data to the EventStore (according to geometry_id). | ||
m_outputSpacePoints(ctx, std::move(spacePoints)); | ||
|
||
return ProcessCode::SUCCESS; | ||
} | ||
|
||
} |