CMS 3D CMS Logo

Classes | Functions | Variables
utils Namespace Reference

Classes

class  BinToBin
 
class  BinToBin1percent
 
class  Chi2
 
class  KS
 
class  StatisticalTest
 
class  unpickler
 

Functions

def ask_ok (prompt, retries=4, complaint='yes or no')
 
def code_generator (kwds)
 
def friendly_since (time_type, since)
 
def functor (code, kwds, debug=0)
 
def get_relval_cmssw_version (file)
 
def get_relval_id (file)
 
def get_relval_max_version (files)
 
def get_relval_version (file)
 ----------------— Make files pairs: RelVal utils ------------------— More...
 
def get_relvaldata_cmssw_version (file)
 
def get_relvaldata_id (file)
 --------------— Make files pairs: RelValData utils -----------------— More...
 
def get_relvaldata_max_version (files)
 
def get_relvaldata_version (file)
 
def getNbins (h)
 
def is_empty (h)
 
def is_relvaldata (files)
 ----------------------— Make files pairs -----------------------— More...
 
def is_sparse (h)
 
def literal2root (literal, rootType)
 
def logger (msg_level, message)
 
def make_files_pairs (files, verbose=True)
 
def parse_word (word)
 
def profile2histo (profile)
 
def setTDRStyle ()
 
def template_directory ()
 
def test_env (tdir, tmpl)
 
def to_datetime (date_string)
 
def to_timestamp (obj)
 
def tree (idir)
 
def user_info (ainput=None)
 
def wget (url)
 

Variables

 _log_level
 
 argv
 
 gErrorIgnoreLevel
 
 TAG
 
 theargv
 

Detailed Description

File that contains utility functions used by various modules, but that do not fit into any single module.

Function Documentation

◆ ask_ok()

def utils.ask_ok (   prompt,
  retries = 4,
  complaint = 'yes or no' 
)

Definition at line 431 of file utils.py.

431 def ask_ok(prompt, retries=4, complaint='yes or no'):
432  while True:
433  ok = raw_input(prompt)
434  if ok in ('y', 'ye', 'yes'):
435  return True
436  if ok in ('n', 'no'):
437  return False
438  retries = retries - 1
439  if retries < 0:
440  raise IOError('refusenik user')
441  print(complaint)
442 
443 #-------------------------------------------------------------------------------
444 

References print().

◆ code_generator()

def utils.code_generator (   kwds)
Code generator function, parse user arguments, load and
return appropriate template generator module.

Definition at line 122 of file utils.py.

122 def code_generator(kwds):
123  """
124  Code generator function, parse user arguments, load and
125  return appropriate template generator module.
126  """
127  debug = kwds.get('debug', None)
128  if debug:
129  print("Configuration:")
130  pprint.pprint(kwds)
131  try:
132  klass = kwds.get('tmpl')
133  mname = 'FWCore.Skeletons.%s' % klass.lower()
134  module = __import__(mname, fromlist=[klass])
135  except ImportError as err:
136  klass = 'AbstractPkg'
137  module = __import__('FWCore.Skeletons.pkg', fromlist=[klass])
138  if debug:
139  print("%s, will use %s" % (str(err), klass))
140  obj = getattr(module, klass)(kwds)
141  return obj
142 

References print(), and str.

Referenced by cms.generate(), and main.generator().

◆ friendly_since()

def utils.friendly_since (   time_type,
  since 
)
Takes a since and, if it is Run-based expressed as Lumi-based,
returns the run number.
Otherwise, returns the since without transformations.

Definition at line 18 of file utils.py.

18 def friendly_since(time_type, since):
19  """
20  Takes a since and, if it is Run-based expressed as Lumi-based,
21  returns the run number.
22  Otherwise, returns the since without transformations.
23  """
24  if time_type == "Run" and (since & 0xffffff) == 0:
25  return since >> 32
26  else:
27  return since

◆ functor()

def utils.functor (   code,
  kwds,
  debug = 0 
)
Auto-generate and execute function with given code and configuration
For details of compile/exec/eval see
http://lucumr.pocoo.org/2011/2/1/exec-in-python/

Definition at line 70 of file utils.py.

