import java.awt.*; import java.applet.*; import java.lang.*; import java.io.DataInputStream; import java.io.BufferedInputStream; import java.io.IOException; import java.net.URL; import java.net.URLConnection; import java.net.MalformedURLException; import java.util.StringTokenizer; public class disc extends Applet implements Runnable { Thread runner1; EventDisplay evdisp; public static SelectPanel sp; public static boolean calo[] = new boolean[36]; Panel controlPanel; public Font font; URL theURL; public static URL base ; public static int initp [] = new int[36]; public static int nphc [] = new int[200]; public static int lphc [] = new int[200]; public static double xphc[] = new double [1000]; public static double yphc[] = new double [1000]; public static boolean debug = false; public static int event = 1; public static int eventd = 0; public static int maxev = 26; public static int runf = 42682; public static int run = 42682; public static TextField runinput; public static Checkbox clearev; public static Checkbox loopmode; public static Label workdone; public static double NLeft = -100; public static double NRight = 4500.; public static double NTop = 3000.; public static double NBottom =-2000.; public static double Left = -100; public static double Right = 4500.; public static double Top = 3000.; public static double Bottom =-2000.; public static int Nxpixel = 900; public static int Nypixel = 700; public static boolean zoom = true; public static boolean same = false; public static int maxhits = 2000; public static int zoomfactor = 1; public static int maxcol = 160; int ncolr = 30; public static byte redm[] = new byte[maxcol]; public static byte greenm[] = new byte[maxcol]; public static byte bluem[] = new byte[maxcol]; byte b255 = (byte)255; public void init(){ URLConnection conn; DataInputStream data; base = getDocumentBase(); String url = "disc.dat"; String line; StringTokenizer st; UserParameters(); CreatePalette(); setForeground(Color.black); font = new Font("Helvetica", Font.BOLD, 12); setLayout(new BorderLayout()); evdisp = new EventDisplay(); evdisp.resize(900,700); resize(950,750); add("Center",evdisp); controlPanel = new Panel(); add("South", controlPanel); loopmode = new Checkbox("Loop"); loopmode.setState(false); controlPanel.add(loopmode); clearev = new Checkbox("Clear"); clearev.setState(true); controlPanel.add(clearev); controlPanel.add(new Button("Help")); controlPanel.add(new Button("<<")); controlPanel.add(new Button("Same event")); controlPanel.add(new Button(">>")); workdone = new Label("Status display"); controlPanel.add(workdone); controlPanel.add(new Button("Selection")); controlPanel.add(new Button("Reset")); controlPanel.add(new Button("Available runs")); runinput = new TextField(String.valueOf(run)); controlPanel.add(runinput); sp = new SelectPanel("Module selection"); sp.resize(500,400); sp.move(0,0); sp.hide(); try { this.theURL = new URL(disc.base,url); } catch ( MalformedURLException e) { System.out.println("Bad URL: " + theURL); } try { conn = this.theURL.openConnection(); conn.connect(); data = new DataInputStream(new BufferedInputStream( conn.getInputStream())); int indpol = 0; int indpoi = 0; int npol; for (int i=0; i<36; i++) { calo[i] = true; initp [i] = indpol ; npol= 10; if(i > 5 && i <30)npol = 3; line = data.readLine(); if(debug)System.out.println(line); for (int j=0; j disc.maxev){ disc.event=1; getnext(); } evdisp.repaint(); } } public boolean mouseUp(Event e, int x, int y) { double zoom_x,zoom_y,width,height; if (disc.zoom && y < 667) { zoomfactor = zoomfactor + 1; zoom_x = disc.Left + (disc.Right-disc.Left)/disc.Nxpixel*x; zoom_y = disc.Bottom + (disc.Top-disc.Bottom)/disc.Nypixel*(Nypixel-y); width = disc.Right-disc.Left; height = disc.Top - disc.Bottom; disc.Left = zoom_x -width/4.; disc.Right = zoom_x + width/4.; disc.Bottom = zoom_y -height/4.; disc.Top = zoom_y + height/4.; System.out.println(x+" "+y); System.out.println(disc.Left+" "+disc.Right+" "+disc.Bottom+" "+disc.Top); stop(); start(); } return true; } public void getnext() { URL loadnext; URLConnection conn; DataInputStream data; String line; StringBuffer buf = new StringBuffer(); try {loadnext= new URL("http://axaonl.cern.ch:8080/dron_com/event.com?next"); // getAppletContext().showDocument(loadnext); try { conn = loadnext.openConnection(); conn.connect(); data = new DataInputStream(new BufferedInputStream( conn.getInputStream())); while ((line = data.readLine()) != null) { buf.append(line + "\n"); } } catch (IOException e5) { System.out.println("IO Error:" + e5.getMessage()); } } catch ( MalformedURLException e1) { System.out.println("Bad URL:event.com " ); } } public boolean action(Event e, Object arg) { URL loadnext; if("Same event".equals(arg)){ same = true; stop(); start(); return true; } if(">>".equals(arg)){ disc.event = disc.event + 1; if(disc.event > disc.maxev){ disc.event=1; getnext(); } stop(); start(); return true; } if("Help".equals(arg)){ try {loadnext= new URL("http://axaonl.cern.ch:8080/public/dron/dronhelp.html"); getAppletContext().showDocument(loadnext); } catch ( MalformedURLException e2) { System.out.println("Bad URL:dronhelp.html " ); } return true; } if("<<".equals(arg)){ disc.event = disc.event - 1; stop(); start(); return true; } if("Selection".equals(arg)){ sp.show(); return true; } if("Reset".equals(arg)){ Left = NLeft;Right=NRight;Bottom=NBottom;Top=NTop; zoomfactor = 1; stop(); start(); return true; } if("Available runs".equals(arg)){ disc.event = 1; try {loadnext= new URL("http://axaonl.cern.ch:8080/dron_com/runlist.com"); getAppletContext().showDocument(loadnext); } catch ( MalformedURLException e2) { System.out.println("Bad URL:runlist.com " ); } stop(); start(); return true; } if(e.target instanceof TextField) { if(e.target == runinput) { run =Integer.valueOf(runinput.getText()).intValue(); disc.event = 1; try {loadnext= new URL("http://axaonl.cern.ch:8080/dron_com/event.com?m00"+run+".dat"); getAppletContext().showDocument(loadnext); } catch ( MalformedURLException e3) { System.out.println("Bad URL:event.com " ); } stop(); start(); } return true; } return true; } } class EventDisplay extends Canvas { URL theURL; public void update(Graphics g) { if(disc.clearev.getState()) { g.setColor(Color.black); g.fillRect(0,0,900,665); } else { g.setColor(Color.black); g.fillRect(0,600,900,665); } paint(g); } public void paint(Graphics g) { URLConnection conn; DataInputStream data; int nseg,numto,numwi,npo,ien; String url ; String line; StringTokenizer st; double xp[] = new double [20]; double yp[] = new double [20]; int i,j,k; for (i=0; i<36; i++) { if(disc.sp != null)disc.calo[i]=disc.sp.getsel(i); } setBackground(Color.black); g.setColor(new Color(150,150,150)); for (i=0; i<36; i++) { if(disc.calo[i])dsmosc(g,i); } disc.workdone.setText(" reading new event "); url = "r"+Integer.toString(disc.runf)+"e"+Integer.toString(disc.event)+".dat"; try { this.theURL = new URL(disc.base, url); } catch ( MalformedURLException e) { System.out.println("Bad URL: " + theURL); } if(disc.debug)System.out.println("next event "+theURL); try { conn = this.theURL.openConnection(); conn.connect(); int ntotel = 0; data = new DataInputStream(new BufferedInputStream( conn.getInputStream())); line = data.readLine(); g.drawString(line,5,625); if(disc.debug)System.out.println(line); disc.workdone.setText(" loading towers"); for (i=0; i<36; i++) { if(!disc.same && (ntotel>disc.maxhits)) break; line = data.readLine(); st = new StringTokenizer(line); nseg=Integer.valueOf(st.nextToken()).intValue(); numto=Integer.valueOf(st.nextToken()).intValue(); if(disc.debug)System.out.println(line); if(numto > 0) { for(j=0; j (disc.maxcol -1))ien = disc.maxcol -1; if(disc.calo[i])dgfa(g,xp,yp,npo,ien); } if(numto > 10) try { Thread.sleep(100);} catch (InterruptedException e) { }; } } disc.workdone.setText(" loading wires"); g.setColor(new Color(0,255,0)); for (i=0; i<36; i++) { if(!disc.same && (ntotel>disc.maxhits)) break; line = data.readLine(); st = new StringTokenizer(line); nseg=Integer.valueOf(st.nextToken()).intValue(); numwi=Integer.valueOf(st.nextToken()).intValue(); if(disc.debug)System.out.println(line); if(numwi > 0) { if(i>5 && i <30)numwi=numwi*2; for(j=0; j 30)try { Thread.sleep(100);} catch (InterruptedException e) { }; } } if(ntotel>disc.maxhits)disc.workdone.setText(" too many hits!"); else disc.workdone.setText(" event complete"); disc.eventd=disc.event; if(disc.same)disc.same=false; } catch (IOException e) { System.out.println("IO Error:" + e.getMessage()); } } void dgpl(Graphics g,double xp[],double yp[], int ip, int np) { int x[] = new int[np]; int y[] = new int[np]; int allequal = 1; for (int k=0; k < np; k++) { x[k] = (int)((xp[k+ip]-disc.Left)/(disc.Right-disc.Left)*disc.Nxpixel); y[k] = (int)((yp[k+ip]-disc.Bottom)/(disc.Top-disc.Bottom)*disc.Nypixel); y[k] = disc.Nypixel - y[k]; if(k > 1 && (x[k] != x[k-1]) ) allequal=0; if(k > 1 && (y[k] != y[k-1]) ) allequal=0; } if(allequal == 1 && np == 5) { x[1] = x[0] + 1; x[2] = x[0] + 1; y[2] = y[0] + 1; y[3] = y[0] + 1; } g.drawPolygon(x,y,np); } void dgfa(Graphics g,double xp[],double yp[], int np,int ic) { int x[] = new int[np]; int y[] = new int[np]; for (int k=0; k < np; k++) { x[k] = (int)((xp[k]-disc.Left)/(disc.Right-disc.Left)*disc.Nxpixel); y[k] = (int)((yp[k]-disc.Bottom)/(disc.Top-disc.Bottom)*disc.Nypixel); y[k] = disc.Nypixel -y[k]; // if(disc.debug)System.out.println(xp[k]+" "+x[k]+" "+yp[k]+" "+y[k]); } g.setColor(new Color(disc.redm[ic],disc.greenm[ic],disc.bluem[ic])); g.fillPolygon(x,y,np); } void dsmosc(Graphics g, int nseg) { double x,y,prevx,prevy; int x1,y1; int x0 = 150; int y0 = 150; int indpo; int ind = disc.initp[nseg]; int npol = 10; if(nseg >5 && nseg <30) npol = 3; if(disc.debug)System.out.println("ind "+ind+" npol "+npol); for (int j=0; j