CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
filesave_online.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 
3 import os,time,sys,shutil,stat,glob
4 from sets import Set
5 
6 #set environments
7 exedir = '/home/dqmprolocal/filecopy' # directory to execute the relevant scripts
8 DIR = '/home/dqmprolocal/output' #directory to search new files
9 TMPDIR = '/data/dqm/.dropbox_tmp' # stealth area on cmsmon
10 FILEDIR = '/data/dqm/dropbox' # directory, to which files are stored
11 TimeTag = '/home/dqmprolocal/output/timetag' #file for time tag for searching new file
12 server = 'srv-c2d05-19' #machine to which files are transfered
13 
14 
15 def filecheck(rootfile):
16  cmd = exedir + '/filechk.sh ' + rootfile
17  a = os.popen(cmd).read().split()
18  tag = a.pop()
19 
20  if tag == '(int)(-1)':
21  #print "File corrupted"
22  return 0
23  elif tag == '(int)0':
24  #print "File is incomplete"
25  return 0
26  elif tag == '(int)1':
27  #print "File is OK"
28  return 1
29  else:
30  return 0
31 
32 
33 def copy2dropbox(org,tmp,final):
34  #server = 'srv-c2d05-19' #machine to which files are transfered (2008-07-29)
35  #file_stats = os.stat(org)
36  #t1 = time.localtime(file_stats[stat.ST_CTIME])[0:5]
37  #t2 = time.localtime()[0:5]
38  #while t1 == t2:
39  #print t1, t2
40  #print 'waiting for file creation is completed...'
41  #time.sleep(60)
42  #t2 = time.localtime()[0:5]
43  ### copy files to stealth area on cmsmon and move to final area
44  #os.popen('scp -Cpc blowfish '+org+' '+server+':'+tmp).read()
45  os.popen('scp '+org+' '+server+':'+tmp).read()
46  os.popen('ssh '+server+' -t mv '+tmp+' '+final).read()
47  a=os.popen('ssh '+server+' -t ls '+final).read().split()
48  # check if file tranfer is success
49  while len(a) != 1:
50  print 'File transfer failed. try again 2 min later ...'
51  time.sleep(120)
52  os.popen('scp '+org+' '+server+':'+tmp).read()
53  os.popen('ssh '+server+' -t mv '+tmp+' '+final).read()
54  a=os.popen('ssh '+server+' -t ls '+final).read().split()
55 
56 
57 def convert(infile, ofile):
58  cmd = exedir + '/convert.sh ' + infile + ' ' +ofile
59  os.system(cmd)
60 
61 
62 WAITTIME = 120 # waiting time for new files (sec)
63 
64 #os.popen('rm '+TMPDIR+'/DQM*') # clean up temporary directory when start
65 TempTag = TimeTag + '-tmp'
66 if not os.path.exists(TimeTag):
67  os.system('touch -t 01010000 '+ TimeTag)
68 
69 
70 
71 ####### ENDLESS LOOP WITH SLEEP
72 while 1:
73  #### search new tag files
74  #NEW_ = os.popen('find '+ DIR +'/ -type f -name "DQM_*_R?????????.root" -newer '+ TimeTag).read().split()
75  NEW_ = os.popen('find '+ DIR +'/ -type f -name "tagfile_runend_?????_*" -newer '+ TimeTag).read().split()
76 
77  if len(NEW_)==0:
78  print 'waiting for new files...'
79  time.sleep(WAITTIME)
80  continue
81 
82  os.system('touch '+ TempTag)
83 
84  #print 'Found '+str(len(NEW_))+' new file(s).'
85  #print os.popen('ls -l '+TimeTag).read()
86 
87  #### sort tag files by run number
88  pairs = []
89  for tagfile in NEW_:
90  i = tagfile.find('/tagfile_runend_')
91  run = tagfile[i+16:i+21] #run number of new tagfile
92  pairs.append((run,tagfile))
93  pairs.sort()
94 
95  #### extract uniq runs
96  Runs = []
97  for pair in pairs:
98  Runs.append(pair[0])
99  UniqRuns = list(Set(Runs)) #remove duplicate run
100  UniqRuns.sort()
101 
102  #### extract new files & copy to dropbox
103  for run in UniqRuns:#loop for runs
104  subfiles = []
105  subfiles = glob.glob(DIR + '/DQM_*_R????' + run + '_T*.root')
106  playbacks = glob.glob(DIR + '/Playback*SiStrip_R????' + run + '_T*.root')
107  subfiles = subfiles + playbacks
108 
109  ## extract head of file name (ex.'/home/dqmprolocal/output/DQM_SiStrip')
110  fheads = []
111  for fname in subfiles:
112  i = fname.rfind('_R')
113  fhead = fname[:i]
114  fheads.append(fhead)
115  UniqHeads = list(Set(fheads))
116 
117  ## extract single good file for single subsys
118  for fhead in UniqHeads:
119  fname = fhead +'_R0000'+run+'.root'
120  fname_Ts = os.popen('ls -rt '+fhead+'_R????'+run+'_T*.root').read().split()
121  if os.path.exists(fname): fname_Ts.append(fname)
122 
123  numbers = range(len(fname_Ts))
124  numbers.reverse()
125  for i in numbers:
126  fname_T = fname_Ts[i]
127  if filecheck(fname_T) == 0:
128  print fname_T +' is incomplete'
129  else:
130  print fname_T +' is OK'
131  ### For SiStrip files
132  if fname_T.rfind('Playback') != -1:
133  dqmfile = fname_T.replace('Playback','DQM')
134  convert(fname_T,dqmfile)
135  #os.remove(fname_T)
136  fname_T = dqmfile
137  fname = fname.replace('Playback','DQM')
138 
139  tmpfile = fname.replace(fname[:fname.find('/DQM_')],TMPDIR)
140  file = fname.replace(fname[:fname.find('/DQM_')],FILEDIR)
141  copy2dropbox(fname_T,tmpfile,file)
142  if not fname_T == fname:
143  os.rename(fname_T,fname)
144  for j in numbers:
145  if not (j==i or j==(i-1)): os.remove(fname_Ts[j])
146  break
147 
148  shutil.copy2(TempTag,TimeTag)
149  os.remove(TempTag)
150 
double split
Definition: MVATrainer.cc:139
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run