gen_cmalgo.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 import sys, os
3 
4 if len(sys.argv)<2:
5  sys.stderr.write('Usage: %s CLASS_NAME\n\n' % sys.argv[0])
6  sys.exit(1)
7 if not 'MRB_TOP' in os.environ.keys():
8  sys.stderr.write('$MRB_TOP not defined!\n\n')
9  sys.exit(1)
10 
11 name='CMAlgo' + sys.argv[1]
12 working_package='CMTool'
13 target_dir='%s/srcs/larreco/RecoAlg/CMTool' % os.environ['MRB_TOP']
14 source_dir='%s/mac/tmp' % target_dir
15 
16 in_source='%s/cmalgo.cxx' % source_dir
17 in_header='%s/cmalgo.h' % source_dir
18 
19 src_list = { in_source : '%s/%s.cxx' % (target_dir,name),
20  in_header : '%s/%s.h' % (target_dir,name) }
21 
22 for src in src_list.keys():
23  if os.path.isfile(src_list[src]):
24  sys.stderr.write('File already exists: %s\n\n' % src_list[src])
25  sys.exit(1)
26 
27 for src in src_list.keys():
28  contents=open(src,'r').read()
29  contents=contents.replace('CMALGO_CLASS_NAME',name.upper())
30  contents=contents.replace('cmalgo_class_name',name.lower())
31  contents=contents.replace('CMAlgo_Class_Name',name)
32  contents=contents.replace('USER',os.environ['USER'])
33  contents=contents.replace('Working_Package',working_package)
34  fout=open(src_list[src],'w')
35  fout.write(contents)
36  fout.close()
37 
38 print
39 print 'Generated the followings under %s.' % target_dir
40 for key in src_list.keys():
41  print ' %s' % src_list[key]
42 print
43 sys.exit(0)
int open(const char *, int)
Opens a file descriptor.