18 opts, args = getopt.getopt(argv,
"hf:",[
"funcname="])
19 except getopt.GetoptError:
20 print 'generate_weightcalc.py -f FUNCNAME' 24 print 'generate_weightcalc.py -f FUNCNAME' 29 print 'option not recognized' 33 print "You must specify function name with option -f!" 36 filename=
"".join(x
for x
in funcname
if x.isalnum())
37 filename=filename+
"WeightCalc.cxx" 39 if (os.path.isfile(filename)):
40 print "File",filename,
"already exists!" 43 print 'Genarating function', filename
46 #include \"larsim/EventWeight/Base/WeightCalcCreator.h\" 47 #include \"larsim/EventWeight/Base/WeightCalc.h\" 49 #include "art/Framework/Services/Registry/ServiceHandle.h" 50 #include "art/Framework/Services/Optional/RandomNumberGenerator.h" 52 #include "CLHEP/Random/RandGaussQ.h" 55 class %(funcname)sWeightCalc : public WeightCalc 58 %(funcname)sWeightCalc(); 59 void Configure(fhicl::ParameterSet const& p); 60 std::vector<std::vector<double> > GetWeight(art::Event & e); 62 CLHEP::RandGaussQ *fGaussRandom; 64 DECLARE_WEIGHTCALC(%(funcname)sWeightCalc) 66 %(funcname)sWeightCalc::%(funcname)sWeightCalc() 70 void %(funcname)sWeightCalc::Configure(fhicl::ParameterSet const& p) 72 //get configuration for this function 73 fhicl::ParameterSet const &pset=p.get<fhicl::ParameterSet> (GetName()); 75 //Prepare random generator 76 art::ServiceHandle<art::RandomNumberGenerator> rng; 77 fGaussRandom = new CLHEP::RandGaussQ(rng->getEngine(GetName())); 80 std::vector<std::vector<double> > %(funcname)sWeightCalc::GetWeight(art::Event & e) 82 //calculate weight(s) here 83 std::vector<std::vector<double> > weight; 86 REGISTER_WEIGHTCALC(%(funcname)sWeightCalc) 88 '''%{
'funcname':funcname}
95 if __name__ ==
"__main__":
int open(const char *, int)
Opens a file descriptor.