Commit in hps-java/src/main/java/org/lcsim/hps/users/phansson on MAIN | |||
mergeSimpleAIDA.java | +24 | -17 | 1.3 -> 1.4 |
"fixed" more strange file path behavior
diff -u -r1.3 -r1.4 --- mergeSimpleAIDA.java 11 Dec 2012 01:01:39 -0000 1.3 +++ mergeSimpleAIDA.java 11 Dec 2012 23:50:48 -0000 1.4 @@ -13,7 +13,7 @@
/** * * @author phansson
- * @version $Id: mergeSimpleAIDA.java,v 1.3 2012/12/11 01:01:39 meeg Exp $
+ * @version $Id: mergeSimpleAIDA.java,v 1.4 2012/12/11 23:50:48 meeg Exp $
*/ public class mergeSimpleAIDA {
@@ -26,6 +26,7 @@
option.addOption("d", true, "File directory"); option.addOption("o", true, "Merged file name"); option.addOption("t", false, "Print files to be merged only");
+ option.addOption("a", false, "Average histograms across files instead of just summing them");
return option; }
@@ -58,10 +59,9 @@
if (cmd.hasOption("o")) { outfile = cmd.getOptionValue("o"); }
- boolean testOnly = false; - if (cmd.hasOption("t")) { - testOnly = true; - }
+ boolean testOnly = cmd.hasOption("t"); + + boolean doAverage = cmd.hasOption("a");
File[] files = listFilesMatching(path, regexp);
@@ -73,20 +73,15 @@
System.out.println("Found " + files.length + " matching files"); if (testOnly) {
-
for (File f : files) { System.out.println(f.getName()); } } else {
- mergeFiles(files, path + "/" + outfile);
+ mergeFiles(files, outfile, doAverage);
}
- - - -
}
- public static void mergeFiles(File[] files, String outFileName) {
+ public static void mergeFiles(File[] files, String outFileName, boolean doAverage) {
System.out.println("Merging " + files.length + " into " + outFileName); AIDA aida = AIDA.defaultInstance();
@@ -96,11 +91,10 @@
for (File f : files) {
- String fname = f.getName();
System.out.println("Processing file f " + f.toString()); ITree tree = null; try {
- tree = af.createTreeFactory().create(fname);
+ tree = af.createTreeFactory().create(f.toString());
} catch (IllegalArgumentException ex) { Logger.getLogger(mergeSimpleAIDA.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) {
@@ -153,12 +147,25 @@
} } }
-
++count;
+ }
- -
+ // divide all histograms by the count to get the average + if (doAverage) { + for (String str : aida.tree().listObjectNames()) { + //if(!str.contains("Cluster energy x")) continue; + IManagedObject obj = aida.tree().find(str); + if (IHistogram.class.isInstance(obj)) { + IHistogram h = (IHistogram) obj; + if (h == null) { + System.out.println("Error " + str + " had problems to be cast to 1D?"); + continue; + } + h.scale(1.0 / count); + } + }
}
+
try { aida.saveAs(outFileName); } catch (IOException ex) {
Use REPLY-ALL to reply to list
To unsubscribe from the LCD-CVS list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=LCD-CVS&A=1