Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

Collision.java

Go to the documentation of this file.
00001 package cedar.jetweb.model;
00002 
00003 import java.util.Collection;
00004 import java.util.Vector;
00005 import java.util.HashMap;
00006 import java.util.Enumeration;
00007 
00008 import cedar.jetweb.*;
00009 import cedar.jetweb.db.DBManager;
00010 
00018 public class Collision implements Storeable {
00019 
00020     private double ecms = -1.0;
00021     //private Vector<Particle> particles = new Vector<Particle>();
00022     private HashMap<Integer, Particle> particles = 
00023     new HashMap<Integer, Particle>();
00024     private int collisionId=0;
00025     private Particle particle1;
00026     private Particle particle2;
00027 
00031     public Collision(int id) throws JetWebException {
00032 
00033     collisionId = id;
00034     retrieve();
00035 
00036     }
00040     public Collision() {
00041     }
00042 
00043     public Collision addParticle(Particle p, Integer pNumber)
00044     throws JetWebException{
00045     if(pNumber >2){
00046         throw new JetWebException("Too many particles for this collision",
00047                       p.getName());
00048     }
00049     particles.put(pNumber, p);
00050 
00051     return this;
00052     }
00053     
00054     public void addParticle(Particle p) 
00055     throws JetWebException {
00056 
00057     if(particles.size()>=2){
00058         throw new JetWebException("Too many particles for this collision",
00059                       p.getName());
00060     }
00061 
00062     Integer pNumber = null;
00063     Integer ii=1;
00064     while(pNumber==null){
00065         if (particles.get(ii)==null){
00066         pNumber = ii;
00067         } 
00068         ++ii;
00069     }
00070 
00071     if(pNumber >2){
00072         throw new JetWebException("Too many particles for this collision",
00073                       p.getName());
00074     }
00075 
00076     particles.put(pNumber, p);
00077     }
00078 
00079 
00080     public Collection<Particle> getParticles(){
00081     return particles.values();
00082     }
00083 
00084     public Integer getNumberOfParticles(){
00085     return(particles.size());
00086     }
00087 
00088     public void setId(int id){collisionId = id; }
00089 
00090     public Particle getParticle1(){ return particles.get(1); }
00091 
00092     public Particle getParticle2(){ return particles.get(2); }
00093 
00098     public boolean equals(Object obj){
00099 
00100     if (obj==null) { return false; }
00101 
00102     if ( !this.getClass().equals(obj.getClass())  ) { return false; }
00103 
00104     Collision c = (Collision)obj;
00105     if (collisionId>0 && c.getId() > 0){
00106         return (collisionId==c.getId());
00107     } else {
00108         return (getParticle1().equals(c.getParticle1()) && 
00109             getParticle2().equals(c.getParticle2()) );
00110     }
00111     }
00112 
00113     public int hashCode(){ return collisionId; }
00114 
00115     public int getId() { 
00116     if (collisionId==0) {
00117         // See if this collision is one we understand.
00118         try {
00119 
00120         System.out.println("Looking up Collison Id in DB");
00121 
00122         DBManager.selectId(this);
00123 
00124         System.out.println("collision id = "+collisionId);
00125 
00126         } catch (Exception e){
00127         collisionId=-1;
00128         }
00129     }
00130     if (collisionId==0) collisionId=-1;
00131     return collisionId; 
00132     }
00133 
00134     public boolean retrieve() throws JetWebException {
00135     return DBManager.selectFromDB(this);
00136     }
00137 
00138     public boolean store() throws JetWebException {
00139     return DBManager.addToDB(this);
00140     }
00141 
00147     public double getCMEnergy(){ 
00148     if (ecms<0) {
00149         calcCME();
00150     }
00151     return ecms;
00152     }
00153 
00154 
00158     public static Vector<Collision> getAll(){
00159     try {
00160         Vector<Collision> colls = DBManager.getAllCollisions();
00161         return colls;
00162     } catch (JetWebException j) {
00163         System.out.println(j);
00164         return null;
00165     }
00166     }
00167 
00168     private void calcCME(){
00169     ecms = 2.*Math.sqrt( getParticle1().getEnergy()*
00170                  getParticle2().getEnergy() );
00171     }
00172 
00173     public String toString(){
00174 
00175     StringBuffer str = new StringBuffer();
00176     str.append(getParticle1().getEnergy());
00177     str.append(getParticle1().getName());
00178     str.append("_");
00179     str.append(getParticle2().getEnergy());
00180     str.append(getParticle2().getName());
00181     return str.toString();
00182     }
00183 }
00184 
00185 
00186 
00187 
00188 
00189 
00190 
00191 
00192 
00193 
00194 
00195 
00196 
00197 
00198 
00199 
00200 
00201 

Generated Wed Jan 17 09:14:27 GMT 2007