82 #include "TRestRealTimeDrawingProcess.h"
84 #include "TRestMessenger.h"
116 fThreadWaitTimeoutMs = 1000;
119 fPauseResponse[
this] =
false;
120 fPauseInvoke =
false;
131 if (fPlots.size() == 0) {
132 TiXmlElement* ele = GetElement(
"TRestAnalysisPlot");
133 while (ele !=
nullptr) {
137 plt->SetName(plt->GetName() +
138 (TString)ToString(
this));
139 fPlots.push_back(plt);
141 ele = GetNextElement(ele);
145 if (fProcessesToDraw.size() == 0) {
146 TiXmlElement* ele = GetElement(
"ProcessDrawing");
147 while (ele !=
nullptr) {
148 string proc = GetParameter(
"processName", ele);
149 if (GetFriendLive(proc) ==
nullptr) {
150 RESTError <<
"TRestRealTimeDrawingProcess: cannot find process \"" << proc
151 <<
"\" to call drawing!" << RESTendl;
154 fProcessesToDraw.push_back(proc);
156 ele = GetNextElement(ele);
166 if (fDrawInterval == 0) {
169 if (GetFullAnalysisTree() ==
nullptr) {
175 while (fPauseInvoke ==
true) {
176 fPauseResponse[
this] =
true;
179 fPauseResponse[
this] =
false;
181 if (GetFullAnalysisTree()->GetEntries() >= fDrawInterval + fLastDrawnEntry) {
184 RESTInfo <<
"TRestRealTimeDrawingProcess: reached drawing flag. Waiting for other processes to pause"
187 for (
auto iter = fPauseResponse.begin(); iter != fPauseResponse.end(); iter++) {
188 if (iter->first ==
this)
continue;
190 while (iter->second ==
false) {
193 if (i > fThreadWaitTimeoutMs) {
196 <<
"TRestRealTimeDrawingProcess: waiting time reaches maximum, plotting job aborted"
198 fPauseInvoke =
false;
205 RESTInfo <<
"TRestRealTimeDrawingProcess: drawing..." << RESTendl;
208 fLastDrawnEntry = GetFullAnalysisTree()->GetEntries();
209 fPauseInvoke =
false;
219 if (fPauseInvoke ==
false) {
220 RESTInfo <<
"TRestRealTimeDrawingProcess: end drawing..." << RESTendl;
227 void TRestRealTimeDrawingProcess::DrawOnce() {
228 Long64_t totalentries = GetFullAnalysisTree()->GetEntries();
229 for (
unsigned int i = 0; i < fPlots.size(); i++) {
230 fPlots[i]->SetTreeEntryRange(totalentries - fLastDrawnEntry, fLastDrawnEntry);
231 fPlots[i]->PlotCombinedCanvas();
233 for (
unsigned int i = 0; i < fProcessesToDraw.size(); i++) {
234 GetFriendLive(fProcessesToDraw[i])->Draw();
239 auto messager = GetMetadata<TRestMessenger>();
241 if (runNumber == -1) {
242 RESTError <<
"TRestRealTimeDrawingProcess::DrawWithNotification: runNumber must be given!"
244 RESTError <<
"consider adding \"--d xx\" in restManager command" << RESTendl;
249 string message = messager->ConsumeMessage();
251 RESTInfo <<
"Recieveing message: " << message << RESTendl;
254 int _runNumber = run->GetRunNumber();
256 if (_runNumber == runNumber) {
257 for (
auto& plot : fPlots) {
258 plot->SetFile(message);
259 plot->PlotCombinedCanvas();
264 RESTWarning <<
"file: " << message << RESTendl;
265 RESTWarning <<
"It is not the file we wanted! runNumber in file: " << _runNumber
266 <<
", run we are processing: " << runNumber << RESTendl;
267 messager->SendMessage(message);
282 RESTMetadata <<
"Number of AnalysisPlots added: " << fPlots.size() << RESTendl;
283 for (
auto p : fPlots) {
284 RESTMetadata << p->GetName();
286 RESTMetadata << RESTendl;
287 RESTMetadata <<
"Number of process plots added: " << fProcessesToDraw.size() << RESTendl;
288 for (
auto p : fProcessesToDraw) {
291 RESTMetadata << RESTendl;
292 RESTMetadata <<
"Draw interval" << fDrawInterval << RESTendl;
293 RESTMetadata <<
"Waiting time for other thread to stop " << fThreadWaitTimeoutMs << RESTendl;
A base class for any REST event.
static Long64_t fLastDrawnEntry
Last drawn entry of analysis tree.
static std::vector< TRestAnalysisPlot * > fPlots
TRestAnalysisPlot object called for drawing.
static std::map< TRestRealTimeDrawingProcess *, bool > fPauseResponse
Pause response flag from other threads when recieving pause signal.
static std::vector< std::string > fProcessesToDraw
TRestAnalysisPlot object called for drawing.
void EndProcess() override
Function to use when all events have been processed.
void DrawWithNotification()
Returns a new instance of this class.
void PrintMetadata() override
It prints out the process parameters stored in the metadata structure.
void InitProcess() override
Function to use in initialization of process members before starting to process the event.
TRestRealTimeDrawingProcess()
Default constructor.
void Initialize() override
Function to initialize input/output event members and define the section name and library version.
TRestEvent * ProcessEvent(TRestEvent *inputEvent) override
The main processing event function.
static bool fPauseInvoke
Pause signal send for other threads when start drawing.
~TRestRealTimeDrawingProcess()
Default destructor.
Data provider and manager in REST.
Int_t StringToInteger(std::string in)
Gets an integer from a string.