001    /*
002     * $RCSfile: SimRecoOpt.java,v $
003     *
004     *
005     * This file is part of the PHENIX Job Submission Front-End.
006     * Copyright (c) 2004 PHENIX Collaboration - Brookhaven National Laboratory
007     *
008     * The PHENIX Job Submission Front-End is free software; you can redistribute
009     * it and/or modify it under the terms of the GNU General Public License as
010     * published by the Free Software Foundation; either version 2 of the License,
011     * or (at your option) any later version.
012     *
013     * The PHENIX Job Submission Front-End is distributed in the hope that it will
014     * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
015     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016     * GNU General Public License for more details.
017     *
018     * You should have received a copy of the GNU General Public License
019     * along with the PHENIX Job Submission Front-End; if not, write to the Free
020     * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
021     * 02111-1307  USA
022     */
023    
024    package gov.bnl.phenix.offline.pjs.shared;
025    
026    import gov.bnl.phenix.offline.pjs.xml.WriteJobFiles;
027    
028    /**
029     * The <code>SimRecoOpt</code> class collects all information specified by 
030     * the {@link gov.bnl.phenix.offline.pjs.gui.SimRecoPanel} information panel. 
031     * This object is then later saved to an XML file in 
032     * {@link gov.bnl.phenix.offline.pjs.xml.WriteConfiguration#dumpConfig()} 
033     * via its inclusion in the {@link gov.bnl.phenix.offline.pjs.shared.JobDefinition#addDefinition(String key, Object value)} 
034     * routine.
035     *
036     * @author Michael Reuter
037     */
038    public class SimRecoOpt implements CommandOptions, FileConstants,
039                                       PacmanConstants { 
040        
041        /**
042         * Variable that stores the name of the simulation reconstruction macro 
043         * package name
044         */
045        private String simRecoMacroPackage;
046    
047        /**
048         * Variable that stores the text of the macro call used to run the 
049         * simulation reconstruction
050         */
051        private String macroDef;
052    
053        /**
054         * Array of the magnetic field configuration Pacman package names
055         */
056        private static String[] magFieldNames = {"zeroField", "run12_bfit", 
057                                                 "run3_bfit", "run4++_bfit", 
058                                                 "run4--_bfit", "run4+-_bfit"};
059    
060        /**
061         * Default constructor
062         */
063        public SimRecoOpt() {
064        }
065    
066        // Setters 
067        /**
068         * Sets the simulation reconstruction macro package name
069         *
070         * @param simRecoMacroPackage Name of the Simulation Reconstruction Macro Package
071         */
072        public void setSimRecoMacroPackage(String simRecoMacroPackage) {
073            this.simRecoMacroPackage = simRecoMacroPackage;
074        }
075    
076        /**
077         * Sets the simulation reconstruction macro definition
078         *
079         * @param macroDef Definition of the Simulation Reconstruction Macro  
080         */
081        public void setMacroDef(String macroDef) {
082            this.macroDef = macroDef;
083        }
084    
085        // Getters
086        /**
087         * Gets the simulation reconstruction macro package name
088         *
089         * @return Name of the Simulation Reconstruction Macro Package
090         */
091        public String getSimRecoMacroPackage() {
092            return simRecoMacroPackage;
093        }
094    
095        /**
096         * Gets the simulation reconstruction macro definition
097         *
098         * @return Definition of the Simulation Reconstruction Macro  
099         */
100        public String getMacroDef() {
101            return macroDef;
102        }
103    
104        /**
105         * Provides the simulation reconstruction specific implementation of 
106         * {@link gov.bnl.phenix.offline.pjs.shared.CommandOptions#getCommand()}. 
107         *
108         * @return the string containing the command definitions for the 
109         *         simluation reconstruction
110         */
111        public String getCommand() {
112            StringBuffer out = new StringBuffer("");
113    
114            out.append("### Simulation Reconstruction Job:").append(ENDL);
115            out.append("root.exe ").append(xmlShellInt).append(ENDL);
116            out.append(macroDef);
117            out.append(".q").append(ENDL);
118            out.append("EOF").append(ENDL);
119            
120            JobDefinition jDef = JobDefinition.getInstance();
121            int numFileTags = ((Integer)jDef.getValueForKey("JobDef.SimReco.NumFileTags")).intValue();
122            if(WriteJobFiles.OUTPUTKLUDGE) {
123                for(int i = 0; i < numFileTags; i++) {
124                    out.append("mv JobDef.SimReco.TempFile").append(i).append(" ");
125                    out.append(defaultOutputDir).append("/JobDef.SimReco.FileTag");
126                    out.append(i).append("_JobDef.SimReco.ProdTag-$run-$seg");
127                    out.append(".JobDef.SimReco.FileExt").append(i).append(ENDL);
128                }
129            }
130    
131            // Write semaphore file
132            out.append("## Create and copy semaphore file").append(ENDL);
133            out.append("set semaphorefile = ");
134            out.append("Semaphore_JobDef.JobName_$jobtag-$run-$seg.ascii");
135            out.append(ENDL);
136            out.append("cat > $semaphorefile ").append(xmlShellInt);
137            out.append(ENDL);
138            for(int i = 0; i < numFileTags; i++) {
139                out.append("$clusterstorage/JobDef.SimReco.FileTag");
140                out.append(i).append("_JobDef.SimReco.ProdTag-$run-$seg");
141                out.append(".JobDef.SimReco.FileExt").append(i);
142                out.append(" $dcachedir").append(ENDL);
143            }
144            out.append("EOF").append(ENDL);
145            out.append("cp $semaphorefile ");
146            out.append("$semaphoredir").append(ENDL);
147    
148            out.append("### End Simulation Reconstruction Job:").append(ENDL);
149    
150            return out.toString();   
151        }
152    
153        /**
154         * Provides the simulation reconstruction specific implementation of 
155         * {@link gov.bnl.phenix.offline.pjs.shared.CommandOptions#getPacman()}. 
156         *
157         * @return the string containing the Pacman definitions for the 
158         *         simluation reconstruction
159         */
160        public String getPacman() {
161            StringBuffer out = new StringBuffer("");
162    
163            JobDefinition jDef = JobDefinition.getInstance();
164            String softwareBuild = (String)jDef.getValueForKey("JobDef.SoftwareBuild");
165    
166            out.append(pacmanGet).append(" ").append(defaultCache);
167            out.append(softwareBuild).append(" ");
168            out.append(xmlShellInt).append(ENDL);
169            out.append("y").append(ENDL).append("y").append(ENDL);
170            out.append("EOF").append(ENDL);
171            out.append(pacmanGet).append(" ").append(defaultCache);
172            out.append(simRecoMacroPackage).append(ENDL);
173            out.append(pacmanGet).append(" ").append(defaultCache);
174    
175            int magFlag = ((Integer)jDef.getValueForKey("JobDef.MagneticFieldFlag")).intValue();
176            out.append(magFieldNames[magFlag]).append(ENDL);
177            out.append("echo \"Pacman status = $status\"").append(ENDL);
178            out.append("source setup.csh").append(ENDL).append(ENDL);
179            out.append("cd ${SIMRECO_EXE}").append(ENDL);
180            if(magFlag > 0) {
181                out.append("ln -s ${BFIELDDIR}fieldIntegral.dat").append(ENDL);
182            }
183    
184            return out.toString();   
185        }
186    
187        /**
188         * Provides the simulation reconstruction specific implementation of 
189         * {@link gov.bnl.phenix.offline.pjs.shared.CommandOptions#requiresInput()}. 
190         *<p>
191         * Returns a <code>boolean</code> value that informs the program that 
192         * simulation reconstruction requires input files to run.
193         * 
194         * @return a boolean informing if simluation reconstruction requires
195         *         input files
196         */
197        public boolean requiresInput() {
198            return true;
199        }
200    
201        /**
202         * Provides the simulation reconstruction specific implementation of 
203         * {@link gov.bnl.phenix.offline.pjs.shared.CommandOptions#whichInput()}. 
204         *<p>
205         * Returns a <code>String</code> value that informs the program which 
206         * input file tag simulation reconstruction needs to use.
207         * 
208         * @return a string informing which input file tag simulation 
209         * reconstruction requires
210         */
211        public String whichInput() {
212            return new String("Pisa");
213        }
214    
215        /**
216         * Provides the simulation reconstruction specific implementation of 
217         * {@link gov.bnl.phenix.offline.pjs.shared.CommandOptions#makeInputFiles(int)}. 
218         *<p>
219         *
220         * @param numFileTags number of file tags the class is expecting
221         * @return array of strings with resulting file names 
222         */
223        public String[] makeInputFiles(int numFileTags) {
224            String[] files = new String[numFileTags];
225            
226            for(int i = 0; i < numFileTags; i++) {
227                StringBuffer file = new StringBuffer("JobDef.Pisa.FileTag");
228                file.append(i).append("-").append("RunDef").append("-");
229                file.append("SegDef").append(pisaExt);
230                files[i] = file.toString();
231            }
232            
233            return files;
234        }
235    
236        /**
237         * Provides the simulation reconstruction specific implementation of 
238         * {@link gov.bnl.phenix.offline.pjs.shared.CommandOptions#makeOutputFiles(int)}. 
239         *<p>
240         *
241         * @param numFileTags number of file tags the class is expecting
242         * @return array of strings with resulting file names 
243         */
244        public String[] makeOutputFiles(int numFileTags) {
245            String[] files = new String[numFileTags];
246            
247            for(int i = 0; i < numFileTags; i++) {
248                StringBuffer file = new StringBuffer("JobDef.SimReco.FileTag");
249                file.append(i).append("_JobDef.SimReco.ProdTag").append("-");
250                file.append("RunDef").append("-").append("SegDef");
251                file.append(".JobDef.SimReco.FileExt").append(i);
252                files[i] = file.toString();
253            }
254            
255            return files;
256        }
257    
258        /**
259         * Provides the simulation reconstruction specific implementation of 
260         * {@link gov.bnl.phenix.offline.pjs.shared.CommandOptions#makeTempFiles(int)}. 
261         *<p>
262         *
263         * @param numFileTags number of file tags the class is expecting
264         * @return array of strings with resulting file names 
265         */
266        public String[] makeTempFiles(int numFileTags) {
267            String[] files = new String[numFileTags];
268    
269            for(int i = 0; i < numFileTags; i++) {
270                StringBuffer file = new StringBuffer("JobDef.SimReco.TempFile");
271                file.append(i);
272                files[i] = file.toString();
273            }
274    
275            return files;
276        }
277    
278        /**
279         * Provides the simulation reconstruction specific implementation of 
280         * {@link gov.bnl.phenix.offline.pjs.shared.CommandOptions#requiresSeedList()}. 
281         *<p>
282         * Returns a <code>boolean</code> value that informs the program that 
283         * simulation reconstruction requires a seed list.
284         * 
285         * @return a boolean informing if simulation reconstruction requires a 
286         *         seed list
287         */
288        public boolean requiresSeedList() {
289            return false;
290        }
291    }