CMS 3D CMS Logo

edm_modernize_messagelogger.py
Go to the documentation of this file.
1 import sys
2 
3 args = sys.argv
4 
5 if len(args) == 1:
6  print("file names must be passed as arguments")
7  exit(-1)
8 if args[1] == '-h' or args[1] == '--help':
9  print(
10 """python edm_modernize_messagelogger.py [-h/--help] filename [...]
11 
12  Converts explicit constructions of cms.Service("MessageLogger") from old MessageLogger
13  configration syntax to new the new syntax.
14  The script expects a list of files to be modified in place.
15 
16  NOTE: The script is known to miss some corner-cases in the conversion so always check
17  the results of the transformation.
18 """
19  )
20  exit(0)
21 
22 for arg in args[1:]:
23  execfile(arg)
24 
25  ml = process.MessageLogger.clone()
26  if hasattr(process.MessageLogger, "statistics"):
27  stat = process.MessageLogger.statistics
28  for s in stat:
29  dest = getattr(ml, s.value())
30  dest.enableStatistics = cms.untracked.bool(True)
31  del ml.statistics
32  dest = process.MessageLogger.destinations
33  files = cms.untracked.PSet()
34  if 'cerr' not in dest:
35  ml.cerr = cms.untracked.PSet(enable = cms.untracked.bool(False))
36  for d in dest:
37  if 'cout' == d:
38  continue
39  if 'cerr' == d:
40  continue
41  setattr(files, d, getattr(ml,d.value()))
42  delattr(ml, d)
43 
44  if hasattr(ml,'categories'):
45  del ml.categories
46  del ml.destinations
47 
48  f = open(arg)
49  newF = open(arg+"new", "w")
50 
51  processingML = False
52  parenthesis = 0
53  for l in f.readlines():
54  if not processingML:
55  if 'process.MessageLogger' == l[0:21]:
56  processingML = True
57  parenthesis = l.count('(')
58  parenthesis -= l.count(')')
59  if 0 == parenthesis:
60  processingML = False
61  continue
62  newF.write(l)
63  else:
64  parenthesis += l.count('(')
65  parenthesis -= l.count(')')
66  if 0 == parenthesis:
67  processingML = False
68  newF.write('process.MessageLogger = '+ml.dumpPython())
69 
70 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def exit(msg="")