File indexing completed on 2025-01-18 10:17:19
0001
0002
0003
0004
0005 #include <JANA/JEventProcessor.h>
0006
0007 #include <podio/podioVersion.h>
0008 #if podio_VERSION_MAJOR == 0 && podio_VERSION_MINOR < 99
0009 #include <podio/ROOTFrameWriter.h>
0010 namespace podio {
0011 using ROOTWriter = podio::ROOTFrameWriter;
0012 }
0013 #else
0014 #include <podio/ROOTWriter.h>
0015 #endif
0016
0017 class PodioFileWriter : public JEventProcessor {
0018
0019 private:
0020 Parameter<std::vector<std::string>> m_collection_names {this,
0021 "podio:output_collections",
0022 {},
0023 "Comma-separated collection names to write to file"};
0024
0025 Parameter<std::string> m_output_filename {this,
0026 "podio:output_file",
0027 "output.root",
0028 "PODIO output filename"};
0029
0030 Parameter<std::string> m_output_category {this,
0031 "podio:output_category",
0032 "events",
0033 "Name of branch to store data in the output file"};
0034
0035 std::unique_ptr<podio::ROOTWriter> m_writer;
0036
0037
0038 public:
0039 PodioFileWriter() {
0040 SetTypeName(NAME_OF_THIS);
0041 SetCallbackStyle(CallbackStyle::ExpertMode);
0042 }
0043
0044 void Init() override {
0045 m_writer = std::make_unique<podio::ROOTWriter>(*m_output_filename);
0046 }
0047
0048 void Finish() override {
0049 m_writer->finish();
0050 }
0051
0052 void ProcessParallel(const JEvent& event) override {
0053
0054 for (const auto& collection_name : *m_collection_names) {
0055
0056
0057
0058
0059
0060 event.GetCollectionBase(collection_name);
0061 }
0062 }
0063
0064 void Process(const JEvent& event) override {
0065
0066 auto* frame = event.GetSingle<podio::Frame>();
0067
0068
0069
0070 m_writer->writeFrame(*frame, *m_output_category);
0071
0072
0073
0074 }
0075
0076 };
0077
0078
0079 extern "C" {
0080 void InitPlugin(JApplication* app) {
0081 InitJANAPlugin(app);
0082 app->Add(new PodioFileWriter());
0083 }
0084 }
0085
0086
0087