REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestManager.cxx
1
28
29#include "TRestManager.h"
30
31#include "TInterpreter.h"
32#include "TRestTask.h"
33#include "TSystem.h"
34
35using namespace std;
36ClassImp(TRestManager);
37
38TRestManager::TRestManager() { Initialize(); }
39
40TRestManager::~TRestManager() {
41 // delete all the added metadata objects(besides self)
42 if (fMetaObjects.size() > 1) {
43 for (unsigned int i = fMetaObjects.size() - 1; i >= 1; i--) {
44 delete fMetaObjects[i];
45 }
46 }
47}
48
53 SetSectionName(this->ClassName());
54 // delete all the added metadata objects(besides self)
55 if (fMetaObjects.size() > 1) {
56 for (unsigned int i = fMetaObjects.size() - 1; i >= 1; i--) {
57 delete fMetaObjects[i];
58 }
59 }
60 // add self to the metadata objects list
61 fMetaObjects.clear();
62 fMetaObjects.push_back(this);
63}
64
66
83Int_t TRestManager::ReadConfig(string keydeclare, TiXmlElement* e) {
84 // if (keydeclare == "TRestRun") {
85 // TRestRun* fRunInfo = new TRestRun();
86 // fRunInfo->SetHostmgr(this);
87 // fRunInfo->LoadConfigFromFile(e, fElementGlobal);
88 // fMetaObjects.push_back(fRunInfo);
89 // gROOT->Add(fRunInfo);
90 // return 0;
91 //}
92
93 // else if (keydeclare == "TRestProcessRunner") {
94 // TRestProcessRunner* fProcessRunner = new TRestProcessRunner();
95 // fProcessRunner->SetHostmgr(this);
96 // fProcessRunner->LoadConfigFromFile(e, fElementGlobal);
97 // fMetaObjects.push_back(fProcessRunner);
98 // gROOT->Add(fProcessRunner);
99 // return 0;
100 //}
101
102 // cout << "----------- " << gROOT->FindObject("SJTU_Proto") << endl;
103
104 if (Count(keydeclare, "TRest") > 0) {
105 TRestMetadata* meta = REST_Reflection::Assembly(keydeclare);
106 if (meta == nullptr) return -1;
107 meta->SetHostmgr(this);
108 fMetaObjects.push_back(meta);
111
112 return 0;
113 }
114
115 else if (keydeclare == "addTask") {
116 string active = GetParameter("value", e, "");
117 if (active != "ON" && active != "On" && active != "on") {
118 RESTDebug << "Inactived task : \"" << ElementToString(e) << "\"" << RESTendl;
119 return 0;
120 }
121 RESTDebug << "Loading Task...";
122
123 const char* type = e->Attribute("type");
124 const char* cmd = e->Attribute("command");
125 if (type == nullptr && cmd == nullptr) {
126 RESTWarning << "command or type should be given!" << RESTendl;
127 return -1;
128 }
129 if (type != nullptr) {
130 RESTDebug << " \"" << type << "\" " << RESTendl;
131 if ((string)type == "processEvents") {
132 auto pr = GetProcessRunner();
133 if (pr != nullptr) pr->RunProcess();
134 } else if ((string)type == "analysisPlot") {
135 auto ap = GetAnaPlot();
136 if (ap != nullptr) ap->PlotCombinedCanvas();
137 } else if ((string)type == "saveMetadata") {
138 auto ri = GetRunInfo();
139 if (ri != nullptr) {
140 ri->FormOutputFile();
141 ri->CloseFile();
142 }
143 } else {
145 if (tsk == nullptr) {
146 RESTWarning << "REST ERROR. Task : " << type << " not found!!" << RESTendl;
147 RESTWarning << "This task will be skipped." << RESTendl;
148 return -1;
149 }
151 tsk->RunTask(this);
152 return 0;
153 }
154 } else if (cmd != nullptr) {
155 RESTDebug << " \"" << cmd << "\" " << RESTendl;
156
157 TRestTask* tsk = TRestTask::GetTaskFromCommand(cmd);
158 if (tsk == nullptr) {
159 RESTWarning << "REST ERROR. Command : " << cmd << " cannot be parsed!!" << RESTendl;
160 RESTWarning << "This task will be skipped." << RESTendl;
161 return -1;
162 }
163 tsk->RunTask(this);
164 return 0;
165 }
166 }
167
168 return -1;
169}
170
171void TRestManager::InitFromTask(string taskName, vector<string> arguments) {
172 TRestTask* tsk = TRestTask::GetTaskFromMacro(taskName);
173 if (tsk == nullptr) {
174 gSystem->Exit(-1);
175 }
176 tsk->SetArgumentValue(arguments);
177 tsk->RunTask(nullptr);
178 gSystem->Exit(0);
179}
180
185 for (unsigned int i = 0; i < fMetaObjects.size(); i++) {
186 if ((string)fMetaObjects[i]->ClassName() == type) {
187 return fMetaObjects[i];
188 }
189 }
190 return nullptr;
191}
192
197 for (unsigned int i = 0; i < fMetaObjects.size(); i++) {
198 if (fMetaObjects[i]->GetName() == name) {
199 return fMetaObjects[i];
200 }
201 }
202 return nullptr;
203}
204
Managing applications and executing tasks.
Definition: TRestManager.h:16
TRestMetadata * GetMetadataClass(std::string type)
Get the application metadata class, according to the type.
void Initialize() override
Set the class name as section name during initialization.
int LoadSectionMetadata() override
This method does some preparation of xml section.
std::vector< TRestMetadata * > fMetaObjects
app-like metadata objects
Definition: TRestManager.h:19
Int_t ReadConfig(std::string keydeclare, TiXmlElement *e)
Respond to the input xml element.
void PrintMetadata() override
PrintMetadata of this class.
TRestMetadata * GetMetadata(std::string name)
Get the application metadata class, according to the name.
A base class for any REST metadata class.
Definition: TRestMetadata.h:74
std::map< std::string, std::string > fVariables
Saving a list of rml variables. name-value std::pair.
endl_t RESTendl
Termination flag object for TRestStringOutput.
std::string ElementToString(TiXmlElement *ele)
Convert an TiXmlElement object to string.
TiXmlElement * fElementGlobal
Saving the global element, to be passed to the resident class, if necessary.
void SetHostmgr(TRestManager *m)
Set the host manager for this class.
Int_t LoadConfigFromElement(TiXmlElement *eSectional, TiXmlElement *eGlobal, std::map< std::string, std::string > envs={})
Main starter method.
void SetConfigFile(std::string configFilename)
set config file path from external
void SetSectionName(std::string sName)
set the section name, clear the section content
virtual Int_t LoadSectionMetadata()
This method does some preparation of xml section.
std::string fConfigFileName
Full name of the rml file.
std::string GetParameter(std::string parName, TiXmlElement *e, TString defaultValue=PARAMETER_NOT_FOUND_STR)
Returns the value for the parameter named parName in the given section.
Wrapping REST macros into tasks.
Definition: TRestTask.h:27
void SetArgumentValue(std::vector< std::string > arg)
Set argument directly with a list of string.
Definition: TRestTask.cxx:151
virtual void RunTask(TRestManager *)
Run the task with command line.
Definition: TRestTask.cxx:162
static TRestTask * GetTaskFromMacro(TString Name)
Static method to instantiate a TRestTask object with "MacroName".
Definition: TRestTask.cxx:269
TRestReflector Assembly(const std::string &typeName)
Assembly an object of type: typeName, returning the allocated memory address and size.
Int_t Count(std::string s, std::string sbstring)
Counts the number of occurences of substring inside the input string in.