babymaker  e95a6a9342d4604277fe7cc6149b6b5b24447d89
link_missing_samples.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 ###### Script that links missing files an "old" production to a "new" production
4 import os, sys, subprocess
5 import pprint
6 import glob
7 
8 # Setting folders
9 oldfolder = '/net/cms27/cms27r0/babymaker/2016_04_29/mc/unskimmed/'
10 newfolder = '/net/cms2/cms2r0/babymaker/babies/2016_06_14/mc/unskimmed/'
11 link_dest = '/net/cms2/cms2r0/babymaker/babies/2016_06_14/mc/unskimmed/'
12 
13 ## Finding tags for each dataset
14 oldsamples, newsamples = set(), set()
15 oldfiles = glob.glob(oldfolder+'/*.root')
16 newfiles = glob.glob(newfolder+'/*.root')
17 for file in oldfiles+newfiles:
18  tag = file.split("RunII")[0]
19  if "SMS-" in tag: continue
20  if ("TTJets_Tune" not in tag) and ("DYJetsToLL_M-50_Tune" not in tag): tag = tag.split("Tune")[0]
21  tag = tag.split("13TeV")[0]
22  tag = tag.split("pythia")[0]
23  tag = tag.split("baby_")[1]
24  tag = tag.split("__")[0]
25  if tag[0] != '_': tag = "_"+tag
26  if tag[-1] != '_': tag = tag+"_"
27  if oldfolder in file: oldsamples.add(tag)
28  else: newsamples.add(tag)
29 
30 
31 missing = sorted(list(oldsamples-newsamples))
32 if len(missing)>0:
33  print "Samples in the old folder that are not found in the new folder:"
34  for itag in missing:
35  print "\t",itag
36  for file in oldfiles:
37  if itag in file:
38  print "Linking:",file
39  os.symlink(file, link_dest+"/"+file.split("/")[-1])
40 else:
41  print "No missing samples in the new production"
42 
43 extras = sorted(list(newsamples-oldsamples))
44 if len(extras)>0:
45  print "Samples in the new folder that are not found in the old folder:"
46  for i in extras:
47  print "\t",i
48 else:
49  print "No extra samples in the new production"
50