Skip to content

Commit

Permalink
Merge pull request cms-sw#52 from nucleosynthesis/nckw-utils-cheapsna…
Browse files Browse the repository at this point in the history
…pshot-fix-for-roocategories

 cheapValueSnapshots and RooCategories
  • Loading branch information
gpetruc committed Oct 24, 2013
2 parents 1f8a119 + a13d457 commit 5740071
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <RooDataHist.h>
#include <RooDataSet.h>
#include <RooRealVar.h>
#include <RooCategory.h>
#include <RooProdPdf.h>
#include <RooProduct.h>
#include <RooSimultaneous.h>
Expand Down Expand Up @@ -478,8 +479,15 @@ void utils::CheapValueSnapshot::readFrom(const RooAbsCollection &src) {
RooLinkedListIter iter = src.iterator(); int i = 0;
for (RooAbsArg *a = (RooAbsArg *) iter.Next(); a != 0; a = (RooAbsArg *) iter.Next(), ++i) {
RooRealVar *rrv = dynamic_cast<RooRealVar *>(a);
if (rrv == 0) throw std::invalid_argument("Collection to read from contains a non-RooRealVar");
values_[i] = rrv->getVal();
if (rrv == 0) {
RooCategory *rc = dynamic_cast<RooCategory *>(a);
if (rc == 0){
throw std::invalid_argument("Collection to read from contains a non-RooRealVar/RooCategory");
}
values_[i] = (double)rc->getIndex();
} else {
values_[i] = rrv->getVal();
}
}
}

Expand All @@ -488,14 +496,22 @@ void utils::CheapValueSnapshot::writeTo(const RooAbsCollection &src) const {
RooLinkedListIter iter = src.iterator(); int i = 0;
for (RooAbsArg *a = (RooAbsArg *) iter.Next(); a != 0; a = (RooAbsArg *) iter.Next(), ++i) {
RooRealVar *rrv = dynamic_cast<RooRealVar *>(a);
rrv->setVal(values_[i]);
if (rrv!=0) rrv->setVal(values_[i]);
else {
RooCategory *rc = dynamic_cast<RooCategory *>(a);
rc->setIndex((int)values_[i]);
}
}
} else {
RooLinkedListIter iter = src_->iterator(); int i = 0;
for (RooAbsArg *a = (RooAbsArg *) iter.Next(); a != 0; a = (RooAbsArg *) iter.Next(), ++i) {
RooAbsArg *a2 = src.find(a->GetName()); if (a2 == 0) continue;
RooRealVar *rrv = dynamic_cast<RooRealVar *>(a2);
rrv->setVal(values_[i]);
if (rrv!=0) rrv->setVal(values_[i]);
else {
RooCategory *rc = dynamic_cast<RooCategory *>(a2);
rc->setIndex((int)values_[i]);
}
}
}
}
Expand Down

0 comments on commit 5740071

Please sign in to comment.