Logo ROOT  
Reference Guide
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
22RooRealMPFE is the multi-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// parellel 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(0),
114 _updateMaster(0),
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(0),
143 _updateMaster(0),
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
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.getSize()) ;
181 _constChanged.resize(_vars.getSize()) ;
182
183 // Force next calculation
184 _forceCalc = true ;
185
186 delete vars ;
187 //delete ncVars ;
188}
189
191{
192 if (_inlineMode) {
193 RooAbsTestStatistic* tmp = dynamic_cast<RooAbsTestStatistic*>(_arg.absArg());
194 if (tmp) return tmp->getCarry();
195 else return 0.;
196 } else {
197 return _evalCarry;
198 }
199}
200
201////////////////////////////////////////////////////////////////////////////////
202/// Initialize the remote process and message passing
203/// pipes between current process and remote process
204
206{
207 // Trivial case: Inline mode
208 if (_inlineMode) {
209 _state = Inline ;
210 return ;
211 }
212
213#ifndef _WIN32
214 // Clear eval error log prior to forking
215 // to avoid confusions...
217 // Fork server process and setup IPC
218 _pipe = new BidirMMapPipe();
219
220 if (_pipe->isChild()) {
221 // Start server loop
223 _state = Server ;
224 serverLoop();
225
226 // Kill server at end of service
227 if (_verboseServer) ccoutD(Minimization) << "RooRealMPFE::initialize(" <<
228 GetName() << ") server process terminating" << endl ;
229
230 delete _arg.absArg();
231 delete _pipe;
232 _exit(0) ;
233 } else {
234 // Client process - fork successul
235 if (_verboseClient) ccoutD(Minimization) << "RooRealMPFE::initialize(" <<
236 GetName() << ") successfully forked server process " <<
237 _pipe->pidOtherEnd() << endl ;
238 _state = Client ;
239 _calcInProgress = false ;
240 }
241#endif // _WIN32
242}
243
244
245
246////////////////////////////////////////////////////////////////////////////////
247/// Server loop of remote processes. This function will return
248/// only when an incoming TERMINATE message is received.
249
251{
252#ifndef _WIN32
253 int msg ;
254
255 Int_t idx, index, 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 = (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 ((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 = 0;
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 = 0;
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.getSize() ; i++) {
450 RooAbsArg *var, *saveVar ;
451 for (std::size_t j=0 ; j<_vars.size() ; j++) {
452 var = _vars.at(j);
453 saveVar = _saveVars.at(j);
454
455 //bool valChanged = !(*var==*saveVar) ;
456 bool valChanged,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 ((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 = ((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 = ((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 beed 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, caling 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 loggin 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 = 0, *msgbuf2 = 0, *msgbuf3 = 0;
608 RooAbsArg *ptr = 0;
609 while (true) {
610 *_pipe >> ptr;
611 if (!ptr) break;
612 *_pipe >> msgbuf1 >> msgbuf2 >> msgbuf3;
613 if (_verboseServer) cout << "RooRealMPFE::evaluate(" << GetName()
614 << ") IPC fromServer> retrieving error log Arg " << ptr << " Msg " << msgbuf1 << endl ;
615
616 logEvalError(reinterpret_cast<RooAbsReal*>(ptr),msgbuf3,msgbuf1,msgbuf2) ;
617 }
618 std::free(msgbuf1);
619 std::free(msgbuf2);
620 std::free(msgbuf3);
621 }
622
623 // Mark end of calculation in progress
624 _calcInProgress = false ;
625 return_value = value ;
626#endif // _WIN32
627 }
628
629 return return_value;
630}
631
632
633
634////////////////////////////////////////////////////////////////////////////////
635/// Terminate remote server process and return front-end class
636/// to standby mode. Calls to calculate() or evaluate() after
637/// this call will automatically recreated the server process.
638
640{
641#ifndef _WIN32
642 if (_state==Client) {
643 if (_pipe->good()) {
644 // Terminate server process ;
645 if (_verboseServer) cout << "RooRealMPFE::standby(" << GetName()
646 << ") IPC toServer> Terminate " << endl;
647 int msg = Terminate;
648 *_pipe << msg << BidirMMapPipe::flush;
649 // read handshake
650 msg = 0;
651 *_pipe >> msg;
652 if (Terminate != msg || 0 != _pipe->close()) {
653 std::cerr << "In " << __func__ << "(" << __FILE__ ", " << __LINE__ <<
654 "): Server shutdown failed." << std::endl;
655 }
656 } else {
657 if (_verboseServer) {
658 std::cerr << "In " << __func__ << "(" << __FILE__ ", " <<
659 __LINE__ << "): Pipe has already shut down, not sending "
660 "Terminate to server." << std::endl;
661 }
662 }
663 // Close pipes
664 delete _pipe;
665 _pipe = 0;
666
667 // Revert to initialize state
669 }
670#endif // _WIN32
671}
672
673
674
675////////////////////////////////////////////////////////////////////////////////
676/// Intercept call to optimize constant term in test statistics
677/// and forward it to object on server side.
678
680{
681#ifndef _WIN32
682 if (_state==Client) {
683
684 int msg = ConstOpt ;
685 int op = opcode;
686 *_pipe << msg << op << doAlsoTracking;
687 if (_verboseServer) cout << "RooRealMPFE::constOptimize(" << GetName()
688 << ") IPC toServer> ConstOpt " << opcode << endl ;
689
690 initVars() ;
691 }
692#endif // _WIN32
693
694 if (_state==Inline) {
695 ((RooAbsReal&)_arg.arg()).constOptimizeTestStatistic(opcode,doAlsoTracking) ;
696 }
697}
698
699
700
701////////////////////////////////////////////////////////////////////////////////
702/// Control verbose messaging related to inter process communication
703/// on both client and server side
704
705void RooRealMPFE::setVerbose(bool clientFlag, bool serverFlag)
706{
707#ifndef _WIN32
708 if (_state==Client) {
709 int msg = Verbose ;
710 *_pipe << msg << serverFlag;
711 if (_verboseServer) cout << "RooRealMPFE::setVerbose(" << GetName()
712 << ") IPC toServer> Verbose " << (serverFlag?1:0) << endl ;
713 }
714#endif // _WIN32
715 _verboseClient = clientFlag ; _verboseServer = serverFlag ;
716}
717
718
719////////////////////////////////////////////////////////////////////////////////
720/// Control verbose messaging related to inter process communication
721/// on both client and server side
722
724{
725#ifndef _WIN32
726 if (_state==Client) {
727 int msg = ApplyNLLW2 ;
728 *_pipe << msg << flag;
729 if (_verboseServer) cout << "RooRealMPFE::applyNLLWeightSquared(" << GetName()
730 << ") IPC toServer> ApplyNLLW2 " << (flag?1:0) << endl ;
731 }
732#endif // _WIN32
733 doApplyNLLW2(flag) ;
734}
735
736
737////////////////////////////////////////////////////////////////////////////////
738
740{
741 RooNLLVar* nll = dynamic_cast<RooNLLVar*>(_arg.absArg()) ;
742 if (nll) {
743 nll->applyWeightSquared(flag) ;
744 }
745}
746
747
748////////////////////////////////////////////////////////////////////////////////
749/// Control verbose messaging related to inter process communication
750/// on both client and server side
751
753{
754#ifndef _WIN32
755 if (_state==Client) {
756 int msg = EnableOffset ;
757 *_pipe << msg << flag;
758 if (_verboseServer) cout << "RooRealMPFE::enableOffsetting(" << GetName()
759 << ") IPC toServer> EnableOffset " << (flag?1:0) << endl ;
760 }
761#endif // _WIN32
762 ((RooAbsReal&)_arg.arg()).enableOffsetting(flag) ;
763}
764
765
766
767////////////////////////////////////////////////////////////////////////////////
768/// Destructor. Terminate all parallel processes still registered with
769/// the sentinel
770
772{
773 for(auto * mpfe : static_range_cast<RooRealMPFE*>(_mpfeSet)) {
774 mpfe->standby() ;
775 }
776}
777
778
779
780////////////////////////////////////////////////////////////////////////////////
781/// Register given multi-processor front-end object with the sentinel
782
784{
785 _mpfeSet.add(mpfe,true) ;
786}
787
788
789
790////////////////////////////////////////////////////////////////////////////////
791/// Remove given multi-processor front-end object from the sentinel
792
794{
795 _mpfeSet.remove(mpfe,true) ;
796}
797
header file for BidirMMapPipe, a class which forks off a child process and serves as communications c...
#define ccoutD(a)
Definition: RooMsgService.h:41
#define ClassImp(name)
Definition: Rtypes.h:375
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
#define free
Definition: civetweb.c:1539
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition: RooAbsArg.h:72
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:365
void clearValueDirty() const
Definition: RooAbsArg.h:605
bool isValueDirty() const
Definition: RooAbsArg.h:424
virtual bool isIdentical(const RooAbsArg &other, bool assumeSameType=false) const =0
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...
Definition: RooAbsArg.cxx:563
friend class RooRealMPFE
Definition: RooAbsArg.h:671
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.
Int_t getSize() const
Return the number of elements in the collection.
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)
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:60
static Int_t numEvalErrorItems()
Definition: RooAbsReal.cxx:312
static bool hideOffset()
Definition: RooAbsReal.cxx:116
static EvalErrorIter evalErrorIter()
Definition: RooAbsReal.cxx:320
static ErrorLoggingMode evalErrorLoggingMode()
Return current evaluation error logging mode.
double _value
Cache for current value of object.
Definition: RooAbsReal.h:496
static void setHideOffset(bool flag)
Definition: RooAbsReal.cxx:115
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.
RooAbsTestStatistic is the abstract base class for all test statistics.
virtual double getCarry() const
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:47
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:56
RooCategory is an 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...
BidirMMapPipe creates a bidirectional channel between the current process and a child it forks.
bool good() const
status of stream is good
bool isChild() const
return if this end of the pipe is the child end
bool eof() const
true if end-of-file
int close()
flush buffers, close pipe
pid_t pidOtherEnd() const
return PID of the process on the other end of the pipe
Class RooNLLVar implements a -log(likelihood) calculation from a dataset and a PDF.
Definition: RooNLLVar.h:30
void applyWeightSquared(bool flag) override
Disables or enables the usage of squared weights.
Definition: RooNLLVar.cxx:200
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,...
RooRealMPFE is the multi-processor front-end for parallel calculation of RooAbsReal objects.
Definition: RooRealMPFE.h:29
State _state
Definition: RooRealMPFE.h:58
RooFit::BidirMMapPipe * _pipe
! connection to child
Definition: RooRealMPFE.h:79
RooArgList _saveVars
Copy of variables.
Definition: RooRealMPFE.h:71
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.
@ CalculateNoOffset
Definition: RooRealMPFE.h:61
bool _calcInProgress
Definition: RooRealMPFE.h:72
RooListProxy _vars
Variables.
Definition: RooRealMPFE.h:70
double _evalCarry
!
Definition: RooRealMPFE.h:85
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:83
void doApplyNLLW2(bool flag)
bool _retrieveDispatched
!
Definition: RooRealMPFE.h:84
bool _verboseClient
Definition: RooRealMPFE.h:73
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:76
std::vector< bool > _constChanged
! Flags if variable needs update on server-side
Definition: RooRealMPFE.h:82
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:81
void enableOffsetting(bool flag) override
Control verbose messaging related to inter process communication on both client and server side.
bool _verboseServer
Definition: RooRealMPFE.h:74
RooRealProxy _arg
Function to calculate in parallel process.
Definition: RooRealMPFE.h:69
bool _inlineMode
Definition: RooRealMPFE.h:75
~RooRealMPFE() override
Destructor.
RooAbsReal::ErrorLoggingMode _remoteEvalErrorLoggingState
Definition: RooRealMPFE.h:77
double getValV(const RooArgSet *nset=nullptr) const override
If value needs recalculation and calculation has not beed started with a call to calculate() start it...
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:40
void setVal(double value) override
Set value of variable to 'value'.
Definition: RooRealVar.cxx:254
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:296
const char * GetName() const override
Returns name of object.
Definition: TNamed.h:47
virtual int GetPid()
Get process id.
Definition: TSystem.cxx:710
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition: Common.h:18
@ Minimization
Definition: RooGlobalFunc.h:62
void Initialize(Bool_t useTMVAStyle=kTRUE)
Definition: tmvaglob.cxx:176
void remove(RooRealMPFE &mpfe)
Remove given multi-processor front-end object from the sentinel.
RooArgSet _mpfeSet
Definition: RooRealMPFE.cxx:83
void add(RooRealMPFE &mpfe)
Register given multi-processor front-end object with the sentinel.
static RooMPSentinel & instance()
Definition: RooRealMPFE.cxx:86
~RooMPSentinel()
Destructor.