File indexing completed on 2025-01-18 10:17:39
0001
0002
0003
0004
0005 #include <JANA/JFactory.h>
0006 #include <JANA/JEvent.h>
0007 #include <JANA/JEventSource.h>
0008 #include <JANA/Utils/JTypeInfo.h>
0009
0010
0011 void JFactory::Create(const std::shared_ptr<const JEvent>& event) {
0012
0013 if (m_app == nullptr && event->GetJApplication() != nullptr) {
0014
0015
0016 m_app = event->GetJApplication();
0017 m_logger = m_app->GetJParameterManager()->GetLogger(GetLoggerName());
0018 }
0019
0020 if (mStatus == Status::Uninitialized) {
0021 DoInit();
0022 }
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 if (TestFactoryFlag(REGENERATE)) {
0035 if (mStatus == Status::Inserted) {
0036
0037 ClearData();
0038
0039 }
0040
0041 }
0042 else {
0043
0044
0045
0046
0047
0048 if (mStatus == Status::Inserted) {
0049
0050
0051 return;
0052 }
0053
0054
0055
0056
0057
0058 auto src = event->GetJEventSource();
0059 if (src != nullptr && src->IsGetObjectsEnabled()) {
0060 bool found_data = false;
0061
0062 CallWithJExceptionWrapper("JEventSource::GetObjects", [&](){
0063 found_data = src->GetObjects(event, this); });
0064
0065 if (found_data) {
0066 mStatus = Status::Inserted;
0067 mCreationStatus = CreationStatus::InsertedViaGetObjects;
0068 return;
0069 }
0070 }
0071
0072 }
0073
0074
0075
0076
0077
0078
0079
0080 if (mStatus == Status::Unprocessed) {
0081 auto run_number = event->GetRunNumber();
0082 if (mPreviousRunNumber != run_number) {
0083 if (mPreviousRunNumber != -1) {
0084 CallWithJExceptionWrapper("JFactory::EndRun", [&](){ EndRun(); });
0085 }
0086 CallWithJExceptionWrapper("JFactory::ChangeRun", [&](){ ChangeRun(event); });
0087 CallWithJExceptionWrapper("JFactory::BeginRun", [&](){ BeginRun(event); });
0088 mPreviousRunNumber = run_number;
0089 }
0090 CallWithJExceptionWrapper("JFactory::Process", [&](){ Process(event); });
0091 mStatus = Status::Processed;
0092 mCreationStatus = CreationStatus::Created;
0093 }
0094 }
0095
0096 void JFactory::DoInit() {
0097 if (mStatus != Status::Uninitialized) {
0098 return;
0099 }
0100 for (auto* parameter : m_parameters) {
0101 parameter->Configure(*(m_app->GetJParameterManager()), m_prefix);
0102 }
0103 for (auto* service : m_services) {
0104 service->Fetch(m_app);
0105 }
0106 CallWithJExceptionWrapper("JFactory::Init", [&](){ Init(); });
0107 mStatus = Status::Unprocessed;
0108 }
0109
0110 void JFactory::DoFinish() {
0111 if (mStatus == Status::Unprocessed || mStatus == Status::Processed) {
0112 if (mPreviousRunNumber != -1) {
0113 CallWithJExceptionWrapper("JFactory::EndRun", [&](){ EndRun(); });
0114 }
0115 CallWithJExceptionWrapper("JFactory::Finish", [&](){ Finish(); });
0116 mStatus = Status::Finished;
0117 }
0118 }
0119
0120 void JFactory::Summarize(JComponentSummary& summary) const {
0121
0122 auto fs = new JComponentSummary::Component(
0123 "Factory",
0124 GetPrefix(),
0125 GetTypeName(),
0126 GetLevel(),
0127 GetPluginName());
0128
0129 auto coll = new JComponentSummary::Collection(
0130 GetTag(),
0131 GetTag(),
0132 GetObjectName(),
0133 GetLevel());
0134
0135 fs->AddOutput(coll);
0136 summary.Add(fs);
0137 }
0138
0139