CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CommonMethods.py
Go to the documentation of this file.
1 import math, re, optparse, commands, os, sys, time, datetime
2 from BeamSpotObj import BeamSpot
3 from IOVObj import IOV
4 
5 lockFile = ".lock"
6 
7 ###########################################################################################
8 def timeoutManager(type,timeout=-1,fileName=".timeout"):
9  if timeout == 0:
10  return 1
11  timeFormat = "%a,%Y/%m/%d,%H:%M:%S"
12  currentTime = time.gmtime()
13  timeoutLine = type + ' ' + time.strftime(timeFormat, currentTime) + '\n'
14  isTimeout = False
15  alreadyThere = False
16  timeoutType = -1;
17  fileExist = os.path.isfile(fileName)
18  text = ''
19  fields = []
20  reset = False
21  if timeout == -1:
22  reset = True
23  if fileExist:
24  file = open(fileName)
25  for line in file:
26  text += line
27  fields = line.strip('\n').split(' ')
28  if fields[0] == type:
29  alreadyThere = True
30  if reset:
31  text = text.replace(line,'')
32  continue
33 
34  fileTime = time.strptime(fields[1],timeFormat)
35  myTime = time.mktime(fileTime)
36  referenceTime = time.mktime(time.gmtime())
37  daylight = 0
38  if currentTime.tm_isdst == 0:
39  daylight = 3600
40  elapsedTime = referenceTime-myTime-daylight
41  if elapsedTime > timeout:
42  isTimeout = True
43  timeoutType = 1
44  print "Timeout! " + str(elapsedTime) + " seconds passed since the " + type + " timeout was set and you can't tolerate more than " + str(timeout) + " seconds!"
45  else:
46  timeoutType = 0
47  print "Timeout of type " + type + " already exist and was generated " + str(elapsedTime) + " seconds ago at " + fields[1]
48 
49  file.close()
50 
51  if not fileExist or not alreadyThere and not reset:
52  timeoutType = -1
53  text += timeoutLine
54 
55  if not fileExist or not alreadyThere or isTimeout or (reset and alreadyThere):
56  if fileExist:
57  commands.getstatusoutput("rm -rf " + fileName)
58  file = open(fileName,'w')
59  file.write(text)
60  file.close()
61 
62  return timeoutType
63 
64 
65 ###########################################################################################
66 def setLockName(name):
67  global lockFile
68  lockFile = name
69 
70 ###########################################################################################
71 def checkLock():
72  global lockFile
73  if os.path.isfile(lockFile):
74  return True
75  else:
76  return False
77 
78 ###########################################################################################
79 def lock():
80  global lockFile
81  commands.getstatusoutput( "touch " + lockFile)
82 
83 ###########################################################################################
84 def rmLock():
85  global lockFile
86  if checkLock():
87  commands.getstatusoutput( "rm " + lockFile)
88 
89 ###########################################################################################
90 def exit(msg=""):
91  rmLock()
92  raise SystemExit(msg or optionstring.replace("%prog",sys.argv[0]))
93 
94 ###########################################################################################
95 def isnan(num):
96  fnum = float(num)
97  return fnum != fnum
98 
99 ###########################################################################################
100 # OPTIONS
101 ###########################################################################################
102 USAGE = re.compile(r'(?s)\s*usage: (.*?)(\n[ \t]*\n|$)')
103 
104 ###########################################################################################
105 def parse(docstring, arglist=None):
106  global optionstring
107  global tagType
108  optionstring = docstring
109  match = USAGE.search(optionstring)
110  if not match: raise ParsingError("Cannot find the option string")
111  optlines = match.group(1).splitlines()
112  try:
113  p = optparse.OptionParser(optlines[0])
114  for line in optlines[1:]:
115  opt, help=line.split(':')[:2]
116  short,long=opt.split(',')[:2]
117  if '=' in opt:
118  action='store'
119  long=long.split('=')[0]
120  else:
121  action='store_true'
122  p.add_option(short.strip(),long.strip(),
123  action = action, help = help.strip())
124  except (IndexError,ValueError):
125  raise ParsingError("Cannot parse the option string correctly")
126  return p.parse_args(arglist)
127 
128 ###########################################################################################
129 def nonzero(self): # will become the nonzero method of optparse.Values
130  "True if options were given"
131  for v in self.__dict__.itervalues():
132  if v is not None: return True
133  return False
134 
135 ###########################################################################################
136 optparse.Values.__nonzero__ = nonzero # dynamically fix optparse.Values
137 
138 # END OPTIONS
139 ###########################################################################################
140 
141 ###########################################################################################
143 
144 ###########################################################################################
145 # General utilities
146 ###########################################################################################
147 ###########################################################################################
148 def sendEmail(mailList,error):
149  print "Sending email to " + mailList + " with body: " + error
150  list = mailList.split(',')
151  for email in list:
152  p = os.popen("mail -s \"Automatic workflow error\" " + email ,"w")
153  p.write(error)
154  status = p.close()
155 
156 ###########################################################################################
157 def dirExists(dir):
158  if dir.find("castor") != -1:
159  lsCommand = "nsls " + dir
160  output = commands.getstatusoutput( lsCommand )
161  return not output[0]
162  else:
163  return os.path.exists(dir)
164 
165 ########################################################################
166 def ls(dir,filter=""):
167  lsCommand = ''
168  listOfFiles = []
169  if dir.find('castor') != -1:
170  lsCommand = 'ns'
171  elif not os.path.exists(dir):
172  print "ERROR: File or directory " + dir + " doesn't exist"
173  return listOfFiles
174 
175  aCommand = lsCommand + 'ls '+ dir
176  #aCommand = lsCommand + 'ls '+ dir + " | grep .txt"
177  if filter != "":
178  aCommand += " | grep " + filter
179 
180  tmpStatus = commands.getstatusoutput( aCommand )
181  listOfFiles = tmpStatus[1].split('\n')
182  if len(listOfFiles) == 1:
183  if listOfFiles[0].find('No such file or directory') != -1:
184  exit("ERROR: File or directory " + dir + " doesn't exist")
185 
186  return listOfFiles
187 
188 ########################################################################
189 def cp(fromDir,toDir,listOfFiles,overwrite=False,smallList=False):
190  cpCommand = ''
191  copiedFiles = []
192  if fromDir.find('castor') != -1 or toDir.find('castor') != -1 :
193  cpCommand = 'rf'
194  elif fromDir.find('resilient') != -1:
195  cpCommand = 'dc'
196  if fromDir[len(fromDir)-1] != '/':
197  fromDir += '/'
198 
199  if toDir[len(toDir)-1] != '/':
200  toDir += '/'
201 
202  for file in listOfFiles:
203  if os.path.isfile(toDir+file):
204  if overwrite:
205  print "File " + file + " already exists in destination directory. We will overwrite it."
206  else:
207  print "File " + file + " already exists in destination directory. We will Keep original file."
208  if not smallList:
209  copiedFiles.append(file)
210  continue
211  # copy to local disk
212  aCommand = cpCommand + 'cp '+ fromDir + file + " " + toDir
213  print " >> " + aCommand
214  tmpStatus = commands.getstatusoutput( aCommand )
215  if tmpStatus[0] == 0:
216  copiedFiles.append(file)
217  else:
218  print "[cp()]\tERROR: Can't copy file " + file
219  return copiedFiles
220 
221 ########################################################################
222 
223 
224 ###########################################################################################
225 # lumi tools CondCore/Utilities/python/timeUnitHelper.py
226 ###########################################################################################
227 def pack(high,low):
228  """pack high,low 32bit unsigned int to one unsigned 64bit long long
229  Note:the print value of result number may appear signed, if the sign bit is used.
230  """
231  h=high<<32
232  return (h|low)
233 
234 ###########################################################################################
235 def unpack(i):
236  """unpack 64bit unsigned long long into 2 32bit unsigned int, return tuple (high,low)
237  """
238  high=i>>32
239  low=i&0xFFFFFFFF
240  return(high,low)
241 
242 ###########################################################################################
244  """unpack 64bit lumiid to dictionary {'run','lumisection'}
245  """
246  j=unpack(i)
247  return {'run':j[0],'lumisection':j[1]}
248 ###########################################################################################
249 # end lumi tools
250 ###########################################################################################
251 
252 ###########################################################################################
253 def cmp_list_run(a,b):
254  if int(a.IOVfirst) < int(b.IOVfirst): return -1
255  if int(a.IOVfirst) == int(b.IOVfirst): return 0
256  if int(a.IOVfirst) > int(b.IOVfirst): return 1
257 
258 ###########################################################################################
259 def cmp_list_lumi(a,b):
260  if int(a.Run) < int(b.Run): return -1
261  if int(a.Run) == int(b.Run):
262  if int(a.IOVfirst) < int(b.IOVfirst): return -1
263  if int(a.IOVfirst) == int(b.IOVfirst): return 0
264  if int(a.IOVfirst) > int(b.IOVfirst): return 1
265  if int(a.Run) > int(b.Run) : return 1
266 
267 ###########################################################################################
268 def weight(x1, x1err,x2,x2err):
269  #print "x1 = "+str(x1)+" +/- "+str(x1err)+" x2 = "+str(x2)+" +/- "+str(x2err)
270  x1 = float(x1)
271  x1err = float(x1err)
272  x2 = float(x2)
273  x2err = float(x2err)
274  tmperr = 0.
275  if x2err < 1e-6 :
276  x2err = 1e-6
277  if x1err < 1e-6:
278  x1 = x2/(x2err * x2err)
279  tmperr = 1/(x2err*x2err)
280  else:
281  x1 = x1/(x1err*x1err) + x2/(x2err * x2err)
282  tmperr = 1/(x1err*x1err) + 1/(x2err*x2err)
283  x1 = x1/tmperr
284  x1err = 1/tmperr
285  x1err = math.sqrt(x1err)
286  return (str(x1), str(x1err))
287 
288 ###########################################################################################
289 def dump( beam, file):
290  end = "\n"
291  file.write("Runnumber "+beam.Run+end)
292  file.write("BeginTimeOfFit "+str(beam.IOVBeginTime)+end)
293  file.write("EndTimeOfFit "+str(beam.IOVEndTime)+end)
294  file.write("LumiRange "+str(beam.IOVfirst)+" - "+str(beam.IOVlast)+end)
295  dumpValues(beam, file)
296 
297 ###########################################################################################
298 def dumpValues( beam, file):
299  end = "\n"
300  file.write("Type "+str(beam.Type)+end)
301  file.write("X0 "+str(beam.X)+end)
302  file.write("Y0 "+str(beam.Y)+end)
303  file.write("Z0 "+str(beam.Z)+end)
304  file.write("sigmaZ0 "+str(beam.sigmaZ)+end)
305  file.write("dxdz "+str(beam.dxdz)+end)
306  file.write("dydz "+str(beam.dydz)+end)
307  file.write("BeamWidthX "+beam.beamWidthX+end)
308  file.write("BeamWidthY "+beam.beamWidthY+end)
309  file.write("Cov(0,j) "+str(math.pow(float(beam.Xerr),2))+" 0 0 0 0 0 0" +end)
310  file.write("Cov(1,j) 0 "+str(math.pow(float(beam.Yerr),2))+" 0 0 0 0 0" +end)
311  file.write("Cov(2,j) 0 0 "+str(math.pow(float(beam.Zerr),2))+" 0 0 0 0" +end)
312  file.write("Cov(3,j) 0 0 0 "+str(math.pow(float(beam.sigmaZerr),2))+" 0 0 0" +end)
313  file.write("Cov(4,j) 0 0 0 0 "+str(math.pow(float(beam.dxdzerr),2))+" 0 0" +end)
314  file.write("Cov(5,j) 0 0 0 0 0 "+str(math.pow(float(beam.dydzerr),2))+" 0" +end)
315  file.write("Cov(6,j) 0 0 0 0 0 0 "+str(math.pow(float(beam.beamWidthXerr),2)) +end)
316  file.write("EmittanceX 0"+end)
317  file.write("EmittanceY 0"+end)
318  file.write("BetaStar 0"+end)
319 
320 ###########################################################################################
321 def delta(x,xerr,nextx,nextxerr):
322  #return math.fabs( float(x) - float(nextx) )/math.sqrt(math.pow(float(xerr),2) + math.pow(float(nextxerr),2))
323  return ( float(x) - float(nextx), math.sqrt(math.pow(float(xerr),2) + math.pow(float(nextxerr),2)) )
324 
325 def deltaSig( x ):
326  return math.fabs(x[0])/x[1]
327 
328 ###########################################################################################
329 def readBeamSpotFile(fileName,listbeam=[],IOVbase="runbase", firstRun='1',lastRun='4999999999'):
330  tmpbeam = BeamSpot()
331  tmpbeamsize = 0
332 
333  #firstRun = "1"
334  #lastRun = "4999999999"
335  if IOVbase == "lumibase" and firstRun=='1' and lastRun=='4999999999' :
336  firstRun = "1:1"
337  lastRun = "4999999999:4999999999"
338 
339  inputfiletype = 0
340  #print "first = " +firstRun
341  #print "last = " +lastRun
342 
343  # for bx
344  maplist = {}
345  hasBX = False
346 
347  tmpfile = open(fileName)
348  atmpline = tmpfile.readline()
349  if atmpline.find('Runnumber') != -1:
350  inputfiletype = 1
351  if len(atmpline.split()) > 2:
352  hasBX = True
353  print " Input data has been calculated as function of BUNCH CROSSINGS."
354  tmpfile.seek(0)
355 
356 
357  if inputfiletype ==1:
358 
359  tmpBX = 0
360  for line in tmpfile:
361 
362  if line.find('Type') != -1:
363  tmpbeam.Type = int(line.split()[1])
364  tmpbeamsize += 1
365  if line.find('X0') != -1:
366  tmpbeam.X = line.split()[1]
367  #tmpbeam.Xerr = line.split()[4]
368  tmpbeamsize += 1
369  #print " x = " + str(tmpbeam.X)
370  if line.find('Y0') != -1:
371  tmpbeam.Y = line.split()[1]
372  #tmpbeam.Yerr = line.split()[4]
373  tmpbeamsize += 1
374  #print " y =" + str(tmpbeam.Y)
375  if line.find('Z0') != -1 and line.find('sigmaZ0') == -1:
376  tmpbeam.Z = line.split()[1]
377  #tmpbeam.Zerr = line.split()[4]
378  tmpbeamsize += 1
379  if line.find('sigmaZ0') !=-1:
380  tmpbeam.sigmaZ = line.split()[1]
381  #tmpbeam.sigmaZerr = line.split()[5]
382  tmpbeamsize += 1
383  if line.find('dxdz') != -1:
384  tmpbeam.dxdz = line.split()[1]
385  #tmpbeam.dxdzerr = line.split()[4]
386  tmpbeamsize += 1
387  if line.find('dydz') != -1:
388  tmpbeam.dydz = line.split()[1]
389  #tmpbeam.dydzerr = line.split()[4]
390  tmpbeamsize += 1
391  if line.find('BeamWidthX') != -1:
392  tmpbeam.beamWidthX = line.split()[1]
393  #tmpbeam.beamWidthXerr = line.split()[6]
394  tmpbeamsize += 1
395  if line.find('BeamWidthY') != -1:
396  tmpbeam.beamWidthY = line.split()[1]
397  #tmpbeam.beamWidthYerr = line.split()[6]
398  tmpbeamsize += 1
399  if line.find('Cov(0,j)') != -1:
400  tmpbeam.Xerr = str(math.sqrt( float( line.split()[1] ) ) )
401  tmpbeamsize += 1
402  if line.find('Cov(1,j)') != -1:
403  tmpbeam.Yerr = str(math.sqrt( float( line.split()[2] ) ) )
404  tmpbeamsize += 1
405  if line.find('Cov(2,j)') != -1:
406  tmpbeam.Zerr = str(math.sqrt( float( line.split()[3] ) ) )
407  tmpbeamsize += 1
408  if line.find('Cov(3,j)') != -1:
409  tmpbeam.sigmaZerr = str(math.sqrt( float( line.split()[4] ) ) )
410  tmpbeamsize += 1
411  if line.find('Cov(4,j)') != -1:
412  tmpbeam.dxdzerr = str(math.sqrt( float( line.split()[5] ) ) )
413  tmpbeamsize += 1
414  if line.find('Cov(5,j)') != -1:
415  tmpbeam.dydzerr = str(math.sqrt( float( line.split()[6] ) ) )
416  tmpbeamsize += 1
417  if line.find('Cov(6,j)') != -1:
418  tmpbeam.beamWidthXerr = str(math.sqrt( float( line.split()[7] ) ) )
419  tmpbeam.beamWidthYerr = tmpbeam.beamWidthXerr
420  tmpbeamsize += 1
421  if line.find('LumiRange') != -1:
422  if IOVbase=="lumibase":
423  tmpbeam.IOVfirst = line.split()[1]
424  tmpbeam.IOVlast = line.split()[3]
425  tmpbeamsize += 1
426  if line.find('Runnumber') != -1:
427  tmpbeam.Run = line.split()[1]
428  if IOVbase == "runbase":
429  tmpbeam.IOVfirst = line.split()[1]
430  tmpbeam.IOVlast = line.split()[1]
431  if hasBX:
432  tmpBX = line.split()[3]
433  tmpbeamsize += 1
434  if line.find('BeginTimeOfFit') != -1:
435  tmpbeam.IOVBeginTime = line.split()[1] +" "+line.split()[2] +" "+line.split()[3]
436  if IOVbase =="timebase":
437  tmpbeam.IOVfirst = time.mktime( time.strptime(line.split()[1] + " " + line.split()[2] + " " + line.split()[3],"%Y.%m.%d %H:%M:%S %Z") )
438  tmpbeamsize += 1
439  if line.find('EndTimeOfFit') != -1:
440  tmpbeam.IOVEndTime = line.split()[1] +" "+line.split()[2] +" "+line.split()[3]
441  if IOVbase =="timebase":
442  tmpbeam.IOVlast = time.mktime( time.strptime(line.split()[1] + " " + line.split()[2] + " " + line.split()[3],"%Y.%m.%d %H:%M:%S %Z") )
443  tmpbeamsize += 1
444  if tmpbeamsize == 20:
445  if IOVbase=="lumibase":
446  tmprunfirst = int(firstRun.split(":")[0])
447  tmprunlast = int(lastRun.split(":")[0])
448  tmplumifirst = int(firstRun.split(":")[1])
449  tmplumilast = int(lastRun.split(":")[1])
450  acceptiov1 = acceptiov2 = False
451  # check lumis in the same run
452  if tmprunfirst == tmprunlast and int(tmpbeam.Run)==tmprunfirst:
453  if int(tmpbeam.IOVfirst) >= tmplumifirst and int(tmpbeam.IOVlast)<=tmplumilast:
454  acceptiov1 = acceptiov2 = True
455  # if different runs make sure you select the correct range of lumis
456  elif int(tmpbeam.Run) == tmprunfirst:
457  if int(tmpbeam.IOVfirst) >= tmplumifirst: acceptiov1 = True
458  elif int(tmpbeam.Run) == tmprunlast:
459  if int(tmpbeam.IOVlast) <= tmplumilast: acceptiov2 = True
460  elif tmprunfirst <= int(tmpbeam.Run) and tmprunlast >= int(tmpbeam.Run):
461  acceptiov1 = acceptiov2 = True
462 
463  if acceptiov1 and acceptiov2:
464  if tmpbeam.Type != 2:
465  print "invalid fit, skip Run "+str(tmpbeam.Run)+" IOV: "+str(tmpbeam.IOVfirst) + " to "+ str(tmpbeam.IOVlast)
466  elif isnan(tmpbeam.Z) or isnan(tmpbeam.Zerr) or isnan(tmpbeam.sigmaZerr) or isnan(tmpbeam.beamWidthXerr) or isnan(tmpbeam.beamWidthYerr):
467  print "invalid fit, NaN values!! skip Run "+str(tmpbeam.Run)+" IOV: "+str(tmpbeam.IOVfirst) + " to "+ str(tmpbeam.IOVlast)
468  elif hasBX:
469  if maplist.has_key(tmpBX) == False:
470  maplist[tmpBX] = [tmpbeam]
471  else:
472  maplist[tmpBX].append(tmpbeam)
473  else:
474  listbeam.append(tmpbeam)
475 
476  elif int(tmpbeam.IOVfirst) >= int(firstRun) and int(tmpbeam.IOVlast) <= int(lastRun):
477  if tmpbeam.Type != 2:
478  print "invalid fit, skip Run "+str(tmpbeam.Run)+" IOV: "+str(tmpbeam.IOVfirst) + " to "+ str(tmpbeam.IOVlast)
479  elif isnan(tmpbeam.Z) or isnan(tmpbeam.Zerr) or isnan(tmpbeam.sigmaZerr) or isnan(tmpbeam.beamWidthXerr) or isnan(tmpbeam.beamWidthYerr):
480  print "invalid fit, NaN values!! skip Run "+str(tmpbeam.Run)+" IOV: "+str(tmpbeam.IOVfirst) + " to "+ str(tmpbeam.IOVlast)
481  else:
482  listbeam.append(tmpbeam)
483 
484  tmpbeamsize = 0
485  tmpbeam = BeamSpot()
486  tmpBX = 0
487  else:
488 
489  for line in tmpfile:
490 
491  if line.find('X0') != -1:
492  tmpbeam.X = line.split()[2]
493  tmpbeam.Xerr = line.split()[4]
494  tmpbeamsize += 1
495  #print " x = " + str(tmpbeam.X)
496  if line.find('Y0') != -1:
497  tmpbeam.Y = line.split()[2]
498  tmpbeam.Yerr = line.split()[4]
499  tmpbeamsize += 1
500  #print " y =" + str(tmpbeam.Y)
501  if line.find('Z0') != -1 and line.find('Sigma Z0') == -1:
502  tmpbeam.Z = line.split()[2]
503  tmpbeam.Zerr = line.split()[4]
504  tmpbeamsize += 1
505  #print " z =" + str(tmpbeam.Z)
506  if line.find('Sigma Z0') !=-1:
507  tmpbeam.sigmaZ = line.split()[3]
508  tmpbeam.sigmaZerr = line.split()[5]
509  tmpbeamsize += 1
510  if line.find('dxdz') != -1:
511  tmpbeam.dxdz = line.split()[2]
512  tmpbeam.dxdzerr = line.split()[4]
513  tmpbeamsize += 1
514  if line.find('dydz') != -1:
515  tmpbeam.dydz = line.split()[2]
516  tmpbeam.dydzerr = line.split()[4]
517  tmpbeamsize += 1
518  if line.find('Beam Width X') != -1:
519  tmpbeam.beamWidthX = line.split()[4]
520  tmpbeam.beamWidthXerr = line.split()[6]
521  tmpbeamsize += 1
522  if line.find('Beam Width Y') != -1:
523  tmpbeam.beamWidthY = line.split()[4]
524  tmpbeam.beamWidthYerr = line.split()[6]
525  tmpbeamsize += 1
526  #if line.find('Run ') != -1:
527  if line.find('for runs') != -1:
528  #tmpbeam.IOVfirst = line.split()[6].strip(',')
529  tmpbeam.Run = line.split()[2]
530  if IOVbase == "runbase":
531  tmpbeam.IOVfirst = line.split()[2]
532  tmpbeam.IOVlast = line.split()[4]
533  tmpbeamsize += 1
534  if line.find('LumiSection') != -1:
535  if IOVbase=="lumibase":
536  tmpbeam.IOVfirst = line.split()[10]
537  tmpbeam.IOVlast = line.split()[10]
538  tmpbeamsize += 1
539  if tmpbeamsize == 10:
540 
541  if IOVbase=="lumibase":
542  tmprunfirst = int(firstRun.split(":")[0])
543  tmprunlast = int(lastRun.split(":")[0])
544  tmplumifirst = int(firstRun.split(":")[1])
545  tmplumilast = int(lastRun.split(":")[1])
546  acceptiov1 = acceptiov2 = False
547  # check lumis in the same run
548  if tmprunfirst == tmprunlast and int(tmpbeam.Run)==tmprunfirst:
549  if int(tmpbeam.IOVfirst) >= tmplumifirst and int(tmpbeam.IOVlast)<=tmplumilast:
550  acceptiov1 = acceptiov2 = True
551  # if different runs make sure you select the correct range of lumis
552  elif int(tmpbeam.Run) == tmprunfirst:
553  if int(tmpbeam.IOVfirst) >= tmplumifirst: acceptiov1 = True
554  elif int(tmpbeam.Run) == tmprunlast:
555  if int(tmpbeam.IOVlast) <= tmplumilast: acceptiov2 = True
556  elif tmprunfirst <= int(tmpbeam.Run) and tmprunlast >= int(tmpbeam.Run):
557  acceptiov1 = acceptiov2 = True
558 
559  if acceptiov1 and acceptiov2:
560  if isnan(tmpbeam.Z) or isnan(tmpbeam.Zerr) or isnan(tmpbeam.sigmaZerr) or isnan(tmpbeam.beamWidthXerr) or isnan(tmpbeam.beamWidthYerr):
561  print "invalid fit, NaN values!! skip Run "+str(tmpbeam.Run)+" IOV: "+str(tmpbeam.IOVfirst) + " to "+ str(tmpbeam.IOVlast)
562  elif hasBX:
563  if maplist.has_key(tmpBX) == False:
564  maplist[tmpBX] = [tmpbeam]
565  else:
566  maplist[tmpBX].append(tmpbeam)
567  else:
568  listbeam.append(tmpbeam)
569 
570  elif int(tmpbeam.IOVfirst) >= int(firstRun) and int(tmpbeam.IOVlast) <= int(lastRun):
571  if isnan(tmpbeam.Z) or isnan(tmpbeam.Zerr) or isnan(tmpbeam.sigmaZerr) or isnan(tmpbeam.beamWidthXerr) or isnan(tmpbeam.beamWidthYerr):
572  print "invalid fit, NaN values!! skip Run "+str(tmpbeam.Run)+" IOV: "+str(tmpbeam.IOVfirst) + " to "+ str(tmpbeam.IOVlast)
573  else:
574  listbeam.append(tmpbeam)
575 
576  tmpbeamsize = 0
577  tmpbeam = BeamSpot()
578  tmpBX = 0
579 
580  tmpfile.close()
581  print " got total number of IOVs = " + str(len(listbeam)) + " from file " + fileName
582  #print " run " + str(listbeam[3].IOVfirst ) + " " + str( listbeam[3].X )
583  if hasBX:
584  return maplist
585  else:
586  return listbeam
587 
588 ###########################################################################################
589 # Sort and clean list of data for consecutive duplicates and bad fits
590 def sortAndCleanBeamList(listbeam=[],IOVbase="lumibase"):
591  # sort the list
592  if IOVbase == "lumibase":
593  listbeam.sort( cmp = cmp_list_lumi )
594  else:
595  listbeam.sort( cmp = cmp_list_run )
596 
597  # first clean list of data for consecutive duplicates and bad fits
598  tmpremovelist = []
599  for ii in range(0,len(listbeam)):
600  ibeam = listbeam[ii]
601  datax = ibeam.IOVfirst
602  #print str(ii) + " " +datax
603  if datax == '0' and IOVbase =="runbase":
604  print " iov = 0? skip this IOV = "+ str(ibeam.IOVfirst) + " to " + str(ibeam.IOVlast)
605  tmpremovelist.append(ibeam)
606 
607  if ii < len(listbeam) -1:
608  #print listbeam[ii+1].IOVfirst
609  if IOVbase =="lumibase":
610  if ibeam.Run == listbeam[ii+1].Run and ibeam.IOVfirst == listbeam[ii+1].IOVfirst:
611  print " duplicate IOV = "+datax+", keep only last duplicate entry"
612  tmpremovelist.append(ibeam)
613  elif datax == listbeam[ii+1].IOVfirst:
614  print " duplicate IOV = "+datax+", keep only last duplicate entry"
615  tmpremovelist.append(ibeam)
616 
617  for itmp in tmpremovelist:
618  listbeam.remove(itmp)
619 
620 ###########################################################################################
621 # CREATE FILE FOR PAYLOADS
622 def createWeightedPayloads(fileName,listbeam=[],weighted=True):
623  newlistbeam = []
624  tmpbeam = BeamSpot()
625  docreate = True
626  countlumi = 0
627  tmprun = ""
628  maxNlumis = 60
629  if weighted:
630  maxNlumis = 999999999
631  for ii in range(0,len(listbeam)):
632 
633  ibeam = listbeam[ii]
634  inextbeam = BeamSpot()
635  iNNbeam = BeamSpot()
636  if docreate:
637  tmpbeam.IOVfirst = ibeam.IOVfirst
638  tmpbeam.IOVBeginTime = ibeam.IOVBeginTime
639  tmpbeam.Run = ibeam.Run
640  tmpbeam.Type = 2
641  docheck = False
642  docreate = False
643 
644  # check last iov
645  if ii < len(listbeam) - 1:
646  inextbeam = listbeam[ii+1]
647  docheck = True
648  if ii < len(listbeam) -2:
649  iNNbeam = listbeam[ii+2]
650  else:
651  print "close payload because end of data has been reached. Run "+ibeam.Run
652  docreate = True
653  # check we run over the same run
654  if ibeam.Run != inextbeam.Run:
655  print "close payload because end of run "+ibeam.Run
656  docreate = True
657  # check maximum lumi counts
658  if countlumi == maxNlumis -1:
659  print "close payload because maximum lumi sections accumulated within run "+ibeam.Run
660  docreate = True
661  countlumi = 0
662  # weighted average position
663  (tmpbeam.X, tmpbeam.Xerr) = weight(tmpbeam.X, tmpbeam.Xerr, ibeam.X, ibeam.Xerr)
664  (tmpbeam.Y, tmpbeam.Yerr) = weight(tmpbeam.Y, tmpbeam.Yerr, ibeam.Y, ibeam.Yerr)
665  (tmpbeam.Z, tmpbeam.Zerr) = weight(tmpbeam.Z, tmpbeam.Zerr, ibeam.Z, ibeam.Zerr)
666  (tmpbeam.sigmaZ, tmpbeam.sigmaZerr) = weight(tmpbeam.sigmaZ, tmpbeam.sigmaZerr, ibeam.sigmaZ, ibeam.sigmaZerr)
667  (tmpbeam.dxdz, tmpbeam.dxdzerr) = weight(tmpbeam.dxdz, tmpbeam.dxdzerr, ibeam.dxdz, ibeam.dxdzerr)
668  (tmpbeam.dydz, tmpbeam.dydzerr) = weight(tmpbeam.dydz, tmpbeam.dydzerr, ibeam.dydz, ibeam.dydzerr)
669  #print "wx = " + ibeam.beamWidthX + " err= "+ ibeam.beamWidthXerr
670  (tmpbeam.beamWidthX, tmpbeam.beamWidthXerr) = weight(tmpbeam.beamWidthX, tmpbeam.beamWidthXerr, ibeam.beamWidthX, ibeam.beamWidthXerr)
671  (tmpbeam.beamWidthY, tmpbeam.beamWidthYerr) = weight(tmpbeam.beamWidthY, tmpbeam.beamWidthYerr, ibeam.beamWidthY, ibeam.beamWidthYerr)
672 
673  if weighted:
674  docheck = False
675  # check offsets
676  #if False:
677  if docheck:
678 
679  # define minimum limit
680  min_limit = 0.0025
681 
682  # limit for x and y
683  limit = float(ibeam.beamWidthX)/2.
684  if limit < min_limit: limit = min_limit
685 
686  # check movements in X
687  adelta1 = delta(ibeam.X, ibeam.Xerr, inextbeam.X, inextbeam.Xerr)
688  adelta2 = (0.,1.e9)
689  adelta1dxdz = delta(ibeam.dxdz, ibeam.dxdzerr, inextbeam.dxdz, inextbeam.dxdzerr)
690  adelta2dxdz = (0.,1.e9)
691  adelta1dydz = delta(ibeam.dydz, ibeam.dydzerr, inextbeam.dydz, inextbeam.dydzerr)
692  adelta2dydz = (0.,1.e9)
693  adelta1widthx = delta(ibeam.beamWidthX, ibeam.beamWidthXerr, inextbeam.beamWidthX, inextbeam.beamWidthXerr)
694  adelta2widthx = (0.,1.e9)
695  adelta1widthy = delta(ibeam.beamWidthY, ibeam.beamWidthYerr, inextbeam.beamWidthY, inextbeam.beamWidthYerr)
696  adelta2widthy = (0.,1.e9)
697 
698  if iNNbeam.Type != -1:
699  adelta2 = delta(inextbeam.X, inextbeam.Xerr, iNNbeam.X, iNNbeam.Xerr)
700  adelta2dxdz = delta(inextbeam.dxdz, inextbeam.dxdzerr, iNNbeam.dxdz, iNNbeam.dxdzerr)
701  adelta2dydz = delta(inextbeam.dydz, inextbeam.dydzerr, iNNbeam.dydz, iNNbeam.dydzerr)
702  adelta2widthx = delta(inextbeam.beamWidthX, inextbeam.beamWidthXerr, iNNbeam.beamWidthX, iNNbeam.beamWidthXerr)
703  adelta2widthy = delta(inextbeam.beamWidthY, inextbeam.beamWidthYerr, iNNbeam.beamWidthY, iNNbeam.beamWidthYerr)
704 
705  deltaX = deltaSig(adelta1) > 3.5 and adelta1[0] >= limit
706  if ii < len(listbeam) -2:
707  if deltaX==False and adelta1[0]*adelta2[0] > 0. and math.fabs(adelta1[0]+adelta2[0]) >= limit:
708  #print " positive, "+str(adelta1[0]+adelta2[0])+ " limit="+str(limit)
709  deltaX = True
710  elif deltaX==True and adelta1[0]*adelta2[0]<=0 and adelta2[0] != 0 and math.fabs(adelta1[0]/adelta2[0]) > 0.33 and math.fabs(adelta1[0]/adelta2[0]) < 3:
711  deltaX = False
712  #print " negative, "+str(adelta1[0]/adelta2[0])
713  #else:
714  # print str(adelta1[0]/adelta2[0])
715 
716  # check movemnts in Y
717  adelta1 = delta(ibeam.Y, ibeam.Yerr, inextbeam.Y, inextbeam.Yerr)
718  adelta2 = (0.,1.e9)
719  if iNNbeam.Type != -1:
720  adelta2 = delta(inextbeam.Y, inextbeam.Yerr, iNNbeam.Y, iNNbeam.Yerr)
721 
722  deltaY = deltaSig(adelta1) > 3.5 and adelta1[0] >= limit
723  if ii < len(listbeam) -2:
724  if deltaY==False and adelta1[0]*adelta2[0] > 0. and math.fabs(adelta1[0]+adelta2[0]) >= limit:
725  deltaY = True
726  elif deltaY==True and adelta1[0]*adelta2[0]<=0 and adelta2[0] != 0 and math.fabs(adelta1[0]/adelta2[0]) > 0.33 and math.fabs(adelta1[0]/adelta2[0]) < 3:
727  deltaY = False
728  # check movements in Z
729  adelta = delta(ibeam.Z, ibeam.Zerr, inextbeam.Z, inextbeam.Zerr)
730 
731 
732  limit = float(ibeam.sigmaZ)/2.
733  deltaZ = deltaSig(adelta) > 3.5 and adelta[0] >= limit
734 
735  adelta = delta(ibeam.sigmaZ, ibeam.sigmaZerr, inextbeam.sigmaZ, inextbeam.sigmaZerr)
736  deltasigmaZ = deltaSig(adelta) > 5.0
737 
738  # check dxdz
739  adelta = delta(ibeam.dxdz, ibeam.dxdzerr, inextbeam.dxdz, inextbeam.dxdzerr)
740  deltadxdz = deltaSig(adelta) > 5.0
741  if deltadxdz and adelta1dxdz[0]*adelta2dxdz[0]<=0 and adelta2dxdz[0] != 0 and math.fabs(adelta1dxdz[0]/adelta2dxdz[0]) > 0.33 and math.fabs(adelta1dxdz[0]/adelta2dxdz[0]) < 3:
742  deltadxdz = False
743  # check dydz
744  adelta = delta(ibeam.dydz, ibeam.dydzerr, inextbeam.dydz, inextbeam.dydzerr)
745  deltadydz = deltaSig(adelta) > 5.0
746  if deltadydz and adelta1dydz[0]*adelta2dydz[0]<=0 and adelta2dydz[0] != 0 and math.fabs(adelta1dydz[0]/adelta2dydz[0]) > 0.33 and math.fabs(adelta1dydz[0]/adelta2dydz[0]) < 3:
747  deltadydz = False
748 
749  adelta = delta(ibeam.beamWidthX, ibeam.beamWidthXerr, inextbeam.beamWidthX, inextbeam.beamWidthXerr)
750  deltawidthX = deltaSig(adelta) > 5
751  if deltawidthX and adelta1widthx[0]*adelta2widthx[0]<=0 and adelta2widthx[0] != 0 and math.fabs(adelta1widthx[0]/adelta2widthx[0]) > 0.33 and math.fabs(adelta1widthx[0]/adelta2widthx[0]) < 3:
752  deltawidthX = False
753 
754  adelta = delta(ibeam.beamWidthY, ibeam.beamWidthYerr, inextbeam.beamWidthY, inextbeam.beamWidthYerr)
755  deltawidthY = deltaSig(adelta) > 5
756  if deltawidthY and adelta1widthy[0]*adelta2widthy[0]<=0 and adelta2widthy[0] != 0 and math.fabs(adelta1widthy[0]/adelta2widthy[0]) > 0.33 and math.fabs(adelta1widthy[0]/adelta2widthy[0]) < 3:
757  deltawidthY = False
758  #if iNNbeam.Type != -1:
759  # deltaX = deltaX and delta(ibeam.X, ibeam.Xerr, iNNbeam.X, iNNbeam.Xerr) > 1.5
760  # deltaY = deltaY and delta(ibeam.Y, ibeam.Yerr, iNNbeam.Y, iNNbeam.Yerr) > 1.5
761  # deltaZ = deltaZ and delta(ibeam.Z, ibeam.Zerr, iNNbeam.Z, iNNbeam.Zerr) > 1.5
762  #
763  # deltasigmaZ = deltasigmaZ and delta(ibeam.sigmaZ, ibeam.sigmaZerr, iNNbeam.sigmaZ, iNNbeam.sigmaZerr) > 2.5
764  # deltadxdz = deltadxdz and delta(ibeam.dxdz, ibeam.dxdzerr, iNNbeam.dxdz, iNNbeam.dxdzerr) > 2.5
765  # deltadydz = deltadydz and delta(ibeam.dydz, ibeam.dydzerr, iNNbeam.dydz, iNNbeam.dydzerr) > 2.5
766  #
767  # deltawidthX = deltawidthX and delta(ibeam.beamWidthX, ibeam.beamWidthXerr, iNNbeam.beamWidthX, iNNbeam.beamWidthXerr) > 3
768  # deltawidthY = deltawidthY and delta(ibeam.beamWidthY, ibeam.beamWidthYerr, iNNbeam.beamWidthY, iNNbeam.beamWidthYerr) > 3
769 
770  if deltaX or deltaY or deltaZ or deltasigmaZ or deltadxdz or deltadydz or deltawidthX or deltawidthY:
771  docreate = True
772  #print "shift here: x="+str(deltaX)+" y="+str(deltaY)
773  #print "x1 = "+ibeam.X + " x1err = "+ibeam.Xerr
774  #print "x2 = "+inextbeam.X + " x2err = "+inextbeam.Xerr
775  #print "Lumi1: "+str(ibeam.IOVfirst) + " Lumi2: "+str(inextbeam.IOVfirst)
776  #print " x= "+ibeam.X+" +/- "+ibeam.Xerr
777  #print "weighted average x = "+tmpbeam.X +" +//- "+tmpbeam.Xerr
778  print "close payload because of movement in X= "+str(deltaX)+", Y= "+str(deltaY) + ", Z= "+str(deltaZ)+", sigmaZ= "+str(deltasigmaZ)+", dxdz= "+str(deltadxdz)+", dydz= "+str(deltadydz)+", widthX= "+str(deltawidthX)+", widthY= "+str(deltawidthY)
779  if docreate:
780  #if ii == len(listbeam)-1:
781  tmpbeam.IOVlast = ibeam.IOVlast
782  tmpbeam.IOVEndTime = ibeam.IOVEndTime
783  print " Run: "+tmpbeam.Run +" Lumi1: "+str(tmpbeam.IOVfirst) + " Lumi2: "+str(tmpbeam.IOVlast)
784  newlistbeam.append(tmpbeam)
785  tmpbeam = BeamSpot()
786  countlumi = 0
787  tmprun = ibeam.Run
788  countlumi += 1
789 
790  payloadfile = open(fileName,"w")
791  for iload in newlistbeam:
792  dump( iload, payloadfile )
793  payloadfile.close()
794  return newlistbeam
795 ###########################################################################################
796 def createWeightedPayloadsNew(fileName,listbeam=[],weighted=True):
797  newlistbeam = []
798  docreate = False
799  docheck = False
800  lastPayload = listbeam[0]
801 
802  firstToUse = 0
803  lastToUse = 0
804  for ii in range(0,len(listbeam)):
805  docreate = False
806  if docheck:
807  deltaX = delta(ibeam.X, ibeam.Xerr, inextbeam.X, inextbeam.Xerr) > 1.5
808  deltaY = delta(ibeam.Y, ibeam.Yerr, inextbeam.Y, inextbeam.Yerr) > 1.5
809  deltaZ = delta(ibeam.Z, ibeam.Zerr, inextbeam.Z, inextbeam.Zerr) > 2.5
810 
811  deltasigmaZ = delta(ibeam.sigmaZ, ibeam.sigmaZerr, inextbeam.sigmaZ, inextbeam.sigmaZerr) > 2.5
812  deltadxdz = delta(ibeam.dxdz, ibeam.dxdzerr, inextbeam.dxdz, inextbeam.dxdzerr) > 2.5
813  deltadydz = delta(ibeam.dydz, ibeam.dydzerr, inextbeam.dydz, inextbeam.dydzerr) > 2.5
814 
815  deltawidthX = delta(ibeam.beamWidthX, ibeam.beamWidthXerr, inextbeam.beamWidthX, inextbeam.beamWidthXerr) > 3
816  deltawidthY = delta(ibeam.beamWidthY, ibeam.beamWidthYerr, inextbeam.beamWidthY, inextbeam.beamWidthYerr) > 3
817 
818  #if iNNbeam.Type != -1:
819  # deltaX = deltaX and delta(ibeam.X, ibeam.Xerr, iNNbeam.X, iNNbeam.Xerr) > 1.5
820  # deltaY = deltaY and delta(ibeam.Y, ibeam.Yerr, iNNbeam.Y, iNNbeam.Yerr) > 1.5
821  # deltaZ = deltaZ and delta(ibeam.Z, ibeam.Zerr, iNNbeam.Z, iNNbeam.Zerr) > 1.5
822  #
823  # deltasigmaZ = deltasigmaZ and delta(ibeam.sigmaZ, ibeam.sigmaZerr, iNNbeam.sigmaZ, iNNbeam.sigmaZerr) > 2.5
824  # deltadxdz = deltadxdz and delta(ibeam.dxdz, ibeam.dxdzerr, iNNbeam.dxdz, iNNbeam.dxdzerr) > 2.5
825  # deltadydz = deltadydz and delta(ibeam.dydz, ibeam.dydzerr, iNNbeam.dydz, iNNbeam.dydzerr) > 2.5
826  #
827  # deltawidthX = deltawidthX and delta(ibeam.beamWidthX, ibeam.beamWidthXerr, iNNbeam.beamWidthX, iNNbeam.beamWidthXerr) > 3
828  # deltawidthY = deltawidthY and delta(ibeam.beamWidthY, ibeam.beamWidthYerr, iNNbeam.beamWidthY, iNNbeam.beamWidthYerr) > 3
829 
830  if deltaX or deltaY or deltaZ or deltasigmaZ or deltadxdz or deltadydz or deltawidthX or deltawidthY:
831  if ii != 0:
832  docreate = True
833  lastToUse = ii-1
834  #print "shift here: x="+str(deltaX)+" y="+str(deltaY)
835  #print "x1 = "+ibeam.X + " x1err = "+ibeam.Xerr
836  #print "x2 = "+inextbeam.X + " x2err = "+inextbeam.Xerr
837  #print "Lumi1: "+str(ibeam.IOVfirst) + " Lumi2: "+str(inextbeam.IOVfirst)
838  #print " x= "+ibeam.X+" +/- "+ibeam.Xerr
839  #print "weighted average x = "+tmpbeam.X +" +//- "+tmpbeam.Xerr
840  print "close payload because of movement in X= "+str(deltaX)+", Y= "+str(deltaY) + ", Z= "+str(deltaZ)+", sigmaZ= "+str(deltasigmaZ)+", dxdz= "+str(deltadxdz)+", dydz= "+str(deltadydz)+", widthX= "+str(deltawidthX)+", widthY= "+str(deltawidthY)
841 
842  #WARNING this will only be fine for Run based IOVs
843  if ii >= len(listbeam) - 1 or listbeam[ii].Run != listbeam[ii+1].Run :
844  print "close payload because end of run has been reached. Run " + listbeam[ii].Run
845  docreate = True
846  lastToUse = ii
847 
848 
849  # check maximum lumi counts
850 #? if countlumi == maxNlumis:
851 #? print "close payload because maximum lumi sections accumulated within run "+ibeam.Run
852 #? docreate = True
853 #? countlumi = 0
854  if docreate:
855  tmpbeam = BeamSpot()
856  for ibeam in listbeam[firstToUse:lastToUse]:
857  (tmpbeam.X, tmpbeam.Xerr) = weight(tmpbeam.X, tmpbeam.Xerr, ibeam.X, ibeam.Xerr)
858  (tmpbeam.Y, tmpbeam.Yerr) = weight(tmpbeam.Y, tmpbeam.Yerr, ibeam.Y, ibeam.Yerr)
859  (tmpbeam.Z, tmpbeam.Zerr) = weight(tmpbeam.Z, tmpbeam.Zerr, ibeam.Z, ibeam.Zerr)
860  (tmpbeam.sigmaZ, tmpbeam.sigmaZerr) = weight(tmpbeam.sigmaZ, tmpbeam.sigmaZerr, ibeam.sigmaZ, ibeam.sigmaZerr)
861  (tmpbeam.dxdz, tmpbeam.dxdzerr) = weight(tmpbeam.dxdz, tmpbeam.dxdzerr, ibeam.dxdz, ibeam.dxdzerr)
862  (tmpbeam.dydz, tmpbeam.dydzerr) = weight(tmpbeam.dydz, tmpbeam.dydzerr, ibeam.dydz, ibeam.dydzerr)
863  #print "wx = " + ibeam.beamWidthX + " err= "+ ibeam.beamWidthXerr
864  (tmpbeam.beamWidthX, tmpbeam.beamWidthXerr) = weight(tmpbeam.beamWidthX, tmpbeam.beamWidthXerr, ibeam.beamWidthX, ibeam.beamWidthXerr)
865  (tmpbeam.beamWidthY, tmpbeam.beamWidthYerr) = weight(tmpbeam.beamWidthY, tmpbeam.beamWidthYerr, ibeam.beamWidthY, ibeam.beamWidthYerr)
866  tmpbeam.IOVfirst = listbeam[firstToUse].IOVfirst
867  tmpbeam.IOVBeginTime = listbeam[firstToUse].IOVBeginTime
868  tmpbeam.Run = listbeam[firstToUse].Run
869  tmpbeam.Type = 2
870  tmpbeam.IOVlast = listbeam[lastToUse].IOVlast
871  tmpbeam.IOVEndTime = listbeam[lastToUse].IOVEndTime
872  newlistbeam.append(tmpbeam)
873  firstToUse = lastToUse+1
874  print "Run: " + tmpbeam.Run + " Lumi1: " + str(tmpbeam.IOVfirst) + " Lumi2: " + str(tmpbeam.IOVlast)
875 
876  payloadfile = open(fileName,"w")
877  for iload in newlistbeam:
878  dump( iload, payloadfile )
879  payloadfile.close()
880 
881 ###########################################################################################
882 def writeSqliteFile(sqliteFileName,tagName,timeType,beamSpotFile,sqliteTemplateFile,tmpDir="/tmp/"):
883  writeDBOut = tmpDir + "write2DB_" + tagName + ".py"
884  wFile = open(sqliteTemplateFile)
885  wNewFile = open(writeDBOut,'w')
886 
887  writeDBTags = [('SQLITEFILE','sqlite_file:' + sqliteFileName),
888  ('TAGNAME',tagName),
889  ('TIMETYPE',timeType),
890  ('BEAMSPOTFILE',beamSpotFile)]
891 
892  for line in wFile:
893  for itag in writeDBTags:
894  line = line.replace(itag[0],itag[1])
895  wNewFile.write(line)
896 
897  wNewFile.close()
898  print "writing sqlite file ..."
899  status_wDB = commands.getstatusoutput('cmsRun '+ writeDBOut)
900  print status_wDB[1]
901 
902  os.system("rm -f " + writeDBOut)
903  return not status_wDB[0]
904 
905 ###########################################################################################
906 def readSqliteFile(sqliteFileName,tagName,sqliteTemplateFile,tmpDir="/tmp/"):
907  readDBOut = tmpDir + "readDB_" + tagName + ".py"
908 
909  rFile = open(sqliteTemplateFile)
910  rNewFile = open(readDBOut,'w')
911 
912  readDBTags = [('SQLITEFILE','sqlite_file:' + sqliteFileName),
913  ('TAGNAME',tagName)]
914 
915  for line in rFile:
916  for itag in readDBTags:
917  line = line.replace(itag[0],itag[1])
918  rNewFile.write(line)
919 
920  rNewFile.close()
921  status_rDB = commands.getstatusoutput('cmsRun '+ readDBOut)
922 
923  outtext = status_rDB[1]
924  print outtext
925  os.system("rm -f " + readDBOut)
926  return not status_rDB[0]
927 
928 ###########################################################################################
929 def appendSqliteFile(combinedSqliteFileName, sqliteFileName, tagName, IOVSince, IOVTill ,tmpDir="/tmp/"):
930  aCommand = "cmscond_export_iov -d sqlite_file:" + tmpDir + combinedSqliteFileName + " -s sqlite_file:" + sqliteFileName + " -i " + tagName + " -t " + tagName + " -l sqlite_file:" + tmpDir + "log.db" + " -b " + IOVSince + " -e " + IOVTill
931  print aCommand
932  std = commands.getstatusoutput(aCommand)
933  print std[1]
934  return not std[0]
935 
936 ###########################################################################################
937 def uploadSqliteFile(sqliteFileDirName, sqliteFileName, dropbox="/DropBox"):
938  # Changing permissions to metadata
939  acmd = "chmod a+w " + sqliteFileDirName + sqliteFileName + ".txt"
940  outcmd = commands.getstatusoutput(acmd)
941  print acmd
942 # print outcmd[1]
943  if outcmd[0]:
944  print "Can't change permission to file: " + sqliteFileDirName + sqliteFileName + ".txt"
945  return False
946 
947  acmd = "cp " + sqliteFileDirName + sqliteFileName + ".db " + sqliteFileDirName + sqliteFileName + ".txt ."
948  print acmd
949  outcmd = commands.getstatusoutput(acmd)
950  print outcmd[1]
951  if outcmd[0]:
952  print "Couldn't cd to " + sqliteFileDirName
953  return False
954 
955  acmd = "tar -cvjf " + sqliteFileName + ".tar.bz2 " + sqliteFileName + ".db " + sqliteFileName + ".txt"
956  print acmd
957  outcmd = commands.getstatusoutput(acmd)
958  print outcmd[1]
959  if outcmd[0]:
960  print "Couldn't zip the files!"
961  return False
962 
963  acmd = "chmod a+w " + sqliteFileName + ".tar.bz2"
964  outcmd = commands.getstatusoutput(acmd)
965  print acmd
966 # print outcmd[1]
967  if outcmd[0]:
968  print "Can't change permission to file: " + sqliteFileDirName + sqliteFileName + ".tar.bz2"
969  return False
970 
971  acmd = "scp -p " + sqliteFileName + ".tar.bz2" + " webcondvm.cern.ch:" + dropbox
972  print acmd
973  outcmd = commands.getstatusoutput(acmd)
974  print outcmd[1]
975  if outcmd[0]:
976  print "Couldn't scp the files to DropBox!"
977  return False
978 
979 
980  acmd = "mv " + sqliteFileName + ".tar.bz2 " + sqliteFileDirName
981  print acmd
982  outcmd = commands.getstatusoutput(acmd)
983  print outcmd[1]
984  if outcmd[0]:
985  print "Couldn't mv the file to " + sqliteFileDirName
986  return False
987 
988  acmd = "rm " + sqliteFileName + ".db " + sqliteFileName + ".txt"
989  print acmd
990  outcmd = commands.getstatusoutput(acmd)
991  print outcmd[1]
992  if outcmd[0]:
993  print "Couldn't rm the db and txt files"
994  return False
995 
996 # acmd = "scp -p " + sqliteFileDirName + sqliteFileName + ".txt webcondvm.cern.ch:/tmp"
997 # outcmd = commands.getstatusoutput(acmd)
998 # print acmd
999 # print outcmd[1]
1000 # if outcmd[0]:
1001 # print "Can't change permission to file: " + sqliteFileName + ".txt"
1002 # return False
1003 
1004 # acmd = "ssh webcondvm.cern.ch \"mv /tmp/" + sqliteFileName + ".db /tmp/" + sqliteFileName + ".txt " + dropbox +"\""
1005 # print acmd
1006 # outcmd = commands.getstatusoutput(acmd)
1007 # print outcmd[1]
1008 # if outcmd[0]:
1009 # print "Can't move files from tmp to dropbox!"
1010  return False
1011 
1012 # acmd = "ssh webcondvm.cern.ch \"mv /tmp/" + final_sqlite_file_name + ".txt "+dropbox +"\""
1013 # outcmd = commands.getstatusoutput(acmd)
1014 # print acmd
1015 # print outcmd[1]
1016 # if outcmd[0]:
1017 # print "Can't change permission to file: " + sqliteFileName + ".txt"
1018 # return False
1019 
1020  return True
1021 
def sendEmail
General utilities.
def createWeightedPayloads
CREATE FILE FOR PAYLOADS.
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
return((rh^lh)&mask)
def createWeightedPayloadsNew
def pack
lumi tools CondCore/Utilities/python/timeUnitHelper.py
def sortAndCleanBeamList
Sort and clean list of data for consecutive duplicates and bad fits.
double split
Definition: MVATrainer.cc:139
def cmp_list_run
end lumi tools