 <?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.lhep.unibe.ch/index.php?action=history&amp;feed=atom&amp;title=Create_flat_tree_mass.sh</id>
	<title>Create flat tree mass.sh - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.lhep.unibe.ch/index.php?action=history&amp;feed=atom&amp;title=Create_flat_tree_mass.sh"/>
	<link rel="alternate" type="text/html" href="https://wiki.lhep.unibe.ch/index.php?title=Create_flat_tree_mass.sh&amp;action=history"/>
	<updated>2026-05-14T00:15:26Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.8</generator>
	<entry>
		<id>https://wiki.lhep.unibe.ch/index.php?title=Create_flat_tree_mass.sh&amp;diff=149&amp;oldid=prev</id>
		<title>Lhep: 1 revision imported</title>
		<link rel="alternate" type="text/html" href="https://wiki.lhep.unibe.ch/index.php?title=Create_flat_tree_mass.sh&amp;diff=149&amp;oldid=prev"/>
		<updated>2015-03-18T07:49:24Z</updated>

		<summary type="html">&lt;p&gt;1 revision imported&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 09:49, 18 March 2015&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Lhep</name></author>
	</entry>
	<entry>
		<id>https://wiki.lhep.unibe.ch/index.php?title=Create_flat_tree_mass.sh&amp;diff=148&amp;oldid=prev</id>
		<title>Lhep at 13:26, 25 October 2013</title>
		<link rel="alternate" type="text/html" href="https://wiki.lhep.unibe.ch/index.php?title=Create_flat_tree_mass.sh&amp;diff=148&amp;oldid=prev"/>
		<updated>2013-10-25T13:26:55Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;The following shell script allows the creation of Highland flat trees from an entire run. It should be easy to modify for running any software on entire ND280 runs (look for the line running RunCreateFlatTree.exe). You need to have the [[Create_list_of_data_files_for_ND280_runs|lists of files]] in the same directory.&lt;br /&gt;
