/** StaveRankingByLab.java Pixel database, java application PDB query. Main program Author : Polina.Netchaeva@ge.infn.it Created : 2-09-2004 Modified : 11-04-2005 by Attilio.Andreazza@mi.infn.it including bug fixes and improvements from W. Walkoviak (command line interfaces) Modified : 11-03-2006 by Attilio.Andreazza@mi.infn.it Added stave manufacturer in printout. : 10-04-2006 by Attilio Andreazza Added a date field to select only tests before a certain date (useful to trace evolution of damages on staves) : 13-04-2006 by Attilio Andreazza Do not call System.exit when invoked in batch mode (needed for the StaveRankingReport) : 17-05-2006 by Attilio Andreazza Allow report with new stave number 1114### : 19-07-2006 by Attilio Andreazza Created static function RunStaveRanking to call from StaveRankingReport without using X11 : 23-07-2006 by Attilio Andreazza added two columns in the _module file, containin last test date and location for each module. **/ import PIXLibrary.*; import java.awt.*; import java.awt.event.*; import java.util.StringTokenizer; import java.lang.*; import java.text.*; import java.sql.*; import java.io.*; public class StaveRanking extends Frame { static String version="StaveRanking: version 2006-07-23"; static String version2=ModuleRanking.getVersion(); static SimpleDateFormat df= new SimpleDateFormat("dd/mm/yyyy"); static Connection conn=null; static int nb=1, ns=0, np=0, nt=0, nt1=0, nc1=0; static String s[] = new String[1000000]; static String t[] = new String[1000]; static String t1[] = new String[1000]; static String tp[] = new String[11]; static String tp1[] = new String[11]; static String tc[] = new String[1000000]; static String c1[] = new String[2000]; static String snStave; static int NM = 13; static int Bad_pixels[] = {0,0,0,0,0,0,0,0,0,0,0,0,0}; static String snModules[] = {"0","0","0","0","0","0","0","0","0","0","0","0","0"}; static int Bad_pixels_s=0; static boolean batch_mode = false; Label versionlabel = new Label(version); Label version2label = new Label(version2); TextField usertext = new TextField(14); Label userlabel = new Label("Username :"); TextField passwdtext = new TextField(14); Label passwdlabel = new Label("Password :"); TextField ownertext = new TextField(14); String ownerkind = "Owner (P_***) :"; Label ownerlabel = new Label(" "); Label date_label = new Label("Test date (DD/MM/YYYY):"); String date = "today"; TextField date_text = new TextField(date,10); Color date_color = Color.black; Button buttonSearch = new Button("Change search criteria"); String search = "Owner"; Button buttonOK = new Button("OK"); Button buttonQuit = new Button("QUIT"); public static void main(String[] args) { if ( args.length > 0 && args[0].matches("-h") ) usage(); try { new StaveRanking(args); } catch (Exception exception) { System.err.println("StaveRanking attribute failed ! " + exception); } } private String GetPassword() { String password = passwdtext.getText(); return password; } private String GetUsername() { String username = usertext.getText(); return username; } private String GetOwner() { String owner = ownertext.getText().toUpperCase(); if (owner.compareTo("SENT") == 0) owner = "Sent"; return owner; } private String GetDate() { String date = date_text.getText(); return date; } public void DrawWindow() { passwdtext.setEchoChar('.'); GridBagConstraints gbc1 = new GridBagConstraints(); // normal object GridBagConstraints gbc2eor = new GridBagConstraints(); // End of row object gbc1.gridx=GridBagConstraints.RELATIVE; gbc1.gridy=GridBagConstraints.RELATIVE; gbc1.insets = new Insets(5,5,5,5); gbc2eor.gridx=GridBagConstraints.RELATIVE; gbc2eor.gridy=GridBagConstraints.RELATIVE; gbc2eor.insets = new Insets(5,5,5,5); gbc2eor.gridwidth = GridBagConstraints.REMAINDER; GridBagLayout gbl = new GridBagLayout(); this.setLayout(gbl); // add the object onto this frame ownerlabel.setText(ownerkind); this.add(ownerlabel, gbc1); this.add(ownertext, gbc2eor); this.add(buttonSearch, gbc2eor); date_text.setText(date); this.add(date_label, gbc1); this.add(date_text, gbc2eor); this.add(userlabel, gbc1); this.add(usertext, gbc2eor); this.add(passwdlabel, gbc1); this.add(passwdtext, gbc2eor); this.add(buttonQuit,gbc1); this.add(buttonOK,gbc2eor); this.add(versionlabel,gbc1); this.add(version2label,gbc1); this.setFont(new Font("Courier", Font.PLAIN, 12)); this.pack(); this.show(); } public StaveRanking(String[] args) { super("Stave Ranking (Pixel Database)"); // create the window if ( args.length > 0 ) { batch_mode = true; batchSetInputValues(args); } passwdtext.setEchoChar('.'); buttonOK.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { RunStaveRanking(GetUsername(), GetPassword(), GetOwner(), search, GetDate()); if ( !batch_mode ) System.exit(0); } } ); buttonSearch.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (search.compareTo("Owner")==0) { search ="Mfr"; ownerkind="Mfr. (P_***) :"; } else if (search.compareTo("Mfr")==0) { search ="Stave"; ownerkind="Stave S/N :"; } else if (search.compareTo("Stave")==0) { search ="Owner"; ownerkind="Owner (P_***) :"; } DrawWindow(); } } ); buttonQuit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Good bye."); System.exit(0); } } ); if ( batch_mode ) { buttonOK.dispatchEvent( new ActionEvent(buttonOK,ActionEvent.ACTION_PERFORMED,"OK")); } else { DrawWindow(); } } static public void RunStaveRanking (String UserName, String Password, String Owner, String Criteria, String Date ) { try { conn=PDB_Lib.connectToDB(UserName,Password); // find item serial numbers by given item parameters: if ( Criteria.compareTo("Owner")==0 ) { String StaveOwner = Owner; s = PDB_Lib.SNquery_ITEMS(conn,"%","%","StaveAssembly","%","%","%","NO","NO","%","%","%","%","%","%","%",StaveOwner); ns= Integer.parseInt(s[0]); np= 1; nb= 1; } else if ( Criteria.compareTo("Mfr")==0 ) { String StaveManufacturer = Owner; s = PDB_Lib.AssemblySNandPositionByParameters(conn,"%","%","%","%","%","%","StaveAssembly","Stave","%","%",StaveManufacturer); ns= 3*Integer.parseInt(s[0]); np= 3; nb= 1; } else if ( Criteria.compareTo("Stave")==0 ) { String StaveSN = Owner; try { if ( Integer.parseInt(StaveSN)<9999 ) StaveSN = "2021200001"+StaveSN; else if ( Integer.parseInt(StaveSN)<19999 ) StaveSN = "202120000"+StaveSN; // AA060517 else if ( Integer.parseInt(StaveSN)<1119999 ) StaveSN = "2021200"+StaveSN; // AA060517 } catch ( Exception e1) { // do nothing } s = PDB_Lib.SNquery_ITEMS(conn,StaveSN,StaveSN,"StaveAssembly","%","%","%","%","%","%","%","%","%","%","%","%","%"); ns= Integer.parseInt(s[0]); np= 1; nb= 1; } else ns=0; System.out.println("Staves found : "+s[0]); // If more than one item found, open the output files and start looping over the modules. if (ns>0) { String AssemblyData[] = new String[7]; String ModuleData[] = new String[13]; String StaveData[] = new String[13]; String myFile = "StaveRanking_"+ Owner + "_modules.txt"; FileOutputStream fos = new FileOutputStream(myFile); PrintStream ps = new PrintStream(fos); String myFile2 = "StaveRanking_"+ Owner +"_debug.txt"; FileOutputStream fos2= new FileOutputStream(myFile2); PrintStream ps2 = new PrintStream(fos2); String myFile3 = "StaveRanking_"+ Owner +".txt"; FileOutputStream fos3= new FileOutputStream(myFile3); PrintStream ps3 = new PrintStream(fos3); ps2.println("items found : "+s[0]); ps2.println(" "); ps2.println(" "); ps.println("S/N \tPASSED\tASSEMBLED\tRANKED\tranking\tNew bad" +"\tsource\tdig.\telctr.\tanalog\tmech." +"\tdisp\tnoise\txtalk\tin-time\tToT\tVDDD" +"\tIleak\trework\tbow\tuser\tdisc.\trebond" +"\tOwner\tMfr\tBumps" +"\tuser stave\tin spec\tTC warm\tTC cold\tStave penalty\tlast test date\tlast test owner"); ps3.println("S/N \tRanking\tAssembled" +"\tModule 1\tranking" +"\tModule 2\tranking" +"\tModule 3\tranking" +"\tModule 4\tranking" +"\tModule 5\tranking" +"\tModule 6\tranking" +"\tModule 7\tranking" +"\tModule 8\tranking" +"\tModule 9\tranking" +"\tModule 10\tranking" +"\tModule 11\tranking" +"\tModule 12\tranking" +"\tModule 13\tranking" ); for (int i=nb; i<=ns; i+=np) { String StaveManufacturer = "Unknown"; boolean ranked=true; Bad_pixels_s=0; ps2.println("Stave S/N: "+s[i]); StaveData = PDB_Lib.ParametersByItemSN(conn,s[i]); c1=PDB_Lib.AssemblySNandPositionByParameters(conn,s[i],s[i],"%","%","%","%","%","Stave","%","%","%"); if ( Integer.parseInt(c1[0])==1 ) { AssemblyData=PDB_Lib.AssemblyParametersBySNandPosition(conn,s[i],c1[2],"1"); StaveManufacturer = AssemblyData[6]; } c1=PDB_Lib.AssemblySNandPositionByParameters(conn,s[i],s[i],"%","%","%","%","%","Module","%","%","%"); for (int a=0; a=0) Bad_pixels_s+=Bad_pixels[id]; else ranked=false; } // If stave is assembled, look for S/N of assembled bi-stave // and replace that in StaveData[4] if ( StaveData[4].compareTo("YES") == 0 ) { c1 = PDB_Lib.AssemblySNByComponentSN(conn,s[i]); int id = Integer.parseInt(c1[0]); if ( id==1 ) StaveData[4]=c1[1]; } ps.println(s[i] +"\t"+StaveManufacturer+"\t"+StaveData[4] +"\t"+ranked+"\t" +Bad_pixels_s+"\t"+StaveData[12]); ps3.println(s[i]+"\t"+Bad_pixels_s+"\t"+StaveData[4] +"\t"+snModules[ 0]+"\t"+Bad_pixels[ 0] +"\t"+snModules[ 1]+"\t"+Bad_pixels[ 1] +"\t"+snModules[ 2]+"\t"+Bad_pixels[ 2] +"\t"+snModules[ 3]+"\t"+Bad_pixels[ 3] +"\t"+snModules[ 4]+"\t"+Bad_pixels[ 4] +"\t"+snModules[ 5]+"\t"+Bad_pixels[ 5] +"\t"+snModules[ 6]+"\t"+Bad_pixels[ 6] +"\t"+snModules[ 7]+"\t"+Bad_pixels[ 7] +"\t"+snModules[ 8]+"\t"+Bad_pixels[ 8] +"\t"+snModules[ 9]+"\t"+Bad_pixels[ 9] +"\t"+snModules[10]+"\t"+Bad_pixels[10] +"\t"+snModules[11]+"\t"+Bad_pixels[11] +"\t"+snModules[12]+"\t"+Bad_pixels[12] ); } fos2.close(); ps.close(); fos.close(); ps2.close(); fos3.close(); ps3.close(); } } catch (Exception exception) { System.err.println("StaveRanking failed ! " + exception); } } public void batchSetInputValues(String[] args) { // User if ( args.length > 0 ) usertext.setText(args[0]); // Passwd if ( args.length > 1 ) passwdtext.setText(args[1]); // Owner if ( args.length > 2 ) { ownertext.setText(args[2]); } else { ownertext.setText("P_SIE"); } // Search search = ( args.length > 3 ) ? args[3] : "Mfr"; date_text.setText("today"); } static public void usage() { System.out.println("\nUsage:"); System.out.println("StaveRanking "+ " "+ " "+ " " ); System.exit(0); } }