CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Functions | Variables
electronDataDiscovery Namespace Reference

Functions

def common_search
 
def getCMSdata
 
def search
 
def search2
 

Variables

tuple dd_cond_re = re.compile(os.environ['DD_COND'].replace('*', '.*'))
 
tuple dd_release_re = re.compile(os.environ['DD_RELEASE'].replace('*', '.*'))
 
tuple dd_run_re = re.compile(os.environ['DD_RUN'].replace('*', '.*'))
 
tuple dd_sample_re = re.compile(os.environ['DD_SAMPLE'].replace('*', '.*'))
 
tuple files = dd.search()
 

Function Documentation

def electronDataDiscovery.common_search (   dd_tier)

Definition at line 60 of file electronDataDiscovery.py.

References das_client.get_data(), print(), sistrip::SpyUtilities.range(), python.rootplot.root2matplotlib.replace(), and str.

Referenced by search(), and search2().

60 
61 def common_search(dd_tier):
62  dd_tier_re = re.compile(dd_tier.replace('*', '.*'));
63 
64  if os.environ['DD_SOURCE'] == "das":
65 
66  query = "dataset instance=cms_dbs_prod_global"
67  if os.environ['DD_RELEASE'] != "":
68  query = query + " release=" + os.environ['DD_RELEASE']
69  if os.environ['DD_SAMPLE'] != "":
70  query = query + " primary_dataset=" + os.environ['DD_SAMPLE']
71  if dd_tier != "":
72  query = query + " tier=" + dd_tier
73  if os.environ['DD_COND'] != "":
74  query = query + " dataset=*" + os.environ['DD_COND'] + "*"
75  if os.environ['DD_RUN'] != "":
76  query = query + " run=" + os.environ['DD_RUN']
77  # query = query + " | unique" # too long ??
78 
79  # data = os.popen('das_client.py --limit=0 --query "'+query+'"')
80  # datalines = data.readlines()
81  # data.close()
82  # datasets = []
83  # for line in datalines:
84  # line = line.rstrip()
85  # if line != "" and line[0] =="/":
86  # datasets.append(line)
87  # dataset = datasets[0]
88 
89  data = das_client.json.loads(das_client.get_data('https://cmsweb.cern.ch', query, 0, 0, 0))
90 
91  if data['nresults'] == 0:
92  print('[electronDataDiscovery.py] No DAS dataset for query:', query)
93  return []
94  while data['nresults'] > 1:
95  if data['data'][0]['dataset'][0]['name'] == data['data'][1]['dataset'][0]['name']:
96  data['data'].pop(0)
97  data['nresults'] -= 1
98  else:
99  print('[electronDataDiscovery.py] Several DAS datasets for query:', query)
100  for i in range(data['nresults']):
101  print(
102  '[electronDataDiscovery.py] dataset[' + str(i) + ']: ' + data['data'][i]['dataset'][0]['name'])
103  return []
104 
105  dataset = data['data'][0]['dataset'][0]['name']
106 
107  query = "file instance=cms_dbs_prod_global dataset=" + dataset
108 
109  # data = os.popen('das_client.py --limit=0 --query "'+query+'"')
110  # datalines = data.readlines()
111  # data.close()
112  # result = []
113  # for line in datalines:
114  # line = line.rstrip()
115  # if line != "" and line[0] =="/":
116  # result.append(line)
117 
118  data = das_client.json.loads(das_client.get_data('https://cmsweb.cern.ch', query, 0, 0, 0))
119 
120  if data['nresults'] == 0:
121  print('[electronDataDiscovery.py] No DAS file in dataset:', dataset)
122  return []
123  else:
124  print('there is %d results' % nresults)
125 
126  result = []
127  for i in range(0, data['nresults']):
128  result.append(str(data['data'][i]['file'][0]['name']))
129 
130  elif os.environ['DD_SOURCE'] == "dbs":
131 
132  input = "find file"
133  separator = " where "
134  if os.environ['DD_RELEASE'] != "":
135  input = input + separator + "release = " + os.environ['DD_RELEASE']
136  separator = " and "
137  if os.environ['DD_SAMPLE'] != "":
138  input = input + separator + "primds = " + os.environ['DD_SAMPLE']
139  separator = " and "
140  if os.environ['DD_RUN'] != "":
141  input = input + separator + "run = " + os.environ['DD_RUN']
142  separator = " and "
143  input = input + separator + "dataset like *" + os.environ['DD_COND'] + "*" + dd_tier + "*"
144 
145  data = os.popen(
146  'dbs search --url="http://cmsdbsprod.cern.ch/cms_dbs_prod_global/servlet/DBSServlet" --query "' + input + '"')
147  datalines = data.readlines()
148  data.close()
149  result = []
150  for line in datalines:
151  line = line.rstrip()
152  if line != "" and line[0] == "/":
153  result.append(line)
154 
155  elif os.environ['DD_SOURCE'] == "http":
156 
157  input = "find file"
158  separator = " where "
159  if os.environ['DD_RELEASE'] != "":
160  input = input + separator + "release = " + os.environ['DD_RELEASE']
161  separator = " and "
162  if os.environ['DD_SAMPLE'] != "":
163  input = input + separator + "primds = " + os.environ['DD_SAMPLE']
164  separator = " and "
165  if os.environ['DD_RUN'] != "":
166  input = input + separator + "run = " + os.environ['DD_RUN']
167  separator = " and "
168  input = input + separator + "dataset like *" + os.environ['DD_COND'] + "*" + dd_tier + "*"
169 
170  url = "https://cmsweb.cern.ch:443/dbs_discovery/aSearch"
171  final_input = urllib.quote(input);
172 
173  agent = "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)"
174  ctypes = "text/plain"
175  headers = {'User-Agent': agent, 'Accept': ctypes}
176  params = {'dbsInst': 'cms_dbs_prod_global',
177  'html': 0, 'caseSensitive': 'on', '_idx': 0, 'pagerStep': -1,
178  'userInput': final_input,
179  'xml': 0, 'details': 0, 'cff': 0, 'method': 'dbsapi'}
180  data = urllib.urlencode(params, doseq=True)
181  req = urllib2.Request(url, data, headers)
182  data = ""
183 
184  try:
185  response = urllib2.urlopen(req)
186  data = response.read()
187  except urllib2.HTTPError as e:
188  if e.code == 201:
189  print(e.headers)
190  print(e.msg)
191  pass
192  else:
193  raise e
194 
195  datalines = data.readlines()
196  data.close()
197  result = []
198  for line in datalines:
199  line = line.rstrip()
200  if line != "" and line[0] == "/":
201  result.append(line)
202 
203  elif os.environ['DD_SOURCE'] == "lsf":
204 
205  dbs_path = '/' + os.environ['DD_SAMPLE'] + '/' + os.environ['DD_RELEASE'] + '-' + os.environ['DD_COND'] + '/' + \
206  os.environ['DD_TIER'] + '"'
207  if __name__ == "__main__":
208  print('dbs path:', dbs_path)
209  data = os.popen('dbs lsf --path="' + dbs_path + '"')
210  datalines = data.readlines()
211  data.close()
212  result = []
213  for line in datalines:
214  line = line.rstrip()
215  if line != "" and line[0] == "/":
216  result.append(line)
217 
218  elif os.environ['DD_SOURCE'].startswith('/castor/cern.ch/cms/'): # assumed to be a castor dir
219 
220  castor_dir = os.environ['DD_SOURCE'].replace('/castor/cern.ch/cms/', '/', 1)
221  result = []
222  data = os.popen('rfdir /castor/cern.ch/cms' + castor_dir)
223  subdirs = data.readlines()
224  data.close()
225  datalines = []
226  for line in subdirs:
227  line = line.rstrip()
228  subdir = line.split()[8]
229  data = os.popen('rfdir /castor/cern.ch/cms' + castor_dir + '/' + subdir)
230  datalines = data.readlines()
231  for line in datalines:
232  line = line.rstrip()
233  file = line.split()[8]
234  if file != "":
235  result.append(castor_dir + '/' + subdir + '/' + file)
236  data.close()
237 
238  elif os.environ['DD_SOURCE'].startswith('/eos/cms/'): # assumed to be an eos dir
239 
240  data = os.popen('eos find -f ' + os.environ['DD_SOURCE'])
241  lines = data.readlines()
242  data.close()
243  result = []
244  for line in lines:
245  line = line.strip().replace('/eos/cms/', '/', 1)
246  if line == "": continue
247  if dd_sample_re.search(line) == None: continue
248  if dd_cond_re.search(line) == None: continue
249  if dd_tier_re.search(line) == None: continue
250  if dd_run_re.search(line) == None: continue
251  result.append(line)
252 
253  else: # os.environ['DD_SOURCE'] is assumed to be a file name
254 
255  result = []
256  for line in open(os.environ['DD_SOURCE']).readlines():
257  line = os.path.expandvars(line.strip())
258  if line == "": continue
259  if dd_sample_re.search(line) == None: continue
260  if dd_cond_re.search(line) == None: continue
261  if dd_tier_re.search(line) == None: continue
262  if dd_run_re.search(line) == None: continue
263  result.append(line)
264 
265  if len(result) == 0:
266  diag = '[electronDataDiscovery.py] No more files after filtering with :'
267  if os.environ['DD_SAMPLE'] != '': diag += ' ' + os.environ['DD_SAMPLE']
268  if os.environ['DD_COND'] != '': diag += ' ' + os.environ['DD_COND']
269  if dd_tier != '': diag += ' ' + dd_tier
270  if os.environ['DD_RUN'] != '': diag += ' ' + os.environ['DD_RUN']
271  print(diag)
272 
273  return result
274 
const uint16_t range(const Frame &aFrame)
def get_data
Definition: das_client.py:276
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
#define str(s)
def electronDataDiscovery.getCMSdata (   data,
  dbs = "prod/global" 
)