70 def functor(code, kwds, debug=0):
71  """
72  Auto-generate and execute function with given code and configuration
73  For details of compile/exec/eval see
74  http://lucumr.pocoo.org/2011/2/1/exec-in-python/
75  """
76  args = []
77  for key, val in kwds.items():
78  if isinstance(val, str):
79  arg = '%s="%s"' % (key, val)
80  elif isinstance(val, list):
81  arg = '%s=%s' % (key, val)
82  else:
83  msg = 'Unsupported data type "%s" <%s>' % (val, type(val))
84  raise Exception(msg)
85  args.append(arg)
86  func = '\nimport sys'
87  func += '\nimport StringIO'
88  func += "\ndef func(%s):\n" % ','.join(args)
89  func += code
90  func += """
91 def capture():
92  "Capture snippet printous"
93  old_stdout = sys.stdout
94  sys.stdout = StringIO.StringIO()
95  func()
96  out = sys.stdout.getvalue()
97  sys.stdout = old_stdout
98  return out\n
99 capture()\n"""
100  if debug:
101  print("\n### generated code\n")
102  print(func)
103  # compile python code as exec statement
104  obj = compile(func, '<string>', 'exec')
105  # define execution namespace
106  namespace = {}
107  # execute compiled python code in given namespace
108  exec(obj, namespace)
109  # located generated function object, run it and return its results
110  return namespace['capture']()
111 

References join(), and print().

Referenced by pkg.AbstractPkg.write().

◆ get_relval_cmssw_version()

def utils.get_relval_cmssw_version (   file)

Definition at line 544 of file utils.py.

544 def get_relval_cmssw_version(file):
545  cmssw_release = re.findall('(CMSSW_\d*_\d*_\d*(?:_[\w\d]*)?)-', file)
546  gr_r_version = re.findall('CMSSW_\d*_\d*_\d*(?:_[\w\d]*)?-([\w\d]*)_V\d*\w?(_[\w\d]*)?-v', file)
547  if cmssw_release and gr_r_version:
548  if "PU" in gr_r_version[0][0] and not "FastSim" in file:
549  __gt = re.sub('^[^_]*_', "", gr_r_version[0][0])
550  __process_string = gr_r_version[0][1]
551  return (__gt, __process_string)
552  elif "PU" in gr_r_version[0][0] and "FastSim" in file: #a check for FastSimPU samples
553  return (cmssw_release[0], "PU_") #with possibly different GT's
554  return (cmssw_release[0], gr_r_version[0])
555 

◆ get_relval_id()

def utils.get_relval_id (   file)
Returns unique relval ID (dataset name) for a given file.

Definition at line 556 of file utils.py.

556 def get_relval_id(file):
557  """Returns unique relval ID (dataset name) for a given file."""
558  dataset_name = re.findall('R\d{9}__([\w\D]*)__CMSSW_', file)
559  __process_string = re.search('CMSSW_\d*_\d*_\d*(?:_[\w\d]*)?-([\w\d]*)_V\d*\w?(_[\w\d]*)?-v', file)
560  _ps = ""
561  if __process_string:
562  if "PU" in __process_string.group(1) and not "FastSim" in file:
563  _ps = re.search('^[^_]*_', __process_string.group(1)).group()
564  elif "PU" in __process_string.group(1) and "FastSim" in file:
565  return dataset_name[0]+"_", _ps
566  return dataset_name[0], _ps
567 

References watchdog.group.

◆ get_relval_max_version()

def utils.get_relval_max_version (   files)
Returns file with maximum version at a) beggining of the file,
e.g. DQM_V000M b) at the end of run, e.g. _run2012-vM. M has to be max.

Definition at line 532 of file utils.py.

532 def get_relval_max_version(files):
533  """Returns file with maximum version at a) beggining of the file,
534  e.g. DQM_V000M b) at the end of run, e.g. _run2012-vM. M has to be max."""
535  max_file = files[0]
536  max_v = get_relval_version(files[0])
537  for file in files:
538  file_v = get_relval_version(file)
539  if file_v[1] > max_v[1] or ((file_v[1] == max_v[1]) and (file_v[0] > max_v[0])):
540  max_file = file
541  max_v = file_v
542  return max_file
543 

References get_relval_version().

◆ get_relval_version()

def utils.get_relval_version (   file)

----------------— Make files pairs: RelVal utils ------------------—

Returns tuple (CMSSW version, run version) for specified file.

Definition at line 525 of file utils.py.

