Skip to content

Commit

Permalink
Merge pull request #91 from JETSCAPE/latessa/refactor-step
Browse files Browse the repository at this point in the history
Refactoring Exec, Init, Clear, and Finish
  • Loading branch information
latessa authored Feb 15, 2023
2 parents ea22f79 + d6a4eec commit f48d661
Show file tree
Hide file tree
Showing 103 changed files with 498 additions and 497 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*.*~
.DS_Store
.vscode
.bash_history
html/*
build*/*
external_packages/LBT*
Expand Down
16 changes: 8 additions & 8 deletions examples/unittests/LiquifierBase.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ TEST(LiquefierBaseTest, TEST_add_a_droplet_and_Clear) {
lqf.add_a_droplet(a_drop);
EXPECT_EQ(1, lqf.get_dropletlist_size());

lqf.Clear();
lqf.ClearTask();
EXPECT_EQ(0, lqf.get_dropletlist_size());
}

Expand Down Expand Up @@ -134,7 +134,7 @@ TEST(LiquefierBaseTest, TEST_add_hydro_source) {
EXPECT_EQ(0, lqf.get_dropletlist_size());
pIn.clear();
pOut.clear();
lqf.Clear();
lqf.ClearTask();

// test when pOut == pIn (hard parton)
pIn.push_back(test2);
Expand All @@ -145,7 +145,7 @@ TEST(LiquefierBaseTest, TEST_add_hydro_source) {
EXPECT_EQ(1, pOut.size());
pIn.clear();
pOut.clear();
lqf.Clear();
lqf.ClearTask();

// test when pOut == pIn (soft parton)
pIn.push_back(test1);
Expand All @@ -159,7 +159,7 @@ TEST(LiquefierBaseTest, TEST_add_hydro_source) {
EXPECT_DOUBLE_EQ(x_test1.t(), (lqf.get_a_droplet(0).get_xmu())[0]);
pIn.clear();
pOut.clear();
lqf.Clear();
lqf.ClearTask();

// test a negative particle
FourVector p_test3(3.0, 0.0, 0.0, 3.0);
Expand All @@ -176,7 +176,7 @@ TEST(LiquefierBaseTest, TEST_add_hydro_source) {
EXPECT_EQ(2, pOut.size());
pIn.clear();
pOut.clear();
lqf.Clear();
lqf.ClearTask();

// test a negative particle and a soft particle
pIn.push_back(test2);
Expand All @@ -191,7 +191,7 @@ TEST(LiquefierBaseTest, TEST_add_hydro_source) {
EXPECT_EQ(3, pOut.size());
pIn.clear();
pOut.clear();
lqf.Clear();
lqf.ClearTask();

// test a negative particle and a hard particle
pIn.push_back(test1);
Expand All @@ -209,7 +209,7 @@ TEST(LiquefierBaseTest, TEST_add_hydro_source) {
EXPECT_EQ(3, pOut.size());
pIn.clear();
pOut.clear();
lqf.Clear();
lqf.ClearTask();

// test a soft particle in pIn only
//pIn.push_back(test1);
Expand All @@ -222,5 +222,5 @@ TEST(LiquefierBaseTest, TEST_add_hydro_source) {
//EXPECT_EQ(0, pOut.size());
//pIn.clear();
//pOut.clear();
//lqf.Clear();
//lqf.ClearTask();
}
1 change: 1 addition & 0 deletions src/afterburner/SmashWrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ std::vector<std::vector<shared_ptr<Hadron>>> TestHadronList() {
}

void SmashWrapper::ExecuteTask() {
VERBOSE(2) << "SMASH afterburner running: " << GetId() << " ...";
AfterburnerModus *modus = smash_experiment_->modus();
// This is necessary to correctly handle indices of particle sets from hydro.
// Every hydro event creates a new structure like jetscape_hadrons_
Expand Down
6 changes: 3 additions & 3 deletions src/framework/Afterburner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ using namespace std;
namespace Jetscape {
void Afterburner::Init() {
// Makes sure that XML file with options and parameters is loaded
JetScapeModuleBase::Init();
JetScapeModuleBase::InitTask();
JSINFO << "Initializing Afterburner : " << GetId() << " ...";
InitTask();
InitTasks();
}

void Afterburner::Exec() {
void Afterburner::ExecuteTask() {
VERBOSE(2) << "Afterburner running: " << GetId() << " ...";
ExecuteTask();
}

void Afterburner::CalculateTime() {
Expand Down
7 changes: 5 additions & 2 deletions src/framework/Afterburner.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@ class Afterburner : public JetScapeModuleBase {
VERBOSE(8);
disconnect_all();
}
// Override Init here as function takes care of calling sub-tasks as well
virtual void Init() override;

// needs to be defined by afterburner modules
virtual void ExecuteTask();

virtual void Init();
virtual void Exec();
virtual void CalculateTime();

/// Fill in bulk media info for (t,x,y,z) from current hadron list (work in progress, see .cc file)
Expand Down
30 changes: 10 additions & 20 deletions src/framework/BulkDynamicsManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,56 +35,46 @@ BulkDynamicsManager::BulkDynamicsManager() : JetScapeModuleBase() {
BulkDynamicsManager::~BulkDynamicsManager() {
// Check if this is all really needed with shared_ptr ...
JSDEBUG;
Clear();
ClearTask();

if (GetNumberOfTasks() > 0)
EraseTaskLast();
}

void BulkDynamicsManager::Clear() {
JSDEBUG << "BulkDynamicsManager clear() ...";
void BulkDynamicsManager::ClearTask() {
JSDEBUG << "BulkDynamicsManager ClearTask() ...";

int n = GetNumberOfTasks();
for (int i = 1; i < n; i++)
EraseTaskLast();

// Clean Up not really working with iterators (see also above!!!) Some logic not clear for me.
JetScapeSignalManager::Instance()->CleanUp();
JetScapeTask::ClearTasks();

}

void BulkDynamicsManager::Init() {
void BulkDynamicsManager::InitTask() {
JSINFO << "Intialize BulkDynamicsManager ...";

//Critical temperature to switch from hydro to something else
Tc = GetXMLElementDouble({"BDM", "Tc"});

if (GetNumberOfTasks() < 1) {
JSWARN << " : No valid bulk dynamics Manager modules found ...";
exit(-1);
}

JSINFO << "Found " << GetNumberOfTasks()
<< " Bulk Dynamics Manager Tasks/Modules Initialize them ... ";

//Critical temperature to switch from hydro to something else
Tc = GetXMLElementDouble({"BDM", "Tc"});

BulkDynamicsManager::InitTasks();

}
void BulkDynamicsManager::Exec() {

void BulkDynamicsManager::ExecuteTask() {
VERBOSE(1) << "Run BulkDynamicsManager Manager ...";
JSDEBUG << "Task Id = " << this_thread::get_id();

if (GetNumberOfTasks() < 1) {
JSWARN << " : No valid Bulk Dynamics Manager modules found ...";
exit(-1);
}

JetScapeTask::ExecuteTasks();

//
VERBOSE(3) << " " << GetNumberOfTasks()
<< " Bulk Dynamics Manager Tasks/Modules finished.";
}

void BulkDynamicsManager::CalculateTime()
Expand Down Expand Up @@ -154,7 +144,7 @@ void BulkDynamicsManager::FinishPerEvent()
JetScapeModuleBase::FinishPerEventTasks();

//JP: Quick fix, to be discussed, similar to writer, clear is only called for active tasks, so call here directly ...
Clear();
ClearTask();
}

void BulkDynamicsManager::UpdateEnergyDepositFromModules(int t, double edop){
Expand Down
6 changes: 3 additions & 3 deletions src/framework/BulkDynamicsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ class BulkDynamicsManager

/** It initializes the tasks attached to the bulk dynamics manager.
*/
virtual void Init();
virtual void InitTask();

/**
*/
virtual void Exec();
virtual void ExecuteTask();

/** It erases the tasks attached with the bulk dynamics manager. It can be overridden by other tasks.
*/
virtual void Clear();
virtual void ClearTask();

virtual void CalculateTime();

Expand Down
8 changes: 4 additions & 4 deletions src/framework/BulkMediaBase.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@

using namespace std;

namespace Jetscape {
namespace Jetscape {
void BulkMediaBase::Init() {
// Makes sure that XML file with options and parameters is loaded
JetScapeModuleBase::Init();
JetScapeModuleBase::InitTask();
JSINFO << "Initializing BulkMediaBase : " << GetId() << " ...";

InitTask();
InitTasks();
}

void BulkMediaBase::Exec() {
void BulkMediaBase::ExecuteTask() {
VERBOSE(2) << "BulkMediaBase running: " << GetId() << " ...";
ExecuteTask();
}

void BulkMediaBase::CalculateTime() {
Expand Down
6 changes: 4 additions & 2 deletions src/framework/BulkMediaBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ class BulkMediaBase : public JetScapeModuleBase {
disconnect_all();
}

virtual void Init();
virtual void Exec();
// Override Init here as function takes care of calling sub-tasks as well
void Init() override;

virtual void ExecuteTask();
virtual void CalculateTime();
virtual void GetBulkInfo(Jetscape::real t, Jetscape::real x, Jetscape::real y,Jetscape::real z,
std::unique_ptr<BulkMediaInfo> &bulk_info_ptr){}
Expand Down
15 changes: 7 additions & 8 deletions src/framework/FluidDynamics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright (c) The JETSCAPE Collaboration, 2018
*
* Modular, task-based framework for simulating all aspects of heavy-ion collisions
*
*
* For the list of contributors see AUTHORS.
*
* Report issues at https://github.com/JETSCAPE/JETSCAPE/issues
Expand Down Expand Up @@ -41,7 +41,7 @@ FluidDynamics::~FluidDynamics() {
}

void FluidDynamics::Init() {
JetScapeModuleBase::Init();
JetScapeModuleBase::InitTask();

JSINFO << "Initialize FluidDynamics : " << GetId() << " ...";

Expand All @@ -60,12 +60,12 @@ void FluidDynamics::Init() {
}

InitializeHydro(parameter_list);
InitTask();

JetScapeTask::InitTasks();
InitTask();
InitTasks();
}

void FluidDynamics::Exec() {
void FluidDynamics::ExecuteTask() {
VERBOSE(2) << "Run Hydro : " << GetId() << " ...";
VERBOSE(8) << "Current Event #" << GetCurrentEvent();

Expand All @@ -75,13 +75,12 @@ void FluidDynamics::Exec() {
}

EvolveHydro();
JetScapeTask::ExecuteTasks();
}

void FluidDynamics::Clear() {
void FluidDynamics::ClearTask() {
clear_up_evolution_data();
if (!weak_ptr_is_uninitialized(liquefier_ptr)) {
liquefier_ptr.lock()->Clear();
liquefier_ptr.lock()->ClearTask();
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/framework/FluidDynamics.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,17 @@ class FluidDynamics : public JetScapeModuleBase {
/** Default destructor. */
virtual ~FluidDynamics();

/** Reads the input parameters from the XML file under the tag <Hydro>. Uses JetScapeSingnalManager Instance to retrive the Initial State Physics information. Calls InitializeHydro(parameter_list) and InitTask(); This explicit call can be used for actual initialization of modules such as @a Brick, @a MpiMusic, or @a OSU-HYDRO if attached as a @a polymorphic class. It also initializes the tasks within the current module.
@sa Read about @a polymorphism in C++.
/** Reads the input parameters from the XML file under the tag <Hydro>. Uses JetScapeSingnalManager Instance to retrive the Initial State Physics information. Calls InitializeHydro(parameter_list) and InitTask(); This explicit call can be used for actual initialization of modules such as @a Brick, @a MpiMusic, or @a OSU-HYDRO if attached as a @a polymorphic class. It also initializes the tasks within the current module.
@sa Read about @a polymorphism in C++. Override Init (not InitTask) here as sub-tasks are called as well.
*/
virtual void Init();
void Init() override;

/** Calls EvolveHydro(); This explicit call can be used for actual execution of hydrodynamic evolution defined in the modules such as @a Brick, @a MpiMusic, or @a OSU-HYDRO if attached as a @a polymorphic class. It also execute the tasks within the current module.
@sa Read about @a polymorphism in C++.
*/
virtual void Exec();
virtual void ExecuteTask();

virtual void Clear();
virtual void ClearTask();

/** @return parameter_list A pointer to the class Parameter which contains a file name for the fluid dynamics task.
@sa Implementation of the class Parameter.
Expand Down
9 changes: 4 additions & 5 deletions src/framework/Hadronization.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ Hadronization::Hadronization() {

Hadronization::~Hadronization() {}

void Hadronization::Clear() {
void Hadronization::ClearTask() {
VERBOSESHOWER(8);
outHadrons.clear();
}

void Hadronization::Init() {
JetScapeModuleBase::Init();
void Hadronization::InitTask() {
JetScapeModuleBase::InitTask();

// May need to read some configuration info from XML file here

Expand All @@ -52,7 +52,6 @@ void Hadronization::Init() {
JSINFO << "Found " << GetNumberOfTasks()
<< " Hadronization Tasks/Modules Initialize them ... ";
VERBOSE(2) << " Module Found is " << GetTaskList()[0]->GetId();
JetScapeTask::InitTasks();
}

void Hadronization::DoHadronize() {
Expand All @@ -66,7 +65,7 @@ void Hadronization::DoHadronize() {
}
}

void Hadronization::Exec() {
void Hadronization::ExecuteTask() {
VERBOSE(2) << "Run Hadronization Exec...";
VERBOSE(2) << "Found " << GetNumberOfTasks()
<< " Hadronization Tasks/Modules Execute them ... ";
Expand Down
8 changes: 4 additions & 4 deletions src/framework/Hadronization.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright (c) The JETSCAPE Collaboration, 2018
*
* Modular, task-based framework for simulating all aspects of heavy-ion collisions
*
*
* For the list of contributors see AUTHORS.
*
* Report issues at https://github.com/JETSCAPE/JETSCAPE/issues
Expand Down Expand Up @@ -33,13 +33,13 @@ class Hadronization : public JetScapeModuleBase,
Hadronization();
virtual ~Hadronization();
virtual shared_ptr<Hadronization> Clone() const { return nullptr; }
virtual void Init();
virtual void Exec();
virtual void InitTask();
virtual void ExecuteTask();
virtual void DoHadronization(vector<vector<shared_ptr<Parton>>> &pIn,
vector<shared_ptr<Hadron>> &hOut,
vector<shared_ptr<Parton>> &pOut){};
virtual void WriteTask(weak_ptr<JetScapeWriter> w);
virtual void Clear();
virtual void ClearTask();

void GetHadrons(vector<shared_ptr<Hadron>>& signal){signal = outHadrons;}
sigslot::signal3<vector<vector<shared_ptr<Parton>>> &,
Expand Down
Loading

0 comments on commit f48d661

Please sign in to comment.