1
2
3
4
5
6 package org.lcsim.recon.tracking.seedtracker.strategybuilder;
7
8 import java.io.File;
9 import org.lcsim.recon.tracking.seedtracker.StrategyXMLUtils;
10 import org.lcsim.util.Driver;
11 import org.lcsim.util.loop.LCSimLoop;
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 public class RunStrategyBuilder {
28 public static void main(String[] args) {
29 String filename="";
30 String outFile = StrategyBuilder.defaultOutputFile;
31 int numEvents=-1;
32 String startingStrategies = "";
33 String prototypeFile = "";
34 int prototypeN = -1;
35 boolean verbose = StrategyBuilder.defaultVerbose;
36 boolean symmetrize = StrategyBuilder.defaultSymmetrize;
37 String lwfn = "";
38 int mintrks = StrategyBuilder.defaultMinUnweightedScore;
39 String filterClassName = "";
40 String altDriver = "";
41
42
43 try{
44 int no_flag_counter = 0;
45 for (int i = 0; i < args.length; i++){
46
47 String arg = args[i];
48
49 if (arg.equals("-h")) {
50 printUsage();
51 System.exit(0);
52 } else if (arg.equals("-o")) {
53 outFile = args[++i];
54 } else if (arg.equals("-e")) {
55 numEvents = Integer.valueOf(args[++i]);
56 } else if (arg.equals("-s")) {
57 startingStrategies = args[++i];
58 } else if (arg.equals("-p")) {
59 prototypeFile = args[++i];
60 prototypeN = Integer.valueOf(args[++i]);
61 } else if (arg.equals("-v")) {
62 verbose = !verbose;
63 } else if (arg.equals("-l")) {
64 lwfn = args[++i];
65 } else if (arg.equals("-m")) {
66 mintrks = Integer.valueOf(args[++i]);
67 } else if (arg.equals("-f")) {
68 filterClassName = args[++i];
69 } else if (arg.equals("-a")) {
70 altDriver = args[++i];
71 } else if (arg.equals("-y")) {
72 symmetrize = !symmetrize;
73 } else if (arg.startsWith("-")){
74 throw new Exception();
75 } else {
76 if (no_flag_counter > 0) throw new Exception();
77 no_flag_counter++;
78 filename = arg;
79 }
80 }
81 if (no_flag_counter == 0) throw new Exception();
82
83 } catch (Exception e){
84 printUsage();
85 System.exit(1);
86 }
87 IStrategyBuilder builder = new StrategyBuilder();
88
89 if (altDriver.length() > 0) {
90 try {
91 builder = (IStrategyBuilder) Class.forName(altDriver).newInstance();
92 } catch (ClassNotFoundException cfne) {
93 System.out.println("Class "+altDriver+ " not found :'( Exiting.");
94 System.exit(3);
95 } catch (InstantiationException ie) {
96 System.out.println("Class "+altDriver+ " could not be instantiated. Does the constructor take arguments? Exiting.");
97 System.exit(4);
98 } catch (IllegalAccessException iae) {
99 System.out.println("IllegalAccessException? WTF does that mean? Exiting.");
100 System.exit(5);
101 } catch (ClassCastException cce) {
102 System.out.println("Unable to cast "+altDriver+ " as a IStrategyBuilder. Exiting");
103 System.exit(6);
104 }
105
106 if (!(builder instanceof Driver)) {
107 System.out.println("Alternative driver must extend Driver. Exiting");
108 System.exit(14123);
109 }
110 }
111
112 builder.setVerbose(verbose);
113 builder.setMinimumUnweightedScore(mintrks);
114 builder.setOutput(outFile);
115 builder.setSymmetrize(symmetrize);
116
117 if (startingStrategies.length() > 0)
118 builder.setStartingStrategyList(startingStrategies);
119
120 if (prototypeFile.length() > 0)
121 builder.setStrategyPrototype(prototypeFile,prototypeN);
122
123 if (lwfn.length() > 0)
124 builder.setLayerWeight(lwfn);
125
126
127
128 if (filterClassName.length() > 0){
129 builder.setParticleFilter(filterClassName);
130 }
131
132
133 File file = new File(filename);
134 if (!file.exists()) {
135 System.out.println("Cannot find data file "+file.toString()+". Exiting. ");
136 System.exit(7);
137 }
138
139
140 if(verbose){
141 System.out.println("Starting... Reading Geometry");
142 }
143
144
145
146 try {
147
148 LCSimLoop loop = new LCSimLoop();
149 loop.setLCIORecordSource(file);
150 loop.add( (Driver) builder );
151 loop.loop(numEvents, null);
152 loop.dispose();
153 } catch (Exception e){
154 e.printStackTrace();
155 throw new RuntimeException("oopsie");
156 }
157 }
158
159
160 private static void printUsage(){
161
162 System.out.println("Usage: RunStrategyBuilder INPUTRECORD [flags]");
163 System.out.println(" -h \t\t\t\tPrint this message");
164 System.out.println(" -v \t\t\t\tBe verbose");
165 System.out.println(" -y \t\t\t\tDon't auto-symmetrize north/south. \n\t\t\t\t You may want to do this is starting strategies\n\t\t\t\t aren't symmetric.");
166 System.out.println(" -o OUTPUTFILE \t\t\tset output XML file to OUTPUTFILE\n\t\t\t\t (default is in TEMP dir)");
167 System.out.println(" -e NUM_EVENTS \t\t\tRun only NUM_EVENTS events instead of all");
168 System.out.println(" -s STARTING_STRATEGY_FILE \tUse starting strategies in the specified file");
169 System.out.println(" -p PROTOTYPE_STRATEGY_FILE N\tUse the Nth strategy in the specified file\n\t\t\t\t as a prototype. N is 0-indexed.");
170 System.out.println(" -l LAYER_WEIGHTS_FILE\t\tUse the weights in the specified file");
171 System.out.println(" -m MIN_TRKS_FOR_STRATEGY \tMinimum number of tracks to \n\t\t\t\t that could theoretically be found" +
172 "\n\t\t\t\tnecessary to make a strategy\n\t\t\t\t (default: 3)");
173 System.out.println(" -f FILTER_CLASS\t\tSpecify an MCParticle filter by naming a " +
174 "\n\t\t\t\t fully qualified (i.e. org.lcsim.etc) class. \n\t\t\t\t By default, " +
175 "a filter based on the prototype \n\t\t\t\t strategy cutoffs is used.");
176 System.out.println(" -a ALTERNATIVE_DRIVER\t\tUse an alternative driver instead of \n\t\t\t\t the default StrategyBuilder. " +
177 "Must implement\n\t\t\t\t IStrategyBuilder and extend Driver. UNTESTED.\n\t\t\t\t " +
178 "Fully qualified class name must be used \n\t\t\t\t (i.e. org.lcsim.etc)");
179 }
180
181 }