83 void add(RooRealMPFE& mpfe) ;
84 void remove(RooRealMPFE& mpfe) ;
89RooMPSentinel& RooMPSentinel::instance() {
90 static RooMPSentinel inst;
95using std::string, std::ostringstream, std::list;
104RooRealMPFE::RooRealMPFE(
const char *
name,
const char *title,
RooAbsReal& arg,
bool calcInline) :
107 _arg(
"arg",
"arg",this,arg),
108 _vars(
"vars",
"vars",this),
109 _calcInProgress(false),
110 _verboseClient(false),
111 _verboseServer(false),
112 _inlineMode(calcInline),
113 _remoteEvalErrorLoggingState(
RooAbsReal::PrintErrors),
115 _updateMaster(nullptr),
116 _retrieveDispatched(false), _evalCarry(0.)
122 RooMPSentinel::instance().add(*
this) ;
132RooRealMPFE::RooRealMPFE(
const RooRealMPFE& other,
const char*
name) :
135 _arg(
"arg",this,other._arg),
136 _vars(
"vars",this,other._vars),
137 _calcInProgress(false),
138 _verboseClient(other._verboseClient),
139 _verboseServer(other._verboseServer),
140 _inlineMode(other._inlineMode),
141 _forceCalc(other._forceCalc),
142 _remoteEvalErrorLoggingState(other._remoteEvalErrorLoggingState),
144 _updateMaster(nullptr),
145 _retrieveDispatched(false), _evalCarry(other._evalCarry)
148 RooMPSentinel::instance().add(*
this) ;
156RooRealMPFE::~RooRealMPFE()
158 if (_state==Client) standby();
159 RooMPSentinel::instance().remove(*
this);
167void RooRealMPFE::initVars()
171 _saveVars.removeAll() ;
174 std::unique_ptr<RooArgSet> vars{_arg->getParameters(
RooArgSet())};
180 _saveVars.addClone(varList) ;
181 _valueChanged.resize(_vars.size()) ;
182 _constChanged.resize(_vars.size()) ;
188double RooRealMPFE::getCarry()
const
191 RooAbsTestStatistic* tmp =
dynamic_cast<RooAbsTestStatistic*
>(_arg.absArg());
192 if (tmp)
return tmp->getCarry();
203void RooRealMPFE::initialize()
214 clearEvalErrorLog() ;
216 _pipe =
new BidirMMapPipe();
218 if (_pipe->isChild()) {
226 GetName() <<
") server process terminating" << std::endl ;
228 delete _arg.absArg();
233 if (_verboseClient) {
234 ccoutD(
Minimization) <<
"RooRealMPFE::initialize(" << GetName() <<
") successfully forked server process "
235 << _pipe->pidOtherEnd() << std::endl;
238 _calcInProgress = false ;
249void RooRealMPFE::serverLoop()
260 clearEvalErrorLog() ;
262 while(*_pipe && !_pipe->eof()) {
264 if (Terminate == msg) {
265 if (_verboseServer) std::cout <<
"RooRealMPFE::serverLoop(" << GetName()
266 <<
") IPC fromClient> Terminate" << std::endl;
268 *_pipe << msg << BidirMMapPipe::flush;
275 *_pipe >> idx >>
value >> isConst;
276 if (_verboseServer) std::cout <<
"RooRealMPFE::serverLoop(" << GetName()
277 <<
") IPC fromClient> SendReal [" << idx <<
"]=" <<
value << std::endl ;
288 *_pipe >> idx >>
index;
289 if (_verboseServer) std::cout <<
"RooRealMPFE::serverLoop(" << GetName()
290 <<
") IPC fromClient> SendCat [" << idx <<
"]=" <<
index << std::endl ;
296 if (_verboseServer) std::cout <<
"RooRealMPFE::serverLoop(" << GetName()
297 <<
") IPC fromClient> Calculate" << std::endl ;
301 case CalculateNoOffset:
302 if (_verboseServer) std::cout <<
"RooRealMPFE::serverLoop(" << GetName()
303 <<
") IPC fromClient> Calculate" << std::endl ;
312 if (_verboseServer) std::cout <<
"RooRealMPFE::serverLoop(" << GetName()
313 <<
") IPC fromClient> Retrieve" << std::endl ;
315 numErrors = numEvalErrors();
316 *_pipe << msg << _value << getCarry() << numErrors;
318 if (_verboseServer) std::cout <<
"RooRealMPFE::serverLoop(" << GetName()
319 <<
") IPC toClient> ReturnValue " << _value <<
" NumError " << numErrors << std::endl ;
323 std::string objidstr;
327 oss2 <<
"PID" <<
gSystem->GetPid() <<
"/";
328 printStream(oss2,
kName|kClassName|kArgs,kInline);
329 objidstr = oss2.str();
331 std::map<const RooAbsArg*,std::pair<string,list<EvalError> > >::const_iterator iter = evalErrorIter();
333 for (
int i = 0; i < numEvalErrorItems(); ++i) {
334 list<EvalError>::const_iterator iter2 = iter->second.second.begin();
335 for (; iter->second.second.end() != iter2; ++iter2) {
337 *_pipe << ptr << iter2->_msg << iter2->_srvval << objidstr;
338 if (_verboseServer) std::cout <<
"RooRealMPFE::serverLoop(" << GetName()
339 <<
") IPC toClient> sending error log Arg " << iter->first <<
" Msg " << iter2->_msg << std::endl ;
348 *_pipe << BidirMMapPipe::flush;
356 *_pipe >> code >> doTrack;
357 if (_verboseServer) std::cout <<
"RooRealMPFE::serverLoop(" << GetName()
358 <<
") IPC fromClient> ConstOpt " << code <<
" doTrack = " << (doTrack?
"T":
"F") << std::endl ;
367 if (_verboseServer) std::cout <<
"RooRealMPFE::serverLoop(" << GetName()
368 <<
") IPC fromClient> Verbose " << (flag?1:0) << std::endl ;
369 _verboseServer = flag ;
378 if (_verboseServer) std::cout <<
"RooRealMPFE::serverLoop(" << GetName()
379 <<
") IPC fromClient> ApplyNLLW2 " << (flag?1:0) << std::endl ;
390 if (_verboseServer) std::cout <<
"RooRealMPFE::serverLoop(" << GetName()
391 <<
") IPC fromClient> EnableOffset " << (flag?1:0) << std::endl ;
394 ((
RooAbsReal&)_arg.arg()).enableOffsetting(flag) ;
404 if (_verboseServer) std::cout <<
"RooRealMPFE::serverLoop(" << GetName()
405 <<
") IPC fromClient> LogEvalError flag = " << flag2 << std::endl ;
411 if (_verboseServer) std::cout <<
"RooRealMPFE::serverLoop(" << GetName()
412 <<
") IPC fromClient> Unknown message (code = " << msg <<
")" << std::endl ;
428void RooRealMPFE::calculate()
const
432 if (_state==Initialize) {
434 const_cast<RooRealMPFE*
>(
this)->
initialize() ;
438 if (_state==Inline) {
446 if (_state==Client) {
453 for (std::size_t j=0 ; j<_vars.size() ; j++) {
455 saveVar = _saveVars.at(j);
460 if (!_updateMaster) {
463 _valueChanged[i] = valChanged ;
464 _constChanged[i] = constChanged ;
466 valChanged = _updateMaster->_valueChanged[i] ;
467 constChanged = _updateMaster->_constChanged[i] ;
470 if ( valChanged || constChanged || _forceCalc) {
472 if (_verboseClient) std::cout <<
"RooRealMPFE::calculate(" << GetName()
473 <<
") variable " << _vars.at(i)->GetName() <<
" changed" << std::endl ;
482 double val = (
static_cast<RooAbsReal*
>(var))->getVal() ;
484 *_pipe << msg << i << val << isC;
486 if (_verboseServer) std::cout <<
"RooRealMPFE::calculate(" << GetName()
487 <<
") IPC toServer> SendReal [" << i <<
"]=" << val << (isC?
" (Constant)":
"") << std::endl ;
491 *_pipe << msg << i << idx;
492 if (_verboseServer) std::cout <<
"RooRealMPFE::calculate(" << GetName()
493 <<
") IPC toServer> SendCat [" << i <<
"]=" << idx << std::endl ;
499 int msg = hideOffset() ? Calculate : CalculateNoOffset;
501 if (_verboseServer) std::cout <<
"RooRealMPFE::calculate(" << GetName()
502 <<
") IPC toServer> Calculate " << std::endl ;
506 _calcInProgress =
true ;
510 *_pipe << msg << BidirMMapPipe::flush;
511 if (_verboseServer) std::cout <<
"RooRealMPFE::evaluate(" << GetName()
512 <<
") IPC toServer> Retrieve " << std::endl ;
513 _retrieveDispatched =
true ;
515 }
else if (_state!=Inline) {
516 std::cout <<
"RooRealMPFE::calculate(" << GetName()
517 <<
") ERROR not in Client or Inline mode" << std::endl ;
533double RooRealMPFE::getValV(
const RooArgSet* )
const
536 if (isValueDirty()) {
541 }
else if (_calcInProgress) {
561double RooRealMPFE::evaluate()
const
564 double return_value = 0;
565 if (_state==Inline) {
566 return_value = _arg ;
567 }
else if (_state==Client) {
569 bool needflush =
false;
575 if (evalErrorLoggingMode() != _remoteEvalErrorLoggingState) {
578 *_pipe << msg << flag;
580 _remoteEvalErrorLoggingState = evalErrorLoggingMode() ;
583 if (!_retrieveDispatched) {
587 if (_verboseServer) std::cout <<
"RooRealMPFE::evaluate(" << GetName()
588 <<
") IPC toServer> Retrieve " << std::endl ;
590 if (needflush) *_pipe << BidirMMapPipe::flush;
591 _retrieveDispatched = false ;
596 *_pipe >> msg >>
value >> _evalCarry >> numError;
598 if (msg!=ReturnValue) {
599 std::cout <<
"RooRealMPFE::evaluate(" << GetName()
600 <<
") ERROR: unexpected message from server process: " << msg << std::endl ;
603 if (_verboseServer) std::cout <<
"RooRealMPFE::evaluate(" << GetName()
604 <<
") IPC fromServer> ReturnValue " <<
value << std::endl ;
606 if (_verboseServer) std::cout <<
"RooRealMPFE::evaluate(" << GetName()
607 <<
") IPC fromServer> NumErrors " << numError << std::endl ;
610 char *msgbuf1 =
nullptr;
611 char *msgbuf2 =
nullptr;
612 char *msgbuf3 =
nullptr;
617 *_pipe >> msgbuf1 >> msgbuf2 >> msgbuf3;
618 if (_verboseServer) std::cout <<
"RooRealMPFE::evaluate(" << GetName()
619 <<
") IPC fromServer> retrieving error log Arg " << ptr <<
" Msg " << msgbuf1 << std::endl ;
621 logEvalError(
reinterpret_cast<RooAbsReal*
>(ptr),msgbuf3,msgbuf1,msgbuf2) ;
629 _calcInProgress = false ;
630 return_value =
value ;
644void RooRealMPFE::standby()
647 if (_state==Client) {
650 if (_verboseServer) std::cout <<
"RooRealMPFE::standby(" << GetName()
651 <<
") IPC toServer> Terminate " << std::endl;
653 *_pipe << msg << BidirMMapPipe::flush;
657 if (Terminate != msg || 0 != _pipe->close()) {
658 std::cerr <<
"In " << __func__ <<
"(" << __FILE__
", " << __LINE__ <<
659 "): Server shutdown failed." << std::endl;
662 if (_verboseServer) {
663 std::cerr <<
"In " << __func__ <<
"(" << __FILE__
", " <<
664 __LINE__ <<
"): Pipe has already shut down, not sending "
665 "Terminate to server." << std::endl;
684void RooRealMPFE::constOptimizeTestStatistic(ConstOpCode opcode,
bool doAlsoTracking)
687 if (_state==Client) {
691 *_pipe << msg << op << doAlsoTracking;
692 if (_verboseServer) std::cout <<
"RooRealMPFE::constOptimize(" << GetName()
693 <<
") IPC toServer> ConstOpt " << opcode << std::endl ;
699 if (_state==Inline) {
700 ((
RooAbsReal&)_arg.arg()).constOptimizeTestStatistic(opcode,doAlsoTracking) ;
710void RooRealMPFE::setVerbose(
bool clientFlag,
bool serverFlag)
713 if (_state==Client) {
715 *_pipe << msg << serverFlag;
716 if (_verboseServer) std::cout <<
"RooRealMPFE::setVerbose(" << GetName()
717 <<
") IPC toServer> Verbose " << (serverFlag?1:0) << std::endl ;
720 _verboseClient = clientFlag ; _verboseServer = serverFlag ;
728void RooRealMPFE::applyNLLWeightSquared(
bool flag)
731 if (_state==Client) {
732 int msg = ApplyNLLW2 ;
733 *_pipe << msg << flag;
734 if (_verboseServer) std::cout <<
"RooRealMPFE::applyNLLWeightSquared(" << GetName()
735 <<
") IPC toServer> ApplyNLLW2 " << (flag?1:0) << std::endl ;
744void RooRealMPFE::doApplyNLLW2(
bool flag)
746 RooNLLVar*
nll =
dynamic_cast<RooNLLVar*
>(_arg.absArg()) ;
748 nll->applyWeightSquared(flag) ;
757void RooRealMPFE::enableOffsetting(
bool flag)
760 if (_state==Client) {
761 int msg = EnableOffset ;
762 *_pipe << msg << flag;
763 if (_verboseServer) std::cout <<
"RooRealMPFE::enableOffsetting(" << GetName()
764 <<
") IPC toServer> EnableOffset " << (flag?1:0) << std::endl ;
767 ((
RooAbsReal&)_arg.arg()).enableOffsetting(flag) ;
776RooMPSentinel::~RooMPSentinel()
788void RooMPSentinel::add(RooRealMPFE& mpfe)
790 _mpfeSet.add(mpfe,
true) ;
798void RooMPSentinel::remove(RooRealMPFE& mpfe)
800 _mpfeSet.remove(mpfe,
true) ;
true
Register systematic variations for multiple existing columns using auto-generated tags.
ROOT::RRangeCast< T, false, Range_t > static_range_cast(Range_t &&coll)
static Roo_reg_AGKInteg1D instance
double evaluate() const override
int Int_t
Signed integer 4 bytes (int)
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int)
return
Invalidate stored TCling state for declarations included in transaction âTâ.
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'.
static void callgrind_zero()
Utility function to trigger zeroing of callgrind counters.
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 Initialize(Bool_t useTMVAStyle=kTRUE)