forked from A2-Collaboration/a2geant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathA2G4Farm
executable file
·145 lines (117 loc) · 4.41 KB
/
A2G4Farm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/sh
#Give the args some sensible names
MacroBase=$1
JobName=$2
FileList=$3
####################################################
###### Beginning of section requiring editing ######
####################################################
#Location and suffix for input files
InputDir="/local/raid0/work/${USER}/MC/g-C12_pi0-C12_thr"
InputPre="EventGen_"
#Location and suffix for output files
OutputDir="/local/raid1/work/${USER}/analysis/${JobName}"
OutputPre="A2G4_"
#Who'll get the emails from the farm
MailAddress="[email protected]"
####################################################
###### End of section requiring editing ############
####################################################
#get the name of this executable
exe=`basename $0`
#the maximum time the job will be allowed HH:MM:SS
#This is the max allowed on the batch_x86 queue.
#Set high in case
WALLTIME=6:00:00
print_usage(){
echo
echo "Usage:"
echo "$exe <Geant4Macro> <JobName> <FileList>"
echo
echo "<Geant4Macro>: Top level Geant4 macro file"
echo "<JobName>: A directory jobs/<JobName> will be created"
echo " if it doesn't exist and scripts put there"
echo "<FileList>: (Optional) list of files to run, otherwise"
echo " run all files in input directory"
echo "Examples: "
echo "$exe macros/doCompton.mac myjob ComptonFiles.dat"
echo "$exe macros/doCompton.mac myjob"
}
#check that we have all the args, otherwise print use
if [ $# -lt 2 ]; then
print_usage;
exit 0;
fi
#if there's no file list specified, then scan input directory into temp
if [ $# -lt 3 ]; then
FileList="TempList.dat"
ls -1 $InputDir/${InputPre}*.root | xargs -n1 basename > $FileList
fi
MainDir=`pwd`
#make some subdirectories for job and setup files
JobDir="jobs/$JobName"
mkdir -p $JobDir
mkdir -p "$JobDir/jobfiles"
MacroDir="${JobDir}/macrofiles"
mkdir -p $MacroDir
mkdir -p $OutputDir
mkdir -p "${OutputDir}/root"
mkdir -p "${OutputDir}/log"
#Make a macro file template with all non-comment
#lines except the input and output file lines
Template="${MacroDir}/A2G4Template.dat"
echo "#Geant4 setup file created automatically using A2G4Farm with $MacroBase as basis." > $Template
echo "#All comments are stripped out" >> $Template
gawk '{if(($1!~"#")&&($1!~"/A2/generator/InputFile")&&($1!~"/A2/event/setOutputFile"))print $0}' $MacroBase >> $Template
#Loop over each line and create the job files
while read line
do
echo "Making a job for Files: $line";
#strip off the .root, and any directory paths
BaseName=`basename $line .root | sed "s/${InputPre}//"`
JobFile="${JobDir}/jobfiles/${BaseName}.sub"
MacroFile="${MacroDir}/${BaseName}.mac"
NodeDir="/scratch/${USER}/${BaseName}"
#write the macro file by copying the template and
#tagging on lines for the input and output files
cp $Template $MacroFile
echo "/A2/generator/InputFile $InputDir/$line" >> $MacroFile
echo "/A2/event/setOutputFile $NodeDir/${OutputPre}${BaseName}.root" >> $MacroFile
#now make the job file
echo "#!/bin/sh" > $JobFile;
echo "#PBS -N A2G4_${USER}" >> $JobFile;
echo "#PBS -m abe" >> $JobFile;
echo "#PBS -M $MailAddress" >> $JobFile;
echo "#PBS -V" >> $JobFile;
echo "#PBS -lwalltime=${WALLTIME}" >> $JobFile;
echo "#PBS -e ${JobDir}/jobfiles" >> $JobFile;
echo "#PBS -o ${JobDir}/jobfiles" >> $JobFile;
echo "#PBS -q batch_x86_64" >> $JobFile;
echo "#" >> $JobFile;
# echo "#InputDir: ${InputDir}" >> $JobFile;
echo "#InputFiles: $line" >> $JobFile;
echo "#" >> $JobFile;
echo "export A2G4_MAINDIR=\"$MainDir\"" >> $JobFile;
echo "export A2G4_MACROFILE=\"$MacroFile\"" >> $JobFile;
echo "export A2G4_NODEDIR=\"$NodeDir\"" >> $JobFile;
echo "export A2G4_OUTPUTDIR=\"$OutputDir\"" >> $JobFile;
echo "#" >> $JobFile;
echo "#This is the executable that gets run on the node" >> $JobFile;
echo "A2G4Node" >> $JobFile;
echo "#" >> $JobFile;
echo "exit 0" >> $JobFile;
echo "##end of job script" >> $JobFile;
chmod +x $JobFile;
done < $FileList
topFile=`ls -1 -r ${MacroDir}/*.mac | tail -1`
topJob=`ls -1 -r ${JobDir}/jobfiles/*.sub | tail -1`
echo
echo "Job submission scripts are in ${JobDir}/jobfiles."
echo "Geant4 macro files are in ${MacroDir}"
echo
echo "Here's the corrseponding job submission script:"
echo "cat $topJob"
echo
cat $topJob
echo
echo