Author: [log in to unmask] Date: Tue Dec 2 15:25:35 2014 New Revision: 1626 Log: Add better handling of run numbers. Truncate computed mean and sigma to 4 decimal places. Modified: java/trunk/ecal-recon/src/main/java/org/hps/recon/ecal/EcalCalibrationsDriver.java Modified: java/trunk/ecal-recon/src/main/java/org/hps/recon/ecal/EcalCalibrationsDriver.java ============================================================================= --- java/trunk/ecal-recon/src/main/java/org/hps/recon/ecal/EcalCalibrationsDriver.java (original) +++ java/trunk/ecal-recon/src/main/java/org/hps/recon/ecal/EcalCalibrationsDriver.java Tue Dec 2 15:25:35 2014 @@ -11,6 +11,7 @@ import java.io.FileWriter; import java.io.IOException; import java.sql.SQLException; +import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; @@ -51,8 +52,11 @@ IFitFactory fitFactory = aida.analysisFactory().createFitFactory(); boolean loadCalibrations = false; boolean performFit = true; + Integer runStart = null; + Integer runEnd = null; File outputFile = null; Set<Integer> runs = new HashSet<Integer>(); + static DecimalFormat decimalFormat = new DecimalFormat("#.####"); /** * Set whether to automatically load the conditions into the database. @@ -60,6 +64,29 @@ */ public void setLoadCalibrations(boolean loadCalibrations) { this.loadCalibrations = loadCalibrations; + } + + /** + * Set the start run number for the conditions record. + * @param runStart The run start number. + */ + public void setRunStart(int runStart) { + if (runStart < 0) { + throw new IllegalArgumentException("The runStart must be >= 0."); + } + this.runStart = runStart; + } + + /** + * Set the end run number for the conditions record. + * It must be >= the runEnd. + * @param runStart The run start number. + */ + public void setRunEnd(int runEnd) { + if (runEnd < 0) { + throw new IllegalArgumentException("The runEnd must be >= 0."); + } + this.runEnd = runEnd; } /** @@ -79,6 +106,16 @@ throw new IllegalArgumentException("The outputFileName argument is null."); } outputFile = new File(outputFileName); + } + + /** + * Start of job hook. + * Check that the run numbers are valid. + */ + public void startOfData() { + if (runEnd < runStart) { + throw new IllegalArgumentException("The runEnd must be >= runStart."); + } } /** @@ -127,6 +164,14 @@ } List<Integer> runList = new ArrayList<Integer>(runs); Collections.sort(runList); + + if (runStart == null) { + runStart = runList.get(0); + } + + if (runEnd == null) { + runEnd = runList.get(runList.size() - 1); + } EcalCalibrationCollection calibrations = new EcalCalibrationCollection(); TableMetaData tableMetaData = conditionsManager.findTableMetaData(TableConstants.ECAL_CALIBRATIONS); @@ -154,6 +199,10 @@ sigma = histogram.rms(); } + // Truncate to 4 decimal places. + mean = Double.valueOf(decimalFormat.format(mean)); + sigma = Double.valueOf(decimalFormat.format(sigma)); + // Create a new calibration object and add it to the collection, using mean for pedestal // and sigma for noise. EcalCalibration calibration = new EcalCalibration(channelId, mean, sigma); @@ -184,7 +233,7 @@ // Load the calibrations into the conditions database? if (loadCalibrations) { - loadCalibrations(runList, calibrations); + loadCalibrations(calibrations); } } @@ -217,20 +266,18 @@ * @param runList The list of runs processed in the job. * @param calibrations The collection of calibration objects. */ - private void loadCalibrations(List<Integer> runList, EcalCalibrationCollection calibrations) { + private void loadCalibrations(EcalCalibrationCollection calibrations) { int collectionId = conditionsManager.getNextCollectionID(TableConstants.ECAL_CALIBRATIONS); try { calibrations.setCollectionId(collectionId); calibrations.insert(); - int runStart = runList.get(0); - int runEnd = runList.get(runList.size() - 1); ConditionsRecord conditionsRecord = new ConditionsRecord( calibrations.getCollectionId(), runStart, runEnd, TableConstants.ECAL_CALIBRATIONS, TableConstants.ECAL_CALIBRATIONS, - "Auto generated by EcalCalibrationsDriver.", + "Generated by EcalCalibrationsDriver.", "eng_run"); conditionsRecord.setTableMetaData(conditionsManager.findTableMetaData(TableConstants.CONDITIONS_RECORD)); conditionsRecord.insert();