Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooRealMPFE.cxx
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * @(#)root/roofitcore:$Id$
5 * Authors: *
6 * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7 * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8 * *
9 * Copyright (c) 2000-2005, Regents of the University of California *
10 * and Stanford University. All rights reserved. *
11 * *
12 * Redistribution and use in source and binary forms, *
13 * with or without modification, are permitted according to the terms *
14 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15 *****************************************************************************/
16
17/**
18\file RooRealMPFE.cxx
19\class RooRealMPFE
20\ingroup Roofitcore
21
22Multi-processor front-end for parallel calculation
23of RooAbsReal objects. Each RooRealMPFE forks a process that calculates
24the value of the proxies RooAbsReal object. The (re)calculation of
25the proxied object is started asynchronously with the calculate() option.
26A subsequent call to getVal() will return the calculated value when available
27If the calculation is still in progress when getVal() is called it blocks
28the calling process until the calculation is done. The forked calculation process
29is terminated when the front-end object is deleted
30Simple use demonstration
31
32~~~{.cpp}
33RooAbsReal* slowFunc ;
34
35double val = slowFunc->getVal() // Evaluate slowFunc in current process
36
37RooRealMPFE mpfe("mpfe","frontend to slowFunc",*slowFunc) ;
38mpfe.calculate() ; // Start calculation of slow-func in remote process
39 // .. do other stuff here ..
40double val = mpfe.getVal() // Wait for remote calculation to finish and retrieve value
41~~~
42
43For general multiprocessing in ROOT, please refer to the TProcessExecutor class.
44
45**/
46
47#include "Riostream.h"
48
49#ifndef _WIN32
50#include "BidirMMapPipe.h"
51#endif
52
53#include <cstdlib>
54#include <sstream>
55#include "RooRealMPFE.h"
56#include "RooArgSet.h"
57#include "RooAbsCategory.h"
58#include "RooRealVar.h"
59#include "RooCategory.h"
60#include "RooMsgService.h"
61#include "RooNLLVar.h"
62#include "RooTrace.h"
63
64#include "Rtypes.h"
65#include "TSystem.h"
66
67
68class RooRealMPFE ;
69
70// RooMPSentinel is a singleton class that keeps track of all
71// parallel execution processes for goodness-of-fit calculations.
72// The primary task of RooMPSentinel is to terminate all server processes
73// when the main ROOT process is exiting.
75
76 static RooMPSentinel& instance();
77
79
80 void add(RooRealMPFE& mpfe) ;
81 void remove(RooRealMPFE& mpfe) ;
82
84};
85
87 static RooMPSentinel inst;
88 return inst;
89}
90
91
92using std::cout, std::endl, std::string, std::ostringstream, std::list;
93using namespace RooFit;
94
95
96////////////////////////////////////////////////////////////////////////////////
97/// Construct front-end object for object 'arg' whose evaluation will be calculated
98/// asynchronously in a separate process. If calcInline is true the value of 'arg'
99/// is calculate synchronously in the current process.
100
101RooRealMPFE::RooRealMPFE(const char *name, const char *title, RooAbsReal& arg, bool calcInline) :
102 RooAbsReal(name,title),
103 _state(Initialize),
104 _arg("arg","arg",this,arg),
105 _vars("vars","vars",this),
106 _calcInProgress(false),
107 _verboseClient(false),
108 _verboseServer(false),
109 _inlineMode(calcInline),
110 _remoteEvalErrorLoggingState(RooAbsReal::PrintErrors),
111 _pipe(nullptr),
112 _updateMaster(nullptr),
113 _retrieveDispatched(false), _evalCarry(0.)
114{
115#ifdef _WIN32
116 _inlineMode = true;
117#endif
118 initVars() ;
120
121}
122
123
124
125////////////////////////////////////////////////////////////////////////////////
126/// Copy constructor. Initializes in clean state so that upon eval
127/// this instance will create its own server processes
128
129RooRealMPFE::RooRealMPFE(const RooRealMPFE& other, const char* name) :
130 RooAbsReal(other, name),
131 _state(Initialize),
132 _arg("arg",this,other._arg),
133 _vars("vars",this,other._vars),
134 _calcInProgress(false),
135 _verboseClient(other._verboseClient),
136 _verboseServer(other._verboseServer),
137 _inlineMode(other._inlineMode),
138 _forceCalc(other._forceCalc),
139 _remoteEvalErrorLoggingState(other._remoteEvalErrorLoggingState),
140 _pipe(nullptr),
141 _updateMaster(nullptr),
142 _retrieveDispatched(false), _evalCarry(other._evalCarry)
143{
144 initVars() ;
146}
147
148
149
150////////////////////////////////////////////////////////////////////////////////
151/// Destructor
152
154{
155 if (_state==Client) standby();
157}
158
159
160
161////////////////////////////////////////////////////////////////////////////////
162/// Initialize list of variables of front-end argument 'arg'
163
165{
166 // Empty current lists
167 _vars.removeAll() ;
169
170 // Retrieve non-constant parameters
171 auto vars = _arg->getParameters(RooArgSet());
172 //RooArgSet* ncVars = (RooArgSet*) vars->selectByAttrib("Constant",false) ;
173 RooArgList varList(*vars) ;
174
175 // Save in lists
176 _vars.add(varList) ;
177 _saveVars.addClone(varList) ;
178 _valueChanged.resize(_vars.size()) ;
179 _constChanged.resize(_vars.size()) ;
180
181 // Force next calculation
182 _forceCalc = true ;
183}
184
186{
187 if (_inlineMode) {
188 RooAbsTestStatistic* tmp = dynamic_cast<RooAbsTestStatistic*>(_arg.absArg());
189 if (tmp) return tmp->getCarry();
190 else return 0.;
191 } else {
192 return _evalCarry;
193 }
194}
195
196////////////////////////////////////////////////////////////////////////////////
197/// Initialize the remote process and message passing
198/// pipes between current process and remote process
199
201{
202 // Trivial case: Inline mode
203 if (_inlineMode) {
204 _state = Inline ;
205 return ;
206 }
207
208#ifndef _WIN32
209 // Clear eval error log prior to forking
210 // to avoid confusions...
212 // Fork server process and setup IPC
213 _pipe = new BidirMMapPipe();
214
215 if (_pipe->isChild()) {
216 // Start server loop
218 _state = Server ;
219 serverLoop();
220
221 // Kill server at end of service
222 if (_verboseServer) ccoutD(Minimization) << "RooRealMPFE::initialize(" <<
223 GetName() << ") server process terminating" << endl ;
224
225 delete _arg.absArg();
226 delete _pipe;
227 _exit(0) ;
228 } else {
229 // Client process - fork successful
230 if (_verboseClient) {
231 ccoutD(Minimization) << "RooRealMPFE::initialize(" << GetName() << ") successfully forked server process "
232 << _pipe->pidOtherEnd() << endl;
233 }
234 _state = Client ;
235 _calcInProgress = false ;
236 }
237#endif // _WIN32
238}
239
240
241
242////////////////////////////////////////////////////////////////////////////////
243/// Server loop of remote processes. This function will return
244/// only when an incoming TERMINATE message is received.
245
247{
248#ifndef _WIN32
249 int msg ;
250
251 Int_t idx;
252 Int_t index;
253 Int_t numErrors;
254 double value ;
255 bool isConst ;
256
258
259 while(*_pipe && !_pipe->eof()) {
260 *_pipe >> msg;
261 if (Terminate == msg) {
262 if (_verboseServer) cout << "RooRealMPFE::serverLoop(" << GetName()
263 << ") IPC fromClient> Terminate" << endl;
264 // send terminate acknowledged to client
265 *_pipe << msg << BidirMMapPipe::flush;
266 break;
267 }
268
269 switch (msg) {
270 case SendReal:
271 {
272 *_pipe >> idx >> value >> isConst;
273 if (_verboseServer) cout << "RooRealMPFE::serverLoop(" << GetName()
274 << ") IPC fromClient> SendReal [" << idx << "]=" << value << endl ;
275 RooRealVar* rvar = static_cast<RooRealVar*>(_vars.at(idx)) ;
276 rvar->setVal(value) ;
277 if (rvar->isConstant() != isConst) {
278 rvar->setConstant(isConst) ;
279 }
280 }
281 break ;
282
283 case SendCat:
284 {
285 *_pipe >> idx >> index;
286 if (_verboseServer) cout << "RooRealMPFE::serverLoop(" << GetName()
287 << ") IPC fromClient> SendCat [" << idx << "]=" << index << endl ;
288 (static_cast<RooCategory*>(_vars.at(idx)))->setIndex(index) ;
289 }
290 break ;
291
292 case Calculate:
293 if (_verboseServer) cout << "RooRealMPFE::serverLoop(" << GetName()
294 << ") IPC fromClient> Calculate" << endl ;
295 _value = _arg ;
296 break ;
297
299 if (_verboseServer) cout << "RooRealMPFE::serverLoop(" << GetName()
300 << ") IPC fromClient> Calculate" << endl ;
301
303 _value = _arg ;
305 break ;
306
307 case Retrieve:
308 {
309 if (_verboseServer) cout << "RooRealMPFE::serverLoop(" << GetName()
310 << ") IPC fromClient> Retrieve" << endl ;
311 msg = ReturnValue;
312 numErrors = numEvalErrors();
313 *_pipe << msg << _value << getCarry() << numErrors;
314
315 if (_verboseServer) cout << "RooRealMPFE::serverLoop(" << GetName()
316 << ") IPC toClient> ReturnValue " << _value << " NumError " << numErrors << endl ;
317
318 if (numErrors) {
319 // Loop over errors
320 std::string objidstr;
321 {
322 ostringstream oss2;
323 // Format string with object identity as this cannot be evaluated on the other side
324 oss2 << "PID" << gSystem->GetPid() << "/";
326 objidstr = oss2.str();
327 }
328 std::map<const RooAbsArg*,std::pair<string,list<EvalError> > >::const_iterator iter = evalErrorIter();
329 const RooAbsArg* ptr = nullptr;
330 for (int i = 0; i < numEvalErrorItems(); ++i) {
331 list<EvalError>::const_iterator iter2 = iter->second.second.begin();
332 for (; iter->second.second.end() != iter2; ++iter2) {
333 ptr = iter->first;
334 *_pipe << ptr << iter2->_msg << iter2->_srvval << objidstr;
335 if (_verboseServer) cout << "RooRealMPFE::serverLoop(" << GetName()
336 << ") IPC toClient> sending error log Arg " << iter->first << " Msg " << iter2->_msg << endl ;
337 }
338 }
339 // let other end know that we're done with the list of errors
340 ptr = nullptr;
341 *_pipe << ptr;
342 // Clear error list on local side
344 }
345 *_pipe << BidirMMapPipe::flush;
346 }
347 break;
348
349 case ConstOpt:
350 {
351 bool doTrack ;
352 int code;
353 *_pipe >> code >> doTrack;
354 if (_verboseServer) cout << "RooRealMPFE::serverLoop(" << GetName()
355 << ") IPC fromClient> ConstOpt " << code << " doTrack = " << (doTrack?"T":"F") << endl ;
356 ((RooAbsReal&)_arg.arg()).constOptimizeTestStatistic(static_cast<RooAbsArg::ConstOpCode>(code),doTrack) ;
357 break ;
358 }
359
360 case Verbose:
361 {
362 bool flag ;
363 *_pipe >> flag;
364 if (_verboseServer) cout << "RooRealMPFE::serverLoop(" << GetName()
365 << ") IPC fromClient> Verbose " << (flag?1:0) << endl ;
366 _verboseServer = flag ;
367 }
368 break ;
369
370
371 case ApplyNLLW2:
372 {
373 bool flag ;
374 *_pipe >> flag;
375 if (_verboseServer) cout << "RooRealMPFE::serverLoop(" << GetName()
376 << ") IPC fromClient> ApplyNLLW2 " << (flag?1:0) << endl ;
377
378 // Do application of weight-squared here
379 doApplyNLLW2(flag) ;
380 }
381 break ;
382
383 case EnableOffset:
384 {
385 bool flag ;
386 *_pipe >> flag;
387 if (_verboseServer) cout << "RooRealMPFE::serverLoop(" << GetName()
388 << ") IPC fromClient> EnableOffset " << (flag?1:0) << endl ;
389
390 // Enable likelihoof offsetting here
391 ((RooAbsReal&)_arg.arg()).enableOffsetting(flag) ;
392 }
393 break ;
394
395 case LogEvalError:
396 {
397 int iflag2;
398 *_pipe >> iflag2;
401 if (_verboseServer) cout << "RooRealMPFE::serverLoop(" << GetName()
402 << ") IPC fromClient> LogEvalError flag = " << flag2 << endl ;
403 }
404 break ;
405
406
407 default:
408 if (_verboseServer) cout << "RooRealMPFE::serverLoop(" << GetName()
409 << ") IPC fromClient> Unknown message (code = " << msg << ")" << endl ;
410 break ;
411 }
412 }
413
414#endif // _WIN32
415}
416
417
418
419////////////////////////////////////////////////////////////////////////////////
420/// Client-side function that instructs server process to start
421/// asynchronuous (re)calculation of function value. This function
422/// returns immediately. The calculated value can be retrieved
423/// using getVal()
424
426{
427
428 // Start asynchronous calculation of arg value
429 if (_state==Initialize) {
430 // cout << "RooRealMPFE::calculate(" << GetName() << ") initializing" << endl ;
431 const_cast<RooRealMPFE*>(this)->initialize() ;
432 }
433
434 // Inline mode -- Calculate value now
435 if (_state==Inline) {
436 // cout << "RooRealMPFE::calculate(" << GetName() << ") performing Inline calculation NOW" << endl ;
437 _value = _arg ;
439 }
440
441#ifndef _WIN32
442 // Compare current value of variables with saved values and send changes to server
443 if (_state==Client) {
444 // cout << "RooRealMPFE::calculate(" << GetName() << ") state is Client trigger remote calculation" << endl ;
445 Int_t i(0) ;
446
447 //for (i=0 ; i<_vars.size() ; i++) {
448 RooAbsArg *var;
449 RooAbsArg *saveVar;
450 for (std::size_t j=0 ; j<_vars.size() ; j++) {
451 var = _vars.at(j);
452 saveVar = _saveVars.at(j);
453
454 //bool valChanged = !(*var==*saveVar) ;
455 bool valChanged;
456 bool constChanged;
457 if (!_updateMaster) {
458 valChanged = !var->isIdentical(*saveVar,true) ;
459 constChanged = (var->isConstant() != saveVar->isConstant()) ;
460 _valueChanged[i] = valChanged ;
461 _constChanged[i] = constChanged ;
462 } else {
463 valChanged = _updateMaster->_valueChanged[i] ;
464 constChanged = _updateMaster->_constChanged[i] ;
465 }
466
467 if ( valChanged || constChanged || _forceCalc) {
468 //cout << "RooRealMPFE::calculate(" << GetName() << " variable " << var->GetName() << " changed " << endl ;
469 if (_verboseClient) cout << "RooRealMPFE::calculate(" << GetName()
470 << ") variable " << _vars.at(i)->GetName() << " changed" << endl ;
471 if (constChanged) {
472 (static_cast<RooRealVar*>(saveVar))->setConstant(var->isConstant()) ;
473 }
474 saveVar->copyCache(var) ;
475
476 // send message to server
477 if (dynamic_cast<RooAbsReal*>(var)) {
478 int msg = SendReal ;
479 double val = (static_cast<RooAbsReal*>(var))->getVal() ;
480 bool isC = var->isConstant() ;
481 *_pipe << msg << i << val << isC;
482
483 if (_verboseServer) cout << "RooRealMPFE::calculate(" << GetName()
484 << ") IPC toServer> SendReal [" << i << "]=" << val << (isC?" (Constant)":"") << endl ;
485 } else if (dynamic_cast<RooAbsCategory*>(var)) {
486 int msg = SendCat ;
487 UInt_t idx = (static_cast<RooAbsCategory*>(var))->getCurrentIndex() ;
488 *_pipe << msg << i << idx;
489 if (_verboseServer) cout << "RooRealMPFE::calculate(" << GetName()
490 << ") IPC toServer> SendCat [" << i << "]=" << idx << endl ;
491 }
492 }
493 i++ ;
494 }
495
496 int msg = hideOffset() ? Calculate : CalculateNoOffset;
497 *_pipe << msg;
498 if (_verboseServer) cout << "RooRealMPFE::calculate(" << GetName()
499 << ") IPC toServer> Calculate " << endl ;
500
501 // Clear dirty state and mark that calculation request was dispatched
503 _calcInProgress = true ;
504 _forceCalc = false ;
505
506 msg = Retrieve ;
507 *_pipe << msg << BidirMMapPipe::flush;
508 if (_verboseServer) cout << "RooRealMPFE::evaluate(" << GetName()
509 << ") IPC toServer> Retrieve " << endl ;
510 _retrieveDispatched = true ;
511
512 } else if (_state!=Inline) {
513 cout << "RooRealMPFE::calculate(" << GetName()
514 << ") ERROR not in Client or Inline mode" << endl ;
515 }
516
517
518#endif // _WIN32
519}
520
521
522
523
524////////////////////////////////////////////////////////////////////////////////
525/// If value needs recalculation and calculation has not been started
526/// with a call to calculate() start it now. This function blocks
527/// until remote process has finished calculation and returns
528/// remote value
529
530double RooRealMPFE::getValV(const RooArgSet* /*nset*/) const
531{
532
533 if (isValueDirty()) {
534 // Cache is dirty, no calculation has been started yet
535 //cout << "RooRealMPFE::getValF(" << GetName() << ") cache is dirty, calling calculate and evaluate" << endl ;
536 calculate() ;
537 _value = evaluate() ;
538 } else if (_calcInProgress) {
539 //cout << "RooRealMPFE::getValF(" << GetName() << ") calculation in progress, calling evaluate" << endl ;
540 // Cache is clean and calculation is in progress
541 _value = evaluate() ;
542 } else {
543 //cout << "RooRealMPFE::getValF(" << GetName() << ") cache is clean, doing nothing" << endl ;
544 // Cache is clean and calculated value is in cache
545 }
546
547// cout << "RooRealMPFE::getValV(" << GetName() << ") value = " << Form("%5.10f",_value) << endl ;
548 return _value ;
549}
550
551
552
553////////////////////////////////////////////////////////////////////////////////
554/// Send message to server process to retrieve output value
555/// If error were logged use logEvalError() on remote side
556/// transfer those errors to the local eval error queue.
557
559{
560 // Retrieve value of arg
561 double return_value = 0;
562 if (_state==Inline) {
563 return_value = _arg ;
564 } else if (_state==Client) {
565#ifndef _WIN32
566 bool needflush = false;
567 int msg;
568 double value;
569
570 // If current error logging state is not the same as remote state
571 // update the remote state
573 msg = LogEvalError ;
575 *_pipe << msg << flag;
576 needflush = true;
578 }
579
580 if (!_retrieveDispatched) {
581 msg = Retrieve ;
582 *_pipe << msg;
583 needflush = true;
584 if (_verboseServer) cout << "RooRealMPFE::evaluate(" << GetName()
585 << ") IPC toServer> Retrieve " << endl ;
586 }
587 if (needflush) *_pipe << BidirMMapPipe::flush;
588 _retrieveDispatched = false ;
589
590
591 Int_t numError;
592
593 *_pipe >> msg >> value >> _evalCarry >> numError;
594
595 if (msg!=ReturnValue) {
596 cout << "RooRealMPFE::evaluate(" << GetName()
597 << ") ERROR: unexpected message from server process: " << msg << endl ;
598 return 0 ;
599 }
600 if (_verboseServer) cout << "RooRealMPFE::evaluate(" << GetName()
601 << ") IPC fromServer> ReturnValue " << value << endl ;
602
603 if (_verboseServer) cout << "RooRealMPFE::evaluate(" << GetName()
604 << ") IPC fromServer> NumErrors " << numError << endl ;
605 if (numError) {
606 // Retrieve remote errors and feed into local error queue
607 char *msgbuf1 = nullptr;
608 char *msgbuf2 = nullptr;
609 char *msgbuf3 = nullptr;
610 RooAbsArg *ptr = nullptr;
611 while (true) {
612 *_pipe >> ptr;
613 if (!ptr) break;
614 *_pipe >> msgbuf1 >> msgbuf2 >> msgbuf3;
615 if (_verboseServer) cout << "RooRealMPFE::evaluate(" << GetName()
616 << ") IPC fromServer> retrieving error log Arg " << ptr << " Msg " << msgbuf1 << endl ;
617
618 logEvalError(reinterpret_cast<RooAbsReal*>(ptr),msgbuf3,msgbuf1,msgbuf2) ;
619 }
620 std::free(msgbuf1);
621 std::free(msgbuf2);
622 std::free(msgbuf3);
623 }
624
625 // Mark end of calculation in progress
626 _calcInProgress = false ;
627 return_value = value ;
628#endif // _WIN32
629 }
630
631 return return_value;
632}
633
634
635
636////////////////////////////////////////////////////////////////////////////////
637/// Terminate remote server process and return front-end class
638/// to standby mode. Calls to calculate() or evaluate() after
639/// this call will automatically recreated the server process.
640
642{
643#ifndef _WIN32
644 if (_state==Client) {
645 if (_pipe->good()) {
646 // Terminate server process ;
647 if (_verboseServer) cout << "RooRealMPFE::standby(" << GetName()
648 << ") IPC toServer> Terminate " << endl;
649 int msg = Terminate;
650 *_pipe << msg << BidirMMapPipe::flush;
651 // read handshake
652 msg = 0;
653 *_pipe >> msg;
654 if (Terminate != msg || 0 != _pipe->close()) {
655 std::cerr << "In " << __func__ << "(" << __FILE__ ", " << __LINE__ <<
656 "): Server shutdown failed." << std::endl;
657 }
658 } else {
659 if (_verboseServer) {
660 std::cerr << "In " << __func__ << "(" << __FILE__ ", " <<
661 __LINE__ << "): Pipe has already shut down, not sending "
662 "Terminate to server." << std::endl;
663 }
664 }
665 // Close pipes
666 delete _pipe;
667 _pipe = nullptr;
668
669 // Revert to initialize state
671 }
672#endif // _WIN32
673}
674
675
676
677////////////////////////////////////////////////////////////////////////////////
678/// Intercept call to optimize constant term in test statistics
679/// and forward it to object on server side.
680
682{
683#ifndef _WIN32
684 if (_state==Client) {
685
686 int msg = ConstOpt ;
687 int op = opcode;
688 *_pipe << msg << op << doAlsoTracking;
689 if (_verboseServer) cout << "RooRealMPFE::constOptimize(" << GetName()
690 << ") IPC toServer> ConstOpt " << opcode << endl ;
691
692 initVars() ;
693 }
694#endif // _WIN32
695
696 if (_state==Inline) {
697 ((RooAbsReal&)_arg.arg()).constOptimizeTestStatistic(opcode,doAlsoTracking) ;
698 }
699}
700
701
702
703////////////////////////////////////////////////////////////////////////////////
704/// Control verbose messaging related to inter process communication
705/// on both client and server side
706
707void RooRealMPFE::setVerbose(bool clientFlag, bool serverFlag)
708{
709#ifndef _WIN32
710 if (_state==Client) {
711 int msg = Verbose ;
712 *_pipe << msg << serverFlag;
713 if (_verboseServer) cout << "RooRealMPFE::setVerbose(" << GetName()
714 << ") IPC toServer> Verbose " << (serverFlag?1:0) << endl ;
715 }
716#endif // _WIN32
717 _verboseClient = clientFlag ; _verboseServer = serverFlag ;
718}
719
720
721////////////////////////////////////////////////////////////////////////////////
722/// Control verbose messaging related to inter process communication
723/// on both client and server side
724
726{
727#ifndef _WIN32
728 if (_state==Client) {
729 int msg = ApplyNLLW2 ;
730 *_pipe << msg << flag;
731 if (_verboseServer) cout << "RooRealMPFE::applyNLLWeightSquared(" << GetName()
732 << ") IPC toServer> ApplyNLLW2 " << (flag?1:0) << endl ;
733 }
734#endif // _WIN32
735 doApplyNLLW2(flag) ;
736}
737
738
739////////////////////////////////////////////////////////////////////////////////
740
742{
743 RooNLLVar* nll = dynamic_cast<RooNLLVar*>(_arg.absArg()) ;
744 if (nll) {
745 nll->applyWeightSquared(flag) ;
746 }
747}
748
749
750////////////////////////////////////////////////////////////////////////////////
751/// Control verbose messaging related to inter process communication
752/// on both client and server side
753
755{
756#ifndef _WIN32
757 if (_state==Client) {
758 int msg = EnableOffset ;
759 *_pipe << msg << flag;
760 if (_verboseServer) cout << "RooRealMPFE::enableOffsetting(" << GetName()
761 << ") IPC toServer> EnableOffset " << (flag?1:0) << endl ;
762 }
763#endif // _WIN32
764 ((RooAbsReal&)_arg.arg()).enableOffsetting(flag) ;
765}
766
767
768
769////////////////////////////////////////////////////////////////////////////////
770/// Destructor. Terminate all parallel processes still registered with
771/// the sentinel
772
774{
775 for(auto * mpfe : static_range_cast<RooRealMPFE*>(_mpfeSet)) {
776 mpfe->standby() ;
777 }
778}
779
780
781
782////////////////////////////////////////////////////////////////////////////////
783/// Register given multi-processor front-end object with the sentinel
784
786{
787 _mpfeSet.add(mpfe,true) ;
788}
789
790
791
792////////////////////////////////////////////////////////////////////////////////
793/// Remove given multi-processor front-end object from the sentinel
794
796{
797 _mpfeSet.remove(mpfe,true) ;
798}
799
#define ccoutD(a)
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
char name[80]
Definition TGX11.cxx:110
R__EXTERN TSystem * gSystem
Definition TSystem.h:561
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition RooAbsArg.h:79
virtual void copyCache(const RooAbsArg *source, bool valueOnly=false, bool setValDirty=true)=0
bool isConstant() const
Check if the "Constant" attribute is set.
Definition RooAbsArg.h:335
void clearValueDirty() const
Definition RooAbsArg.h:576
bool isValueDirty() const
Definition RooAbsArg.h:393
virtual bool isIdentical(const RooAbsArg &other, bool assumeSameType=false) const =0
friend class RooRealMPFE
Definition RooAbsArg.h:642
A space to attach TBranches.
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
virtual bool remove(const RooAbsArg &var, bool silent=false, bool matchByNameOnly=false)
Remove the specified argument from our list.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Storage_t::size_type size() const
virtual RooAbsArg * addClone(const RooAbsArg &var, bool silent=false)
Add a clone of the specified argument to list.
void setConstant(bool value=true)
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:59
static Int_t numEvalErrorItems()
static bool hideOffset()
static ErrorLoggingMode evalErrorLoggingMode()
Return current evaluation error logging mode.
double _value
Cache for current value of object.
Definition RooAbsReal.h:536
static void setHideOffset(bool flag)
static std::map< constRooAbsArg *, std::pair< std::string, std::list< RooAbsReal::EvalError > > >::iterator evalErrorIter()
static Int_t numEvalErrors()
Return the number of logged evaluation errors since the last clearing.
static void setEvalErrorLoggingMode(ErrorLoggingMode m)
Set evaluation error logging mode.
void logEvalError(const char *message, const char *serverValueString=nullptr) const
Log evaluation error message.
static void clearEvalErrorLog()
Clear the stack of evaluation error messages.
Abstract base class for all test statistics.
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:22
RooAbsArg * at(Int_t idx) const
Return object at given index, or nullptr if index is out of range.
Definition RooArgList.h:110
RooAbsArg * absArg() const
Return pointer to contained argument.
Definition RooArgProxy.h:46
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
Object to represent discrete states.
Definition RooCategory.h:28
void removeAll() override
Remove all argument inset using remove(const RooAbsArg&).
bool add(const RooAbsArg &var, bool valueServer, bool shapeServer, bool silent)
Overloaded RooCollection_t::add() method insert object into set and registers object as server to own...
Implements a -log(likelihood) calculation from a dataset and a PDF.
Definition RooNLLVar.h:20
virtual void printStream(std::ostream &os, Int_t contents, StyleOption style, TString indent="") const
Print description of object on ostream, printing contents set by contents integer,...
Multi-processor front-end for parallel calculation of RooAbsReal objects.
Definition RooRealMPFE.h:29
RooFit::BidirMMapPipe * _pipe
! connection to child
Definition RooRealMPFE.h:81
RooArgList _saveVars
Copy of variables.
Definition RooRealMPFE.h:73
void calculate() const
Client-side function that instructs server process to start asynchronuous (re)calculation of function...
void initialize()
Initialize the remote process and message passing pipes between current process and remote process.
void serverLoop()
Server loop of remote processes.
void standby()
Terminate remote server process and return front-end class to standby mode.
bool _calcInProgress
Definition RooRealMPFE.h:74
RooListProxy _vars
Variables.
Definition RooRealMPFE.h:72
double _evalCarry
!
Definition RooRealMPFE.h:87
void applyNLLWeightSquared(bool flag)
Control verbose messaging related to inter process communication on both client and server side.
void initVars()
Initialize list of variables of front-end argument 'arg'.
RooRealMPFE * _updateMaster
! Update master
Definition RooRealMPFE.h:85
void doApplyNLLW2(bool flag)
bool _retrieveDispatched
!
Definition RooRealMPFE.h:86
bool _verboseClient
Definition RooRealMPFE.h:75
void setVerbose(bool clientFlag=true, bool serverFlag=true)
Control verbose messaging related to inter process communication on both client and server side.
bool _forceCalc
Definition RooRealMPFE.h:78
std::vector< bool > _constChanged
! Flags if variable needs update on server-side
Definition RooRealMPFE.h:84
double evaluate() const override
Send message to server process to retrieve output value If error were logged use logEvalError() on re...
void constOptimizeTestStatistic(ConstOpCode opcode, bool doAlsoTracking=true) override
Intercept call to optimize constant term in test statistics and forward it to object on server side.
virtual double getCarry() const
std::vector< bool > _valueChanged
! Flags if variable needs update on server-side
Definition RooRealMPFE.h:83
void enableOffsetting(bool flag) override
Control verbose messaging related to inter process communication on both client and server side.
bool _verboseServer
Definition RooRealMPFE.h:76
RooRealProxy _arg
Function to calculate in parallel process.
Definition RooRealMPFE.h:71
bool _inlineMode
Definition RooRealMPFE.h:77
~RooRealMPFE() override
Destructor.
RooAbsReal::ErrorLoggingMode _remoteEvalErrorLoggingState
Definition RooRealMPFE.h:79
double getValV(const RooArgSet *nset=nullptr) const override
If value needs recalculation and calculation has not been started with a call to calculate() start it...
Variable that can be changed from the outside.
Definition RooRealVar.h:37
void setVal(double value) override
Set value of variable to 'value'.
static void callgrind_zero()
Utility function to trigger zeroing of callgrind counters.
Definition RooTrace.cxx:353
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
virtual int GetPid()
Get process id.
Definition TSystem.cxx:707
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition JSONIO.h:26
void remove(RooRealMPFE &mpfe)
Remove given multi-processor front-end object from the sentinel.
RooArgSet _mpfeSet
void add(RooRealMPFE &mpfe)
Register given multi-processor front-end object with the sentinel.
static RooMPSentinel & instance()
~RooMPSentinel()
Destructor.