364 lines
9.5 KiB
C++
364 lines
9.5 KiB
C++
/**
|
||
* @file WorkFlowFile.h
|
||
* @brief 工作流文件类
|
||
*
|
||
* @author 黄军
|
||
* @date 2011-7-27
|
||
*/
|
||
|
||
#ifndef PAI_FRAME_WORKFLOWENGINE_WORKFLOWFILE_H
|
||
#define PAI_FRAME_WORKFLOWENGINE_WORKFLOWFILE_H
|
||
|
||
#include <string>
|
||
#include <vector>
|
||
#include <iostream>
|
||
|
||
#include "WorkflowConstants.h"
|
||
#include "ModuleInformation.h"
|
||
#include "ModuleConnection.h"
|
||
|
||
namespace pai {
|
||
namespace workflow {
|
||
/**
|
||
* @brief 模块并行方式-GPU并行
|
||
*/
|
||
const std::string GPU_PARALLEL_FLAG = "GPU";
|
||
|
||
/**
|
||
* @brief 界面工作流编辑事件类型
|
||
*/
|
||
enum WorkflowEventType
|
||
{
|
||
MODULE_ADD_EVENT, //添加模块事件
|
||
MODULE_PARAM_CHANGE_EVENT, //模块参数改变事件
|
||
MODULE_TYPE_CHANGE_EVENT, //模块类型改变事件
|
||
MODULE_REMOVE_EVENT //删除模块事件
|
||
};
|
||
|
||
/**
|
||
* @brief 工作流文件对象
|
||
*
|
||
*/
|
||
class PAI_WORKFLOWENGINE_EXPORT CWorkFlowFile
|
||
{
|
||
|
||
private:
|
||
|
||
long long m_id;
|
||
/*
|
||
* workflow名称
|
||
* 字段不能为空
|
||
* */
|
||
std::string m_strName;
|
||
/*
|
||
* workflow优先级
|
||
* 字段不能为空
|
||
* */
|
||
int m_iPriority;
|
||
/*
|
||
* workflow断点
|
||
* 默认值等于false
|
||
* */
|
||
bool m_bBreakpoint;
|
||
/*
|
||
* 是否是集群作业
|
||
* 默认值等于true
|
||
* */
|
||
bool m_bClusterJob;
|
||
/**
|
||
* 含有有pstm模块则为真
|
||
*/
|
||
bool isParallelJob;
|
||
/**
|
||
* 是否是统计-应用多次并行作业
|
||
* 目前这样的模块主要是地表一致性相关模块(振幅补偿,反褶积)
|
||
*/
|
||
// bool isStatisApplyJob;
|
||
/**
|
||
* 是否是多波作业
|
||
*/
|
||
bool isMultiwaveJob;
|
||
/**
|
||
* 工作流队列名称
|
||
*/
|
||
std::string m_strQueueName;
|
||
std::string m_strComments;
|
||
/**
|
||
* 并行方式(CPU,GPU等)
|
||
*/
|
||
bool m_gpuWorkflow;
|
||
//当前工作流完成后需要删除的数据
|
||
std::vector<std::string> m_NeedDelFiles;
|
||
//workflow包含的工作流集合
|
||
std::vector<pai::workflow::CModuleConnection*>* m_vctConnections;
|
||
std::vector<CModuleInformation*>* m_vctModInfos;
|
||
void Clone(const CWorkFlowFile& workflowfile);
|
||
CWorkFlowFile & operator=(const CWorkFlowFile&);
|
||
public:
|
||
/**
|
||
* @biref 目前只能计算浅层的内存统计,主要用于GUI排查内存增长问题
|
||
* @return 对象占用内存的大小
|
||
*/
|
||
unsigned long GetMemorySize();
|
||
|
||
long long GetID() const
|
||
{
|
||
return m_id;
|
||
}
|
||
|
||
void SetID(long long id)
|
||
{
|
||
m_id = id;
|
||
}
|
||
|
||
std::string GetQueueName() const
|
||
{
|
||
return this->m_strQueueName;
|
||
}
|
||
|
||
void SetQueueName(const std::string& queueName){
|
||
this->m_strQueueName = queueName;
|
||
}
|
||
|
||
std::string GetName() const
|
||
{
|
||
return this->m_strName;
|
||
}
|
||
void SetName(const std::string& strName)
|
||
{
|
||
this->m_strName = strName;
|
||
}
|
||
|
||
int GetPriority() const
|
||
{
|
||
return this->m_iPriority;
|
||
}
|
||
void SetPriority(int iPriority)
|
||
{
|
||
this->m_iPriority = iPriority;
|
||
}
|
||
|
||
bool GetBreakpoint() const
|
||
{
|
||
return this->m_bBreakpoint;
|
||
}
|
||
void SetBreakpoint(bool bBreakpoint)
|
||
{
|
||
this->m_bBreakpoint = bBreakpoint;
|
||
}
|
||
|
||
bool IsClusterJob() const
|
||
{
|
||
return this->m_bClusterJob;
|
||
}
|
||
bool IsParallelJob() const
|
||
{
|
||
return this->isParallelJob;
|
||
}
|
||
// bool IsStatisApplyJob() const
|
||
// {
|
||
// return this->isStatisApplyJob;
|
||
// }
|
||
bool IsMultiwaveJob() const
|
||
{
|
||
return this->isMultiwaveJob;
|
||
}
|
||
void SetClusterJob(bool bClusterJob)
|
||
{
|
||
this->m_bClusterJob = bClusterJob;
|
||
}
|
||
void SetParallelJob(bool parallelJob)
|
||
{
|
||
this->isParallelJob = parallelJob;
|
||
}
|
||
// void SetStatisApplyJob(bool statisApplyJob)
|
||
// {
|
||
// this->isStatisApplyJob = statisApplyJob;
|
||
// }
|
||
void SetMultiwaveJob(bool isMultiwaveJob)
|
||
{
|
||
this->isMultiwaveJob = isMultiwaveJob;
|
||
}
|
||
void setGPUWorkflow(bool gpuWorkflow)
|
||
{
|
||
this->m_gpuWorkflow = gpuWorkflow;
|
||
}
|
||
|
||
bool IsGPUWorkflow() const
|
||
{
|
||
return this->m_gpuWorkflow;
|
||
}
|
||
/**
|
||
* @deprecated should be moved to editor component
|
||
*/
|
||
std::string GetComments() const
|
||
{
|
||
return this->m_strComments;
|
||
}
|
||
void SetComments(std::string strComments)
|
||
{
|
||
this->m_strComments = strComments;
|
||
}
|
||
|
||
std::vector<CModuleInformation*>* GetModuleInfos() const
|
||
{
|
||
return this->m_vctModInfos;
|
||
}
|
||
|
||
std::vector<CModuleConnection*>* GetModuleConnections() const
|
||
{
|
||
return this->m_vctConnections;
|
||
}
|
||
std::vector<std::string>& GetNeedDelFiles();
|
||
void AddNeedDelFile(const std::string &delFile);
|
||
bool AddModule(CModuleInformation*);
|
||
bool RemoveModule(int moduleId);
|
||
CModuleInformation* GetSpecifiedModule(int moduleId);
|
||
bool AddConnection(CModuleConnection* connection);
|
||
bool RemoveConnection(CModuleConnection* connection);
|
||
void RemoveModuleConnections(int);
|
||
|
||
/**
|
||
* @brief 当工作流中有被禁用的模块时,返回去除禁用模块后的工作流;
|
||
* 当工作流中没有被禁用的模块时,返回工作流副本
|
||
* @return 需要运行的工作流
|
||
* @warn 返回的指针需要释放
|
||
*/
|
||
CWorkFlowFile* GetEnabledWorkflow();
|
||
|
||
/**
|
||
* @brief 界面工作流发生变化时调用的函数
|
||
* @param pModule 发生改变的模块,对于添加和修改是改变后的模块,对于删除是将要删除的模块
|
||
* @param type 工作流改变的类型
|
||
*/
|
||
void ProcessForChange(CModuleInformation *pModuleInfo, WorkflowEventType type);
|
||
/**
|
||
* @brief 查找指定的pModule是否存在
|
||
* @param pModule 指定的模块句柄
|
||
*/
|
||
bool HasModule(CModuleInformation* pModule);
|
||
/*
|
||
* @brief 获取当前工作流的所有输出路径
|
||
* @param[in/out] files 返回当前工作流的所有输出路径
|
||
*/
|
||
void GetOutPutFilePaths(std::vector<std::string>& files);
|
||
/*
|
||
* @brief 设置当前工作流的所有输出路径
|
||
* @param[in] files 当前工作流的所有输出路径
|
||
*/
|
||
void SetOutPutFilePaths(const std::vector<std::string>& files);
|
||
|
||
/*
|
||
* @brief 获取当前工作流的所有输入路径
|
||
* @param[in/out] files 返回当前工作流的所有输入路径
|
||
*/
|
||
void GetInPutFilePaths(std::vector<std::string>& files);
|
||
|
||
bool HasRealTimeModule()
|
||
{
|
||
for(std::vector<CModuleInformation*>::iterator iter = m_vctModInfos->begin();
|
||
iter != m_vctModInfos->end(); iter++)
|
||
{
|
||
if((*iter)->GetClassName() == "CRealTimeModule")
|
||
{
|
||
return true;
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
void GetAllRealTimeModule(std::vector<CModuleInformation*>& moduleList)
|
||
{
|
||
for(std::vector<CModuleInformation*>::iterator iter = m_vctModInfos->begin();
|
||
iter != m_vctModInfos->end(); iter++)
|
||
{
|
||
if((*iter)->GetClassName() == "CRealTimeModule")
|
||
{
|
||
moduleList.push_back(*iter);
|
||
}
|
||
}
|
||
}
|
||
bool HasRealTimeModuleConn()
|
||
{
|
||
for(std::vector<CModuleInformation*>::iterator iter = m_vctModInfos->begin();
|
||
iter != m_vctModInfos->end(); iter++)
|
||
{
|
||
if((*iter)->GetClassName() == "CRealTimeModule")
|
||
{
|
||
int moduleId = (*iter)->GetId();
|
||
for(std::vector<pai::workflow::CModuleConnection*>::iterator connIter = m_vctConnections->begin();
|
||
connIter != m_vctConnections->end(); connIter++)
|
||
{
|
||
if((*connIter)->GetDestId() == moduleId || (*connIter)->GetSourceId() == moduleId)
|
||
{
|
||
return true;
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
}
|
||
}
|
||
/**
|
||
* @brief 通过moduleid获取workflowfile中的moduleinformation
|
||
* @param[in/out] moduleID workflowfile中的模块id
|
||
*/
|
||
CModuleInformation* GetModuleInfoByModuleID(const int moduleID);
|
||
/**
|
||
* @brief 通过moduleName获取workflowfile中的moduleinformation
|
||
* @param[in/out] moduleName workflowfile中的模块className
|
||
*/
|
||
void GetModuleInfoByClassName(std::vector<CModuleInformation*>& moduleList, const std::string& moduleName);
|
||
/**
|
||
* @brief 通过moduleid获取workflowfile中的CModuleConnection,并且,moduleid
|
||
* 为moduleconnection的source
|
||
* @param[in] moduleID workflowfile中的模块id
|
||
* @param[out] result
|
||
*/
|
||
void GetModuleConnByModuleIDInSource(std::vector<CModuleConnection*>& result, const int moduleID);
|
||
/**
|
||
* @brief 通过moduleid获取workflowfile中的CModuleConnection,并且,moduleid
|
||
* 为moduleconnection的dest
|
||
* @param[in] moduleID workflowfile中的模块id
|
||
* @param[out] result
|
||
*/
|
||
void GetModuleConnByModuleIDInDest(std::vector<CModuleConnection*>& result, const int moduleID);
|
||
|
||
void Print();
|
||
/**
|
||
*@brief 得到模块的输入模块个数序列,例如vector<1,2>>表示有两个Module,分别有1,2个输入分支
|
||
*@param vector 模块所有输入模块的个数集合
|
||
*@param moduleClassName 模块类名
|
||
*/
|
||
std::vector<int>GetModuleInputSequence(const std::string& moduleClassName);
|
||
/**
|
||
*@brief 查找第一个多并行模块
|
||
*@return 如果查找到返回对象,否则返回NULL;
|
||
*/
|
||
CModule* FindFirstMutiParallModule();
|
||
/**
|
||
*@brief 查找模块的下游模块,不传参数则表示查询所有模块
|
||
*@return 返回下游模块id集合;
|
||
*/
|
||
std::vector<int> GetChildrenModule(int moduleId=-1);
|
||
// /**
|
||
// *@brief 查找模块的下游模块
|
||
// *@return 返回下游模块集合;
|
||
// */
|
||
// vector<CModuleInformation *> GetChildrenModule(CModuleInformation *parent);
|
||
|
||
CWorkFlowFile();
|
||
CWorkFlowFile(const CWorkFlowFile& workflowfile);
|
||
virtual ~CWorkFlowFile();
|
||
/**
|
||
* @brief 对==运算符进行重载,比较两个工作流对是否相等
|
||
*/
|
||
friend bool operator ==(const CWorkFlowFile &workflow_1, const CWorkFlowFile &workflow_2);
|
||
|
||
private:
|
||
CCompositeParameterItem* CastCompositeParam(CParameterItem* param);
|
||
|
||
};
|
||
|
||
}
|
||
}
|
||
#endif
|