/** Default Constructor */ public DetIDGenerator() { query = new String(); try { c = CDBConnection.getConnection(); if (DetIDGenerator.export || DetIDGenerator.updateCB) { /* Just to check that we can connect to the export database Better to see it now rather than after all the computing... */ configureExportDatabaseConnection(); c.connect(); c.disconnect(); // Ok it's working, let's go! } c.setUser("prod_consult"); c.setUrl( "jdbc:oracle:thin:@(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = ccdbcl01.in2p3.fr)(PORT = 1521))(ADDRESS = (PROTOCOL = TCP)(HOST = ccdbcl02.in2p3.fr)(PORT = 1521))(LOAD_BALANCE = yes)(CONNECT_DATA = (SERVER = DEDICATED)(SERVICE_NAME = cccmstrktaf.in2p3.fr)(FAILOVER_MODE =(TYPE = SELECT)(METHOD = BASIC)(RETRIES = 180)(DELAY = 5))))"); c.setPassword("am8bilo8gy"); c.connect(); } catch (java.sql.SQLException e) { Error("SQL Error : \n" + query + "\n" + e.getMessage()); } catch (java.lang.ClassNotFoundException e) { Error("Can not find Oracle driver"); } }
private void exportData(ArrayList<ArrayList<String>> list) throws java.sql.SQLException, ClassNotSupportedException { c.disconnect(); if (DetIDGenerator.mtcc) { for (String[] s : TOBMTCC) { ArrayList<String> n = new ArrayList<String>(); n.add(s[0]); n.add(s[1]); n.add(s[2]); n.add(s[3]); list.add(n); } } if (DetIDGenerator.export) { configureExportDatabaseConnection(); c.connect(); } else { System.out.print( "<?xml version=\"1.0\"?>\n<ROWSET xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation='http://cmsdoc.cern.ch/cms/cmt/System_aspects/FecControl/binaries/misc/conversionSchema.xsd'>\n"); } for (int i = 0; i < list.size(); i++) { ArrayList<String> v = list.get(i); int dcuID = Integer.parseInt(v.get(0)); int detID = Integer.parseInt(v.get(1)); float length = new java.lang.Float(v.get(2)); int apvNumber = Integer.parseInt(v.get(3)); if (DetIDGenerator.export) { int res = ((OracleConnection) c) .callFunction("PkgDcuInfo.setValues", dcuID, detID, length, apvNumber); // ArrayList<ArrayList<String>> count = c.selectQuery("select count(*) from dcuInfo"); // if(count.size()!=0){ // int nbOk = Integer.parseInt(count.get(0).get(0)); // System.out.println(v); // System.out.println("Trace : Nb in db : "+nbOk+"\nInsertion Nb : "+i+"\nPLSQL result // :"+res+"\n"); // } } else { System.out.println( "<DCUINFO dcuHardId=\"" + dcuID + "\" detId=\"" + detID + "\" fibreLength=\"" + length + "\" apvNumber=\"" + apvNumber + "\" />"); } if (DetIDGenerator.verbose) System.out.print(((i * 100) / list.size()) + " %\r"); } if (!DetIDGenerator.export) { System.out.println("</ROWSET>"); } }
/** * Perform the treatment : * * <ul> * <li>Get the Det IDs for TEC and TOB * <li>Get the DCU IDs associated to the module IDs * <li>Get the fiber's length * <li>Get the number of APVs * <li>Export the data to a DB or print them on the screen * </ul> */ public void go() { try { ArrayList<ArrayList<String>> list = new ArrayList<ArrayList<String>>(); IDetIdGenerator tec = new TECAnalyzer(); IDetIdGenerator tob = new TOBAnalyzer(); list.addAll(tec.getDetIds()); list.addAll(tob.getDetIds()); if (DetIDGenerator.verbose) System.out.println(list.size() + " modules found"); if (!DetIDGenerator.updateCB) { if (DetIDGenerator.verbose) System.out.println("Retrieving the fibers length..."); getFiberLength(list); } if (DetIDGenerator.verbose) System.out.println("Converting DetIds to 32 bits..."); compactDetIds(list); if (!DetIDGenerator.updateCB) { if (DetIDGenerator.verbose) System.out.println("Retrieving the number of APVs..."); getApvNumber(list); } if (DetIDGenerator.verbose) System.out.println("Searching the DCU ids..."); getDCU(list); if (DetIDGenerator.verbose) System.out.println("Reversing the DCU ids..."); reverseDcuIds(list); if (!DetIDGenerator.updateCB) { if (DetIDGenerator.verbose) System.out.println("Exporting..."); exportData(list); } else { System.out.println("updating the construction DB..."); updateConstructionDB(list); } c.disconnect(); } catch (java.sql.SQLException e) { Error("SQL Error : \n" + query + "\n" + e.getMessage()); } catch (ClassNotSupportedException e) { Error("ClassNotSupportedException :\n" + e.getMessage()); } catch (java.lang.ClassNotFoundException e) { Error("Can not find Oracle driver"); } catch (Exception e) { Error("Error : \n" + e.getMessage()); } }
private void updateConstructionDB(ArrayList<ArrayList<String>> list) throws java.sql.SQLException, ClassNotSupportedException, java.lang.Exception { if (DetIDGenerator.updateCB) { c.disconnect(); configureExportDatabaseConnection(); c.connect(); c.beginTransaction(); c.executeQuery("delete tec_detid"); c.executeQuery("delete tob_detid"); for (ArrayList<String> record : list) { int dcuID = Integer.parseInt(record.get(0)); int detID = Integer.parseInt(record.get(1)); DetIdConverter det = new DetIdConverter(detID); if (det.getSubDetector() == 6) { // TEC TECDetIdConverter d = new TECDetIdConverter(detID); d.compact(); String query = "insert into tec_detid (DETECTOR,DISK,SECTOR,FRONT_BACK,RING,POSITION,STEREO,DCUID,DETID) values (\'TEC" + (d.getTEC() == 1 ? "-" : "+") + "\'," + d.getWheel() + "," + d.getPetal() + ",'" + (d.getFrontBack() == 1 ? "F" : "B") + "'," + d.getRing() + "," + d.getModNumber() + ",'" + ((d.getStereo() == 1) ? "S" : (d.getStereo() == 0 ? "G" : "M")) + "'," + dcuID + "," + detID + ")"; System.out.println(query); c.executeQuery(query); } if (det.getSubDetector() == 5) { // TOB TOBDetIdConverter d = new TOBDetIdConverter(detID); d.compact(); String query = "insert into tob_detid (LAYER,ROD,FRONT_BACK,POSITION,STEREO,DCUID,DETID) values (" + d.getLayer() + "," + d.getRod() + ",'" + (d.getFrontBack() == 1 ? "F" : "B") + "'," + d.getModNumber() + ",'" + ((d.getStereo() == 1) ? "S" : (d.getStereo() == 0 ? "U" : "R")) + "'," + dcuID + "," + detID + ")"; System.out.println(query); c.executeQuery(query); // System.out.println(dcuID+","+detID+",TOB,"+d.getLayer()+","+d.getRod()+","+d.getFrontBack()+","+d.getModNumber()+","+d.getStereo()); } } c.commit(); } }