File indexing completed on 2025-01-18 10:01:38
0001
0002
0003
0004
0005 #pragma once
0006
0007 #include <podio/ROOTFrameWriter.h>
0008 #include "CollectionTabulators.h"
0009 #include <JANA/JEventProcessor.h>
0010
0011 #include <set>
0012
0013
0014
0015 struct MyFileWriter : public JEventProcessor {
0016
0017
0018 PodioInput<ExampleCluster> m_evt_clusters_in {this, {.name="clusters"}};
0019
0020
0021 Input<podio::Frame> m_evt_frame_in {this, {.name = "",
0022 .level = JEventLevel::PhysicsEvent}};
0023
0024 Input<podio::Frame> m_ts_frame_in {this, {.name = "",
0025 .level = JEventLevel::Timeslice,
0026 .is_optional = true }};
0027
0028 std::unique_ptr<podio::ROOTFrameWriter> m_writer = nullptr;
0029 std::mutex m_mutex;
0030
0031 MyFileWriter() {
0032 SetTypeName(NAME_OF_THIS);
0033 SetCallbackStyle(CallbackStyle::ExpertMode);
0034 }
0035
0036 void Init() {
0037 m_writer = std::make_unique<podio::ROOTFrameWriter>("output.root");
0038 }
0039
0040 void Process(const JEvent& event) {
0041
0042 std::lock_guard<std::mutex> guard(m_mutex);
0043 if (event.HasParent(JEventLevel::Timeslice)) {
0044
0045 auto& ts = event.GetParent(JEventLevel::Timeslice);
0046 auto ts_nr = ts.GetEventNumber();
0047
0048 if (event.GetEventIndex() == 0) {
0049 m_writer->writeFrame(*(m_ts_frame_in().at(0)), "timeslices");
0050 }
0051
0052 LOG_DEBUG(GetLogger())
0053 << "Event " << event.GetEventNumber() << " from Timeslice " << ts_nr
0054 << "\nClusters\n"
0055 << TabulateClusters(m_evt_clusters_in())
0056 << LOG_END;
0057 }
0058 else {
0059
0060 LOG_DEBUG(GetLogger())
0061 << "Event " << event.GetEventNumber()
0062 << "\nClusters\n"
0063 << TabulateClusters(m_evt_clusters_in())
0064 << LOG_END;
0065 }
0066
0067 m_writer->writeFrame(*(m_evt_frame_in().at(0)), "events");
0068
0069 }
0070
0071 void Finish() {
0072 m_writer->finish();
0073 }
0074 };
0075
0076