All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Functions
generate_weightcalc Namespace Reference

Functions

def main
 

Function Documentation

def generate_weightcalc.main (   argv)

Definition at line 14 of file generate_weightcalc.py.

14 
15 def main(argv):
16  funcname = ''
17 
18  try:
19  opts, args = getopt.getopt(argv,"hf:",["funcname="])
20  except getopt.GetoptError:
21  print 'generate_weightcalc.py -f FUNCNAME'
22  sys.exit(2)
23  for opt, arg in opts:
24  if opt == '-h':
25  print 'generate_weightcalc.py -f FUNCNAME'
26  sys.exit()
27  elif opt == '-f':
28  funcname = arg
29  else:
30  print 'option not recognized'
31  sys.exit(2)
32 
33  if ( funcname=='' ):
34  print "You must specify function name with option -f!"
35  sys.exit(2)
36 
37  filename="".join(x for x in funcname if x.isalnum())
38  filename=filename+"WeightCalc.cxx"
39 
40  if (os.path.isfile(filename)):
41  print "File",filename,"already exists!"
42  sys.exit(2)
43 
44  print 'Genarating function', filename
45 
46  ofstr='''
47 #include \"larsim/EventWeight/Base/WeightCalcCreator.h\"
48 #include \"larsim/EventWeight/Base/WeightCalc.h\"
49 
50 #include "art/Framework/Services/Registry/ServiceHandle.h"
51 #include "art/Framework/Services/Optional/RandomNumberGenerator.h"
52 
53 #include "CLHEP/Random/RandGaussQ.h"
54 
55 namespace evwgh {
56  class %(funcname)sWeightCalc : public WeightCalc
57  {
58  public:
59  %(funcname)sWeightCalc();
60  void Configure(fhicl::ParameterSet const& p);
61  std::vector<std::vector<double> > GetWeight(art::Event & e);
62  private:
63  CLHEP::RandGaussQ *fGaussRandom;
64 
65  DECLARE_WEIGHTCALC(%(funcname)sWeightCalc)
66  };
67  %(funcname)sWeightCalc::%(funcname)sWeightCalc()
68  {
69  }
70 
71  void %(funcname)sWeightCalc::Configure(fhicl::ParameterSet const& p)
72  {
73  //get configuration for this function
74  fhicl::ParameterSet const &pset=p.get<fhicl::ParameterSet> (GetName());
75 
76  //Prepare random generator
77  art::ServiceHandle<art::RandomNumberGenerator> rng;
78  fGaussRandom = new CLHEP::RandGaussQ(rng->getEngine(GetName()));
79  }
80 
81  std::vector<std::vector<double> > %(funcname)sWeightCalc::GetWeight(art::Event & e)
82  {
83  //calculate weight(s) here
84  std::vector<std::vector<double> > weight;
85  return weight;
86  }
87  REGISTER_WEIGHTCALC(%(funcname)sWeightCalc)
88 }
89 '''%{'funcname':funcname}
90 
91  of=open(filename,'w')
92 
93  of.write(ofstr)
94  of.close()
S join(S const &sep, Coll const &s)
Returns a concatenation of strings in s separated by sep.
open(RACETRACK) or die("Could not open file $RACETRACK for writing")