Error: No memory for static n\0\0

Hello again,

I’m reading in a tree and using it to generate a TGraph:

void GetTimeComp(char *infilename) {

  gStyle->SetOptFit(1111);
  TFile* fin = new TFile(infilename,"read");
  TTree* uin = (TTree*) fin->Get("tUCN");
  static const Int_t n = uin->GetEntries();
  Double_t entry[n],timeE[n];
  ULong_t prev = 0;
  for(int i=0;i<n;i++) {
    sin->GetEvent(i);
    timeE[i] = tTimeE;
    entry[i] = tEntry - prev;
    prev = tEntry;
  }
  TGraph *gEventE = new TGraph(n,timeE,entry);
...
}

However, I get the error,

I tried moving the static declaration as high up as possible, but the error remains. I do NOT have a gROOT->Reset() command. It will run if I do

[midas@localhost UCNAnalyzer]$ root GetTimeComp.C+ root [0] Processing GetTimeComp.C+... [midas@localhost UCNAnalyzer]$

So presumably it compiles, but the output.root won’t open and I would prefer to view the output in CINT before converting to a compiled program. Is there a workaround so that I can run this on CINT instead of ACLiC?

1 Like

Try something like: void GetTimeComp(char *infilename) { if (!( infilename && (*infilename) )) return; // just a precaution TFile *fin = new TFile(infilename, "READ"); TTree *uin; fin->GetObject("tUCN", uin); if (!uin) { delete fin; return; } // "tUCN" not found in "fin" const Long64_t n = uin->GetEntries(); if (!n) { delete fin; return; } // "tUCN" found but it's empty Double_t *entry = new Double_t[n]; Double_t *timeE = new Double_t[n]; // ... // event loop comes here // ... delete fin; // automatically deletes "uin", too delete[] entry; delete[] timeE; return; }

1 Like

Aha! That worked! The lines

did the trick. Thanks

1 Like