importdata311dpsam.sh
Go to the documentation of this file.
1 #!/bin/sh
2 
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
7 # to be redone a bit.
8 
9 # set testmode to 1 to test interactively
10 testmode=0
11 
12 source /cvmfs/dune.opensciencegrid.org/products/dune/setup_dune.sh
13 setup dunetpc v06_49_00 -q e14:prof
14 
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
18 
19 # Tom's interactive testing
20 
21 if [[ $testmode = 1 ]]; then
22  _CONDOR_SCRATCH_DIR=/dune/data2/users/trj/wa105testprod/
23  path_to_dropbox=/pnfs/dune/scratch/users/trj/batchtest/
24 fi
25 path_to_working_dir=$_CONDOR_SCRATCH_DIR
26 
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}`
31 
32 touch dropboxlist.txt
33 rm dropboxlist.txt
34 ifdh ls ${path_to_dropbox} > dropboxlist.txt
35 
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
39 
40 for file in `samweb list-files file_name="wa105%.dat" | grep -v recotask | grep -v symlink`
41 do
42  echo Processing: $file
43 
44 # check to see if we already have this file, either in SAM or waiting in the dropbox
45 
46  filebase=`basename $file .dat`
47  outputfile=${filebase}_importpass2.root
48  if [[ x`grep ${outputfile} dropboxlist.txt` != x ]]; then
49  continue
50  fi
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
53  continue
54  fi
55 # if [[ x`samweb list-files file_name=${outputfile}` != x ]]; then
56 # continue
57 # fi
58 
59 
60  fileurl=`samweb get-file-access-url $file`
61  ifdh cp -D $fileurl .
62 
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
65 
66  tmp2=${tmpfilename#*r}
67  runnum=${tmp2%-*}
68  echo run number $runnum
69 
70  tmp1=${tmpfilename#*-}
71  subrun=${tmp1%.*}
72  echo subrun $subrun
73 
74  touch tmpfcl.fcl
75  rm tmpfcl.fcl
76 cat > tmpfcl.fcl <<EOF
77 #include "ImportFull311File.fcl"
78 source.PedestalFile: "$path_to_pedestal"
79 outputs.out1.compressionLevel: 1
80 EOF
81 
82  lar -c tmpfcl.fcl $tmpfilename -o $outputfile
83 
84  jsonfile=${outputfile}.json
85  touch $jsonfile
86  rm $jsonfile
87  echo Making $jsonfile
88 
89  size=`stat -c %s $outputfile`
90  nev=`echo "Events->GetEntriesFast()" | root -b -l $outputfile 2>&1 | tail -1 | cut -d')' -f2`
91  nevm1=$(($nev-1))
92  echo Number of events: $nev and minus 1: $nevm1
93 
94  dunetpcversion=`ups active | grep dunetpc | awk '{print $2}'`
95 
96 cat >> $jsonfile <<EOF
97 {
98  "file_name": "${outputfile}",
99  "file_size": ${size},
100  "file_type": "test-data",
101  "event_count": ${nev},
102  "first_event": 0,
103  "last_event": ${nevm1},
104  "runs": [ [ $runnum, "test" ] ],
105  "Online.Run": ${runnum},
106  "Online.RunNumber": ${runnum},
107  "Online.Subrun": ${subrun},
108  "file_format": "root",
109  "data_tier": "raw",
110  "group": "dune",
111  "application": {
112  "family": "art",
113  "name": "ImportFull311File",
114  "version": "${dunetpcversion}"
115  },
116  "lbne_data.name": "wa105_testdata_2017",
117  "lbne_data.detector_type": "3x1x1dp",
118  "parents": [
119  {
120  "file_name": "$file"
121  }
122  ]
123 }
124 EOF
125 
126  if [[ $testmode = 0 ]]; then
127  samweb declare-file $jsonfile
128  fi
129 
130  if [[ x`ifdh ls ${path_to_dropbox}/${outputfile}` = x ]]; then
131  ifdh cp -D ${outputfile} ${path_to_dropbox}
132  fi
133  if [[ x`ifdh ls ${path_to_dropbox}/${jsonfile}` = x ]]; then
134  ifdh cp -D ${jsonfile} ${path_to_dropbox}
135  fi
136 
137 # clean up
138  rm $file
139  rm $tmpfilename
140  rm $outputfile
141  rm $jsonfile
142  rm tmpfcl.fcl
143 
144  if [[ $testmode = 1 ]]; then
145  echo "Test mode. Just running one file"
146  exit
147  fi
148 
149 done
150