[Rivet] Rivet Analysis Class 'Gotcha'

Hendrik Hoeth hendrik.hoeth at cern.ch
Mon Dec 17 13:50:00 GMT 2012


Hi David,

sorry for the late reply. I don't really understand your mail, so I'll
put some questions and comments below:

Thus spake David Bjergaard (david.b at duke.edu):

> 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;

Which Rivet version are you using? That line is in a completely
different place in the version I'm looking at.

> 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.  

Once you normalized your histogram, strictly speaking it's no longer a
histogram but a DataPointSet. Much of the statistics information needed
for a proper histogram gets lost in that step. Which, by the way, is one
of the reasons that we are currently getting rid of AIDA as
histogramming backend and will switch to YODA for Rivet 2.0.

> 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. 

Which is a surprise to me. I'm doing pretty much the same thing
successfully. Can you please send us an example code that crashes?

Cheers,

   Hendrik

-- 
If your dreams don't scare you, then you are not dreaming big enough.


More information about the Rivet mailing list