Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:29:38

0001 
0002 // Copyright 2024, Jefferson Science Associates, LLC.
0003 // Subject to the terms in the LICENSE file found in the top-level directory.
0004 
0005 #pragma once
0006 
0007 #include <JANA/JEventProcessor.h>
0008 #include "CollectionTabulators.h"
0009 
0010 #include <podio/podioVersion.h>
0011 #if podio_VERSION_MAJOR == 0 && podio_VERSION_MINOR < 99
0012 #include <podio/ROOTFrameWriter.h>
0013 namespace podio {
0014 using ROOTWriter = podio::ROOTFrameWriter;
0015 }
0016 #else
0017 #include <podio/ROOTWriter.h>
0018 #endif
0019 
0020 
0021 
0022 struct MyFileWriter : public JEventProcessor {
0023 
0024     // Trigger the creation of clusters
0025     PodioInput<ExampleCluster> m_evt_clusters_in {this, {.name="clusters"}};
0026 
0027     // Retrieve the PODIO frame so we can write it directly
0028     Input<podio::Frame> m_evt_frame_in {this, {.name = "", 
0029                                                .level = JEventLevel::PhysicsEvent}};
0030 
0031     Input<podio::Frame> m_ts_frame_in {this, {.name = "", 
0032                                               .level = JEventLevel::Timeslice,
0033                                               .is_optional = true }};
0034 
0035     std::unique_ptr<podio::ROOTWriter> m_writer = nullptr;
0036     std::mutex m_mutex;
0037     
0038     MyFileWriter() {
0039         SetTypeName(NAME_OF_THIS);
0040         SetCallbackStyle(CallbackStyle::ExpertMode);
0041     }
0042 
0043     void Init() {
0044         m_writer = std::make_unique<podio::ROOTWriter>("output.root");
0045     }
0046 
0047     void Process(const JEvent& event) {
0048 
0049         std::lock_guard<std::mutex> guard(m_mutex);
0050         if (event.HasParent(JEventLevel::Timeslice)) {
0051 
0052             auto& ts = event.GetParent(JEventLevel::Timeslice);
0053             auto ts_nr = ts.GetEventNumber();
0054 
0055             if (event.GetEventIndex() == 0) {
0056                 m_writer->writeFrame(*(m_ts_frame_in().at(0)), "timeslices");
0057             }
0058 
0059             LOG_DEBUG(GetLogger()) 
0060                 << "Event " << event.GetEventNumber() << " from Timeslice " << ts_nr
0061                 << "\nClusters\n"
0062                 << TabulateClusters(m_evt_clusters_in())
0063                 << LOG_END;
0064         }
0065         else {
0066 
0067             LOG_DEBUG(GetLogger()) 
0068                 << "Event " << event.GetEventNumber()
0069                 << "\nClusters\n"
0070                 << TabulateClusters(m_evt_clusters_in())
0071                 << LOG_END;
0072         }
0073 
0074         m_writer->writeFrame(*(m_evt_frame_in().at(0)), "events");
0075 
0076     }
0077 
0078     void Finish() {
0079         m_writer->finish();
0080     }
0081 };
0082 
0083