Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:36:43

0001 // Copyright 2024, Jefferson Science Associates, LLC.
0002 // Subject to the terms in the LICENSE file found in the top-level directory.
0003 // Created by Nathan Brei
0004 
0005 #pragma once
0006 
0007 #include <JANA/JApplication.h>
0008 
0009 class JEvent;
0010 namespace jana::components {
0011 
0012 
0013 class JHasRunCallbacks {
0014 
0015 protected:
0016     struct ResourceBase {
0017         virtual void ChangeRun(int32_t run_nr, JApplication* app) = 0;
0018     };
0019 
0020     std::vector<ResourceBase*> m_resources;
0021     int32_t m_last_run_number = -1;
0022 
0023 public:
0024     void RegisterResource(ResourceBase* resource) {
0025         m_resources.push_back(resource);
0026     }
0027 
0028     template <typename ServiceT, typename ResourceT, typename LambdaT>
0029     class Resource : public ResourceBase {
0030         ResourceT m_data;
0031         LambdaT m_lambda;
0032 
0033     public:
0034 
0035         Resource(JHasRunCallbacks* owner, LambdaT lambda) : m_lambda(lambda) {
0036             owner->RegisterResource(this);
0037         };
0038 
0039         const ResourceT& operator()() { return m_data; }
0040 
0041     protected:
0042 
0043         void ChangeRun(int32_t run_nr, JApplication* app) override {
0044             std::shared_ptr<ServiceT> service = app->template GetService<ServiceT>();
0045             m_data = m_lambda(service, run_nr);
0046         }
0047     };
0048 
0049     // ExpertMode
0050     virtual void ChangeRun(const JEvent&) {}
0051 
0052     // Compatibility interface
0053     virtual void BeginRun(const std::shared_ptr<const JEvent>&) {}
0054 
0055     virtual void ChangeRun(const std::shared_ptr<const JEvent>&) {}
0056 
0057     virtual void EndRun() {}
0058 
0059 };
0060 
0061 
0062 } // namespace jana::components