Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
hal_jobs.cpp
1#include "Cout.h"
2#include "Jobs.h"
3#include "Std.h"
4#include "StdString.h"
5
6#include <TString.h>
7#include <TSystem.h>
8#include <iostream>
9#include <vector>
10
11
73void printHelp() {
74 std::cout << "Class for managing job arrays/job groups" << std::endl;
75 std::cout << " Usage:" << std::endl;
76 std::cout << "\thal-jobs [file] where file is name of xml file with settings" << std::endl;
77 std::cout << "\thal-jobs --debug=[file] where file is name of xml file with settings, submit commands are displayed"
78 << std::endl;
79 std::cout << "hal-jobs --prepare=[X] where X" << std::endl;
80 std::cout << "\t pbs_single for torque" << std::endl;
81 std::cout << "\t pbs_array for torque array" << std::endl;
82 std::cout << "\t sbatch_single for sbatch" << std::endl;
83 std::cout << "\t sbatch_array for sbatch array" << std::endl;
84 std::cout << "hal-jobs --submit=[Y] --stage=[X] prepares jobs" << std::endl;
85 std::cout << "\t Y - name of the files with configured jobs " << std::endl;
86 std::cout << "\t X stage of deploying:" << std::endl;
87 std::cout << "\t create - only creates job file(s)" << std::endl;
88 std::cout << "\t deploy - only submit job(s)" << std::endl;
89 std::cout << "--export=[X] --id=[Y] --par=[Z] - prints the name of the value from "
90 "configuration file"
91 << std::endl;
92 std::cout << "X - configuration parm, Y job id, par parameter number" << std::endl;
93}
94int main(int argc, char* argv[]) {
95 if (argc < 2) {
96 Hal::Cout::PrintInfo("No arguments! run: hal-jobs --help to get help", Hal::EInfo::kCriticalError);
97 return 0;
98 }
99 std::vector<std::pair<TString, TString>> args = Hal::Std::ConvertMainArgs(argc, argv);
100
101 Int_t nArgs = args.size();
102 if (nArgs == 1) {
103 TString flag1 = args[0].first;
104 TString val1 = args[0].second;
105 if (flag1 == "help") {
106 printHelp();
107 return 0;
108 } else if (flag1 == "" && val1.EndsWith(".xml")) {
109 Hal::Jobs jobs(val1);
110 jobs.CreateJobs();
111 jobs.SubmitJobs();
112 return 0;
113 } else if (flag1 == "debug" && val1.EndsWith(".xml")) {
114 Hal::Jobs jobs(val1);
115 jobs.DebugCommands();
116 jobs.CreateJobs();
117 jobs.SubmitJobs();
118 } else if (flag1 == "prepare") {
119 TString name = val1 + ".xml";
120 TString path = Hal::Std::GetHalrootPlus();
121 Hal::Std::CopyFiles(Form("%s/job_patterns/%s", path.Data(), name.Data()), name);
122 gSystem->mkdir("jobs");
123 gSystem->mkdir("logs");
124 gSystem->mkdir("errors");
125 return 0;
126 }
127 } else if (nArgs == 2) {
128 TString flag1 = args[0].first;
129 TString val1 = args[0].second;
130 TString flag2 = args[1].first;
131 TString val2 = args[1].second;
132 if (flag1 == "submit" && val2 == "create") {
133 Hal::Jobs jobs(val1);
134 jobs.CreateJobs();
135 return 0;
136 } else if (flag1 == "submit" && val2 == "deploy") {
137 Hal::Jobs jobs(val1);
138 jobs.SubmitJobs();
139 return 0;
140 }
141 } else if (nArgs == 3) {
142 TString flag1 = args[0].first;
143 TString flag2 = args[1].first;
144 TString flag3 = args[2].first;
145 TString val1 = args[0].second;
146 TString val2 = args[1].second;
147 TString val3 = args[2].second;
148 if (flag1 == "export" && flag2 == "id" && flag3 == "par") {
149 return 0;
150 TString job_id = val1;
151 TString parameter_id = val2;
152 TString textfile = val3;
153 std::cout << Hal::Jobs::GetParameter(textfile, job_id.Atoi(), parameter_id.Atoi()) << std::endl;
154 return 0;
155 }
156 }
157 std::cout << "Uknown parameter try --help" << std::endl;
158 return 1;
159}
static void PrintInfo(TString text, Hal::EInfo status)
Definition Cout.cxx:370
static TString GetParameter(TString textfile, Int_t job_no, Int_t var_no)
Definition Jobs.cxx:133