Save external postscript file in ROOT file

Hello,

is there an easy way to save a PostScript file produced by an external program in a ROOT file?

I tried something like that but no luck:

ifstream in(“file.ps”);
string line;

TPostScript myps(“inrootfile.ps”);
while(getline(in,line)){
myps.PrintStr(line.c_str());
}
myps.Close();

Thank you,

Philippe

Hi, look at this:

void
foo ()
{
  TFile echo ("foo.root", "recreate");
  TPostScript bar ("bar.ps");
  bar.Close ();

  gSystem->Exec (">bar.ps");

  ifstream ifstr ("foo.ps");
  ofstream ofstr ("bar.ps");

  Char_t line[256];

  while (ifstr.getline (line, 256))
    {
      ofstr << line << '\n';
    }

  ofstr.close ();
  ifstr.close ();  
  
  bar.Write ();
  echo.Close ();
}

so the line gSystem->Exec (">bar.ps"); empty the file (bash) so you can figure out how to do it if you are working with zsh or ksh or some other shell :smiley:.

Hi probably this is better :laughing::

void
foo ()
{
  TFile echo ("foo.root", "recreate");
  TPostScript bar ("bar.ps");
  bar.Close ();

  gSystem->Exec ("cp foo.ps bar.ps");
 
  bar.Write ();
  echo.Close ();
} 

Hi,

I used this code


  TFile echo ("foo.root", "recreate");
  TPostScript bar ("bar.ps");
  bar.Close ();

  gSystem->Exec ("cp foo.ps bar.ps"); 

to write the PS file but I cannot pop it on the screen from a TBrowser… Nothing happens. I got this warning on startup:
Warning in TStreamerInfo::BuildCheck:
The StreamerInfo of class TVirtualPS read from file rootfile.root
has the same version (=0) as the active class but a different checksum.
You should update the version to ClassDef(TVirtualPS,1).
Do not try to write objects with the current class definition,
the files will not be readable.

I am using version 5.02. I tried to save a PNG image instead with the TASImage class but ROOT crashes when I click the PNG file in a TBrowser with the following output:

Generating stack trace…
0xb619545b in TASImage::Browse(TBrowser*) + 0x17 from /usr/local/lib/root/libASImage.so
0xb7a10ada in TKey::Browse(TBrowser*) + 0x12a from /usr/local/lib/libCore.so
0xb6588d37 in TRootBrowser::IconBoxAction(TObject*) + 0x3ab from /usr/local/lib/root/libGui.so
0xb6589df0 in TRootBrowser::ProcessMessage(long, long, long) + 0xed8 from /usr/local/lib/root/libGui.so
0xb650724e in TGFrame::HandleClientMessage(Event_t*) + 0x36 from /usr/local/lib/root/libGui.so
0xb65092be in TGMainFrame::HandleClientMessage(Event_t*) + 0x22 from /usr/local/lib/root/libGui.so
0xb650962d in TGFrame::HandleEvent(Event_t*) + 0x30b from /usr/local/lib/root/libGui.so
0xb64e59b9 in TGClient::HandleEvent(Event_t*) + 0xef from /usr/local/lib/root/libGui.so
0xb64e5a3b in TGClient::ProcessOneEvent() + 0x6b from /usr/local/lib/root/libGui.so
0xb64e5af2 in TGClient::HandleInput() + 0x26 from /usr/local/lib/root/libGui.so
0xb64e5b2e in TGInputHandler::Notify() + 0x1e from /usr/local/lib/root/libGui.so
0xb7b3d3de in TUnixSystem::DispatchOneEvent(bool) + 0x52 from /usr/local/lib/libCore.so
0xb7a5235a in TSystem::InnerLoop() + 0x18 from /usr/local/lib/libCore.so
0xb7a52300 in TSystem::Run() + 0x6e from /usr/local/lib/libCore.so
0xb79e583f in TApplication::Run(bool) + 0x37 from /usr/local/lib/libCore.so
0xb6d64499 in TRint::Run(bool) + 0x347 from /usr/local/lib/libRint.so
0x08048d20 in main + 0x68 from /usr/local/bin/root.exe
0xb6b07e4b in __libc_start_main + 0xcb from /lib/tls/libc.so.6
0x08048c31 in TApplicationImp::ShowMembers(TMemberInspector&, char*) + 0x31 from /usr/local/bin/root.exe

I saw a post from February 2005 in which René Brun tells that the pixel data are not written to the file…
http://root.cern.ch/phpBB2/viewtopic.php?t=1577

Is it fixed?

Thank you

Philippe

Could you send the concrete file (with the necessary data files) that
rep[roduces this problem?
I do not understand why the few lines suggested in your example can
produce a crash in TASImage.

Rene