macro chain_nt 1='NONE' 2='0' 3='chain' 4='YES' 5='1' on error GOTO DONE * * chain a bunch of ntuples together * *[1] = path name (for example /data8/e787/pass2/km21_02) REQUIRED *[2] = wild card (for example pass2_km21_541*) DEFAULT = 0 *[3] = name of chain DEFAULT = 'chain' *[4] = make a new chain? DEFAULT = 'YES' *[5] = verbosity. 0=errors only,1=minimum,2=more,3=all DEFAULT = 1 * *Example 1: for chaining all the ntuples in the path * PAW>exec chain_nt /data8/e787/pass2/km21_02 0 km21 *Example 2: for chaining some ntuples in the path * PAW>exec chain_nt /data8/e787/pass2/km21_02 pass2_km21_541* km21 * * 11jul02 original from http://www.phy.bnl.gov/e949/software/kofia/nt_ana/chain_nt.txt * fixed and modified by d.jaffe * ************************************ * input arguments and their validity ************************************ dir = [1] name= [2] cname = [3] new = [4] verbo = [5] if [dir]='NONE' then MESS CHAIN_NT Invalid first argument. Should be path name to ntuple directory goto DONE endif if [dir]='USAGE' .or. [dir]='usage' then MESS Usage CHAIN_NT path_name Wild_card Chain_name Make_new_Chain? Verbosity goto DONE endif if [verbo]>0 then mess CHAIN_NT inputs [dir] [name] [cname] [new] [verbo] endif ************************************************************************* * get list of files and the number of entries in the list. ************************************************************************** ntotal = 0 if ( [name] .eq. 0 ) then cmd = ls -1 [dir] else cmd = ls -1 [dir]/[name] endif filelist = $shell([cmd]) ntotal = $words([filelist],' ') if [verbo]>2 then MESS CHAIN_NT filelist is [filelist] endif *********************************************************************** * now loop over file list, creating a chain of the existing files. * the old chain will be deleted if requested. * NOTE: If old chain does not exist, then a message will be printed by paw * if you try to delete it. * ****************************************************************** nused = 0 do i = 1, [ntotal] file = $word([filelist],[i],1,' ') dfile = [dir]/[file] ************************************************* * 16jul02 Make sure the file exists. * If it doesn't, try to the input directory * as a prefix to the file name. ************************************************* if $FEXIST([file]) then else if $FEXIST([dfile]) then file = [dfile] endif endif if $FEXIST([file]) then nused = [nused] + 1 if [new]='YES'.and.[nused]=1 then chain -[cname] if [verbo]>0 then MESS CHAIN_NT Deleted old chain [cname] endif endif if [verbo]>1 then MESS CHAIN_NT Adding file [file] to chain [cname] endif chain [cname] [file] endif enddo ************************************************** * summarize what was done and, if possible, * change to the chain so that it can be traversed ************************************************** if [nused]=0 then MESS CHAIN_NT Could not make chain [cname], no entries found in [dir] else cdir //[cname] if [verbo]>0 then if [new]='YES' then MESS CHAIN_NT Made new chain [cname] with [ntotal] entries else MESS CHAIN_NT Added [ntotal] entries to old chain [cname] endif endif endif DONE: return