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 namespace std;
93using namespace RooFit;
94
96
97
98////////////////////////////////////////////////////////////////////////////////
99/// Construct front-end object for object 'arg' whose evaluation will be calculated
100/// asynchronously in a separate process. If calcInline is true the value of 'arg'
101/// is calculate synchronously in the current process.
102
103RooRealMPFE::RooRealMPFE(const char *name, const char *title, RooAbsReal& arg, bool calcInline) :
104 RooAbsReal(name,title),
105 _state(Initialize),
106 _arg("arg","arg",this,arg),
107 _vars("vars","vars",this),
108 _calcInProgress(false),
109 _verboseClient(false),
110 _verboseServer(false),
111 _inlineMode(calcInline),
112 _remoteEvalErrorLoggingState(RooAbsReal::PrintErrors),
113 _pipe(nullptr),
114 _updateMaster(nullptr),
115 _retrieveDispatched(false), _evalCarry(0.)
116{
117#ifdef _WIN32
118 _inlineMode = true;
119#endif
120 initVars() ;
122
123}
124
125
126
127////////////////////////////////////////////////////////////////////////////////
128/// Copy constructor. Initializes in clean state so that upon eval
129/// this instance will create its own server processes
130
131RooRealMPFE::RooRealMPFE(const RooRealMPFE& other, const char* name) :
132 RooAbsReal(other, name),
133 _state(Initialize),
134 _arg("arg",this,other._arg),
135 _vars("vars",this,other._vars),
136 _calcInProgress(false),
137 _verboseClient(other._verboseClient),
138 _verboseServer(other._verboseServer),
139 _inlineMode(other._inlineMode),
140 _forceCalc(other._forceCalc),
141 _remoteEvalErrorLoggingState(other._remoteEvalErrorLoggingState),
142 _pipe(nullptr),
143 _updateMaster(nullptr),
144 _retrieveDispatched(false), _evalCarry(other._evalCarry)
145{
146 initVars() ;
148}
149
150
151
152////////////////////////////////////////////////////////////////////////////////
153/// Destructor
154
156{
157 if (_state==Client) standby();
159}
160
161
162
163////////////////////////////////////////////////////////////////////////////////
164/// Initialize list of variables of front-end argument 'arg'
165
167{
168 // Empty current lists
169 _vars.removeAll() ;
171
172 // Retrieve non-constant parameters
173 auto vars = _arg->getParameters(RooArgSet());
174 //RooArgSet* ncVars = (RooArgSet*) vars->selectByAttrib("Constant",false) ;
175 RooArgList varList(*vars) ;
176
177 // Save in lists
178 _vars.add(varList) ;
179 _saveVars.addClone(varList) ;
180 _valueChanged.resize(_vars.size()) ;
181 _constChanged.resize(_vars.size()) ;
182
183 // Force next calculation
184 _forceCalc = true ;
185}
186
188{
189 if (_inlineMode) {
190 RooAbsTestStatistic* tmp = dynamic_cast<RooAbsTestStatistic*>(_arg.absArg());
191 if (tmp) return tmp->getCarry();
192 else return 0.;
193 } else {
194 return _evalCarry;
195 }
196}
197
198////////////////////////////////////////////////////////////////////////////////
199/// Initialize the remote process and message passing
200/// pipes between current process and remote process
201
203{
204 // Trivial case: Inline mode
205 if (_inlineMode) {
206 _state = Inline ;
207 return ;
208 }
209
210#ifndef _WIN32
211 // Clear eval error log prior to forking
212 // to avoid confusions...
214 // Fork server process and setup IPC
215 _pipe = new BidirMMapPipe();
216
217 if (_pipe->isChild()) {
218 // Start server loop
220 _state = Server ;
221 serverLoop();
222
223 // Kill server at end of service
224 if (_verboseServer) ccoutD(Minimization) << "RooRealMPFE::initialize(" <<
225 GetName() << ") server process terminating" << endl ;
226
227 delete _arg.absArg();
228 delete _pipe;
229 _exit(0) ;
230 } else {
231 // Client process - fork successful
232 if (_verboseClient) {
233 ccoutD(Minimization) << "RooRealMPFE::initialize(" << GetName() << ") successfully forked server process "
234 << _pipe->pidOtherEnd() << endl;
235 }
236 _state = Client ;
237 _calcInProgress = false ;
238 }
239#endif // _WIN32
240}
241
242
243
244////////////////////////////////////////////////////////////////////////////////
245/// Server loop of remote processes. This function will return
246/// only when an incoming TERMINATE message is received.
247
249{
250#ifndef _WIN32
251 int msg ;
252
253 Int_t idx;
254 Int_t index;
255 Int_t numErrors;
256 double value ;
257 bool isConst ;
258
260
261 while(*_pipe && !_pipe->eof()) {
262 *_pipe >> msg;
263 if (Terminate == msg) {
264 if (_verboseServer) cout << "RooRealMPFE::serverLoop(" << GetName()
265 << ") IPC fromClient> Terminate" << endl;
266 // send terminate acknowledged to client
267 *_pipe << msg << BidirMMapPipe::flush;
268 break;
269 }
270
271 switch (msg) {
272 case SendReal:
273 {
274 *_pipe >> idx >> value >> isConst;
275 if (_verboseServer) cout << "RooRealMPFE::serverLoop(" << GetName()
276 << ") IPC fromClient> SendReal [" << idx << "]=" << value << endl ;
277 RooRealVar* rvar = static_cast<RooRealVar*>(_vars.at(idx)) ;
278 rvar->setVal(value) ;
279 if (rvar->isConstant() != isConst) {
280 rvar->setConstant(isConst) ;
281 }
282 }
283 break ;
284
285 case SendCat:
286 {
287 *_pipe >> idx >> index;
288 if (_verboseServer) cout << "RooRealMPFE::serverLoop(" << GetName()
289 << ") IPC fromClient> SendCat [" << idx << "]=" << index << endl ;
290 (static_cast<RooCategory*>(_vars.at(idx)))->setIndex(index) ;
291 }
292 break ;
293
294 case Calculate:
295 if (_verboseServer) cout << "RooRealMPFE::serverLoop(" << GetName()
296 << ") IPC fromClient> Calculate" << endl ;
297 _value = _arg ;
298 break ;
299
301 if (_verboseServer) cout << "RooRealMPFE::serverLoop(" << GetName()
302 << ") IPC fromClient> Calculate" << endl ;
303
305 _value = _arg ;
307 break ;
308
309 case Retrieve:
310 {
311 if (_verboseServer) cout << "RooRealMPFE::serverLoop(" << GetName()
312 << ") IPC fromClient> Retrieve" << endl ;
313 msg = ReturnValue;
314 numErrors = numEvalErrors();
315 *_pipe << msg << _value << getCarry() << numErrors;
316
317 if (_verboseServer) cout << "RooRealMPFE::serverLoop(" << GetName()
318 << ") IPC toClient> ReturnValue " << _value << " NumError " << numErrors << endl ;
319
320 if (numErrors) {
321 // Loop over errors
322 std::string objidstr;
323 {
324 ostringstream oss2;
325 // Format string with object identity as this cannot be evaluated on the other side
326 oss2 << "PID" << gSystem->GetPid() << "/";
328 objidstr = oss2.str();
329 }
330 std::map<const RooAbsArg*,pair<string,list<EvalError> > >::const_iterator iter = evalErrorIter();
331 const RooAbsArg* ptr = nullptr;
332 for (int i = 0; i < numEvalErrorItems(); ++i) {
333 list<EvalError>::const_iterator iter2 = iter->second.second.begin();
334 for (; iter->second.second.end() != iter2; ++iter2) {
335 ptr = iter->first;
336 *_pipe << ptr << iter2->_msg << iter2->_srvval << objidstr;
337 if (_verboseServer) cout << "RooRealMPFE::serverLoop(" << GetName()
338 << ") IPC toClient> sending error log Arg " << iter->first << " Msg " << iter2->_msg << endl ;
339 }
340 }
341 // let other end know that we're done with the list of errors
342 ptr = nullptr;
343 *_pipe << ptr;
344 // Clear error list on local side
346 }
347 *_pipe << BidirMMapPipe::flush;
348 }
349 break;
350
351 case ConstOpt:
352 {
353 bool doTrack ;
354 int code;
355 *_pipe >> code >> doTrack;
356 if (_verboseServer) cout << "RooRealMPFE::serverLoop(" << GetName()
357 << ") IPC fromClient> ConstOpt " << code << " doTrack = " << (doTrack?"T":"F") << endl ;
358 ((RooAbsReal&)_arg.arg()).constOptimizeTestStatistic(static_cast<RooAbsArg::ConstOpCode>(code),doTrack) ;
359 break ;
360 }
361
362 case Verbose:
363 {
364 bool flag ;
365 *_pipe >> flag;
366 if (_verboseServer) cout << "RooRealMPFE::serverLoop(" << GetName()
367 << ") IPC fromClient> Verbose " << (flag?1:0) << endl ;
368 _verboseServer = flag ;
369 }
370 break ;
371
372
373 case ApplyNLLW2:
374 {
375 bool flag ;
376 *_pipe >> flag;
377 if (_verboseServer) cout << "RooRealMPFE::serverLoop(" << GetName()
378 << ") IPC fromClient> ApplyNLLW2 " << (flag?1:0) << endl ;
379
380 // Do application of weight-squared here
381 doApplyNLLW2(flag) ;
382 }
383 break ;
384
385 case EnableOffset:
386 {
387 bool flag ;
388 *_pipe >> flag;
389 if (_verboseServer) cout << "RooRealMPFE::serverLoop(" << GetName()
390 << ") IPC fromClient> EnableOffset " << (flag?1:0) << endl ;
391
392 // Enable likelihoof offsetting here
393 ((RooAbsReal&)_arg.arg()).enableOffsetting(flag) ;
394 }
395 break ;
396
397 case LogEvalError:
398 {
399 int iflag2;
400 *_pipe >> iflag2;
403 if (_verboseServer) cout << "RooRealMPFE::serverLoop(" << GetName()
404 << ") IPC fromClient> LogEvalError flag = " << flag2 << endl ;
405 }
406 break ;
407
408
409 default:
410 if (_verboseServer) cout << "RooRealMPFE::serverLoop(" << GetName()
411 << ") IPC fromClient> Unknown message (code = " << msg << ")" << endl ;
412 break ;
413 }
414 }
415
416#endif // _WIN32
417}
418
419
420
421////////////////////////////////////////////////////////////////////////////////
422/// Client-side function that instructs server process to start
423/// asynchronuous (re)calculation of function value. This function
424/// returns immediately. The calculated value can be retrieved
425/// using getVal()
426
428{
429
430 // Start asynchronous calculation of arg value
431 if (_state==Initialize) {
432 // cout << "RooRealMPFE::calculate(" << GetName() << ") initializing" << endl ;
433 const_cast<RooRealMPFE*>(this)->initialize() ;
434 }
435
436 // Inline mode -- Calculate value now
437 if (_state==Inline) {
438 // cout << "RooRealMPFE::calculate(" << GetName() << ") performing Inline calculation NOW" << endl ;
439 _value = _arg ;
441 }
442
443#ifndef _WIN32
444 // Compare current value of variables with saved values and send changes to server
445 if (_state==Client) {
446 // cout << "RooRealMPFE::calculate(" << GetName() << ") state is Client trigger remote calculation" << endl ;
447 Int_t i(0) ;
448
449 //for (i=0 ; i<_vars.size() ; i++) {
450 RooAbsArg *var;
451 RooAbsArg *saveVar;
452 for (std::size_t j=0 ; j<_vars.size() ; j++) {
453 var = _vars.at(j);
454 saveVar = _saveVars.at(j);
455
456 //bool valChanged = !(*var==*saveVar) ;
457 bool valChanged;
458 bool constChanged;
459 if (!_updateMaster) {
460 valChanged = !var->isIdentical(*saveVar,true) ;
461 constChanged = (var->isConstant() != saveVar->isConstant()) ;
462 _valueChanged[i] = valChanged ;
463 _constChanged[i] = constChanged ;
464 } else {
465 valChanged = _updateMaster->_valueChanged[i] ;
466 constChanged = _updateMaster->_constChanged[i] ;
467 }
468
469 if ( valChanged || constChanged || _forceCalc) {
470 //cout << "RooRealMPFE::calculate(" << GetName() << " variable " << var->GetName() << " changed " << endl ;
471 if (_verboseClient) cout << "RooRealMPFE::calculate(" << GetName()
472 << ") variable " << _vars.at(i)->GetName() << " changed" << endl ;
473 if (constChanged) {
474 (static_cast<RooRealVar*>(saveVar))->setConstant(var->isConstant()) ;
475 }
476 saveVar->copyCache(var) ;
477
478 // send message to server
479 if (dynamic_cast<RooAbsReal*>(var)) {
480 int msg = SendReal ;
481 double val = (static_cast<RooAbsReal*>(var))->getVal() ;
482 bool isC = var->isConstant() ;
483 *_pipe << msg << i << val << isC;
484
485 if (_verboseServer) cout << "RooRealMPFE::calculate(" << GetName()
486 << ") IPC toServer> SendReal [" << i << "]=" << val << (isC?" (Constant)":"") << endl ;
487 } else if (dynamic_cast<RooAbsCategory*>(var)) {
488 int msg = SendCat ;
489 UInt_t idx = (static_cast<RooAbsCategory*>(var))->getCurrentIndex() ;
490 *_pipe << msg << i << idx;
491 if (_verboseServer) cout << "RooRealMPFE::calculate(" << GetName()
492 << ") IPC toServer> SendCat [" << i << "]=" << idx << endl ;
493 }
494 }
495 i++ ;
496 }
497
498 int msg = hideOffset() ? Calculate : CalculateNoOffset;
499 *_pipe << msg;
500 if (_verboseServer) cout << "RooRealMPFE::calculate(" << GetName()
501 << ") IPC toServer> Calculate " << endl ;
502
503 // Clear dirty state and mark that calculation request was dispatched
505 _calcInProgress = true ;
506 _forceCalc = false ;
507
508 msg = Retrieve ;
509 *_pipe << msg << BidirMMapPipe::flush;
510 if (_verboseServer) cout << "RooRealMPFE::evaluate(" << GetName()
511 << ") IPC toServer> Retrieve " << endl ;
512 _retrieveDispatched = true ;
513
514 } else if (_state!=Inline) {
515 cout << "RooRealMPFE::calculate(" << GetName()
516 << ") ERROR not in Client or Inline mode" << endl ;
517 }
518
519
520#endif // _WIN32
521}
522
523
524
525
526////////////////////////////////////////////////////////////////////////////////
527/// If value needs recalculation and calculation has not been started
528/// with a call to calculate() start it now. This function blocks
529/// until remote process has finished calculation and returns
530/// remote value
531
532double RooRealMPFE::getValV(const RooArgSet* /*nset*/) const
533{
534
535 if (isValueDirty()) {
536 // Cache is dirty, no calculation has been started yet
537 //cout << "RooRealMPFE::getValF(" << GetName() << ") cache is dirty, calling calculate and evaluate" << endl ;
538 calculate() ;
539 _value = evaluate() ;
540 } else if (_calcInProgress) {
541 //cout << "RooRealMPFE::getValF(" << GetName() << ") calculation in progress, calling evaluate" << endl ;
542 // Cache is clean and calculation is in progress
543 _value = evaluate() ;
544 } else {
545 //cout << "RooRealMPFE::getValF(" << GetName() << ") cache is clean, doing nothing" << endl ;
546 // Cache is clean and calculated value is in cache
547 }
548
549// cout << "RooRealMPFE::getValV(" << GetName() << ") value = " << Form("%5.10f",_value) << endl ;
550 return _value ;
551}
552
553
554
555////////////////////////////////////////////////////////////////////////////////
556/// Send message to server process to retrieve output value
557/// If error were logged use logEvalError() on remote side
558/// transfer those errors to the local eval error queue.
559
561{
562 // Retrieve value of arg
563 double return_value = 0;
564 if (_state==Inline) {
565 return_value = _arg ;
566 } else if (_state==Client) {
567#ifndef _WIN32
568 bool needflush = false;
569 int msg;
570 double value;
571
572 // If current error logging state is not the same as remote state
573 // update the remote state
575 msg = LogEvalError ;
577 *_pipe << msg << flag;
578 needflush = true;
580 }
581
582 if (!_retrieveDispatched) {
583 msg = Retrieve ;
584 *_pipe << msg;
585 needflush = true;
586 if (_verboseServer) cout << "RooRealMPFE::evaluate(" << GetName()
587 << ") IPC toServer> Retrieve " << endl ;
588 }
589 if (needflush) *_pipe << BidirMMapPipe::flush;
590 _retrieveDispatched = false ;
591
592
593 Int_t numError;
594
595 *_pipe >> msg >> value >> _evalCarry >> numError;
596
597 if (msg!=ReturnValue) {
598 cout << "RooRealMPFE::evaluate(" << GetName()
599 << ") ERROR: unexpected message from server process: " << msg << endl ;
600 return 0 ;
601 }
602 if (_verboseServer) cout << "RooRealMPFE::evaluate(" << GetName()
603 << ") IPC fromServer> ReturnValue " << value << endl ;
604
605 if (_verboseServer) cout << "RooRealMPFE::evaluate(" << GetName()
606 << ") IPC fromServer> NumErrors " << numError << endl ;
607 if (numError) {
608 // Retrieve remote errors and feed into local error queue
609 char *msgbuf1 = nullptr;
610 char *msgbuf2 = nullptr;
611 char *msgbuf3 = nullptr;
612 RooAbsArg *ptr = nullptr;
613 while (true) {
614 *_pipe >> ptr;
615 if (!ptr) break;
616 *_pipe >> msgbuf1 >> msgbuf2 >> msgbuf3;
617 if (_verboseServer) cout << "RooRealMPFE::evaluate(" << GetName()
618 << ") IPC fromServer> retrieving error log Arg " << ptr << " Msg " << msgbuf1 << endl ;
619
620 logEvalError(reinterpret_cast<RooAbsReal*>(ptr),msgbuf3,msgbuf1,msgbuf2) ;
621 }
622 std::free(msgbuf1);
623 std::free(msgbuf2);
624 std::free(msgbuf3);
625 }
626
627 // Mark end of calculation in progress
628 _calcInProgress = false ;
629 return_value = value ;
630#endif // _WIN32
631 }
632
633 return return_value;
634}
635
636
637
638////////////////////////////////////////////////////////////////////////////////
639/// Terminate remote server process and return front-end class
640/// to standby mode. Calls to calculate() or evaluate() after
641/// this call will automatically recreated the server process.
642
644{
645#ifndef _WIN32
646 if (_state==Client) {
647 if (_pipe->good()) {
648 // Terminate server process ;
649 if (_verboseServer) cout << "RooRealMPFE::standby(" << GetName()
650 << ") IPC toServer> Terminate " << endl;
651 int msg = Terminate;
652 *_pipe << msg << BidirMMapPipe::flush;
653 // read handshake
654 msg = 0;
655 *_pipe >> msg;
656 if (Terminate != msg || 0 != _pipe->close()) {
657 std::cerr << "In " << __func__ << "(" << __FILE__ ", " << __LINE__ <<
658 "): Server shutdown failed." << std::endl;
659 }
660 } else {
661 if (_verboseServer) {
662 std::cerr << "In " << __func__ << "(" << __FILE__ ", " <<
663 __LINE__ << "): Pipe has already shut down, not sending "
664 "Terminate to server." << std::endl;
665 }
666 }
667 // Close pipes
668 delete _pipe;
669 _pipe = nullptr;
670
671 // Revert to initialize state
673 }
674#endif // _WIN32
675}
676
677
678
679////////////////////////////////////////////////////////////////////////////////
680/// Intercept call to optimize constant term in test statistics
681/// and forward it to object on server side.
682
684{
685#ifndef _WIN32
686 if (_state==Client) {
687
688 int msg = ConstOpt ;
689 int op = opcode;
690 *_pipe << msg << op << doAlsoTracking;
691 if (_verboseServer) cout << "RooRealMPFE::constOptimize(" << GetName()
692 << ") IPC toServer> ConstOpt " << opcode << endl ;
693
694 initVars() ;
695 }
696#endif // _WIN32
697
698 if (_state==Inline) {
699 ((RooAbsReal&)_arg.arg()).constOptimizeTestStatistic(opcode,doAlsoTracking) ;
700 }
701}
702
703
704
705////////////////////////////////////////////////////////////////////////////////
706/// Control verbose messaging related to inter process communication
707/// on both client and server side
708
709void RooRealMPFE::setVerbose(bool clientFlag, bool serverFlag)
710{
711#ifndef _WIN32
712 if (_state==Client) {
713 int msg = Verbose ;
714 *_pipe << msg << serverFlag;
715 if (_verboseServer) cout << "RooRealMPFE::setVerbose(" << GetName()
716 << ") IPC toServer> Verbose " << (serverFlag?1:0) << endl ;
717 }
718#endif // _WIN32
719 _verboseClient = clientFlag ; _verboseServer = serverFlag ;
720}
721
722
723////////////////////////////////////////////////////////////////////////////////
724/// Control verbose messaging related to inter process communication
725/// on both client and server side
726
728{
729#ifndef _WIN32
730 if (_state==Client) {
731 int msg = ApplyNLLW2 ;
732 *_pipe << msg << flag;
733 if (_verboseServer) cout << "RooRealMPFE::applyNLLWeightSquared(" << GetName()
734 << ") IPC toServer> ApplyNLLW2 " << (flag?1:0) << endl ;
735 }
736#endif // _WIN32
737 doApplyNLLW2(flag) ;
738}
739
740
741////////////////////////////////////////////////////////////////////////////////
742
744{
745 RooNLLVar* nll = dynamic_cast<RooNLLVar*>(_arg.absArg()) ;
746 if (nll) {
747 nll->applyWeightSquared(flag) ;
748 }
749}
750
751
752////////////////////////////////////////////////////////////////////////////////
753/// Control verbose messaging related to inter process communication
754/// on both client and server side
755
757{
758#ifndef _WIN32
759 if (_state==Client) {
760 int msg = EnableOffset ;
761 *_pipe << msg << flag;
762 if (_verboseServer) cout << "RooRealMPFE::enableOffsetting(" << GetName()
763 << ") IPC toServer> EnableOffset " << (flag?1:0) << endl ;
764 }
765#endif // _WIN32
766 ((RooAbsReal&)_arg.arg()).enableOffsetting(flag) ;
767}
768
769
770
771////////////////////////////////////////////////////////////////////////////////
772/// Destructor. Terminate all parallel processes still registered with
773/// the sentinel
774
776{
777 for(auto * mpfe : static_range_cast<RooRealMPFE*>(_mpfeSet)) {
778 mpfe->standby() ;
779 }
780}
781
782
783
784////////////////////////////////////////////////////////////////////////////////
785/// Register given multi-processor front-end object with the sentinel
786
788{
789 _mpfeSet.add(mpfe,true) ;
790}
791
792
793
794////////////////////////////////////////////////////////////////////////////////
795/// Remove given multi-processor front-end object from the sentinel
796
798{
799 _mpfeSet.remove(mpfe,true) ;
800}
801
double _evalCarry
! carry of Kahan sum in evaluatePartition
#define ccoutD(a)
#define ClassImp(name)
Definition Rtypes.h:377
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:560
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition RooAbsArg.h:77
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:361
RooFit::OwningPtr< RooArgSet > getParameters(const RooAbsData *data, bool stripDisconnected=true) const
Create a list of leaf nodes in the arg tree starting with ourself as top node that don't match any of...
void clearValueDirty() const
Definition RooAbsArg.h:602
bool isValueDirty() const
Definition RooAbsArg.h:419
virtual bool isIdentical(const RooAbsArg &other, bool assumeSameType=false) const =0
friend class RooRealMPFE
Definition RooAbsArg.h:668
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 EvalErrorIter evalErrorIter()
static ErrorLoggingMode evalErrorLoggingMode()
Return current evaluation error logging mode.
double _value
Cache for current value of object.
Definition RooAbsReal.h:543
static void setHideOffset(bool flag)
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:55
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:50
void applyWeightSquared(bool flag) override
Disables or enables the usage of squared weights.
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'.
const T & arg() const
Return reference to object held in proxy.
static void callgrind_zero()
Utility function to trigger zeroing of callgrind counters.
Definition RooTrace.cxx:354
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
virtual int GetPid()
Get process id.
Definition TSystem.cxx:694
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.