3 # Tom Junk, August 2017
4 # import data from wa105 raw .dat files to larsoft root files.
5 # since the CPU usage is so slight, import all of the files in one job. If the job does not finish, it can
6 # be resubmitted and it will pick up where it left off. If we need to parallelize this, then the logic will have
9 # set testmode to 1 to test interactively
12 source /cvmfs/dune.opensciencegrid.org/products/dune/setup_dune.sh
13 setup dunetpc v06_49_00 -q e14:prof
15 # change this when we install pedestals in dune_pardata:
16 data_path_to_pedestal=/pnfs/dune/persistent/users/trj/wa105pedestals/pedestal_run729_1.ped
17 path_to_dropbox=/pnfs/dune/scratch/dunepro/dropbox/data
19 # Tom's interactive testing
21 if [[ $testmode = 1 ]]; then
22 _CONDOR_SCRATCH_DIR=/dune/data2/users/trj/wa105testprod/
23 path_to_dropbox=/pnfs/dune/scratch/users/trj/batchtest/
25 path_to_working_dir=$_CONDOR_SCRATCH_DIR
27 mkdir -p $path_to_working_dir
28 cd $path_to_working_dir
29 ifdh cp -D ${data_path_to_pedestal} .
30 path_to_pedestal=`basename ${data_path_to_pedestal}`
34 ifdh ls ${path_to_dropbox} > dropboxlist.txt
36 touch alreadyinsamlist.txt
37 rm alreadyinsamlist.txt
38 samweb list-files file_name=wa105%.root and data_tier=raw and lbne_data.name=wa105_testdata_2017 and version=v06_49_00 > alreadyinsamlist.txt
40 for file in `samweb list-files file_name="wa105%.dat" | grep -v recotask | grep -v symlink`
42 echo Processing: $file
44 # check to see if we already have this file, either in SAM or waiting in the dropbox
46 filebase=`basename $file .dat`
47 outputfile=${filebase}_importpass2.root
48 if [[ x`grep ${outputfile} dropboxlist.txt` != x ]]; then
51 # efficiency speedup -- use the grep of just one samweb command output instead of querying SAM for every file
52 if [[ x`grep ${outputfile} alreadyinsamlist.txt` != x ]]; then
55 # if [[ x`samweb list-files file_name=${outputfile}` != x ]]; then
60 fileurl=`samweb get-file-access-url $file`
63 tmpfilename=`echo $file | sed -e "s/wa105\_/wa105/" | sed -e "s/\_s/-/" | sed -e "s/\_.*.dat/.dat/" | sed -e "s/wa105/wa105\_/"`
64 ln -s $file $tmpfilename
66 tmp2=${tmpfilename#*r}
68 echo run number $runnum
70 tmp1=${tmpfilename#*-}
76 cat > tmpfcl.fcl <<EOF
77 #include "ImportFull311File.fcl"
78 source.PedestalFile: "$path_to_pedestal"
79 outputs.out1.compressionLevel: 1
82 lar -c tmpfcl.fcl $tmpfilename -o $outputfile
84 jsonfile=${outputfile}.json
89 size=`stat -c %s $outputfile`
90 nev=`echo "Events->GetEntriesFast()" | root -b -l $outputfile 2>&1 | tail -1 | cut -d')' -f2`
92 echo Number of events: $nev and minus 1: $nevm1
94 dunetpcversion=`ups active | grep dunetpc | awk '{print $2}'`
96 cat >> $jsonfile <<EOF
98 "file_name": "${outputfile}",
100 "file_type": "test-data",
101 "event_count": ${nev},
103 "last_event": ${nevm1},
104 "runs": [ [ $runnum, "test" ] ],
105 "Online.Run": ${runnum},
106 "Online.RunNumber": ${runnum},
107 "Online.Subrun": ${subrun},
108 "file_format": "root",
113 "name": "ImportFull311File",
114 "version": "${dunetpcversion}"
116 "lbne_data.name": "wa105_testdata_2017",
117 "lbne_data.detector_type": "3x1x1dp",
126 if [[ $testmode = 0 ]]; then
127 samweb declare-file $jsonfile
130 if [[ x`ifdh ls ${path_to_dropbox}/${outputfile}` = x ]]; then
131 ifdh cp -D ${outputfile} ${path_to_dropbox}
133 if [[ x`ifdh ls ${path_to_dropbox}/${jsonfile}` = x ]]; then
134 ifdh cp -D ${jsonfile} ${path_to_dropbox}
144 if [[ $testmode = 1 ]]; then
145 echo "Test mode. Just running one file"