525 def get_relval_version(file):
526  """Returns tuple (CMSSW version, run version) for specified file."""
527  cmssw_version = re.findall('DQM_V(\d*)_', file)
528  run_version = re.findall('CMSSW_\d*_\d*_\d*(?:_[\w\d]*)?-[\w\d]*_V\d*\w?(?:_[\w\d]*)?-v(\d*)__', file)
529  if cmssw_version and run_version:
530  return (int(cmssw_version[0]), int(run_version[0]))
531 

References createfilelist.int.

Referenced by get_relval_max_version().

◆ get_relvaldata_cmssw_version()

def utils.get_relvaldata_cmssw_version (   file)
Returns tuple (CMSSW release, GR_R version) for specified RelValData file.

Definition at line 494 of file utils.py.

495  """Returns tuple (CMSSW release, GR_R version) for specified RelValData file."""
496  cmssw_release = re.findall('(CMSSW_\d*_\d*_\d*(?:_[\w\d]*)?)-', file)
497  gr_r_version = re.findall('-(GR_R_\d*_V\d*\w?)(?:_RelVal)?_', file)
498  if not gr_r_version:
499  gr_r_version = re.findall('CMSSW_\d*_\d*_\d*(?:_[\w\d]*)?-(\w*)_RelVal_', file)
500  if cmssw_release and gr_r_version:
501  return (cmssw_release[0], gr_r_version[0])
502 

◆ get_relvaldata_id()

def utils.get_relvaldata_id (   file)

--------------— Make files pairs: RelValData utils -----------------—

Returns unique relvaldata ID for a given file.

Definition at line 484 of file utils.py.

484 def get_relvaldata_id(file):
485  """Returns unique relvaldata ID for a given file."""
486  run_id = re.search('R\d{9}', file)
487  run = re.search('_RelVal_([\w\d]*)-v\d__', file)
488  if not run:
489  run = re.search('GR_R_\d*_V\d*C?_([\w\d]*)-v\d__', file)
490  if run_id and run:
491  return (run_id.group(), run.group(1))
492  return None
493 

◆ get_relvaldata_max_version()

def utils.get_relvaldata_max_version (   files)
Returns file with maximum version at a) beggining of the file,
e.g. DQM_V000M b) at the end of run, e.g. _run2012-vM. M has to be max.

Definition at line 512 of file utils.py.

512 def get_relvaldata_max_version(files):
513  """Returns file with maximum version at a) beggining of the file,
514  e.g. DQM_V000M b) at the end of run, e.g. _run2012-vM. M has to be max."""
515  max_file = files[0]
516  max_v = get_relvaldata_version(files[0])
517  for file in files:
518  file_v = get_relvaldata_version(file)
519  if file_v[1] > max_v[1] or ((file_v[1] == max_v[1]) and (file_v[0] > max_v[0])):
520  max_file = file
521  max_v = file_v
522  return max_file
523 

References get_relvaldata_version().

◆ get_relvaldata_version()

def utils.get_relvaldata_version (   file)
Returns tuple (CMSSW version, run version) for specified file.

Definition at line 503 of file utils.py.

503 def get_relvaldata_version(file):
504  """Returns tuple (CMSSW version, run version) for specified file."""
505  cmssw_version = re.findall('DQM_V(\d*)_', file)
506  run_version = re.findall('_RelVal_[\w\d]*-v(\d)__', file)
507  if not run_version:
508  run_version = re.findall('GR_R_\d*_V\d*C?_[\w\d]*-v(\d)__', file)
509  if cmssw_version and run_version:
510  return (int(cmssw_version[0]), int(run_version[0]))
511 

References createfilelist.int.

Referenced by get_relvaldata_max_version().

◆ getNbins()

def utils.getNbins (   h)
To be used in loops on bin number with range()
For each dimension there are GetNbinsX()+2 bins including underflow 
and overflow, and range() loops starts from 0. So the total number
of bins as upper limit of a range() loop already includes the next 
to last value needed.

Definition at line 94 of file utils.py.

94 def getNbins(h):
95  """
96  To be used in loops on bin number with range()
97  For each dimension there are GetNbinsX()+2 bins including underflow
98  and overflow, and range() loops starts from 0. So the total number
99  of bins as upper limit of a range() loop already includes the next
100  to last value needed.
101  """
102  biny=h.GetNbinsY()
103  if biny>1: biny+=2
104  binz=h.GetNbinsZ()
105  if binz>1:binz+=2
106  return (h.GetNbinsX()+2)*(biny)*(binz)
107 
108 #-------------------------------------------------------------------------------
109 
110 

