Linear Collider Forum



Home » Software Tools » org.lcsim » Two naive questions for using Driver
Re: Two naive questions for using Driver [message #1155 is a reply to message #1154] Thu, 27 September 2007 13:50 Go to previous message
tonyj
Messages: 138
Registered: January 2004

zhaohw wrote on Thu, 27 September 2007 13:14

Hello,

I have two naive questions for using org.lcsim Driver class:

1. How to output some printout into a txt file ?
For example, I want to write out the values of a variable,
say, the energies of particles, into a ASCII file,
myfile.txt, How to do in a Driver ? Can you give me a
code template ?


Here is an example:
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import org.lcsim.event.EventHeader;
import org.lcsim.util.Driver;

public class PrintDriver extends Driver
{
   private PrintWriter writer;
   public PrintDriver() throws IOException
   {
      writer = new PrintWriter(new FileWriter("c:\\myFile.txt"));   
   }
   
   protected void process(EventHeader event)
   {
      writer.println("Got "+event);
      super.process(event);
   }
   protected void suspend()
   {
      // Not really necessary, but just to be safe.
      writer.flush();
      super.suspend();
   }   
}


Quote:


2. How to use a Driver in a Driver ?
As I know, My question is: Supposing Driver A has a method
A.setSomethingOnA(), how do I use this method in
Driver C ?


Your last example looks about right,

   public class C extends Driver
    {
      public C(){        
        Driver a = new A();    
        a.setSomethingOnA();  
        add(a);      
        add(new B()); // just construct B
      }
    }

 
Read Message
Read Message
Previous Topic:How to use hep.lcd classes in lcsim ?
Next Topic:Reconstructing Events
Goto Forum:
  


Current Time: Tue Apr 24 00:01:49 Pacific Daylight Time 2018
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.1.
Copyright ©2001-2010 FUDforum Bulletin Board Software