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

MCProcessType.java

Go to the documentation of this file.
00001 package cedar.jetweb.model;
00002 
00003 import cedar.jetweb.*;
00004 import cedar.jetweb.db.DBManager;
00005 import cedar.jetweb.db.JetWebDBException;
00006 import cedar.jetweb.db.DBBlob2Array;
00007 
00008 import java.util.Vector;
00009 import java.util.Enumeration;
00010 import java.util.HashMap;
00011 import java.util.Date;
00012 import java.lang.Comparable;
00013 import java.sql.Blob;
00014 import java.sql.SQLException;
00015 
00028 public class MCProcessType implements Storeable, Comparable {
00029 
00030     private int processId = 0;
00031     private int collisionId = -1;
00032     private Collision collision;
00033     private String processName;
00034     private static HashMap<Integer, Vector<Integer> > 
00035     compatibleProcesses_ = new HashMap<Integer, Vector<Integer>>();
00036     private Vector<Integer> thisCompatibleProcesses_ = null;
00037     private boolean dirtyThisCompatibleProcesses_ = true;
00038     private static Vector<MCProcessType> allProcs;
00039     private float lumi_;
00040 
00041     //cache the process_types so we only look them up in the DB once.
00042     private static HashMap<Integer, MCProcessType> knownProcs_ = 
00043     new HashMap<Integer, MCProcessType>();
00044 
00045     //private static HashMap<Integer, Boolean> isValid_ = 
00046     //  new HashMap<Integer, Boolean>();
00047     private boolean valid_;
00048 
00049     public static final String HIGHET = "High ET";
00050     public static final String DIS = "DIS";
00051     public static final String MINBIAS = "Minimum Bias";
00052     public static final String CHARM = "Charm Only";
00053     public static final String CHARMDIS = "Charm Only DIS";
00054     public static final String BEAUTY = "Beauty Only";
00055     public static final String BEAUTYDIS = "Beauty Only DIS";
00056     public static final String ANNIHILATION = "Electron-positron annhilation";
00057     public static final String PHOTONPHOTON = "Photon Photon";
00058     public static final String PHOTONPARTON = "Photon Parton";
00059     public static final String PARTONPARTON = "Parton Parton";
00060     public static final String CHARMPHOTONPHOTON = "Charm Photon Photon";
00061     public static final String CHARMPHOTONPARTON = "Charm Photon Parton";
00062     public static final String CHARMPARTONPARTON = "Charm Parton Parton";
00063     public static final String BEAUTYPHOTONPHOTON = "Beauty Photon Photon";
00064     public static final String BEAUTYPHOTONPARTON = "Beauty Photon Parton";
00065     public static final String BEAUTYPARTONPARTON = "Beauty Parton Parton";
00066     //public static final String DIRECT = "Direct Photoproduction";
00067     //public static final String RESOLVED = "Resolved Photoproduction";
00068     
00072     public MCProcessType() {
00073 
00074     setIsValid(false);
00075 
00076     Vector<Integer> tmp = new Vector<Integer>(1);
00077     tmp.add(new Integer(-1));
00078 
00079     if(!compatibleProcesses_.containsKey(-1)){
00080         compatibleProcesses_.put(new Integer(-1), tmp);
00081         compatibleProcesses_.put(new Integer(0), tmp);
00082     }
00083 
00084     }
00093     public MCProcessType(int id) {
00094 
00095     if(knownProcs_.containsKey(new Integer(id))){
00096         
00097         MCProcessType proc = knownProcs_.get(new Integer(id));
00098         
00099         this.processId = proc.getId();
00100         this.collision = proc.getCollision(); 
00101         this.processName = proc.getMCProcessName();
00102         this.lumi_ = proc.getDefaultLumi();
00103         // new, JMB
00104         this.valid_ = proc.isValid();
00105         //this = knownProcs_.get(id);
00106     }else{
00107         
00108         this.processId = id;
00109         if(id>0){
00110         try {
00111             
00112             DBManager.selectFromDB(this);
00113             
00114             //temporary until the DB contains the isValid column
00115             //and the compatible processes column
00116             
00117             //setIsValid(true);//set all processes valid for now
00118             
00119         } catch (Exception e){
00120             System.out.println(e);
00121         }
00122         
00123         knownProcs_.put(this.processId, this);
00124         }else{
00125         setIsValid(false);
00126         }
00127     }
00128     }
00129 
00137     public MCProcessType(String procName, Collision col){
00138     processName = procName;
00139     collision = col;
00140     getId();
00141     }
00142 
00143 
00149     public MCProcessType(MCProcessType proc) {
00150     this.processId = proc.getId();
00151     this.collision = proc.getCollision(); 
00152     this.processName = proc.getMCProcessName();
00153     this.lumi_ = proc.getDefaultLumi();
00154     }
00155 
00160     public int getId(){ 
00161 
00162     if (processId==0) {
00163         // See if this MCProcessType is one we understand.
00164         try {
00165         DBManager.selectId(this);
00166         } catch (Exception e){
00167         processId=-1;
00168         }
00169     }
00170 
00171     return processId; 
00172     }
00173 
00178     public void setDefaultLumi(float lumi){
00179 
00180     lumi_ = lumi;
00181     }
00182 
00187     public float getDefaultLumi(){
00188     return lumi_;
00189     }
00190 
00191 
00196     public int getProcessId(){
00197     return(getId());
00198     }
00199 
00204     public String getMCProcessName(){ return processName; }
00205 
00210     public String getProcessName(){
00211     return(getMCProcessName());
00212     }
00213 
00218     public void setMCProcessName(String name){ processName = name; 
00219     }
00220 
00221     //Duplicate setMCProcessName to match the entry in the DB:
00222 
00223     public void setProcessName(String name){
00224     setMCProcessName(name);
00225     return;
00226     }
00227 
00232     public Collision getCollision(){ 
00233     return collision; 
00234     }
00235 
00240     public void setId(int id){ 
00241     processId = id; 
00242     return;
00243     }
00247     public void setProcessId(int id){
00248     setId(id);
00249     return;
00250     }
00251 
00256     public void setCollision(Collision c){ collision = c; }
00257 
00263     //Allow the collision to be set from the collision Id in the DB:
00264 
00265     public void setCollisionId(int cId){
00266     try{
00267         collision = new Collision(cId);
00268     }catch(JetWebException err){
00269         System.out.println(err.getMessage());
00270     }
00271     return;
00272     }
00273 
00279     public int getCollisionId(){
00280     return(getCollision().getId());
00281     }
00282 
00287     public void setIsValid(boolean isValid){
00288 
00289     valid_=isValid;
00290 
00291     //System.out.println("called setIsValid "+isValid_.size()+" id "+processId);
00292     //if(isValid_.containsKey(this.processId))return;
00293     
00294     //isValid_.put(this.processId, isValid);
00295     return;
00296     }
00298 
00302     public boolean isValid(){
00303     //System.out.println("checking validity for process "+this.processId);
00304     //System.out.println("isValid "+isValid_);
00305     //return(isValid_.get(this.processId));
00306     return(valid_);
00307     }
00309  
00313     public boolean getIsValid(){
00314     return(isValid());
00315     }
00317   
00324     public Vector<Integer> getCompatibleProcesses(){
00325 
00326     if(dirtyThisCompatibleProcesses_){
00327 
00328         thisCompatibleProcesses_ = 
00329         compatibleProcesses_.get(this.processId);
00330         dirtyThisCompatibleProcesses_ = false;
00331     }
00332     
00333     //stop-gap measure for now until entries are in 
00334     //the process_type table of the DB.  If this process is a 
00335     //non-zero Id then it is compatible with itself
00336     //(zero id means it has not been initialised properly)
00337 
00338     if(thisCompatibleProcesses_==null&&processId>0){
00339         thisCompatibleProcesses_ = new Vector<Integer>();
00340         thisCompatibleProcesses_.add(this.processId);
00341     }
00342 
00343     return(thisCompatibleProcesses_);
00344     }
00346     /*  public byte[] getCompatibleProcesses(){
00347 
00348     return()
00349     }*/
00351  
00357     public void setCompatibleProcesses(Blob compat){
00358 
00359     if(compatibleProcesses_.containsKey(this.processId)) return;
00360     Vector<Integer> compatPIds = null;
00361 
00362     try{
00363         compatPIds = DBBlob2Array.getInteger(compat);
00364     }catch(SQLException err){
00365         System.out.println("Error: could not convert Blob to array");
00366         System.out.println(err.getMessage());
00367     }
00368 
00369     compatibleProcesses_.put(this.processId, compatPIds);
00370     thisCompatibleProcesses_ = compatPIds;
00371     dirtyThisCompatibleProcesses_ = false;
00372     return;
00373     }
00375     
00381     public void setCompatibleProcesses(Vector<Integer> compat){
00382 
00383     compatibleProcesses_.put(this.processId, compat);
00384     thisCompatibleProcesses_ = compat;
00385     dirtyThisCompatibleProcesses_ = false;
00386 
00387 
00388     return;
00389     }
00391 
00395     public Vector<String> getUnspecifiedParameters(){
00396     Vector<String> missing = new Vector<String>();
00397     if (collision==null) missing.add("collision");
00398     if (processName==null) missing.add("process name");
00399     return missing;
00400     }
00401 
00402 
00409     public static Vector<MCProcessType> getAll(boolean selectable){
00410     try {
00411         allProcs = DBManager.getAllMCProcessTypes(selectable);
00412     } catch (JetWebException j) {
00413         System.out.println(j);
00414         return null;
00415     }
00416     return allProcs; 
00417     }
00425     public static Vector<MCProcessType> getAll(Collision collision, boolean selectable){
00426 
00427     if (collision==null) { return getAll(selectable); } 
00428     try {
00429         Vector<MCProcessType> procs = 
00430         DBManager.getAllMCProcessTypes(collision,selectable);
00431         return procs;
00432     } catch (JetWebException j) {
00433         System.out.println(j);
00434         return null;
00435     }
00436     }
00437 
00441     public boolean matches(MCProcessType proc){
00442 
00443     if (processId>0 && proc.getId()>0) {
00444         if (proc.getId()==processId) { 
00445         return true; 
00446         } else {
00447         return false;
00448         }
00449     }
00450 
00451     if (getCollision()!=null){
00452         if (!getCollision().equals(proc.getCollision())) { 
00453         return false;
00454         }
00455     }
00456 
00457     if (processName.length()!=0 && proc.getMCProcessName().length()!=0 && 
00458         processName.equalsIgnoreCase(proc.getMCProcessName())) {return false;}
00459 
00460 
00461     //System.out.println("matched");
00462 
00463     return true;
00464     }
00465 
00470     public boolean equals(Object obj){
00471 
00472     if (obj==null) { return false; }
00473 
00474     if ( !this.getClass().equals(obj.getClass())  ) { return false; }
00475 
00476     MCProcessType p = (MCProcessType)obj;
00477     return (processId==p.getId());
00478 
00479     }
00480 
00485     public int compareTo(Object obj){
00486 
00487     boolean objNull = obj==null ||
00488         obj.getClass()!=this.getClass();
00489     //  boolean obj2Null = obj2==null ||
00490     //  obj2.getClass()!=this.getClass();
00491 
00492     //if(obj1Null && obj2Null) return 0;
00493     //if(obj1Null) return -1;
00494     //if(obj2Null) return 1;
00495 
00496     if(objNull) return -1;
00497 
00498     return this.getId() - ((MCProcessType)obj).getId();
00499     }
00500 
00501     public int hashCode(){ return processId; }
00502 
00503 
00507     public String getBeams(){
00508 
00509     String beams = getCollision().getParticle1().getName()+       
00510         getCollision().getParticle2().getName();       
00511 
00512     return beams;
00513     }
00514 
00520     public static boolean checkCollision(int collId, int procId) throws JetWebException {
00521     return DBManager.checkCollision(collId, procId);
00522     }
00523 
00524     
00525     // Below follow a series of "Short cut" access methods for
00526     // information which can be deduced from the contents of an
00527     // MCProcessType.
00528 
00535     public boolean hasPhoton(){
00536 
00537     if(getCollision()==null)return true;
00538 
00539     Particle p1 = getCollision().getParticle1();
00540     Particle p2 = getCollision().getParticle2();
00541     if (p1==null || p2==null) return true;
00542 
00543     if ((p1.getName().equalsIgnoreCase(Particle.ELECTRON) || 
00544          p1.getName().equalsIgnoreCase(Particle.POSITRON) ||
00545          p2.getName().equalsIgnoreCase(Particle.ELECTRON) || 
00546          p2.getName().equalsIgnoreCase(Particle.POSITRON)) &&
00547         processName.indexOf(DIS)<=0 &&
00548         !processName.equals(ANNIHILATION)){
00549         return true;
00550     }else {
00551         return false;
00552     }
00553     }
00560     public boolean hasProton(){
00561     if(getCollision()==null)return true;
00562     Particle p1 = getCollision().getParticle1();
00563     Particle p2 = getCollision().getParticle2();
00564     if (p1==null || p2==null) return true;
00565 
00566     if (p1.getName().equalsIgnoreCase(Particle.PROTON) || 
00567         p1.getName().equalsIgnoreCase(Particle.ANTIPROTON) ||
00568         p2.getName().equalsIgnoreCase(Particle.PROTON) || 
00569         p2.getName().equalsIgnoreCase(Particle.ANTIPROTON)){
00570         return true;
00571     }else {
00572         return false;
00573     }
00574     }
00575 
00576 
00580     public boolean isPhotoproduction(){
00581     if (hasProton()&&hasPhoton()) return true;
00582     return false;
00583     }
00584 
00588     public boolean isDIS(){
00589     if (processName.indexOf(DIS)>=0) return true;
00590     return false;
00591     }
00592 
00596     public boolean isGammaGamma(){
00597     if (hasPhoton() && !hasProton() && processName.indexOf(DIS)<=0) return true;
00598     return false;
00599     }
00600 
00604     public boolean isPP(){
00605     if (!hasPhoton() && hasProton() && processName.indexOf(DIS)<=0) return true;
00606     return false;
00607     }
00608 
00612     public String toString(){
00613 
00614     String name = null;
00615     
00616     if(processName!=null){
00617         name = new String(processName);
00618     }else{
00619         name = "";
00620     }
00621 
00622     int ii = name.indexOf(" "); 
00623     while(ii>-1){
00624         name = name.substring(0,ii)+name.substring(ii+1);
00625         ii = name.indexOf(" ");
00626     }
00627     StringBuffer str = new StringBuffer(name);
00628     
00629     if(collision!=null){
00630         str.append(collision.toString());
00631     }
00632     
00633     return str.toString();
00634     }
00635 
00642     public boolean store() throws JetWebException {
00643     return DBManager.addToDB(this); 
00644     }
00645 
00646 
00651     public boolean retrieve() throws JetWebException{
00652     DBManager.selectFromDB(this);
00653     return true;
00654     }
00655 
00660     public boolean delete() throws JetWebException{
00661     DBManager.deleteFromDB(this);
00662     return true;
00663     }
00664 
00665 
00666 }
00667 
00668 
00669 
00670 
00671 
00672 
00673 
00674 
00675 
00676 
00677 
00678 
00679 
00680 
00681 
00682 
00683 
00684 

Generated Wed Jan 17 09:14:27 GMT 2007