Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:19:19

0001 /*******************************************************************************
0002  * Copyright (c) The JETSCAPE Collaboration, 2018
0003  *
0004  * Modular, task-based framework for simulating all aspects of heavy-ion collisions
0005  * 
0006  * For the list of contributors see AUTHORS.
0007  *
0008  * Report issues at https://github.com/JETSCAPE/JETSCAPE/issues
0009  *
0010  * or via email to bugs.jetscape@gmail.com
0011  *
0012  * Distributed under the GNU General Public License 3.0 (GPLv3 or later).
0013  * See COPYING for details.
0014  ******************************************************************************/
0015 
0016 // JetScapeTask class
0017 // \TODO: Implement truly recursively (not yet done)
0018 // (see https://root.cern.ch/doc/v608/TTask_8cxx_source.html l248)
0019 // (not really though ...)
0020 
0021 #ifndef JETSCAPETASK_H
0022 #define JETSCAPETASK_H
0023 
0024 #include <list>
0025 #include <vector>
0026 #include <string>
0027 #include <memory>
0028 
0029 using std::vector;
0030 using std::string;
0031 using std::weak_ptr;
0032 using std::shared_ptr;
0033 
0034 namespace Jetscape {
0035 
0036 // need forward declaration
0037 class JetScapeWriter;
0038 class JetScapeModuleMutex;
0039 class Parton;
0040 
0041 class JetScapeTask {
0042 
0043 public:
0044   /** Default constructor to create a JetScapeTask. It sets the flag "active_exec" to true and  "id" to default string value.
0045   */
0046   JetScapeTask();
0047 
0048   /** Default destructor for a JetScapeTask.                     
0049    */
0050   virtual ~JetScapeTask();
0051 
0052   /**  A virtual function to define a default initialization function for a JetScapeTask. It can  be overridden by different modules tasks.                                
0053   */
0054   virtual void Init();
0055 
0056   /** A virtual function to define a default Exec() function for a JetScapeTask. It can be overridden by different modules/tasks.
0057   */
0058   virtual void Exec();
0059 
0060   /** A virtual function to define a default Finish() function for a JetScapeTask. It can  be overridden by different modules/tasks.
0061    */
0062   virtual void Finish(){};
0063 
0064   /** A virtual function to define a default Clear() function for a JetScapeTask. It can be overridden by different modules/tasks.
0065    */
0066   virtual void Clear(){};
0067 
0068   // Extensions for "recursive" handling ...
0069   /** Recursive Execution of all the subtasks of the JetScapeTask.
0070    */
0071   virtual void ExecuteTasks();
0072 
0073   /** A virtual function to define a default ExecuteTask() function for a JetScapeTask. It can be overridden by different modules/tasks. 
0074    */
0075   virtual void ExecuteTask(){};
0076 
0077   /** A virtual function to define a default InitTask() function for a JetScapeTask. It can be overridden by different modules/tasks.                                 
0078    */
0079   virtual void InitTask(){};
0080 
0081   /** Recursive initialization of all the subtasks of the JetScapeTask. Subtasks are also of type JetScapeTask such as Pythia Gun, Trento, Energy Loss Matter and Martini etc.
0082   */
0083   virtual void InitTasks();
0084 
0085   // really decide and think what is the best way (workflow ...)
0086   /** Recursively calls Clear() function of the subtasks of a JetScapeTask.
0087    */
0088   virtual void ClearTasks();
0089 
0090   /** A virtual function to define a default ClearTask() function for a JetScapeTask. It can be overridden by different modules/tasks.
0091    */
0092   virtual void ClearTask(){};
0093 
0094   /** A virtual function to define a default FinishTask() function for a JetScapeTask. It can be overridden by different modules/tasks.                           
0095    */
0096   virtual void FinishTask(){};
0097 
0098   /** A virtual function to define a default FinishTasks() function for a JetScapeTask. It can be overridden by different modules/tasks.
0099    */
0100   virtual void FinishTasks(){};
0101 
0102   /** Recursively write the output information of different tasks/subtasks of a JetScapeTask into a file.
0103       We use "active_exec" flag to decide whether to write the output in the file or not.
0104   */
0105   virtual void WriteTasks(weak_ptr<JetScapeWriter> w);
0106 
0107   //add here a write task (depending on if JetScapeWriter is initiallized and active) ...
0108   // Think about workflow ...
0109   /** A virtual function to define a default WriteTask() function for a JetScapeTask.
0110       It can be overridden by different modules/tasks.
0111       Current setup: Every task gets handed a pointer to the writer
0112       and can add any information it likes to it
0113       (using predefined functions like WriteComment())
0114       This is maximally flexible but makes it difficult to 
0115       properly store information for a variety of outputs.
0116       E.g., sigmaGen: A HardProcess can easily write the xsec to any stream-type output
0117       using WriteComment. But to set it in a HepMC file, either HardProcess needs to 
0118       make a case-by-case selection, meaning a new file format would need to percolate
0119       through multiple base classes, or the writer needs to know this information 
0120       and implement WriteEvent appropriately. The latter is obviously better, but
0121       it's non-trivial to collect this information.
0122    */
0123   virtual void WriteTask(weak_ptr<JetScapeWriter> w){};
0124 
0125   /** Should get called only by CollectHeaders. Maybe make protected?
0126       @param w is a pointer of type JetScapeWrite class.
0127   */
0128   virtual void CollectHeader(weak_ptr<JetScapeWriter> w){};
0129 
0130   /** Recursively collect the header information of different tasks/subtasks of a JetScapeTask into a writer.
0131       We use "active_exec" flag to decide whether to write the output in the file or not.
0132   */
0133   virtual void CollectHeaders(weak_ptr<JetScapeWriter> w);
0134 
0135   /** This function adds the module "m_tasks" into the vector of subtask of a JetScapeTask.
0136   */
0137   virtual void Add(shared_ptr<JetScapeTask> m_tasks);
0138 
0139   /** This function returns the current task number. 
0140    */
0141   virtual const inline int GetMyTaskNumber() const { return my_task_number_; };
0142 
0143   /** This function returns the vector of tasks of a JetScapeTask.
0144    */
0145   const vector<shared_ptr<JetScapeTask>> GetTaskList() const { return tasks; }
0146 
0147   /** This function returns the task at  ith location in the vector of tasks of a JetScapeTask.*/
0148   shared_ptr<JetScapeTask> GetTaskAt(int i) { return tasks.at(i); }
0149 
0150   /** This function deletes the last task in the vector  of tasks of a JetScapeTask. */
0151   void EraseTaskLast() { tasks.erase(tasks.begin() + (tasks.size() - 1)); }
0152   //funny syntax (why last() not working here!?)
0153 
0154   /** This function deletes the task at ith location in the vector of tasks of a JetScapeTask.
0155    */
0156   void EraseTaskAt(int i) { tasks.erase((tasks.begin() + i)); }
0157 
0158   /** This function resizes the length of the vector of tasks to "i". If "i" is less than the current size, it will keep the first i elements of the vector of the tasks of a JetScapeTask. 
0159    */
0160   void ResizeTaskList(int i) { tasks.resize(i); }
0161 
0162   /** This function removes all the tasks in the vector of tasks of a JetScapeTask and changes the size to 0.
0163    */
0164   void ClearTaskList() { tasks.clear(); }
0165 
0166   /** This function returns the number of tasks of a JetScapeTask stored in the vector array of tasks.
0167    */
0168   int GetNumberOfTasks() { return (int)tasks.size(); }
0169 
0170   /** This function tells whether the task is active or not.
0171    */
0172   const bool GetActive() const { return active_exec; }
0173 
0174   /** This functions sets the flag "active_exec" to true (active) or false(deactive).
0175    */
0176   void SetActive(bool m_active_exec) { active_exec = m_active_exec; }
0177   // needed to access tasks not recursively by default but individually ...
0178   // also usefull to prevent hydro if multiple read ins of the same event ...
0179 
0180   /** This function sets the string "id" of the task of a JetScapeTask.
0181    */
0182   void SetId(string m_id) { id = m_id; }
0183 
0184   /** This function returns the id of the task of a JetScapeTask.
0185    */
0186   const string GetId() const { return id; }
0187 
0188   /** This function returns the mutex of a JetScapeTask.
0189    */
0190   const shared_ptr<JetScapeModuleMutex> GetMutex() const { return mutex; }
0191 
0192   /** This function sets the "mutex" of a JetScapeTask.
0193    */
0194   void SetMutex(shared_ptr<JetScapeModuleMutex> m_mutex) { mutex = m_mutex; }
0195 
0196 private:
0197   // can be made sortabele to put in correct oder or via xml file ...
0198   vector<shared_ptr<JetScapeTask>> tasks;
0199   //list<shared_ptr<JetScapeTask>> tasks; // list vs vector any advantage of list?
0200 
0201   bool active_exec;
0202   string id;
0203   // if for example a search rather position ... (or always sort with predefined order!?)
0204 
0205   int my_task_number_;
0206   shared_ptr<JetScapeModuleMutex> mutex;
0207 };
0208 
0209 } // end namespace Jetscape
0210 
0211 #endif