Referenced by utils.Chi2.absval(), utils.BinToBin.do_test(), utils.BinToBin1percent.do_test(), and utils.StatisticalTest.get_rank().

◆ is_empty()

def utils.is_empty (   h)

Definition at line 179 of file utils.py.

179 def is_empty(h):
180  for i in range(0,getNbins(h)):
181  if h.GetBinContent(i)!=0: return False
182  return True
183  #return h.GetSumOfWeights()==0
184 
185 #-------------------------------------------------------------------------------
186 

Referenced by DTSectColl.addTSTheta(), DEcompare< T >.get_ncand(), utils.StatisticalTest.get_rank(), and DEcompare< T >.SortCollections().

◆ is_relvaldata()

def utils.is_relvaldata (   files)

----------------------— Make files pairs -----------------------—

Definition at line 569 of file utils.py.

569 def is_relvaldata(files):
570  is_relvaldata_re = re.compile('_RelVal_')
571  return any([is_relvaldata_re.search(filename) for filename in files])
572 

References any().

Referenced by make_files_pairs().

◆ is_sparse()

def utils.is_sparse (   h)

Definition at line 187 of file utils.py.

187 def is_sparse(h):
188  filled_bins=0.
189  nbins=h.GetNbinsX()
190  for ibin in range(0,nbins+2):
191  if h.GetBinContent(ibin)>0:
192  filled_bins+=1
193  #print "%s %s --> %s" %(filled_bins,nbins,filled_bins/nbins)
194  if filled_bins/nbins < .5:
195  return True
196  else:
197  return False
198 
199 #-------------------------------------------------------------------------------
200 

References FastTimerService_cff.range.

◆ literal2root()

def utils.literal2root (   literal,
  rootType 
)

Definition at line 71 of file utils.py.

71 def literal2root (literal,rootType):
72  bitsarray = array.array('B')
73  bitsarray.fromstring(literal.decode('hex'))
74 
75  tbuffer=0
76  try:
77  tbuffer = TBufferFile(TBufferFile.kRead, len(bitsarray), bitsarray, False,0)
78  except:
79  print("could not transform to object array:")
80  print([ i for i in bitsarray ])
81 
82  # replace a couple of shortcuts with the real root class name
83  if rootType == 'TPROF':
84  rootType = 'TProfile'
85  if rootType == 'TPROF2D':
86  rootType = 'TProfile2D'
87 
88  root_class=eval(rootType+'.Class()')
89 
90  return tbuffer.ReadObject(root_class)
91 
92 #-------------------------------------------------------------------------------
93 

References print().

◆ logger()

def utils.logger (   msg_level,
  message 
)

Definition at line 49 of file utils.py.

49 def logger(msg_level,message):
50  if msg_level>=_log_level:
51  print("[%s] %s" %(asctime(),message))
52 
53 #-------------------------------------------------------------------------------

References print().

◆ make_files_pairs()

def utils.make_files_pairs (   files,
  verbose = True 
)

Definition at line 573 of file utils.py.

573 def make_files_pairs(files, verbose=True):
574 
575  if is_relvaldata(files):
576  is_relval_data = True
577  get_cmssw_version = get_relvaldata_cmssw_version
578  get_id = get_relvaldata_id
579  get_max_version = get_relvaldata_max_version
580  # print 'Pairing Data RelVal files.'
581  else:
582  is_relval_data = False
583  get_cmssw_version = get_relval_cmssw_version
584  get_id = get_relval_id
585  get_max_version = get_relval_max_version
586  # print 'Pairing Monte Carlo RelVal files.'
587 
588 
589  versions_files = dict()
590  for file in files:
591  version = get_cmssw_version(file)
592  if version in versions_files:
593  versions_files[version].append(file)
594  else:
595  versions_files[version] = [file]
596 
597 
598  if verbose:
599  print('\nFound versions:')
600  for version in versions_files:
601  print('%s: %d files' % (str(version), len(versions_files[version])))
602 
603  if len(versions_files) <= 1:
604  print('\nFound too little versions, there is nothing to pair. Exiting...\n')
605  exit()
606 
607 
608  versions = versions_files.keys()
609  sizes = [len(value) for value in versions_files.values()]
610  v1 = versions[sizes.index(max(sizes))]
611  versions.remove(v1)
612  sizes.remove(max(sizes))
613  v2 = versions[sizes.index(max(sizes))]
614 
615 
616  if verbose:
617  print('\nPairing %s (%d files) and %s (%d files)' % (str(v1),
618  len(versions_files[v1]), str(v2), len(versions_files[v2])))
619 
620 
621  print('\nGot pairs:')
622  pairs = []
623  for unique_id in set([get_id(file) for file in versions_files[v1]]):
624  if is_relval_data:
625  dataset_re = re.compile(unique_id[0]+'_')
626  run_re = re.compile(unique_id[1])
627  c1_files = [file for file in versions_files[v1] if dataset_re.search(file) and run_re.search(file)]
628  c2_files = [file for file in versions_files[v2] if dataset_re.search(file) and run_re.search(file)]
629  else:
630  dataset_re = re.compile(unique_id[0]+'_')
631  ps_re = re.compile(unique_id[1])
632 
633  c1_files = [file for file in versions_files[v1] if dataset_re.search(file) and ps_re.search(file)]
634  c2_files = [file for file in versions_files[v2] if dataset_re.search(file) and ps_re.search(file)]
635 
636  if len(c1_files) > 0 and len(c2_files) > 0:
637  first_file = get_max_version(c1_files)
638  second_file = get_max_version(c2_files)
639  print('%s\n%s\n' % (first_file, second_file))
640  pairs.extend((first_file, second_file))
641  if verbose:
642  print("Paired and got %d files.\n" % len(pairs))
643  return pairs

