Hi,
Int_t GetNtuple(Int_t stage, TFile* &fin, TNtuple* &nin)
You'll need to pass the arg by ref (better but uncommonway of stating
that: You'll need to define the method such that the arg gets passed by
ref), to allow GetNtuple to change the arg.
Cheers, Axel.
> Hi all,
>
> I should know this but
>
> I have files
> photon_1.root with ntuple phot1
> photon_2.root with ntuple phot2
> photon_3.root with ntuple phot3
>
> If the file is there I want to return a pointer to it and a pointer to the
> ntuple it contains.
>
> If it is not there, I want to return a pointer to a file ready to write to
> and a pointer to an ntuple ready to fill.
>
> the new TFile and new TNtuple are lost when I go out of scope (I believe)
> so when I do nin->GetEntries() before leaving I get the anwer when I do it
> after leaving the function, I get a seg fault. I now its a scope thing but
> I cannot recall the solution.
>
> Core example it is below.
>
> Thanks,
> Kevin
>
>
>
> Int_t GetNtuple(Int_t stage, TFile *fin, TNtuple *nin)
> {
> char fname[256];
> sprintf(fname,"photons_%d.root",stage);
> char ntname[256];
> sprintf(ntname,"phot%d",stage);
> cout << ntname << " " << fname << endl;
> TFile *tfin = new TFile("photons_1.root","READ");
> if (!fin->IsOpen()) {
> fin = new TFile(fname,"RECREATE");
> nin=new TNtuple(ntname,"photons","x:y:z:dx:dy:dz:lambda");
> } else {
> tnin = (TNtuple*)gROOT->FindObject(ntname);
> }
> fin=tfin->Copy((TObject*)tfin);
> nin=tnin->Copy((TObject*)tnin);
> cout << nin->GetEntries() << endl;
> //works here (there are 10,000 if file is there else 0)
> return 0;
> }
>
> int main()
> {
> TNtuple *phot1;
> TFile *f1;
>
> Int_t nocode=GetNtuple(1,f1,phot1);
> cout << phot1->GetEntries() << endl; // segfault
> }
>
> |------------------------------------|---------------------------------|
> | Kevin Reil | 2575 Sand Hill Road, MS 26 |
> | X2447, 103D A&E Bldg. 041 | Menlo Park, CA 94025 |
> |------------------------------------|---------------------------------|
> | http://www.slac.stanford.edu/~reil | Office (650) 926-2447 |
> | reil@slac.stanford.edu | Home (650) 938-1767 |
> | http://reil.no-ip.org | Fax (650) 926-5368 |
> |----------------------------------------------------------------------|
> | And my father dwelt in a tent. |
> |----------------------------------------------------------------------|
>
> On Thu, 29 May 2003, Mayly Sanchez wrote:
>
>>
>>Hi Rene,
>>the root file is here:
>>http://minos.phy.tufts.edu/msanchez/dchisq90_c.root
>>Mayly
>>
>>On Thursday, May 29, 2003, at 01:47 PM, Rene Brun wrote:
>>
>>> Hi Mayly,
>>>
>>> Could you send the canvas.root file instead of canvas.gif?
>>>
>>> Rene Brun
>>>
>>> On Thu, 29 May
>>> 2003, Mayly Sanchez wrote:
>>>
>>>>
>>>> Thanks Rene, that fixed the contours but now it has a funny problem in
>>>> the lego plots. For some cases (I still have to determine the
>>>> pattern),
>>>> it draws lego plots where part of it shows as a wireframe while the
>>>> rest seems ok. The best way to explain is a picture:
>>>> http://minos.phy.tufts.edu/msanchez/dchisq90_lego.gif
>>>>
>>>> Any ideas?
>>>> Mayly
>>>>
>>>> On Wednesday, May 21, 2003, at 06:42 PM, Rene Brun wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> Some changes have been made in the past few weeks by Olivier Couet
>>>>> to solve the kind of problems you are reporting.
>>>>> Take the version from CVS head and install from source.
>>>>>
>>>>> Rene Brun
>>>>>
>>>>> On Wed,
>>>>> 21 May 2003, Mayly Sanchez wrote:
>>>>>
>>>>>>
>>>>>> Hi,
>>>>>> I have a macro for drawing non-equidistant 2d contours that used to
>>>>>> work before but fails in most recent versions of root. The latest
>>>>>> test
>>>>>> has been done with 3.05/05.
>>>>>>
>>>>>> Here are the steps I follow:
>>>>>> {TH2F *ch = new
>>>>>> TH2F("ch","",nbinx,nbinxmin,nbinxmax,nbiny,nbinymin,nbinymax);
>>>>>> ch->Fill(x,y,weight);
>>>>>> ch->SetContour(2);
>>>>>> ch->SetContourLevel(0,0.0)
>>>>>> ch->SetContourLevel(1,2.0)
>>>>>>
>>>>>> ch->Draw("cont2");
>>>>>> }
>>>>>>
>>>>>> Now what happens is: that if I do a lego2 plot before drawing the
>>>>>> contours, the levels are set at the proper heights. Once I have run
>>>>>> Draw("cont2") or any of the other cont options it recalculates the
>>>>>> levels in a weird way. It seems to put the first level at the
>>>>>> GetMinimum value and the second half way between the maximum and the
>>>>>> minimum, as if it wanted to do equidistant contours.
>>>>>>
>>>>>> Did something change? Can I force it to do non-equidistant contours
>>>>>> again? I need this urgently so any workarounds are welcome, thanks,
>>>>>>
>>>>>> Mayly
>>>>>>
>>>>>> ps. the method with SetContourLevels(2,vector) was also tested and
>>>>>> gave
>>>>>> the same results
>>>>>>
>>>>>>
>>>>
>>
>>
>
This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:12 MET