Code Difference Between Root 5 and Root 6

I have a macro which allowed for me to save 2D cuts when I was using root 5. I recently installed root 6 on my Debian machine, but the macro does not work in root 6. I am a bit new to root so if there is an easier way to do this I would be happy to know. Here is the code.

void
save_all_cuts(const char* filename)
{
  FILE* f = fopen(filename,"w");
  fprintf(f,"{\n\n");
  int np = gROOT->GetListOfSpecials()->GetSize();
  for(int i(0); i<np; ++i)  {
    TCutG* ccc = (TCutG*)gROOT->GetListOfSpecials()->At(i);
    ccc->write(f);
    fprintf(f, "\n//--------------------------\n\n);
  }
  fprintf(f,"}");
  fclose(f);
};

I make a 2D gate from the toolbar option “Graphical Cut” which I believe gets temporarily stored in gROOT. When I load this macro in root 6, an error occurs that says "no matching member function for call to ‘Write.’ Another error says that in TObject.h: note: candidate function not viable: no known conversion from ‘FILE *’ (aka ‘IO_FILE *’) to ‘const char *’ for 1st argument. Here are the full errors:

In file included from input_line_79:1:
/home/e12001/root_12001/n2analysis/utils_Jason.C:77:10: error: no matching
      member function for call to 'Write'
    ccc->Write(f);
    ~~~~~^~~~~
/home/pauldeyoung/cern-root6-builddir/include/TObject.h:140:24: note: candidate
      function not viable: no known conversion from 'FILE *' (aka '_IO_FILE *')
      to 'const char *' for 1st argument
   virtual Int_t       Write(const char *name=0, Int_t option=0, Int_t b...
                       ^
/home/pauldeyoung/cern-root6-builddir/include/TObject.h:141:24: note: candidate
      function not viable: no known conversion from 'FILE *' (aka '_IO_FILE *')
      to 'const char *' for 1st argument
   virtual Int_t       Write(const char *name=0, Int_t option=0, Int_t b...

Thank you for your help.

Seems to me your small piece of code has several mistakes (quote missing, extra ; , wrong method name…

let me try to fix what I see:

void save_all_cuts(const char* filename)
{
  FILE* f = fopen(filename,"w");
  fprintf(f,"{\n\n");
  int np = gROOT->GetListOfSpecials()->GetSize();
  for(int i(0); i<np; ++i)  {
    TCutG* ccc = (TCutG*)gROOT->GetListOfSpecials()->At(i);
    ccc->Write(f);
    fprintf(f, "\n//--------------------------\n\n");
  }
  fprintf(f,"}");
  fclose(f);
}
```

You may want to add:

if (! f) {
   fprinf(stderr, "ERROR: Unable to open '%s' for writing!", filename);
   return;
}

@couet Can you write a TCutG to a FILE pointer? I don’t think there is a method for TObject::Write(FILE*)?

You are right I was just fixing the obvious mistakes. I did not run it. running it you obviously get:

root [3] .x saveallcuts.C("aaa")
In file included from input_line_12:1:
/Users/couet/roottest/saveallcuts.C:8:10: error: no matching member function for call to 'Write'
    ccc->Write(f);
    ~~~~~^~~~~
/Users/couet/git/roottrunk-bin/include/TObject.h:135:24: note: candidate function not viable: no known conversion from 'FILE *' (aka '__sFILE *') to 'const char *' for 1st argument
   virtual Int_t       Write(const char *name=0, Int_t option=0, Int_t bufsize=0);
                       ^
/Users/couet/git/roottrunk-bin/include/TObject.h:136:24: note: candidate function not viable: no known conversion from 'FILE *' (aka '__sFILE *') to 'const char *' for 1st argument
   virtual Int_t       Write(const char *name=0, Int_t option=0, Int_t bufsize=0) const;
                       ^

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.