References mps_setup.append, beamvalidation.exit(), is_relvaldata(), SiStripPI.max, print(), and str.

Referenced by ValidationMatrix.get_filenames_from_pool().

◆ parse_word()

def utils.parse_word (   word)

Definition at line 37 of file utils.py.

37 def parse_word(word):
38  "Parse word which contas double underscore tag"
39  output = set()
40  words = word.split()
41  for idx in range(0, len(words)):
42  pat = words[idx]
43  if pat and len(pat) > 4 and pat[:2] == '__': # we found enclosure
44  tag = pat[2:pat.rfind('__')]
45  if tag.find('__') != -1: # another pattern
46  for item in tag.split('__'):
47  if TAG.match(item):
48  output.add('__%s__' % item)
49  else:
50  output.add('__%s__' % tag)
51  return output
52 

References FastTimerService_cff.range.

Referenced by pkg.AbstractPkg.tmpl_tags().

◆ profile2histo()

def utils.profile2histo (   profile)

Definition at line 228 of file utils.py.

228 def profile2histo(profile):
229  if not profile.InheritsFrom("TH1"):
230  return profile
231 
232  bin_low_edges=[]
233  n_bins=profile.GetNbinsX()
234 
235  for ibin in range(1,n_bins+2):
236  bin_low_edges.append(profile.GetBinLowEdge(ibin))
237  bin_low_edges=array.array('f',bin_low_edges)
238  histo=TH1F(profile.GetName(),profile.GetTitle(),n_bins,bin_low_edges)
239  for ibin in range(0,n_bins+2):
240  histo.SetBinContent(ibin,profile.GetBinContent(ibin))
241  histo.SetBinError(ibin,profile.GetBinError(ibin))
242 
243  return histo
244 #-------------------------------------------------------------------------------
245 

References FastTimerService_cff.range.

◆ setTDRStyle()

def utils.setTDRStyle ( )

Definition at line 54 of file utils.py.

54 def setTDRStyle():
55  this_dir=dirname(this_module_name)
56  this_dir_one_up=this_dir[:this_dir.rfind("/")+1]
57  #this_dir_two_up=this_dir_one_up[:this_dir_one_up.rfind("/")+1]
58  style_file=''
59  if "RELMON_SA" in os.environ:
60  style_file=this_dir_one_up+"data/tdrstyle_mod.C"
61  else:
62  style_file="%s/src/Utilities/RelMon/data/tdrstyle_mod.C"%(os.environ["CMSSW_BASE"])
63  try:
64  gROOT.ProcessLine(".L %s" %style_file)
65  gROOT.ProcessLine("setTDRStyle()")
66  except:
67  "Print could not set the TDR style. File %s not found?" %style_file
68 
69 
70 #-------------------------------------------------------------------------------

References BTVHLTOfflineSource_cfi.dirname.

◆ template_directory()

def utils.template_directory ( )

Definition at line 23 of file utils.py.

