3 import os, sys, shlex, subprocess
6 samweb = samweb_client.SAMWebClient( experiment =
"nova" )
8 fname = os.path.basename( os.getenv(
"fname" ) )
11 md = samweb.getMetadata( fname )
13 print >> sys.stderr,
"Could not retrieve metadata for \"%s\"" % fname
17 end_time = md[
"Online.SubRunEndTime" ]
18 start_time = md[
"Online.SubRunStartTime" ]
20 print >> sys.stderr,
"Could not retrieve subrun start/end time metadata for \"%s\"" % fname
24 dims =
"file_type importedDetector and data_tier raw" 25 dims +=
" and data_stream beamline and online.detector testbeam-beamline" 26 dims +=
" and Beamline.FirstTriggerTime < %d and Beamline.LastTriggerTime > %d" % ( end_time, start_time )
28 beamline_files = samweb.listFiles( dimensions = dims )
30 if len( beamline_files ) > 0 :
31 print "\nBeamline files matched to detector file \"%s\":" % fname
32 for f
in beamline_files :
34 print "\nFetching beamline files..." 37 print "\nNo matching beamline files found for detector file \"%s\"" % fname
41 for f
in beamline_files :
43 if os.path.isfile( os.path.join( os.getcwd(), f ) ) :
44 print "\nBeamline file \"%s\" already exists in working directory" % f
48 print "\nFetching beamline file \"%s\"..." % f
49 cmd =
"ifdh_fetch -e nova %s" % f
50 p = subprocess.Popen( shlex.split( cmd ) )
54 print >> sys.stderr,
"ifdh_fetch failed for beamline file \"%s\"" % f