From 9e974e6a9b7a831f3f35b09ac13929ef2eb7527f Mon Sep 17 00:00:00 2001 From: Pherring04 <158035107+Pherring04@users.noreply.github.com> Date: Tue, 29 Oct 2024 11:05:33 -0500 Subject: [PATCH] Addressed phantom frame log restart jobs (#1787) * Frame Log DRG now manage their own jobs (no longer add a phantom restart job) * Actually removed frame log drg restart jobs this time * Refactored to avoid duplicate code * Refactor * Fixed DR constructors * Fixed some syntax stuff centos was throwing a tantrum about * More centos whining * Centos... * Centos... * Clean up --- include/trick/DRAscii.hh | 3 +- include/trick/DRBinary.hh | 2 +- include/trick/DRHDF5.hh | 3 +- include/trick/DataRecordGroup.hh | 16 ++++++++- .../sim_services/DataRecord/DRAscii.cpp | 2 +- .../sim_services/DataRecord/DRBinary.cpp | 4 +-- .../sim_services/DataRecord/DRHDF5.cpp | 2 +- .../DataRecord/DataRecordGroup.cpp | 36 ++++++++++++------- .../FrameLog/FrameDataRecordGroup.cpp | 2 +- 9 files changed, 48 insertions(+), 22 deletions(-) diff --git a/include/trick/DRAscii.hh b/include/trick/DRAscii.hh index bdcc227d..6da2c839 100644 --- a/include/trick/DRAscii.hh +++ b/include/trick/DRAscii.hh @@ -13,6 +13,7 @@ PROGRAMMERS: #include "trick/DataRecordGroup.hh" #ifdef SWIG +%feature("compactdefaultargs","0") ; %feature("shadow") Trick::DRAscii::DRAscii(std::string in_name) %{ def __init__(self, *args): this = $action(*args) @@ -68,7 +69,7 @@ namespace Trick { @code = trick.DRAscii("") @endcode @copydoc Trick::DataRecordGroup::DataRecordGroup(string in_name) */ - DRAscii( std::string in_name) ; + DRAscii( std::string in_name, Trick::DR_Type dr_type = Trick::DR_Type::DR_Type_Ascii ) ; /** @copybrief Trick::DataRecordGroup::format_specific_header diff --git a/include/trick/DRBinary.hh b/include/trick/DRBinary.hh index bcf5c4ef..323ce788 100644 --- a/include/trick/DRBinary.hh +++ b/include/trick/DRBinary.hh @@ -93,7 +93,7 @@ namespace Trick { @code = trick.DRBinary("") @endcode @copydoc Trick::DataRecordGroup::DataRecordGroup(string in_name) */ - DRBinary( std::string in_name, bool register_group = true ) ; + DRBinary( std::string in_name, bool register_group = true, Trick::DR_Type dr_type = Trick::DR_Type::DR_Type_Binary ) ; /** @copybrief Trick::DataRecordGroup::format_specific_header diff --git a/include/trick/DRHDF5.hh b/include/trick/DRHDF5.hh index a241f20a..54d5cfbd 100644 --- a/include/trick/DRHDF5.hh +++ b/include/trick/DRHDF5.hh @@ -24,6 +24,7 @@ PROGRAMMERS: #endif #ifdef SWIG +%feature("compactdefaultargs","0") ; %feature("shadow") Trick::DRHDF5::DRHDF5(std::string in_name) %{ def __init__(self, *args): this = $action(*args) @@ -101,7 +102,7 @@ GROUP "/" { @code = trick.DRHDF5("") @endcode @copydoc Trick::DataRecordGroup::DataRecordGroup(string in_name) */ - DRHDF5( std::string in_name) ; + DRHDF5( std::string in_name, Trick::DR_Type dr_type = Trick::DR_Type::DR_Type_HDF5) ; /** @copybrief Trick::DataRecordGroup::format_specific_header diff --git a/include/trick/DataRecordGroup.hh b/include/trick/DataRecordGroup.hh index d6587083..184a65ec 100644 --- a/include/trick/DataRecordGroup.hh +++ b/include/trick/DataRecordGroup.hh @@ -42,6 +42,14 @@ namespace Trick { DR_Not_Specified = 3 /**< Unknown type */ } ; + enum DR_Type { + DR_Type_None, + DR_Type_Ascii, + DR_Type_Binary, + DR_Type_HDF5, + DR_Type_FrameLogDataRecord + } ; + class DataRecordBuffer { public: char *buffer; /* ** generic holding buffer for data */ @@ -149,7 +157,7 @@ namespace Trick { @brief Constructor that creates a new data recording group with the given @c in_name. @param in_name - the new data recording group name */ - DataRecordGroup( std::string in_name = "" ) ; + DataRecordGroup( std::string in_name = "", Trick::DR_Type dr_type = Trick::DR_Type::DR_Type_None ) ; ~DataRecordGroup() ; @@ -405,6 +413,12 @@ namespace Trick { */ virtual int add_time_variable() ; + /** + @brief This function adds jobs to the DRG based on the dr type. + @returns void + */ + void configure_jobs(DR_Type type) ; + /** Check that a variable is supported by data recording. */ /** Variable must be a single primitive type - no STL, array, structured, string */ bool isSupportedType(REF2 * ref2, std::string& message); diff --git a/trick_source/sim_services/DataRecord/DRAscii.cpp b/trick_source/sim_services/DataRecord/DRAscii.cpp index 1d6f80ce..55ce144a 100644 --- a/trick_source/sim_services/DataRecord/DRAscii.cpp +++ b/trick_source/sim_services/DataRecord/DRAscii.cpp @@ -18,7 +18,7 @@ PROGRAMMERS: #include "trick/message_type.h" #include "trick/bitfield_proto.h" -Trick::DRAscii::DRAscii( std::string in_name ) : Trick::DataRecordGroup( in_name ) { +Trick::DRAscii::DRAscii( std::string in_name, Trick::DR_Type dr_type ) : Trick::DataRecordGroup( in_name, dr_type ) { ascii_float_format = "%20.8g" ; ascii_double_format = "%20.16g" ; diff --git a/trick_source/sim_services/DataRecord/DRBinary.cpp b/trick_source/sim_services/DataRecord/DRBinary.cpp index eaa8f314..2b9b2038 100644 --- a/trick_source/sim_services/DataRecord/DRBinary.cpp +++ b/trick_source/sim_services/DataRecord/DRBinary.cpp @@ -22,7 +22,7 @@ PROGRAMMERS: Other classes inherit from DRBinary. In these cases, we don't want to register the memory as DRBinary, so register_group will be set to false. */ -Trick::DRBinary::DRBinary( std::string in_name , bool register_group ) : Trick::DataRecordGroup(in_name) { +Trick::DRBinary::DRBinary( std::string in_name, bool register_group, Trick::DR_Type dr_type ) : Trick::DataRecordGroup(in_name, dr_type) { if ( register_group ) { register_group_with_mm(this, "Trick::DRBinary") ; } @@ -190,4 +190,4 @@ int Trick::DRBinary::format_specific_shutdown() { close(fd) ; } return(0) ; -} \ No newline at end of file +} diff --git a/trick_source/sim_services/DataRecord/DRHDF5.cpp b/trick_source/sim_services/DataRecord/DRHDF5.cpp index 8f70f196..0ea955f6 100644 --- a/trick_source/sim_services/DataRecord/DRHDF5.cpp +++ b/trick_source/sim_services/DataRecord/DRHDF5.cpp @@ -14,7 +14,7 @@ PROGRAMMERS: #include "trick/memorymanager_c_intf.h" #include "trick/message_proto.h" -Trick::DRHDF5::DRHDF5( std::string in_name ) : Trick::DataRecordGroup(in_name) { +Trick::DRHDF5::DRHDF5( std::string in_name, Trick::DR_Type dr_type ) : Trick::DataRecordGroup(in_name, dr_type) { register_group_with_mm(this, "Trick::DRHDF5") ; } diff --git a/trick_source/sim_services/DataRecord/DataRecordGroup.cpp b/trick_source/sim_services/DataRecord/DataRecordGroup.cpp index 5808e9dc..13d057fe 100644 --- a/trick_source/sim_services/DataRecord/DataRecordGroup.cpp +++ b/trick_source/sim_services/DataRecord/DataRecordGroup.cpp @@ -54,7 +54,7 @@ Trick::DataRecordBuffer::~DataRecordBuffer() { free(ref) ; } -Trick::DataRecordGroup::DataRecordGroup( std::string in_name ) : +Trick::DataRecordGroup::DataRecordGroup( std::string in_name, Trick::DR_Type dr_type ) : record(true) , inited(false) , group_name(in_name) , @@ -96,18 +96,7 @@ Trick::DataRecordGroup::DataRecordGroup( std::string in_name ) : // sim object name name = std::string("trick_data_record_group_") + in_name ; - // add_jobs_to_queue will fill in job_id later - // make the init job run after all other initialization jobs but before the post init checkpoint - // job so users can allocate memory in initialization jobs and checkpointing data rec groups will work - add_job(0, 1, (char *)"initialization", NULL, cycle, (char *)"init", (char *)"TRK", 65534) ; - add_job(0, 2, (char *)"end_of_frame", NULL, 1.0, (char *)"write_data", (char *)"TRK") ; - add_job(0, 3, (char *)"checkpoint", NULL, 1.0, (char *)"checkpoint", (char *)"TRK") ; - add_job(0, 4, (char *)"post_checkpoint", NULL, 1.0, (char *)"clear_checkpoint_vars", (char *)"TRK") ; - // run the restart job in phase 60001 - add_job(0, 5, (char *)"restart", NULL, 1.0, (char *)"restart", (char *)"TRK", 60001) ; - add_job(0, 6, (char *)"shutdown", NULL, 1.0, (char *)"shutdown", (char *)"TRK") ; - - write_job = add_job(0, 99, (char *)job_class.c_str(), NULL, cycle, (char *)"data_record" , (char *)"TRK") ; + configure_jobs(dr_type) ; add_time_variable() ; } @@ -429,6 +418,27 @@ int Trick::DataRecordGroup::init() { } +void Trick::DataRecordGroup::configure_jobs(DR_Type type) { + switch(type) { + default: + // run the restart job in phase 60001 + add_job(0, 5, (char *)"restart", NULL, 1.0, (char *)"restart", (char *)"TRK", 60001) ; + + case DR_Type::DR_Type_FrameLogDataRecord: + // add_jobs_to_queue will fill in job_id later + // make the init job run after all other initialization jobs but before the post init checkpoint + // job so users can allocate memory in initialization jobs and checkpointing data rec groups will work + add_job(0, 1, (char *)"initialization", NULL, cycle, (char *)"init", (char *)"TRK", 65534) ; + add_job(0, 2, (char *)"end_of_frame", NULL, 1.0, (char *)"write_data", (char *)"TRK") ; + add_job(0, 3, (char *)"checkpoint", NULL, 1.0, (char *)"checkpoint", (char *)"TRK") ; + add_job(0, 4, (char *)"post_checkpoint", NULL, 1.0, (char *)"clear_checkpoint_vars", (char *)"TRK") ; + add_job(0, 6, (char *)"shutdown", NULL, 1.0, (char *)"shutdown", (char *)"TRK") ; + + write_job = add_job(0, 99, (char *)job_class.c_str(), NULL, cycle, (char *)"data_record" , (char *)"TRK") ; + break ; + } +} + int Trick::DataRecordGroup::checkpoint() { unsigned int jj ; diff --git a/trick_source/sim_services/FrameLog/FrameDataRecordGroup.cpp b/trick_source/sim_services/FrameLog/FrameDataRecordGroup.cpp index c0da71b2..f66cb6a6 100644 --- a/trick_source/sim_services/FrameLog/FrameDataRecordGroup.cpp +++ b/trick_source/sim_services/FrameLog/FrameDataRecordGroup.cpp @@ -9,7 +9,7 @@ -# All instances get the end_of_frame frame_log_clear job. */ Trick::FrameDataRecordGroup::FrameDataRecordGroup( int in_thread_id , std::string in_name ) - : Trick::DRBinary(in_name, false) , thread_id(in_thread_id ) { + : Trick::DRBinary(in_name, false, Trick::DR_Type::DR_Type_FrameLogDataRecord ), thread_id(in_thread_id ) { if ( thread_id > 0 ) { add_job(thread_id, 1000, (char *)"top_of_frame", NULL, 1.0, (char *)"start_timer", (char *)"TRK", 1) ; // Frame logging uses phase 65533 in FrameLog.ccp. Stop the timer just before that.