23 def template_directory():
24  "Return location of template directory"
25  mkTemplates = "src/FWCore/Skeletons/mkTemplates"
26  # Check developer area first
27  if "CMSSW_BASE" in os.environ:
28  ret = os.path.join(os.environ["CMSSW_BASE"], mkTemplates)
29  if os.path.exists(ret):
30  return ret
31  # Then release area
32  ret = os.path.join(os.environ["CMSSW_RELEASE_BASE"], mkTemplates)
33  if not os.path.exists(ret):
34  raise Exception("Did not find 'FWCore/Skeletons/mkTemplates' directory in the developer area nor in the release area")
35  return ret
36 

Referenced by main.generator().

◆ test_env()

def utils.test_env (   tdir,
  tmpl 
)
Test user environment, look-up if user has run cmsenv, otherwise
provide meaningful error message back to the user.

Definition at line 53 of file utils.py.

53 def test_env(tdir, tmpl):
54  """
55  Test user environment, look-up if user has run cmsenv, otherwise
56  provide meaningful error message back to the user.
57  """
58  if not tdir or not os.path.isdir(tdir):
59  print("Unable to access template dir: %s" % tdir)
60  sys.exit(1)
61  if not os.listdir(tdir):
62  print("No template files found in template dir %s" % tdir)
63  sys.exit(0)
64  if not tmpl:
65  msg = "No template type is provided, "
66  msg += "see available templates via --templates option"
67  print(msg)
68  sys.exit(1)
69 

References print().

Referenced by main.generator().

◆ to_datetime()

def utils.to_datetime (   date_string)
Takes a date string with the format Y-m-d H:m:S.f and gives back a datetime.datetime object

Definition at line 12 of file utils.py.

12 def to_datetime(date_string):
13  """
14  Takes a date string with the format Y-m-d H:m:S.f and gives back a datetime.datetime object
15  """
16  return datetime.datetime.strptime(date_string.replace(",", "."), "%Y-%m-%d %H:%M:%S.%f")
17 

Referenced by querying_tests.global_tag_tests().

◆ to_timestamp()

def utils.to_timestamp (   obj)
Takes a datetime object and outputs a timestamp string with the format Y-m-d H:m:S.f

Definition at line 6 of file utils.py.

6 def to_timestamp(obj):
7  """
8  Takes a datetime object and outputs a timestamp string with the format Y-m-d H:m:S.f
9  """
10  return obj.strftime('%Y-%m-%d %H:%M:%S.%f') if isinstance(obj, datetime.datetime) else obj
11 

◆ tree()

def utils.tree (   idir)

Definition at line 143 of file utils.py.

143 def tree(idir):
144  "Print directory content, similar to tree UNIX command"
145  if idir[-1] == '/':
146  idir = idir[-1]
147  dsep = ''
148  fsep = ''
149  dtot = -1 # we'll not count initial directory
150  ftot = 0
151  for root, dirs, files in os.walk(idir):
152  dirs = root.split('/')
153  ndirs = len(dirs)
154  if ndirs > 1:
155  dsep = '| '*(ndirs-1)
156  print('%s%s/' % (dsep, dirs[-1]))
157  dtot += 1
158  for fname in files:
159  fsep = dsep + '|--'
160  print('%s %s' % (fsep, fname))
161  ftot += 1
162  if dtot == -1 or not dtot:
163  dmsg = ''
164  else:
165  dmsg = '%s directories,' % dtot
166  if ftot:
167  fmsg = '%s file' % ftot
168  if ftot > 1:
169  fmsg += 's'
170  else:
171  fmsg = ''
172  if dmsg and fmsg:
173  print("Total: %s %s" % (dmsg, fmsg))
174  else:
175  print("No directories/files in %s" % idir)

References print().

◆ user_info()

def utils.user_info (   ainput = None)

Definition at line 112 of file utils.py.

112 def user_info(ainput=None):
113  "Return user name and office location, based on UNIX finger"
114  if ainput:
115  return ainput
116  pwdstr = pwd.getpwnam(os.getlogin())
117  author = pwdstr.pw_gecos
118  if author and isinstance(author, str):
119  author = author.split(',')[0]
120  return author
121 

◆ wget()

def utils.wget (   url)
Fetch the WHOLE file, not in bunches... To be optimised.

Definition at line 459 of file utils.py.

