Line data Source code
1 : /* This file is property of and copyright by the ALICE HLT Project *
2 : * ALICE Experiment at CERN, All rights reserved. *
3 : * See cxx source for full Copyright notice */
4 :
5 : /** @file AliZMQhistViewer.cxx
6 : @author Mikolaj Krzewicki (mkrzewic@cern.ch)
7 : */
8 :
9 : #include "zmq.h"
10 : #include <algorithm>
11 : #include <iostream>
12 : #include "AliHLTDataTypes.h"
13 : #include "AliHLTComponent.h"
14 : #include "AliHLTMessage.h"
15 : #include "TClass.h"
16 : #include "TCanvas.h"
17 : #include "TVirtualPad.h"
18 : #include "TPad.h"
19 : #include "TMap.h"
20 : #include "TPRegexp.h"
21 : #include "TObjString.h"
22 : #include "TDirectory.h"
23 : #include "TList.h"
24 : #include "AliZMQhelpers.h"
25 : #include "TMessage.h"
26 : #include "TSystem.h"
27 : #include "TApplication.h"
28 : #include "TH1.h"
29 : #include "TH1F.h"
30 : #include <time.h>
31 : #include <string>
32 : #include <map>
33 : #include "TSystem.h"
34 : #include "TStyle.h"
35 : #include "TNamed.h"
36 : #include "signal.h"
37 : #include "AliZMQhistViewer.h"
38 : #include "TThread.h"
39 : #include "AliAnalysisDataContainer.h"
40 :
41 : #define safename(i) (i->object)?i->object->GetName():"NULL"
42 : #define safetitle(i) (i->object)?i->object->GetTitle():"NULL"
43 :
44 : using namespace std;
45 :
46 8 : ClassImpQ(AliZMQhistViewer)
47 :
48 : //_______________________________________________________________________________________
49 0 : AliZMQhistViewer::AliZMQhistViewer():
50 0 : fCanvas(NULL),
51 0 : fVerbose ( kFALSE ),
52 0 : fZMQconfigIN ( "PULL>tcp://localhost:60211" ),
53 0 : fZMQsocketModeIN(1 ),
54 0 : fZMQconfigCONFIG("PULL>inproc://viewerConfig"),
55 0 : fFilter ( "" ),
56 0 : fPollInterval ( 0),
57 0 : fPollTimeout ( 100000),
58 0 : fSort ( kTRUE),
59 0 : fZMQcontext ( NULL),
60 0 : fZMQin ( NULL),
61 0 : fZMQconfig( NULL),
62 0 : fZMQsleeper(NULL),
63 0 : fTrashQueue(),
64 0 : fContent(),
65 0 : fStatus ( ""),
66 0 : fRunNumber ( 0),
67 0 : fSelectionRegexp ( NULL),
68 0 : fUnSelectionRegexp ( NULL),
69 0 : fDrawOptions(),
70 0 : fScaleLogX ( kFALSE),
71 0 : fScaleLogY ( kFALSE),
72 0 : fScaleLogZ ( kFALSE),
73 0 : fResetOnRequest ( kFALSE),
74 0 : fHistStats (0),
75 0 : fAllowResetAtSOR ( kTRUE),
76 0 : iterations(0),
77 0 : fIncoming(NULL),
78 0 : fInfo(),
79 0 : fClearCanvas(),
80 0 : fUpdateCanvas(true),
81 0 : fTerminated(false)
82 0 : {
83 : //init stuff
84 : //ZMQ init
85 0 : fZMQcontext = alizmq_context();
86 0 : alizmq_socket_init(fZMQconfig, fZMQcontext, fZMQconfigCONFIG.Data());
87 0 : }
88 :
89 : //_______________________________________________________________________________________
90 : int AliZMQhistViewer::Run(void* arg)
91 : {
92 0 : if (!fCanvas) fCanvas = new TCanvas();
93 0 : fCanvas->SetBorderSize(10);
94 0 : if (!fIncoming) fIncoming = new std::vector<ZMQviewerObject>;
95 0 : fIncoming->reserve(1000);
96 :
97 : //main loop
98 0 : while(!GetTerminated())
99 : {
100 0 : int sleepInterrupt=0;
101 0 : errno=0;
102 : //send a request if we are using REQ
103 0 : if (fZMQsocketModeIN==ZMQ_REQ)
104 : {
105 0 : string request;
106 :
107 0 : if (fSelectionRegexp || fUnSelectionRegexp)
108 : {
109 0 : if (fSelectionRegexp) request += " select="+fSelectionRegexp->GetPattern();
110 0 : if (fUnSelectionRegexp) request += " unselect="+fUnSelectionRegexp->GetPattern();
111 0 : if (fResetOnRequest) request += " ResetOnRequest";
112 0 : alizmq_msg_send("CONFIG", request, fZMQin, ZMQ_SNDMORE);
113 0 : }
114 :
115 0 : if (fVerbose) Printf("sending request CONFIG %s", request.c_str());
116 0 : alizmq_msg_send("", "", fZMQin, 0);
117 0 : }
118 :
119 : //wait for the data
120 0 : zmq_pollitem_t sockets[] = {
121 0 : { fZMQin, 0, ZMQ_POLLIN, 0 },
122 0 : { fZMQconfig, 0, ZMQ_POLLIN, 0 },
123 : };
124 0 : int rc = zmq_poll(sockets, 2, (fZMQsocketModeIN==ZMQ_REQ)?fPollTimeout:-1);
125 :
126 0 : if (fVerbose) printf("poll exits with rc %i, \"%s\"\n", rc, (rc<0)?zmq_strerror(errno):0);
127 :
128 0 : if (rc==-1 && errno==ETERM)
129 : {
130 0 : if (fVerbose) Printf("ZMQ context terminated, jumping out");
131 0 : break;
132 : }
133 :
134 0 : if (!(sockets[0].revents & ZMQ_POLLIN))
135 : {
136 : //server died
137 0 : Printf("connection timed out, server %s died?", fZMQconfigIN.Data());
138 0 : fZMQsocketModeIN = alizmq_socket_init(fZMQin, fZMQcontext, fZMQconfigIN.Data());
139 0 : if (fZMQsocketModeIN < 0) return -1;
140 0 : continue;
141 : }
142 0 : else if (sockets[0].revents & ZMQ_POLLIN) //ZMQin
143 : {
144 0 : GetData(fZMQin);
145 0 : if (fUpdateCanvas) {
146 0 : UpdateCanvas(fCanvas,fSelectionRegexp, fUnSelectionRegexp);
147 0 : }
148 : }
149 0 : else if (sockets[1].revents & ZMQ_POLLIN) //ZMQconfig
150 : {
151 0 : aliZMQmsg message; //only string messages expected here
152 0 : alizmq_msg_recv(&message, fZMQconfig, 0);
153 0 : for (aliZMQmsg::iterator part=message.begin(); part!=message.end(); ++part)
154 : {
155 : //we just take the payloads, in this channel we dont expect anything else than
156 : //config strings
157 0 : string configString;
158 0 : alizmq_msg_iter_data(part, configString);
159 0 : ProcessOptionString(configString.c_str());
160 0 : }
161 0 : }
162 0 : sleepInterrupt=0;
163 : //sleep
164 0 : rc = zmq_recv(fZMQsleeper, &sleepInterrupt, sizeof(sleepInterrupt), 0);
165 0 : if (fVerbose) { printf(" sleeper rc: %i (%s)\n", rc, zmq_strerror(errno)); }
166 0 : }//main loop
167 :
168 0 : if (fVerbose) printf("trying to close the ZMQ socket %s\n", fZMQconfigIN.Data());
169 0 : zmq_close(fZMQin); fZMQin=NULL;
170 0 : zmq_close(fZMQsleeper); fZMQsleeper=NULL;
171 0 : zmq_close(fZMQconfig); fZMQconfig=NULL;
172 0 : if (fVerbose) printf("sockets closed\n");
173 :
174 0 : GetIncoming(NULL); //destroy the buffer
175 0 : return 0;
176 0 : }
177 :
178 : //_______________________________________________________________________________________
179 : int AliZMQhistViewer::GetData(void* socket)
180 : {
181 : //get all data (topic+body), possibly many of them
182 0 : aliZMQmsg message;
183 0 : alizmq_msg_recv(&message, socket, 0);
184 :
185 0 : vector<ZMQviewerObject>* incomingObjects = new vector<ZMQviewerObject>;
186 0 : incomingObjects->reserve(message.size());
187 :
188 : //process message, deserialize objects, puth them in the container
189 0 : for (aliZMQmsg::iterator i=message.begin(); i!=message.end(); ++i)
190 : {
191 0 : if (alizmq_msg_iter_check_id(i, "INFO")==0)
192 : {
193 : //check if we have a runnumber in the string
194 0 : string info;
195 0 : alizmq_msg_iter_data(i,info);
196 0 : if (fVerbose) Printf("processing INFO %s", info.c_str());
197 0 : GetInfo(&info);
198 :
199 0 : size_t runTagPos = info.find("run");
200 0 : if (runTagPos != std::string::npos)
201 : {
202 0 : size_t runStartPos = info.find("=",runTagPos);
203 0 : size_t runEndPos = info.find(" ");
204 0 : string runString = info.substr(runStartPos+1,runEndPos-runStartPos-1);
205 :
206 0 : if (fVerbose) printf("received run=%s\n",runString.c_str());
207 :
208 0 : int runnumber = atoi(runString.c_str());
209 :
210 0 : if (runnumber!=fRunNumber && fAllowResetAtSOR)
211 : {
212 0 : if (fVerbose) printf("Run changed, resetting!\n");
213 0 : GetIncoming(NULL); //this clears it
214 0 : bool clear = true;
215 0 : GetClearCanvas(&clear);
216 0 : }
217 0 : fRunNumber = runnumber;
218 0 : }
219 : continue;
220 0 : }
221 0 : if (alizmq_msg_iter_check_id(i,kAliHLTDataTypeStreamerInfo)==0)
222 : {
223 0 : if (fVerbose) printf("extracting schema\n");
224 0 : alizmq_msg_iter_init_streamer_infos(i);
225 : continue;
226 : }
227 :
228 : //incoming ROOT objects
229 : {
230 0 : TObject* tmp = NULL;
231 0 : alizmq_msg_iter_data(i, tmp);
232 0 : if (!tmp) continue;
233 :
234 0 : std::vector<TObject*> listOfObjects; listOfObjects.reserve(100);
235 0 : AliAnalysisDataContainer* analKont = dynamic_cast<AliAnalysisDataContainer*>(tmp);
236 0 : if (analKont) {
237 0 : if (fVerbose) printf("--in AliAnalysisDataContainer %p\n",analKont);
238 0 : GetObjects(analKont, &listOfObjects);
239 0 : if (fVerbose) printf(" destroying anal container %p\n",tmp);
240 0 : delete tmp;
241 : } else {
242 0 : TCollection* collection = dynamic_cast<TCollection*>(tmp);
243 0 : if (collection) {
244 0 : if (fVerbose) printf("--in TCollection %p\n",collection);
245 0 : GetObjects(collection, &listOfObjects);
246 0 : if (fVerbose) printf(" destroying collection %p\n",tmp);
247 0 : delete tmp;
248 : } else {
249 0 : if (fVerbose) printf("--in TObject\n");
250 0 : listOfObjects.push_back(tmp);
251 : }
252 : }
253 :
254 : //add all extracted objects to the list of veiwer objects
255 0 : for (std::vector<TObject*>::iterator i=listOfObjects.begin(); i!=listOfObjects.end(); ++i) {
256 0 : ZMQviewerObject object(*i);
257 0 : if (fVerbose) Printf(" adding: %s (%s), %p", (*i)->GetName(), (*i)->ClassName(), *i);
258 0 : incomingObjects->push_back(object);
259 0 : }
260 0 : }
261 : } //for iterator i
262 0 : alizmq_msg_close(&message);
263 :
264 0 : GetIncoming(incomingObjects);
265 :
266 0 : DataReady(); //emit a signal
267 :
268 : return 0;
269 0 : }
270 :
271 : //______________________________________________________________________________
272 : int AliZMQhistViewer::GetObjects(AliAnalysisDataContainer* kont, std::vector<TObject*>* list, const char* prefix)
273 : {
274 0 : const char* analName = kont->GetName();
275 0 : TObject* analData = kont->GetData();
276 0 : std::string name = analName;
277 0 : std::string namePrefix = name + "/";
278 0 : TCollection* collection = dynamic_cast<TCollection*>(analData);
279 0 : if (collection) {
280 0 : if (fVerbose) Printf(" have a collection %p",collection);
281 0 : const char* collName = collection->GetName();
282 0 : GetObjects(collection, list, namePrefix.c_str());
283 0 : if (fVerbose) printf(" destroying collection %p\n",collection);
284 0 : delete collection;
285 0 : kont->SetDataOwned(kFALSE);
286 0 : } else { //if (collection)
287 0 : TNamed* named = dynamic_cast<TNamed*>(analData);
288 0 : name = namePrefix + analData->GetName();
289 0 : std::string title = namePrefix + analData->GetTitle();
290 0 : if (named) {
291 0 : named->SetName(name.c_str());
292 0 : named->SetTitle(title.c_str());
293 : }
294 0 : if (fVerbose) Printf("--in (from analysis container): %s (%s), %p",
295 0 : named->GetName(),
296 0 : named->ClassName(),
297 : named );
298 0 : kont->SetDataOwned(kFALSE);
299 0 : list->push_back(analData);
300 0 : }
301 : return 0;
302 0 : }
303 :
304 : //______________________________________________________________________________
305 : int AliZMQhistViewer::GetObjects(TCollection* collection, std::vector<TObject*>* list, const char* prefix)
306 : {
307 0 : TIter next(collection);
308 0 : while (TObject* tmp = next()) {
309 0 : collection->Remove(tmp);
310 0 : std::string name = tmp->GetName();
311 0 : name = prefix + name;
312 0 : if (fVerbose) Printf("--in (from a TCollection): %s (%s), %p",
313 0 : tmp->GetName(), tmp->ClassName(), tmp);
314 0 : AliAnalysisDataContainer* analKont = dynamic_cast<AliAnalysisDataContainer*>(tmp);
315 0 : if (analKont) {
316 0 : if (fVerbose) Printf(" have an analysis container %p",analKont);
317 0 : GetObjects(analKont,list,name.c_str());
318 0 : if (fVerbose) printf(" destroying anal container %p\n",analKont);
319 0 : delete analKont;
320 : } else {
321 0 : TNamed* named = dynamic_cast<TNamed*>(tmp);
322 0 : if (named) {
323 0 : name = named->GetName();
324 0 : name = prefix + name;
325 0 : std::string title = named->GetTitle();
326 0 : title = prefix + title;
327 0 : named->SetName(name.c_str());
328 0 : named->SetTitle(title.c_str());
329 0 : }
330 0 : list->push_back(tmp);
331 : }
332 0 : collection->SetOwner(kTRUE);
333 0 : } //while
334 : return 0;
335 0 : }
336 :
337 : //______________________________________________________________________________
338 : int AliZMQhistViewer::UpdateCanvas(TCanvas* canvas,
339 : TPRegexp* selectionRegexp,
340 : TPRegexp* unSelectionRegexp)
341 : {
342 : //use the thread safe access
343 0 : std::vector<ZMQviewerObject>* incomingObjects = GetIncoming();
344 0 : if (!incomingObjects) return 1;
345 :
346 0 : string info = GetInfo();
347 0 : bool forceClearCanvas = GetClearCanvas();
348 0 : if (forceClearCanvas && fVerbose) printf("##forceClearCanvas\n");
349 :
350 0 : if (forceClearCanvas && fContent) {
351 0 : canvas->Clear();
352 0 : fTrashQueue.push_back(fContent);
353 0 : fContent = NULL;
354 0 : }
355 :
356 0 : if (!fContent) {
357 0 : fContent = new vector<ZMQviewerObject>;
358 0 : fContent->reserve(incomingObjects->size());
359 : }
360 :
361 0 : gStyle->SetOptStat(fHistStats);
362 :
363 0 : const char* drawOptions = fDrawOptions;
364 0 : bool verbose = fVerbose;
365 :
366 : int nNewPlots = 0;
367 : int nPlotsToDraw = 0;
368 0 : for (vector<ZMQviewerObject>::iterator incoming=incomingObjects->begin();
369 0 : incoming!=incomingObjects->end();
370 0 : ++incoming)
371 : {
372 : Bool_t selected = kTRUE;
373 : Bool_t unselected = kFALSE;
374 0 : if (selectionRegexp) selected = selectionRegexp->Match(safename(incoming));
375 0 : if (unSelectionRegexp) unselected = unSelectionRegexp->Match(safename(incoming));
376 0 : if (!selected || unselected)
377 : {
378 0 : if (fVerbose) printf("object %s did not pass selection (%s) && !(%s)\n",
379 0 : safename(incoming), (selectionRegexp)?selectionRegexp->GetPattern().Data():"",
380 0 : (unSelectionRegexp)?unSelectionRegexp->GetPattern().Data():"");
381 0 : incoming->redraw = false;
382 0 : continue;
383 : }
384 : else
385 : {
386 0 : incoming->redraw=true;
387 : }
388 :
389 : //check if it will replace something
390 : bool found=false;
391 0 : for (vector<ZMQviewerObject>::iterator current=fContent->begin();
392 0 : current!=fContent->end();
393 0 : ++current)
394 : {
395 0 : if (strcmp(safename(incoming), safename(current))==0)
396 : {
397 0 : if (fVerbose) printf(" updating %s %s\n",safename(incoming), safetitle(incoming));
398 : found = true;
399 0 : if (!(incoming->object)) { printf("WARNING: null pointer in input data"); }
400 : else {
401 0 : if (current->SwapObject(*incoming)) {
402 0 : if (verbose) printf(" swapped plot %s %s\n", safename(incoming),safetitle(incoming));
403 : } else {
404 0 : printf("duplicate histogram in incoming message! skipping %s\n", safename(incoming));
405 : }
406 : }
407 0 : break;
408 : }
409 : }
410 0 : if (!found)
411 : {
412 0 : if (fVerbose) printf(" new object %s\n",safename(incoming));
413 0 : ZMQviewerObject tmp(*incoming); incoming->object=NULL;
414 0 : tmp.options = drawOptions;
415 0 : fContent->push_back(tmp); //completely new one
416 0 : nNewPlots++;
417 0 : }
418 0 : }
419 :
420 : //MUST reset isnew after updating
421 0 : for (vector<ZMQviewerObject>::iterator current=fContent->begin();
422 0 : current!=fContent->end();
423 0 : ++current)
424 : {
425 0 : current->isnew = false;
426 : }
427 :
428 : //re-sort the new list if we have new plots
429 0 : if (nNewPlots>0 && fSort) {
430 0 : if (fVerbose) printf(" re-sorting and setting new pad numbers\n");
431 0 : std::sort(fContent->begin(), fContent->end(), ZMQviewerObjectTitleComparator());
432 0 : for (int i=0; i<fContent->size(); i++) {
433 0 : (*fContent)[i].pad=i+1;
434 0 : (*fContent)[i].redraw=true;
435 : }
436 0 : }
437 :
438 0 : if (nNewPlots>0)
439 : {
440 : forceClearCanvas = true;
441 0 : }
442 :
443 0 : canvas->cd();
444 :
445 : //after we clear the canvas, the pads are gone, clear the pad cache as well
446 0 : int nDrawables = fContent->size();
447 0 : int nPads = CountPads(canvas);
448 :
449 0 : if (verbose) printf(" nDrawables: %i, nPads: %i\n", nDrawables, nPads);
450 0 : if (nDrawables > nPads || forceClearCanvas)
451 : {
452 0 : canvas->SetEditable(kTRUE);
453 0 : canvas->Clear();
454 0 : canvas->DivideSquare(nDrawables);
455 0 : canvas->SetEditable(kFALSE);
456 0 : nPads = CountPads(canvas);
457 0 : if (verbose) printf(" reorganizing canvas, now %i pads\n",nPads);
458 : }
459 :
460 : //if we have new plots we need to replot the whole thing as the old plots may have been
461 : //moved
462 : //if we have no new plots, we just draw the incoming ones at correct locations
463 : {
464 0 : if (verbose) printf(" drawing (%lu) plots\n", fContent->size());
465 0 : for (vector<ZMQviewerObject>::iterator current=fContent->begin(); current!=fContent->end(); ++current)
466 : {
467 0 : if (!(current->redraw)) {
468 0 : if (verbose) printf(" not replotting %s\n", safename(current));
469 : continue;
470 : }
471 0 : if (verbose) printf(" plotting %s at pad %i\n", safename(current),current->pad);
472 0 : TVirtualPad* pad = canvas->cd(current->pad);
473 0 : if (!pad) pad = canvas->cd();
474 0 : if (fScaleLogX) gPad->SetLogx();
475 0 : if (fScaleLogY) gPad->SetLogy();
476 0 : if (fScaleLogZ) gPad->SetLogz();
477 0 : pad->SetEditable(kFALSE);
478 0 : if (current->object)
479 : {
480 0 : if (verbose) printf(" removing previous %s at %p\n", safename(current), current->previous);
481 0 : pad->SetName(safename(current));
482 0 : pad->RecursiveRemove(current->previous);
483 0 : pad->GetListOfPrimitives()->Add(current->object,current->options.c_str());
484 0 : pad->Modified(kTRUE);
485 : }
486 0 : else { if (verbose) printf(" missing object\n"); }
487 0 : }
488 : }
489 0 : canvas->SetTitle(info.c_str());
490 0 : canvas->Update();
491 :
492 0 : fTrashQueue.push_back(incomingObjects);
493 : //garbage collect
494 0 : if (fTrashQueue.size()>0)
495 : {
496 0 : if (verbose) printf(" garbage collecting\n");
497 0 : vector<ZMQviewerObject>* pieceOfTrash = *(fTrashQueue.begin());
498 0 : for (vector<ZMQviewerObject>::iterator i=pieceOfTrash->begin();
499 0 : i!=pieceOfTrash->end();
500 0 : ++i)
501 : {
502 0 : if (verbose) printf(" destroying %s, %p\n",safename(i),i->object);
503 0 : delete i->object;
504 : //if (verbose) printf("destroying previous %s, %p\n",i->name.c_str(),i->previous);
505 : //delete i->previous;
506 : }
507 0 : fTrashQueue.pop_front();
508 0 : }
509 :
510 : return 0;
511 0 : }
512 :
513 : //______________________________________________________________________________
514 : int AliZMQhistViewer::ProcessOption(TString option, TString value)
515 : {
516 : int ret = 0;
517 0 : fZMQcontext = alizmq_context();
518 0 : TH1::AddDirectory(kFALSE);
519 0 : TDirectory::AddDirectory(kFALSE);
520 :
521 : //process passed options
522 0 : if (option.EqualTo("PollInterval") || option.EqualTo("sleep"))
523 : {
524 0 : fPollInterval = round(value.Atof()*1e3);
525 0 : if (fPollInterval<0) {fPollInterval = -1;}
526 : }
527 0 : else if (option.EqualTo("PollTimeout") || option.EqualTo("timeout"))
528 : {
529 0 : fPollTimeout = round(value.Atof()*1e3);
530 0 : }
531 0 : else if (option.EqualTo("ZMQconfigIN") || option.EqualTo("in") )
532 : {
533 0 : string valuestr = value.Data();
534 0 : GetZMQconfig(&valuestr);
535 0 : fZMQsocketModeIN = alizmq_socket_init(fZMQin, fZMQcontext, value.Data(), -1, 2);
536 0 : if (fZMQsocketModeIN < 0) return -1;
537 0 : }
538 0 : else if (option.EqualTo("Verbose"))
539 : {
540 0 : fVerbose=kTRUE;
541 0 : }
542 0 : else if (option.EqualTo("select"))
543 : {
544 0 : std::string tmp = value.Data();
545 0 : GetSelection(&tmp);
546 0 : }
547 0 : else if (option.EqualTo("unselect"))
548 : {
549 0 : std::string tmp = value.Data();
550 0 : GetUnSelection(&tmp);
551 0 : }
552 0 : else if (option.EqualTo("ResetOnRequest"))
553 : {
554 0 : fResetOnRequest = kTRUE;
555 0 : }
556 0 : else if (option.EqualTo("drawoptions"))
557 : {
558 0 : fDrawOptions = value;
559 0 : }
560 0 : else if (option.EqualTo("logx"))
561 : {
562 0 : fScaleLogX=kTRUE;
563 0 : }
564 0 : else if (option.EqualTo("logy"))
565 : {
566 0 : fScaleLogY=kTRUE;
567 0 : }
568 0 : else if (option.EqualTo("logz"))
569 : {
570 0 : fScaleLogZ=kTRUE;
571 0 : }
572 0 : else if (option.EqualTo("sort"))
573 : {
574 0 : fSort=value.Contains(0)?kFALSE:kTRUE;
575 0 : }
576 0 : else if (option.EqualTo("histstats"))
577 : {
578 0 : fHistStats = value.Atoi();
579 0 : gStyle->SetOptStat(fHistStats);
580 0 : }
581 0 : else if (option.EqualTo("AllowResetAtSOR"))
582 : {
583 0 : fAllowResetAtSOR = (option.Contains("0")||option.Contains("no"))?kFALSE:kTRUE;
584 0 : }
585 : else
586 : {
587 : ret = -1;
588 : }
589 0 : int rc = alizmq_socket_init(fZMQsleeper, fZMQcontext, "PULL@inproc://sleep", fPollInterval);
590 0 : if (fZMQsocketModeIN == ZMQ_REQ && fPollInterval<=0) fPollInterval=60000;
591 0 : if (fZMQsocketModeIN != ZMQ_REQ ) fPollInterval=0;
592 : return ret;
593 0 : }
594 :
595 : //______________________________________________________________________________
596 : Int_t AliZMQhistViewer::CountPads(TVirtualPad *pad) {
597 : //count the number of pads in pad
598 0 : if (!pad) return 0;
599 : Int_t npads = 0;
600 : TObject *obj;
601 0 : TIter next(pad->GetListOfPrimitives());
602 0 : while ((obj = next())) {
603 0 : if (obj->InheritsFrom(TVirtualPad::Class())) npads++;
604 : }
605 : return npads;
606 0 : }
607 :
608 : //______________________________________________________________________________
609 : std::vector<ZMQviewerObject>*
610 : AliZMQhistViewer::GetIncoming(std::vector<ZMQviewerObject>* in)
611 : {
612 : std::vector<ZMQviewerObject>* tmp = NULL;
613 0 : TThread::Lock();
614 0 : if (!in) { //POP
615 : tmp = fIncoming;
616 0 : fIncoming = NULL;
617 0 : } else { //PUSH, this will destroy anything that was not consumed
618 0 : if (fIncoming) {
619 0 : for (std::vector<ZMQviewerObject>::iterator i=fIncoming->begin(); i!=fIncoming->end(); ++i)
620 : {
621 0 : if (i->object) { if (fVerbose) printf("destroying non consumed object %s %p\n",safename(i), i->object); }
622 0 : delete i->object; i->object = NULL;
623 : }
624 0 : delete fIncoming;
625 : }
626 0 : fIncoming = in;
627 : }
628 0 : TThread::UnLock();
629 0 : return tmp;
630 : }
631 :
632 : //______________________________________________________________________________
633 : std::string AliZMQhistViewer::GetInfo(std::string* in ) {
634 0 : string tmp;
635 0 : TThread::Lock();
636 0 : if (!in) {
637 0 : tmp = fInfo;
638 : } else {
639 0 : fInfo.assign(*in);
640 0 : tmp = fInfo;
641 : }
642 0 : TThread::UnLock();
643 : return tmp;
644 0 : }
645 :
646 : //______________________________________________________________________________
647 : bool AliZMQhistViewer::GetClearCanvas(bool* in ) {
648 : bool tmp;
649 0 : TThread::Lock();
650 0 : if (!in) {
651 0 : tmp = fClearCanvas;
652 0 : fClearCanvas = false;
653 0 : } else {
654 0 : fClearCanvas = *in;;
655 0 : tmp = fClearCanvas;
656 : }
657 0 : TThread::UnLock();
658 0 : return tmp;
659 : }
660 :
661 : //______________________________________________________________________________
662 : bool AliZMQhistViewer::GetTerminated(bool* in) {
663 : bool tmp;
664 0 : TThread::Lock();
665 0 : if (!in) {
666 0 : tmp = fTerminated;
667 0 : fTerminated = false;
668 0 : } else {
669 0 : fTerminated = *in;
670 0 : tmp = fTerminated;
671 : }
672 0 : TThread::UnLock();
673 0 : return tmp;
674 : }
675 :
676 : //______________________________________________________________________________
677 : bool AliZMQhistViewer::GetUpdateCanvas(bool* in) {
678 : bool tmp;
679 0 : TThread::Lock();
680 0 : if (!in) {
681 0 : tmp = fUpdateCanvas;
682 0 : fUpdateCanvas = false;
683 0 : } else {
684 0 : fUpdateCanvas = *in;
685 0 : tmp = fUpdateCanvas;
686 : }
687 0 : TThread::UnLock();
688 0 : return tmp;
689 : }
690 :
691 : //______________________________________________________________________________
692 : int AliZMQhistViewer::GetPollInterval(int* in) {
693 : int tmp;
694 0 : TThread::Lock();
695 0 : if (!in) {
696 0 : tmp = fPollInterval;
697 0 : } else {
698 0 : fPollInterval = *in;
699 : tmp = fPollInterval;
700 : }
701 0 : TThread::UnLock();
702 0 : return tmp;
703 : }
704 :
705 : //______________________________________________________________________________
706 : void AliZMQhistViewer::DataReady()
707 : {
708 0 : TThread::Lock();
709 0 : Emit("DataReady()");
710 0 : TThread::UnLock();
711 0 : }
712 :
713 : //______________________________________________________________________________
714 : string AliZMQhistViewer::GetZMQconfig(string* in)
715 : {
716 0 : string tmp;
717 0 : TThread::Lock();
718 0 : if (!in) {
719 0 : tmp = fZMQconfigIN.Data();
720 : } else {
721 0 : fZMQconfigIN = *in;
722 0 : tmp = *in;
723 : }
724 0 : TThread::UnLock();
725 : return tmp;
726 0 : }
727 :
728 : //______________________________________________________________________________
729 : TPRegexp* AliZMQhistViewer::GetSelection(string* in)
730 : {
731 : TPRegexp* tmp = NULL;
732 0 : TThread::Lock();
733 0 : if (!in) {
734 0 : if (fSelectionRegexp) {
735 0 : tmp = new TPRegexp(*fSelectionRegexp);
736 0 : }
737 : } else {
738 0 : delete fSelectionRegexp; fSelectionRegexp = NULL;
739 0 : if (in->size()>0) fSelectionRegexp = new TPRegexp(in->c_str());
740 0 : tmp = fSelectionRegexp;
741 0 : if (fVerbose) printf("GetSelection: %s\n",(in)?in->c_str():"NULL");
742 : }
743 0 : TThread::UnLock();
744 0 : return tmp;
745 0 : }
746 :
747 : //______________________________________________________________________________
748 : TPRegexp* AliZMQhistViewer::GetUnSelection(string* in)
749 : {
750 : TPRegexp* tmp = NULL;
751 0 : TThread::Lock();
752 0 : if (!in) {
753 0 : if (fUnSelectionRegexp) {
754 0 : tmp = new TPRegexp(*fUnSelectionRegexp);
755 0 : }
756 : } else {
757 0 : delete fUnSelectionRegexp; fUnSelectionRegexp = NULL;
758 0 : if (in->size()>0) fUnSelectionRegexp = new TPRegexp(in->c_str());
759 0 : tmp = fUnSelectionRegexp;
760 0 : if (fVerbose) printf("GetUnSelection: %s\n",(in)?in->c_str():"NULL");
761 : }
762 0 : TThread::UnLock();
763 0 : return tmp;
764 0 : }
765 :
766 :
|