80 void add(RooRealMPFE& mpfe) ;
81 void remove(RooRealMPFE& mpfe) ;
86RooMPSentinel& RooMPSentinel::instance() {
87 static RooMPSentinel inst;
92using std::string, std::ostringstream, std::list;
101RooRealMPFE::RooRealMPFE(
const char *
name,
const char *title,
RooAbsReal& arg,
bool calcInline) :
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),
112 _updateMaster(nullptr),
113 _retrieveDispatched(false), _evalCarry(0.)
119 RooMPSentinel::instance().add(*
this) ;
129RooRealMPFE::RooRealMPFE(
const RooRealMPFE& other,
const char*
name) :
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),
141 _updateMaster(nullptr),
142 _retrieveDispatched(false), _evalCarry(other._evalCarry)
145 RooMPSentinel::instance().add(*
this) ;
153RooRealMPFE::~RooRealMPFE()
155 if (_state==Client) standby();
156 RooMPSentinel::instance().remove(*
this);
164void RooRealMPFE::initVars()
168 _saveVars.removeAll() ;
171 std::unique_ptr<RooArgSet> vars{_arg->getParameters(
RooArgSet())};
177 _saveVars.addClone(varList) ;
178 _valueChanged.resize(_vars.size()) ;
179 _constChanged.resize(_vars.size()) ;
185double RooRealMPFE::getCarry()
const
188 RooAbsTestStatistic* tmp =
dynamic_cast<RooAbsTestStatistic*
>(_arg.absArg());
189 if (tmp)
return tmp->getCarry();
200void RooRealMPFE::initialize()
211 clearEvalErrorLog() ;
213 _pipe =
new BidirMMapPipe();
215 if (_pipe->isChild()) {
221 if (_verboseServer)
ccoutD(Minimization) <<
"RooRealMPFE::initialize(" <<
222 GetName() <<
") server process terminating" << std::endl ;
224 delete _arg.absArg();
229 if (_verboseClient) {
230 ccoutD(Minimization) <<
"RooRealMPFE::initialize(" <<
GetName() <<
") successfully forked server process "
231 << _pipe->pidOtherEnd() << std::endl;
234 _calcInProgress = false ;
245void RooRealMPFE::serverLoop()
256 clearEvalErrorLog() ;
258 while(*_pipe && !_pipe->eof()) {
260 if (Terminate == msg) {
261 if (_verboseServer) std::cout <<
"RooRealMPFE::serverLoop(" <<
GetName()
262 <<
") IPC fromClient> Terminate" << std::endl;
264 *_pipe << msg << BidirMMapPipe::flush;
271 *_pipe >> idx >>
value >> isConst;
272 if (_verboseServer) std::cout <<
"RooRealMPFE::serverLoop(" <<
GetName()
273 <<
") IPC fromClient> SendReal [" << idx <<
"]=" <<
value << std::endl ;
284 *_pipe >> idx >>
index;
285 if (_verboseServer) std::cout <<
"RooRealMPFE::serverLoop(" <<
GetName()
286 <<
") IPC fromClient> SendCat [" << idx <<
"]=" <<
index << std::endl ;
292 if (_verboseServer) std::cout <<
"RooRealMPFE::serverLoop(" <<
GetName()
293 <<
") IPC fromClient> Calculate" << std::endl ;
297 case CalculateNoOffset:
298 if (_verboseServer) std::cout <<
"RooRealMPFE::serverLoop(" <<
GetName()
299 <<
") IPC fromClient> Calculate" << std::endl ;
308 if (_verboseServer) std::cout <<
"RooRealMPFE::serverLoop(" <<
GetName()
309 <<
") IPC fromClient> Retrieve" << std::endl ;
311 numErrors = numEvalErrors();
312 *_pipe << msg << _value << getCarry() << numErrors;
314 if (_verboseServer) std::cout <<
"RooRealMPFE::serverLoop(" <<
GetName()
315 <<
") IPC toClient> ReturnValue " << _value <<
" NumError " << numErrors << std::endl ;
319 std::string objidstr;
324 printStream(oss2,
kName|kClassName|kArgs,kInline);
325 objidstr = oss2.str();
327 std::map<const RooAbsArg*,std::pair<string,list<EvalError> > >::const_iterator iter = evalErrorIter();
329 for (
int i = 0; i < numEvalErrorItems(); ++i) {
330 list<EvalError>::const_iterator iter2 = iter->second.second.begin();
331 for (; iter->second.second.end() != iter2; ++iter2) {
333 *_pipe << ptr << iter2->_msg << iter2->_srvval << objidstr;
334 if (_verboseServer) std::cout <<
"RooRealMPFE::serverLoop(" <<
GetName()
335 <<
") IPC toClient> sending error log Arg " << iter->first <<
" Msg " << iter2->_msg << std::endl ;
344 *_pipe << BidirMMapPipe::flush;
352 if (_verboseServer) std::cout <<
"RooRealMPFE::serverLoop(" <<
GetName()
353 <<
") IPC fromClient> Verbose " << (flag?1:0) << std::endl ;
354 _verboseServer = flag ;
363 if (_verboseServer) std::cout <<
"RooRealMPFE::serverLoop(" <<
GetName()
364 <<
") IPC fromClient> ApplyNLLW2 " << (flag?1:0) << std::endl ;
375 if (_verboseServer) std::cout <<
"RooRealMPFE::serverLoop(" <<
GetName()
376 <<
") IPC fromClient> EnableOffset " << (flag?1:0) << std::endl ;
379 ((
RooAbsReal&)_arg.arg()).enableOffsetting(flag) ;
389 if (_verboseServer) std::cout <<
"RooRealMPFE::serverLoop(" <<
GetName()
390 <<
") IPC fromClient> LogEvalError flag = " << flag2 << std::endl ;
396 if (_verboseServer) std::cout <<
"RooRealMPFE::serverLoop(" <<
GetName()
397 <<
") IPC fromClient> Unknown message (code = " << msg <<
")" << std::endl ;
413void RooRealMPFE::calculate()
const
417 if (_state==Initialize) {
418 const_cast<RooRealMPFE*
>(
this)->
initialize() ;
422 if (_state==Inline) {
429 if (_state==Client) {
435 for (std::size_t j=0 ; j<_vars.size() ; j++) {
437 saveVar = _saveVars.at(j);
442 if (!_updateMaster) {
445 _valueChanged[i] = valChanged ;
446 _constChanged[i] = constChanged ;
448 valChanged = _updateMaster->_valueChanged[i] ;
449 constChanged = _updateMaster->_constChanged[i] ;
452 if ( valChanged || constChanged || _forceCalc) {
453 if (_verboseClient) std::cout <<
"RooRealMPFE::calculate(" <<
GetName()
454 <<
") variable " << _vars.at(i)->GetName() <<
" changed" << std::endl ;
463 double val = (
static_cast<RooAbsReal*
>(var))->getVal() ;
465 *_pipe << msg << i << val << isC;
467 if (_verboseServer) std::cout <<
"RooRealMPFE::calculate(" <<
GetName()
468 <<
") IPC toServer> SendReal [" << i <<
"]=" << val << (isC?
" (Constant)":
"") << std::endl ;
472 *_pipe << msg << i << idx;
473 if (_verboseServer) std::cout <<
"RooRealMPFE::calculate(" <<
GetName()
474 <<
") IPC toServer> SendCat [" << i <<
"]=" << idx << std::endl ;
480 int msg = hideOffset() ? Calculate : CalculateNoOffset;
482 if (_verboseServer) std::cout <<
"RooRealMPFE::calculate(" <<
GetName()
483 <<
") IPC toServer> Calculate " << std::endl ;
487 _calcInProgress = true ;
491 *_pipe << msg << BidirMMapPipe::flush;
492 if (_verboseServer) std::cout <<
"RooRealMPFE::evaluate(" <<
GetName()
493 <<
") IPC toServer> Retrieve " << std::endl ;
494 _retrieveDispatched = true ;
496 }
else if (_state!=Inline) {
497 std::cout <<
"RooRealMPFE::calculate(" <<
GetName()
498 <<
") ERROR not in Client or Inline mode" << std::endl ;
514double RooRealMPFE::getValV(
const RooArgSet* )
const
517 if (isValueDirty()) {
521 }
else if (_calcInProgress) {
538double RooRealMPFE::evaluate()
const
541 double return_value = 0;
542 if (_state==Inline) {
543 return_value = _arg ;
544 }
else if (_state==Client) {
546 bool needflush =
false;
552 if (evalErrorLoggingMode() != _remoteEvalErrorLoggingState) {
555 *_pipe << msg << flag;
557 _remoteEvalErrorLoggingState = evalErrorLoggingMode() ;
560 if (!_retrieveDispatched) {
564 if (_verboseServer) std::cout <<
"RooRealMPFE::evaluate(" <<
GetName()
565 <<
") IPC toServer> Retrieve " << std::endl ;
567 if (needflush) *_pipe << BidirMMapPipe::flush;
568 _retrieveDispatched = false ;
573 *_pipe >> msg >>
value >> _evalCarry >> numError;
575 if (msg!=ReturnValue) {
576 std::cout <<
"RooRealMPFE::evaluate(" <<
GetName()
577 <<
") ERROR: unexpected message from server process: " << msg << std::endl ;
580 if (_verboseServer) std::cout <<
"RooRealMPFE::evaluate(" <<
GetName()
581 <<
") IPC fromServer> ReturnValue " <<
value << std::endl ;
583 if (_verboseServer) std::cout <<
"RooRealMPFE::evaluate(" <<
GetName()
584 <<
") IPC fromServer> NumErrors " << numError << std::endl ;
587 char *msgbuf1 =
nullptr;
588 char *msgbuf2 =
nullptr;
589 char *msgbuf3 =
nullptr;
594 *_pipe >> msgbuf1 >> msgbuf2 >> msgbuf3;
595 if (_verboseServer) std::cout <<
"RooRealMPFE::evaluate(" <<
GetName()
596 <<
") IPC fromServer> retrieving error log Arg " << ptr <<
" Msg " << msgbuf1 << std::endl ;
598 logEvalError(
reinterpret_cast<RooAbsReal*
>(ptr),msgbuf3,msgbuf1,msgbuf2) ;
606 _calcInProgress = false ;
607 return_value =
value ;
621void RooRealMPFE::standby()
624 if (_state==Client) {
627 if (_verboseServer) std::cout <<
"RooRealMPFE::standby(" <<
GetName()
628 <<
") IPC toServer> Terminate " << std::endl;
630 *_pipe << msg << BidirMMapPipe::flush;
634 if (Terminate != msg || 0 != _pipe->close()) {
635 std::cerr <<
"In " << __func__ <<
"(" << __FILE__
", " << __LINE__ <<
636 "): Server shutdown failed." << std::endl;
639 if (_verboseServer) {
640 std::cerr <<
"In " << __func__ <<
"(" << __FILE__
", " <<
641 __LINE__ <<
"): Pipe has already shut down, not sending "
642 "Terminate to server." << std::endl;
660void RooRealMPFE::setVerbose(
bool clientFlag,
bool serverFlag)
663 if (_state==Client) {
665 *_pipe << msg << serverFlag;
666 if (_verboseServer) std::cout <<
"RooRealMPFE::setVerbose(" <<
GetName()
667 <<
") IPC toServer> Verbose " << (serverFlag?1:0) << std::endl ;
670 _verboseClient = clientFlag ; _verboseServer = serverFlag ;
678void RooRealMPFE::applyNLLWeightSquared(
bool flag)
681 if (_state==Client) {
682 int msg = ApplyNLLW2 ;
683 *_pipe << msg << flag;
684 if (_verboseServer) std::cout <<
"RooRealMPFE::applyNLLWeightSquared(" <<
GetName()
685 <<
") IPC toServer> ApplyNLLW2 " << (flag?1:0) << std::endl ;
694void RooRealMPFE::doApplyNLLW2(
bool flag)
696 RooNLLVar*
nll =
dynamic_cast<RooNLLVar*
>(_arg.absArg()) ;
698 nll->applyWeightSquared(flag) ;
707void RooRealMPFE::enableOffsetting(
bool flag)
710 if (_state==Client) {
711 int msg = EnableOffset ;
712 *_pipe << msg << flag;
713 if (_verboseServer) std::cout <<
"RooRealMPFE::enableOffsetting(" <<
GetName()
714 <<
") IPC toServer> EnableOffset " << (flag?1:0) << std::endl ;
717 ((
RooAbsReal&)_arg.arg()).enableOffsetting(flag) ;
726RooMPSentinel::~RooMPSentinel()
738void RooMPSentinel::add(RooRealMPFE& mpfe)
740 _mpfeSet.add(mpfe,
true) ;
748void RooMPSentinel::remove(RooRealMPFE& mpfe)
750 _mpfeSet.remove(mpfe,
true) ;
ROOT::RRangeCast< T, false, Range_t > static_range_cast(Range_t &&coll)
static Roo_reg_AGKInteg1D instance
int Int_t
Signed integer 4 bytes (int)
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int)
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
R__EXTERN TSystem * gSystem
Common abstract base class for objects that represent a value and a "shape" in RooFit.
virtual void copyCache(const RooAbsArg *source, bool valueOnly=false, bool setValDirty=true)=0
bool isConstant() const
Check if the "Constant" attribute is set.
virtual bool isIdentical(const RooAbsArg &other, bool assumeSameType=false) const =0
A space to attach TBranches.
void setConstant(bool value=true)
Abstract base class for objects that represent a real value and implements functionality common to al...
static void setHideOffset(bool flag)
static void setEvalErrorLoggingMode(ErrorLoggingMode m)
Set evaluation error logging mode.
RooArgList is a container object that can hold multiple RooAbsArg objects.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Object to represent discrete states.
Variable that can be changed from the outside.
void setVal(double value) override
Set value of variable to 'value'.
virtual int GetPid()
Get process id.
RooCmdArg Verbose(bool flag=true)
double nll(double pdf, double weight, int binnedL, int doBinOffset)
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
void evaluate(typename Architecture_t::Tensor_t &A, EActivationFunction f)
Apply the given activation function to each value in the given tensor A.
void initialize(typename Architecture_t::Matrix_t &A, EInitialization m)
void Initialize(Bool_t useTMVAStyle=kTRUE)
std::string GetName(TCppScope_t)