459 def wget(url):
460  """ Fetch the WHOLE file, not in bunches... To be optimised.
461  """
462  opener=build_opener(X509CertOpen())
463  datareq = Request(url)
464  datareq.add_header('authenticated_wget', "The ultimate wgetter")
465  bin_content=None
466  try:
467  filename=basename(url)
468  print("Checking existence of file %s on disk..."%filename)
469  if not isfile("./%s"%filename):
470  bin_content=opener.open(datareq).read()
471  else:
472  print("File %s exists, skipping.." %filename)
473  except ValueError:
474  print("Error: Unknown url %s" %url)
475 
476  if bin_content!=None:
477  ofile = open(filename, 'wb')
478  ofile.write(bin_content)
479  ofile.close()
480 
481 #-------------------------------------------------------------------------------

References print(), and readEcalDQMStatus.read.

Variable Documentation

◆ _log_level

utils._log_level
private

Definition at line 48 of file utils.py.

◆ argv

utils.argv

Definition at line 25 of file utils.py.

◆ gErrorIgnoreLevel

utils.gErrorIgnoreLevel

Definition at line 27 of file utils.py.

Referenced by main(), FWFileEntry.openFile(), and TkAlStyle.set().

◆ TAG

utils.TAG

Definition at line 21 of file utils.py.

◆ theargv

utils.theargv

Definition at line 24 of file utils.py.

utils.is_sparse
def is_sparse(h)
Definition: utils.py:187
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
utils.parse_word
def parse_word(word)
Definition: utils.py:37
utils.get_relvaldata_max_version
def get_relvaldata_max_version(files)
Definition: utils.py:512
utils.get_relval_id
def get_relval_id(file)
Definition: utils.py:556
utils.template_directory
def template_directory()
Definition: utils.py:23
join
static std::string join(char **cmd)
Definition: RemoteFile.cc:17
utils.is_relvaldata
def is_relvaldata(files)
----------------------— Make files pairs -----------------------—
Definition: utils.py:569
utils.wget
def wget(url)
Definition: utils.py:459
utils.user_info
def user_info(ainput=None)
Definition: utils.py:112
utils.get_relval_version
def get_relval_version(file)
----------------— Make files pairs: RelVal utils ------------------—
Definition: utils.py:525
any
bool any(const std::vector< T > &v, const T &what)
Definition: ECalSD.cc:38
BTVHLTOfflineSource_cfi.dirname
dirname
Definition: BTVHLTOfflineSource_cfi.py:7
utils.tree
def tree(idir)
Definition: utils.py:143
utils.is_empty
def is_empty(h)
Definition: utils.py:179
utils.get_relval_cmssw_version
def get_relval_cmssw_version(file)
Definition: utils.py:544
str
#define str(s)
Definition: TestProcessor.cc:52
utils.getNbins
def getNbins(h)
Definition: utils.py:94
utils.profile2histo
def profile2histo(profile)
Definition: utils.py:228
utils.get_relvaldata_cmssw_version
def get_relvaldata_cmssw_version(file)
Definition: utils.py:494
utils.ask_ok
def ask_ok(prompt, retries=4, complaint='yes or no')
Definition: utils.py:431
utils.get_relval_max_version
def get_relval_max_version(files)
Definition: utils.py:532
utils.to_datetime
def to_datetime(date_string)
Definition: utils.py:12
print
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:46
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
Exception
mps_setup.append
append
Definition: mps_setup.py:85
utils.test_env
def test_env(tdir, tmpl)
Definition: utils.py:53
createfilelist.int
int
Definition: createfilelist.py:10
utils.logger
def logger(msg_level, message)
Definition: utils.py:49
utils.get_relvaldata_version
def get_relvaldata_version(file)
Definition: utils.py:503
utils.code_generator
def code_generator(kwds)
Definition: utils.py:122
readEcalDQMStatus.read
read
Definition: readEcalDQMStatus.py:38
utils.friendly_since
def friendly_since(time_type, since)
Definition: utils.py:18
utils.make_files_pairs
def make_files_pairs(files, verbose=True)
Definition: utils.py:573
beamvalidation.exit
def exit(msg="")
Definition: beamvalidation.py:53
utils.to_timestamp
def to_timestamp(obj)
Definition: utils.py:6
utils.literal2root
def literal2root(literal, rootType)
Definition: utils.py:71
utils.setTDRStyle
def setTDRStyle()
Definition: utils.py:54
utils.get_relvaldata_id
def get_relvaldata_id(file)
--------------— Make files pairs: RelValData utils -----------------—
Definition: utils.py:484
watchdog.group
group
Definition: watchdog.py:82
utils.functor
def functor(code, kwds, debug=0)
Definition: utils.py:70