53 #include "TRestEventProcess.h"
57 #include <TDataMember.h>
59 #include "TRestManager.h"
70 fObservablesDefined.clear();
71 fObservablesUpdated.clear();
72 fSingleThreadOnly =
false;
73 fCanvasSize = TVector2(800, 600);
99 vector<string> TRestEventProcess::ReadObservables() {
100 TiXmlElement* e = GetElement(
"observable");
101 vector<string> obsNames;
102 vector<string> obsTypes;
103 vector<string> obsDesc;
105 while (e !=
nullptr) {
106 const char* obschr = e->Attribute(
"name");
107 const char* _value = e->Attribute(
"value");
108 const char* _type = e->Attribute(
"type");
109 const char* _desc = e->Attribute(
"description");
112 if (_value ==
nullptr)
117 if (_type ==
nullptr)
122 if (_desc ==
nullptr)
128 if (obschr !=
nullptr) {
129 RESTDebug << this->ClassName() <<
" : setting observable \"" << obschr <<
"\"" << RESTendl;
131 obsNames.emplace_back(obschr);
132 obsTypes.push_back(type);
133 obsDesc.push_back(description);
137 e = e->NextSiblingElement(
"observable");
141 for (
unsigned int i = 0; i < obsNames.size(); i++) {
142 string obsName = this->GetName() + (string)
"_" + obsNames[i];
143 fAnalysisTree->AddObservable(obsName, obsTypes[i], obsDesc[i]);
144 int id = fAnalysisTree->GetObservableID(obsName);
146 fObservablesDefined[(string)GetName() +
"_" + obsNames[i]] = id;
154 fAnalysisTree = tree;
155 if (fAnalysisTree ==
nullptr)
return;
164 if (p ==
nullptr)
return;
165 for (
const auto& fFriendlyProcess : fFriendlyProcesses) {
166 if (fFriendlyProcess->GetName() == p->GetName()) {
170 fFriendlyProcesses.push_back(p);
175 if (p ==
nullptr)
return;
176 for (
const auto& fParallelProcess : fParallelProcesses) {
177 if (fParallelProcess == p ||
this == p) {
181 fParallelProcesses.push_back(p);
186 Bool_t TRestEventProcess::OpenInputFiles(
const vector<string>& files) {
return false; }
195 if (
ToUpper(GetParameter(
"observable",
"")) ==
"ALL" ||
196 ToUpper(GetParameter(
"observables",
"")) ==
"ALL") {
202 if (
ToUpper(GetParameter(
"cutsEnabled",
"false")) ==
"TRUE") {
203 TiXmlElement* ele = fElement->FirstChildElement();
204 while (ele !=
nullptr) {
205 if (ele->Value() !=
nullptr && (
string)ele->Value() ==
"cut") {
206 if (ele->Attribute(
"name") !=
nullptr && ele->Attribute(
"value") !=
nullptr) {
207 string name = ele->Attribute(
"name");
208 name = (string)this->GetName() +
"_" + name;
210 if (value.X() != value.Y()) fCuts.push_back(pair<string, TVector2>(name, value));
214 else if (ele->Value() !=
nullptr && (
string)ele->Value() ==
"parameter") {
215 if (ele->Attribute(
"name") !=
nullptr && ele->Attribute(
"value") !=
nullptr) {
216 string name = ele->Attribute(
"name");
217 if (name.find(
"Cut") == name.size() - 3 || name.find(
"CutRange") == name.size() - 8) {
218 name = name.substr(0, name.find(
"Cut") + 3);
220 if (value.X() != value.Y()) fCuts.push_back(pair<string, TVector2>(name, value));
225 ele = ele->NextSiblingElement();
239 if (fRunInfo !=
nullptr) {
240 m = fRunInfo->GetMetadata(name);
241 if (m ==
nullptr) m = fRunInfo->GetMetadataClass(name);
243 if (fHostmgr !=
nullptr) {
244 if (m ==
nullptr) m = fHostmgr->GetMetadata(name);
245 if (m ==
nullptr) m = fHostmgr->GetMetadataClass(name);
264 if (proc ==
nullptr) {
266 if (friendfromfile !=
nullptr && friendfromfile->InheritsFrom(
"TRestEventProcess")) {
280 for (
const auto& fFriendlyProcess : fFriendlyProcesses) {
281 if ((
string)fFriendlyProcess->GetName() == nameOrType ||
282 (
string)fFriendlyProcess->ClassName() == nameOrType) {
283 return fFriendlyProcess;
299 if (i >= 0 && i < (
int)fParallelProcesses.size()) {
300 return fParallelProcesses[i];
309 bool TRestEventProcess::ApplyCut() {
310 for (
auto cut : fCuts) {
311 string type = (string)fAnalysisTree->GetObservableType(cut.first);
312 if (fAnalysisTree !=
nullptr && type ==
"double") {
313 double val = fAnalysisTree->GetObservableValue<
double>(cut.first);
314 if (val > cut.second.Y() || val < cut.second.X()) {
318 if (fAnalysisTree !=
nullptr && type ==
"int") {
319 int val = fAnalysisTree->GetObservableValue<
int>(cut.first);
320 if (val > cut.second.Y() || val < cut.second.X()) {
347 RESTDebug <<
"Entering " << ClassName() <<
"::BeginOfEventProcess, Initializing output event..."
349 if (inEv !=
nullptr && GetOutputEvent().address !=
nullptr && (
TRestEvent*)GetOutputEvent() != inEv) {
353 outEv->SetID(inEv->GetID());
354 outEv->SetSubID(inEv->GetSubID());
355 outEv->SetSubEventTag(inEv->GetSubEventTag());
357 outEv->SetRunOrigin(inEv->GetRunOrigin());
358 outEv->SetSubRunOrigin(inEv->GetSubRunOrigin());
360 outEv->
SetTime(inEv->GetTime());
363 fObservablesUpdated.clear();
382 RESTDebug <<
"Entering TRestEventProcess::EndOfEventProcess (" << ClassName() <<
")" << RESTendl;
383 if (fValidateObservables) {
384 if (fObservablesDefined.size() != fObservablesUpdated.size()) {
385 for (
auto x : fObservablesDefined) {
386 if (fObservablesUpdated.count(x.first) == 0) {
389 <<
"The observable '" << x.first <<
"' is defined but not set by "
391 <<
", the event is empty? Makesure all observables are set through ProcessEvent()"
416 RESTMetadata.setcolor(COLOR_BOLDGREEN);
417 RESTMetadata.setborder(
"||");
418 RESTMetadata.setlength(100);
421 RESTMetadata <<
"=" << RESTendl;
422 RESTMetadata <<
"Process : " << ClassName() << RESTendl;
423 RESTMetadata <<
"Name: " << GetName() <<
" Title: " << GetTitle()
424 <<
" VerboseLevel: " << GetVerboseLevelString() << RESTendl;
425 RESTMetadata <<
" ----------------------------------------------- " << RESTendl;
426 RESTMetadata <<
" " << RESTendl;
428 if (!fObservablesDefined.empty()) {
429 RESTMetadata <<
" Analysis tree observables added by this process " << RESTendl;
430 RESTMetadata <<
" +++++++++++++++++++++++++++++++++++++++++++++++ " << RESTendl;
433 auto iter = fObservablesDefined.begin();
434 while (iter != fObservablesDefined.end()) {
435 RESTMetadata <<
" ++ " << iter->first << RESTendl;
439 if (!fObservablesDefined.empty()) {
440 RESTMetadata <<
" +++++++++++++++++++++++++++++++++++++++++++++++ " << RESTendl;
441 RESTMetadata <<
" " << RESTendl;
450 void TRestEventProcess::EndPrintProcess() {
451 if (fCuts.size() > 0) {
452 RESTMetadata <<
"Cuts enabled" << RESTendl;
453 RESTMetadata <<
"------------" << RESTendl;
455 auto iter = fCuts.begin();
456 while (iter != fCuts.end()) {
457 if (iter->second.X() != iter->second.Y())
458 RESTMetadata << iter->first <<
", range : ( " << iter->second.X() <<
" , " << iter->second.Y()
459 <<
" ) " << RESTendl;
464 RESTMetadata <<
" " << RESTendl;
465 RESTMetadata <<
"=" << RESTendl;
466 RESTMetadata << RESTendl;
467 RESTMetadata.resetcolor();
468 RESTMetadata.setborder(
"");
469 RESTMetadata.setlength(10000);
505 if (fHostmgr !=
nullptr && fHostmgr->GetProcessRunner() !=
nullptr)
506 return fHostmgr->GetProcessRunner()->GetOutputAnalysisTree();
512 std::vector<string> TRestEventProcess::GetListOfAddedObservables() {
514 auto iter = fObservablesDefined.begin();
515 while (iter != fObservablesDefined.end()) {
516 list.push_back(iter->first);
REST core data-saving helper based on TTree.
A base class for any REST event process.
virtual void EndOfEventProcess(TRestEvent *inputEvent=nullptr)
End of event process. Nothing to do. Called directly after ProcessEvent()
void BeginPrintProcess()
[name, cut range]
void SetAnalysisTree(TRestAnalysisTree *tree)
Set analysis tree of this process, then add observables to it.
T * GetMetadata()
Get a metadata object from the host TRestRun.
virtual void BeginOfEventProcess(TRestEvent *inputEvent=nullptr)
Begin of event process, preparation work. Called right before ProcessEvent()
void SetParallelProcess(TRestEventProcess *p)
Add parallel process to this process.
Int_t LoadSectionMetadata() override
This method does some preparation of xml section.
void SetFriendProcess(TRestEventProcess *p)
Add friendly process to this process.
A base class for any REST event.
void SetTime(Double_t time)
virtual void Initialize()=0
std::string ToUpper(std::string in)
Convert string to its upper case. Alternative of TString::ToUpper.
TVector2 StringTo2DVector(std::string in)
Gets a 2D-vector from a string.