Definition at line 284 of file electronDataDiscovery.py.

References SiPixelLorentzAngle_cfi.read, and python.rootplot.root2matplotlib.replace().

285 def getCMSdata(data, dbs="prod/global"):
286  # Read DAS database.
287  cmd = 'dasgoclient --query="file dataset=DATA instance=DBS" | sort'
288  cmd2 = cmd.replace('DATA', data).replace('DBS', dbs)
289  files = os.popen(cmd2).read()
290  # Create python list containing file names.
291  flist = files.split('\n')
292  del flist[-1]
293  return flist
def electronDataDiscovery.search ( )

Definition at line 275 of file electronDataDiscovery.py.

References common_search(), and print().

276 def search():
277  print('search in %s' % 'DD_TIER')
278  return common_search(os.environ['DD_TIER'])
279 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def electronDataDiscovery.search2 ( )

Definition at line 280 of file electronDataDiscovery.py.

References common_search().

Referenced by DQMPFCandidateAnalyzer.dqmBeginRun(), and METAnalyzer.dqmBeginRun().

281 def search2():
282  return common_search(os.environ['DD_TIER_SECONDARY'])
283 

Variable Documentation

tuple electronDataDiscovery.dd_cond_re = re.compile(os.environ['DD_COND'].replace('*', '.*'))

Definition at line 56 of file electronDataDiscovery.py.

tuple electronDataDiscovery.dd_release_re = re.compile(os.environ['DD_RELEASE'].replace('*', '.*'))

Definition at line 54 of file electronDataDiscovery.py.

tuple electronDataDiscovery.dd_run_re = re.compile(os.environ['DD_RUN'].replace('*', '.*'))

Definition at line 57 of file electronDataDiscovery.py.

tuple electronDataDiscovery.dd_sample_re = re.compile(os.environ['DD_SAMPLE'].replace('*', '.*'))

Definition at line 55 of file electronDataDiscovery.py.

tuple electronDataDiscovery.files = dd.search()

Definition at line 11 of file electronDataDiscovery.py.