CMS 3D CMS Logo

filesave_online.py

Go to the documentation of this file.
00001 #! /usr/bin/env python
00002 
00003 import os,time,sys,shutil
00004 
00005 server = 'srv-c2c06-02' #machine to which files are transfered
00006 #DIR = '/tmp/dqmpro/output'  #directory to search new files
00007 #TMPDIR = '/cms/mon/data/.dropbox_tmp' # stealth area on cmsmon
00008 #FILEDIR = '/cms/mon/data/dropbox' # directory, to which files are stored
00009 #TimeTag = '/tmp/dqmpro/output/timetag' #file for time tag for searching new file
00010 
00011 ### Fore test and development
00012 DIR = '/home/dqmprolocal/output'  #directory to search new files
00013 TMPDIR = '/cms/mon/data/.dropbox_tmp' # stealth area on cmsmon
00014 FILEDIR = '/cms/mon/data/dropbox_test' # directory, to which files are stored
00015 TimeTag = '/home/dqmprolocal/output/timetag' #file for time tag for searching new file
00016 
00017 WAITTIME = 120 # waiting time for new files (sec)
00018 
00019 #os.popen('rm '+TMPDIR+'/DQM*')  # clean up temporary directory when start
00020 TempTag = TimeTag + '-tmp'
00021 if not os.path.exists(TimeTag):
00022         os.system('touch -t 01010000 '+ TimeTag)
00023 
00024 ####### ENDLESS LOOP WITH SLEEP
00025 while 1:
00026     #### search new files
00027     #NEW_ = os.popen('find '+ DIR +'/ -type f -name "DQM_*_R?????????.root" -newer '+ TimeTag +' | grep -v DQM_V').read().split()
00028     NEW_ = os.popen('find '+ DIR +'/ -type f -name "DQM_*_R?????????.root" -newer '+ TimeTag).read().split()
00029     if len(NEW_)==0:
00030         print 'waiting for new files...'
00031         time.sleep(WAITTIME)
00032         continue
00033 
00034     os.system('touch '+ TempTag)
00035     print 'Found '+str(len(NEW_))+' new file(s).'
00036     print os.popen('ls -l '+TimeTag).read()
00037 
00038     #### sort new files by run number
00039     pairs = []
00040     for fname in NEW_:
00041         run = fname[-14:-5] #run number of new file
00042         pairs.append((run,fname))
00043     pairs.sort()
00044 
00045     #### loop for new files
00046     for pair in pairs:
00047         fname = pair[1]
00048         tmpfile = fname.replace(fname[:fname.find('/DQM_')],TMPDIR)
00049         file = fname.replace(fname[:fname.find('/DQM_')],FILEDIR)
00050         print os.popen('ls -l '+fname).read()
00051         
00052         ### copy files to stealth area cmsmon and move to final area
00053         os.popen('scp '+fname+' '+server+':'+tmpfile).read()
00054         os.popen('ssh '+server+' -t mv '+tmpfile+' '+file).read()
00055 
00056     shutil.copy2(TempTag,TimeTag)
00057     

Generated on Tue Jun 9 17:33:09 2009 for CMSSW by  doxygen 1.5.4