|
[Rivet] Rivet Analysis Class 'Gotcha'David Bjergaard david.b at duke.eduTue Dec 4 19:12:41 GMT 2012
Hi, I'm using rivet to do analysis for the BOOST group. There are a few idioms that I thought were sensible, but weren't, and they stem from the same issue. Can someone explain why my histogram pointer is set to null: src/Core/Analysis.cc, Analysis::scale() >558: // Set histo pointer to null - it can no longer be used. >559: histo = 0; I didn't allocate the pointer, but it is a member of my class. This means I can't do things like: normalize(myHisto,1.0); double mean=myHisto->mean(); double rms=myHisto->rms(); But: double mean=myHisto->mean(); double rms=myHisto->rms(); normalize(myHisto,1.0); Is valid. I know std::maps are expensive, but I would rather express things succinctly and then change it later if it becomes a performance issue. What I have in mind is: typedef std::map<std::string,AIDA::IHistogramID*> BookedHistos; class MyAnalysis : public Analysis { ... public: void init() { Histos["MyHisto"]=bookHistogram1D(...); } void analyze() { Histos["MyHisto"]->fill(); } void finalize(){ foreach(BookedHistos::value_type h, Histos){ //calculate/store statistics for each histo normalize(h); } } private: BookedHistos Histos; } But this code will segfault when finalize() is called because the default destructer will try to delete stuff that is set to NULL by normalize. Sincerely, Dave
More information about the Rivet mailing list |