Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /jana2/src/libraries/JANA/JEventFolder.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // Copyright 2024, Jefferson Science Associates, LLC.
0002 // Subject to the terms in the LICENSE file found in the top-level directory.
0003 
0004 #pragma once
0005 
0006 #include <JANA/Components/JComponent.h>
0007 #include <JANA/Components/JHasInputs.h>
0008 #include <JANA/Components/JHasOutputs.h>
0009 #include <JANA/Components/JHasRunCallbacks.h>
0010 #include <JANA/JEvent.h>
0011 
0012 class JApplication;
0013 class JEventFolder : public jana::components::JComponent,
0014                      public jana::components::JHasRunCallbacks,
0015                      public jana::components::JHasInputs,
0016                      public jana::components::JHasOutputs {
0017 
0018 private:
0019     int32_t m_last_run_number = -1;
0020     JEventLevel m_child_level;
0021     bool m_call_preprocess_upstream = true;
0022 
0023 
0024 public:
0025     JEventFolder() {
0026         m_type_name = "JEventFolder";
0027     }
0028     virtual ~JEventFolder() {};
0029  
0030     virtual void Preprocess(const JEvent& /*parent*/) const {};
0031 
0032     virtual void Fold(const JEvent& /*child*/, JEvent& /*parent*/, int /*item_nr*/) {
0033         throw JException("Not implemented yet!");
0034     };
0035 
0036     virtual void Finish() {};
0037 
0038 
0039     // Configuration
0040 
0041     void SetParentLevel(JEventLevel level) { m_level = level; }
0042 
0043     void SetChildLevel(JEventLevel level) { m_child_level = level; }
0044 
0045     void SetCallPreprocessUpstream(bool call_upstream) { m_call_preprocess_upstream = call_upstream; }
0046     
0047     JEventLevel GetChildLevel() { return m_child_level; }
0048 
0049 
0050  public:
0051     // Backend
0052 
0053     void DoPreprocess(const JEvent& child) {
0054         {
0055             if (!m_is_initialized) {
0056                 throw JException("JEventFolder: Component needs to be initialized and not finalized before Fold can be called");
0057             }
0058         }
0059         for (auto* input : m_inputs) {
0060             input->TriggerFactoryCreate(child);
0061         }
0062         for (auto* variadic_input : m_variadic_inputs) {
0063             variadic_input->TriggerFactoryCreate(child);
0064         }
0065         CallWithJExceptionWrapper("JEventFolder::Preprocess", [&](){
0066             Preprocess(child);
0067         });
0068     }
0069 
0070     void DoFold(const JEvent& child, JEvent& parent) {
0071         std::lock_guard<std::mutex> lock(m_mutex);
0072         if (!m_is_initialized) {
0073             throw JException("Component needs to be initialized and not finalized before Fold() can be called");
0074         }
0075         if (!m_call_preprocess_upstream) {
0076             CallWithJExceptionWrapper("JEventFolder::Preprocess", [&](){
0077                 Preprocess(child);
0078             });
0079         }
0080         if (m_last_run_number != parent.GetRunNumber()) {
0081             for (auto* resource : m_resources) {
0082                 resource->ChangeRun(parent.GetRunNumber(), m_app);
0083             }
0084             CallWithJExceptionWrapper("JEventFolder::ChangeRun", [&](){
0085                 ChangeRun(parent);
0086             });
0087             m_last_run_number = parent.GetRunNumber();
0088         }
0089         for (auto* input : m_inputs) {
0090             input->Populate(child);
0091         }
0092         for (auto* variadic_input : m_variadic_inputs) {
0093             variadic_input->Populate(child);
0094         }
0095         auto child_number = child.GetEventIndex();
0096         CallWithJExceptionWrapper("JEventFolder::Fold", [&](){
0097             Fold(child, parent, child_number);
0098         });
0099 
0100         for (auto* output : GetOutputs()) {
0101             output->EulerianStore(*parent.GetFactorySet());
0102         }
0103         for (auto* output : GetVariadicOutputs()) {
0104             output->EulerianStore(*parent.GetFactorySet());
0105         }
0106     }
0107 
0108     void DoFinish() {
0109         std::lock_guard<std::mutex> lock(m_mutex);
0110         if (!m_is_finalized) {
0111             CallWithJExceptionWrapper("JEventFolder::Finish", [&](){
0112                 Finish();
0113             });
0114             m_is_finalized = true;
0115         }
0116     }
0117 
0118     void Summarize(JComponentSummary& summary) const override {
0119         auto* us = new JComponentSummary::Component( 
0120             "Folder", GetPrefix(), GetTypeName(), GetLevel(), GetPluginName());
0121 
0122         SummarizeInputs(*us);
0123         SummarizeOutputs(*us);
0124         summary.Add(us);
0125     }
0126 
0127 };
0128 
0129