&lt;br /&gt;
Note: this will create a directory with one root file per oaAnalysis file. Run the analysis on the individual files to make sure also the nRooTracker tree is keept. Don&amp;#039;t use hadd!&lt;br /&gt;
&lt;br /&gt;
There are also a lot of log files and empty control files created in the output directory. Feel free to delete them, once everything is finished tested, but keep in mind they are needed if you need to rerun the script to repeat failed runs!&lt;br /&gt;
&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 ###################################################################################################&lt;br /&gt;
 #&lt;br /&gt;
 # create_flat_tree_mass.sh&lt;br /&gt;
 #&lt;br /&gt;
 # Set LIST to a list of file names to process, starting with &amp;quot;/production005/...&amp;quot;.&lt;br /&gt;
 # OUTDIR will be the name of the directory to put the files in.&lt;br /&gt;
 # NCPU is the number of parallel running processes. The limit might be exceeded occaisonally.&lt;br /&gt;
 # Don&amp;#039;t change the PREFIX, this points to our SE.&lt;br /&gt;
 #&lt;br /&gt;
 if [ -z &amp;quot;$1&amp;quot; -o ! -f &amp;quot;list_$1&amp;quot; ]; then&lt;br /&gt;
   echo &amp;quot;Specify one of the following runs:&amp;quot;&lt;br /&gt;
   ls list_run* | sed -e &amp;quot;s/list_//g&amp;quot;&lt;br /&gt;
   exit 1&lt;br /&gt;
 fi&lt;br /&gt;
 LIST=&amp;quot;list_$1&amp;quot;&lt;br /&gt;
 OUTDIR=&amp;quot;flattree_$1&amp;quot;&lt;br /&gt;
 NCPU=4&lt;br /&gt;
 PREFIX=&amp;quot;srm://dpm.lhep.unibe.ch/dpm/lhep.unibe.ch/home/t2k.org&amp;quot;&lt;br /&gt;
 #&lt;br /&gt;
 # Hint for real experts:&lt;br /&gt;
 #&lt;br /&gt;
 # If there are broken files on our SE (usually indicated by reproducable prefetch failures), delete&lt;br /&gt;
 # them using the following command:&lt;br /&gt;
 #   for i in &amp;lt;put_list_failed_runs_here&amp;gt; ; do lcg-del -l `cat &amp;lt;put_outdir_here&amp;gt;/prefetch.$i.log | grep SURL | sed -e &amp;quot;s/^.*SURL //&amp;quot; -e &amp;quot;s/ ...$//&amp;quot; | head -n 1` ; done&lt;br /&gt;
 # and run grid-replicate.sh again. DO THIS ONLY IF YOU KNOW WHAT YOU ARE DOING!&lt;br /&gt;
 #&lt;br /&gt;
 ###################################################################################################&lt;br /&gt;
 &lt;br /&gt;
 #&lt;br /&gt;
 # set priority&lt;br /&gt;
 #&lt;br /&gt;
 renice 10 -p $$ &amp;gt; /dev/null&lt;br /&gt;
 &lt;br /&gt;
 #&lt;br /&gt;
 # clean up potential left-overs from last run&lt;br /&gt;
 #&lt;br /&gt;
 if [ -e $OUTDIR ]; then&lt;br /&gt;
   echo -n &amp;quot;Warning: output directory $OUTDIR is not empty. Delete all files in it, try to resume, or abort (d/r/a)? &amp;quot;&lt;br /&gt;
   read -n 1 answer&lt;br /&gt;
   echo &amp;quot;&amp;quot;&lt;br /&gt;
   if [ &amp;quot;$answer&amp;quot; = &amp;quot;d&amp;quot; ]; then&lt;br /&gt;
     rm -rf $OUTDIR&lt;br /&gt;
   elif [ &amp;quot;$answer&amp;quot; = &amp;quot;r&amp;quot; ]; then&lt;br /&gt;
     RESUME=1&lt;br /&gt;
   else&lt;br /&gt;
     echo &amp;quot;Aborted.&amp;quot;&lt;br /&gt;
     exit 1&lt;br /&gt;
   fi&lt;br /&gt;
 fi&lt;br /&gt;
 mkdir -p $OUTDIR&lt;br /&gt;
 &lt;br /&gt;
 #&lt;br /&gt;
 # initialise grid&lt;br /&gt;
 #&lt;br /&gt;
 export DPM_HOST=dpm.lhep.unibe.ch&lt;br /&gt;
 export DPNS_HOST=dpm.lhep.unibe.ch&lt;br /&gt;
 &lt;br /&gt;
 echo -n &amp;quot;Password for GRID certificate: &amp;quot;&lt;br /&gt;
 read -s PASSWORD&lt;br /&gt;
 echo &amp;quot;&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 voms-proxy-destroy &amp;gt; /dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
 echo $PASSWORD | voms-proxy-init --voms t2k.org -pwstdin&lt;br /&gt;
 voms-proxy-info &amp;gt; /dev/null 2&amp;gt;&amp;amp;1 || exit 1&lt;br /&gt;
 &lt;br /&gt;
 #&lt;br /&gt;
 # create temporary file for collecting PIDs of running jobs&lt;br /&gt;
 #&lt;br /&gt;
 JOBLIST=`mktemp`&lt;br /&gt;
 &lt;br /&gt;
 #&lt;br /&gt;
 # redirect Ctrl+C to terminate sub-processes&lt;br /&gt;
 #&lt;br /&gt;
 function sigint() {&lt;br /&gt;
   trap true SIGINT&lt;br /&gt;
   rm $JOBLIST&lt;br /&gt;
   echo &amp;quot;&amp;quot;&lt;br /&gt;
   echo Terminating all sub-processes...&lt;br /&gt;
   kill 0&lt;br /&gt;
   exit 1&lt;br /&gt;
 }&lt;br /&gt;
 trap sigint SIGINT&lt;br /&gt;
 &lt;br /&gt;
 #&lt;br /&gt;
 # function to print information&lt;br /&gt;
 #&lt;br /&gt;
 function printinfo() {&lt;br /&gt;
   FINISHED=`ls $OUTDIR/finished.* 2&amp;gt;/dev/null | wc -l`&lt;br /&gt;
   SUCCESS=`ls $OUTDIR/success.* 2&amp;gt;/dev/null | wc -l`&lt;br /&gt;
   FAILED=$(( FINISHED - SUCCESS ))&lt;br /&gt;
   PREFETCH_STARTED=`ls $OUTDIR/prefetch.started.* 2&amp;gt;/dev/null | wc -l`&lt;br /&gt;
   PREFETCH_DONE=`ls $OUTDIR/prefetch.done.* 2&amp;gt;/dev/null | wc -l`&lt;br /&gt;
   PREFETCHING=$(( PREFETCH_STARTED - PREFETCH_DONE ))&lt;br /&gt;
   PERCENT=$(( ( FINISHED ) * 100 / NFILES ))&lt;br /&gt;
   RUNNING=`cat $JOBLIST | wc -l`&lt;br /&gt;
   ELAPSED_TIME=$(( `date +%s` - STARTDATE ))&lt;br /&gt;
   if [ $(( FINISHED - FINISHED0 )) -ge $NCPU ]; then&lt;br /&gt;
     ETA=`echo &amp;quot;$ELAPSED_TIME / ( $FINISHED - $FINISHED0 ) * ( $NFILES - $FINISHED ) / 3600&amp;quot; | bc`&lt;br /&gt;
   else&lt;br /&gt;
     ETA=&amp;quot;---&amp;quot;&lt;br /&gt;
   fi&lt;br /&gt;
   echo -n -e &amp;quot;${PERCENT}% | ETA: ${ETA}h | RUNNING: $RUNNING | SUCCESS: $SUCCESS | FAILED: $FAILED | PREFETCHING: $PREFETCHING\r&amp;quot;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 #&lt;br /&gt;
 # preparations&lt;br /&gt;
 #&lt;br /&gt;
 NFILES=`cat $LIST | wc -l`&lt;br /&gt;
 STARTDATE=`date +%s`&lt;br /&gt;
 IDX=0&lt;br /&gt;
 FINISHED0=`ls $OUTDIR/success.* 2&amp;gt;/dev/null | wc -l`&lt;br /&gt;
 &lt;br /&gt;
 #&lt;br /&gt;
 # cleanup in case of resuming&lt;br /&gt;
 #&lt;br /&gt;
 if [ -n &amp;quot;$RESUME&amp;quot; ]; then&lt;br /&gt;
   rm -f $OUTDIR/prefetch.started.*&lt;br /&gt;
   rm -f $OUTDIR/prefetch.done.*&lt;br /&gt;
   for (( i=0; i&amp;lt;NFILES; i++ )); do&lt;br /&gt;
     test -f $OUTDIR/success.${i} || rm -f $OUTDIR/finished.${i}&lt;br /&gt;
   done&lt;br /&gt;
 fi&lt;br /&gt;
 &lt;br /&gt;
 #&lt;br /&gt;
 # loop over all files in the list&lt;br /&gt;
 #&lt;br /&gt;
 cat $LIST | while read LINE ; do&lt;br /&gt;
   if [ -e &amp;quot;$OUTDIR/success.${IDX}&amp;quot; ]; then&lt;br /&gt;
     echo &amp;quot;Skipping already successful job $IDX&amp;quot;&lt;br /&gt;
     IDX=$(( IDX + 1 ))&lt;br /&gt;
     continue&lt;br /&gt;
   fi&lt;br /&gt;
   echo ${IDX}: $LINE&lt;br /&gt;
 &lt;br /&gt;
   #&lt;br /&gt;
   # start background prefetching of this file&lt;br /&gt;
   #&lt;br /&gt;
   (&lt;br /&gt;
     echo &amp;quot;prefetch $IDX                                                                   &amp;quot;&lt;br /&gt;
     touch &amp;quot;$OUTDIR/prefetch.started.${IDX}&amp;quot;&lt;br /&gt;
     # initialise grid certificate&lt;br /&gt;
     export X509_USER_PROXY=`mktemp`&lt;br /&gt;
     echo $PASSWORD | voms-proxy-init --voms t2k.org -pwstdin &amp;gt;&amp;gt; $OUTDIR/prefetch.${IDX}.log 2&amp;gt;&amp;amp;1&lt;br /&gt;
     # copy the file to local disk&lt;br /&gt;
     echo &amp;quot;lcg-cp -v $PREFIX$LINE $OUTDIR/prefetch.${IDX}.root&amp;quot; &amp;gt;&amp;gt; $OUTDIR/prefetch.${IDX}.log&lt;br /&gt;
     lcg-cp -v $PREFIX$LINE $OUTDIR/prefetch.${IDX}.root &amp;gt;&amp;gt; $OUTDIR/prefetch.${IDX}.log 2&amp;gt;&amp;amp;1   &amp;amp;&amp;amp;&lt;br /&gt;
       echo &amp;quot;prefetch done $IDX                                                            &amp;quot;     ||&lt;br /&gt;
       echo &amp;quot;prefetch FAILED $IDX                                                          &amp;quot;&lt;br /&gt;
     touch &amp;quot;$OUTDIR/prefetch.done.${IDX}&amp;quot;&lt;br /&gt;
     # cleanup&lt;br /&gt;
     voms-proxy-destroy&lt;br /&gt;
   ) &amp;amp;&lt;br /&gt;
 &lt;br /&gt;
   #&lt;br /&gt;
   # start the actual processing of the file in the background&lt;br /&gt;
   #&lt;br /&gt;
   (&lt;br /&gt;
     MPID=$!&lt;br /&gt;
     # wait until prefetching is finished&lt;br /&gt;
     while [ ! -f &amp;quot;$OUTDIR/prefetch.done.${IDX}&amp;quot; ]; do&lt;br /&gt;
       sleep 0.6&lt;br /&gt;
     done&lt;br /&gt;
     # wait until less than $NCPU processes are running&lt;br /&gt;
     while [ `cat $JOBLIST | wc -l` -ge $NCPU ]; do&lt;br /&gt;
        sleep 0.7&lt;br /&gt;
     done&lt;br /&gt;
     # start processing&lt;br /&gt;
     echo &amp;quot;start $IDX                                                                      &amp;quot;&lt;br /&gt;
     flock $JOBLIST -c &amp;quot;echo $MPID &amp;gt;&amp;gt; $JOBLIST&amp;quot;&lt;br /&gt;
     RunCreateFlatTree.exe $OUTDIR/prefetch.${IDX}.root -o $OUTDIR/flattree_${IDX}.root &amp;gt; $OUTDIR/${IDX}.log 2&amp;gt;&amp;amp;1   &amp;amp;&amp;amp;&lt;br /&gt;
       touch &amp;quot;$OUTDIR/success.${IDX}&amp;quot;                                                                                   &amp;amp;&amp;amp;&lt;br /&gt;
       echo &amp;quot;done $IDX                                                                     &amp;quot;                             ||&lt;br /&gt;
       echo &amp;quot;FAILED $IDX                                                                   &amp;quot;&lt;br /&gt;
     touch &amp;quot;$OUTDIR/finished.${IDX}&amp;quot;&lt;br /&gt;
     rm -f $OUTDIR/prefetch.started.${IDX}&lt;br /&gt;
     rm -f $OUTDIR/prefetch.${IDX}.root&lt;br /&gt;
     rm -f $OUTDIR/prefetch.done.${IDX}&lt;br /&gt;
     flock $JOBLIST -c &amp;quot;grep -v ^$MPID\$ $JOBLIST &amp;gt; $JOBLIST.temp ; mv $JOBLIST.temp $JOBLIST || echo &amp;gt; $JOBLIST&amp;quot;&lt;br /&gt;
   ) &amp;amp;&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
   # throttle and print info&lt;br /&gt;
   printinfo&lt;br /&gt;
   sleep 0.4&lt;br /&gt;
 &lt;br /&gt;
   #&lt;br /&gt;
   # wait if at least 2*$NCPU files are prefetched (prefetched files are deleted after processing)&lt;br /&gt;
   #&lt;br /&gt;
   while [ `ls $OUTDIR/prefetch.started.* 2&amp;gt;/dev/null | wc -l` -ge $(( NCPU * 2 )) ]; do&lt;br /&gt;
     # throttle and print info&lt;br /&gt;
     sleep 0.5&lt;br /&gt;
     printinfo&lt;br /&gt;
   done&lt;br /&gt;
 &lt;br /&gt;
   # increment file index&lt;br /&gt;
   IDX=$(( IDX + 1 ))&lt;br /&gt;
 done&lt;br /&gt;
 &lt;br /&gt;
 #&lt;br /&gt;
 # wait until all background jobs are completed&lt;br /&gt;
 #&lt;br /&gt;
 while [ `ls $OUTDIR/prefetch.started.* 2&amp;gt;/dev/null | wc -l` -gt 0 ]; do&lt;br /&gt;
   # throttle and print info&lt;br /&gt;
   sleep 0.5&lt;br /&gt;
   printinfo&lt;br /&gt;
 done&lt;br /&gt;
 &lt;br /&gt;
 #&lt;br /&gt;
 # print information&lt;br /&gt;
 #&lt;br /&gt;
 FINISHED=`ls $OUTDIR/finished.* 2&amp;gt;/dev/null | wc -l`&lt;br /&gt;
 SUCCESS=`ls $OUTDIR/success.* 2&amp;gt;/dev/null | wc -l`&lt;br /&gt;
 FAILED=$(( FINISHED - SUCCESS ))&lt;br /&gt;
 ELAPSED_TIME=$(( `date +%s` - STARTDATE ))&lt;br /&gt;
 echo &amp;quot;100% | SUCCESS: $FINISHED | FAILED: $FAILED | TIME: $ELAPSED_TIME                            &amp;quot;&lt;br /&gt;
 if [ &amp;quot;$FAILED&amp;quot; -gt 0 ]; then&lt;br /&gt;
   echo -n &amp;quot;Failed runs: &amp;quot;&lt;br /&gt;
   for (( i=0; i&amp;lt;NFILES; i++ )); do&lt;br /&gt;
     test -f $OUTDIR/success.${i} || echo -n &amp;quot; $i&amp;quot;&lt;br /&gt;
   done&lt;br /&gt;
   echo &amp;quot;&amp;quot;&lt;br /&gt;
 fi&lt;br /&gt;
 &lt;br /&gt;
 #&lt;br /&gt;
 # cleanup&lt;br /&gt;
 #&lt;br /&gt;
 rm $JOBLIST&lt;/div&gt;</summary>
		<author><name>Lhep</name></author>
	</entry>
</feed>