Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
evg::GenieOutput Class Reference
Inheritance diagram for evg::GenieOutput:
art::EDAnalyzer art::detail::Analyzer art::detail::LegacyModule art::Observer art::ModuleBase

Public Types

using Parameters = art::EDAnalyzer::Table< evg::GenieOutputParams >
 
- Public Types inherited from art::EDAnalyzer
using WorkerType = WorkerT< EDAnalyzer >
 
using ModuleType = EDAnalyzer
 

Public Member Functions

 GenieOutput (const Parameters &params)
 
 ~GenieOutput ()
 
 GenieOutput (GenieOutput const &)=delete
 
 GenieOutput (GenieOutput &&)=delete
 
GenieOutputoperator= (GenieOutput const &)=delete
 
GenieOutputoperator= (GenieOutput &&)=delete
 
void analyze (art::Event const &e) override
 
- Public Member Functions inherited from art::EDAnalyzer
 EDAnalyzer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 EDAnalyzer (Table< Config > const &config)
 
std::string workerType () const
 
- Public Member Functions inherited from art::detail::Analyzer
virtual ~Analyzer () noexcept
 
 Analyzer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 Analyzer (Table< Config > const &config)
 
void doBeginJob ()
 
void doEndJob ()
 
void doRespondToOpenInputFile (FileBlock const &fb)
 
void doRespondToCloseInputFile (FileBlock const &fb)
 
void doRespondToOpenOutputFiles (FileBlock const &fb)
 
void doRespondToCloseOutputFiles (FileBlock const &fb)
 
bool doBeginRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doEndRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doBeginSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEndSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEvent (EventPrincipal &ep, ModuleContext const &mc, std::atomic< std::size_t > &counts_run, std::atomic< std::size_t > &counts_passed, std::atomic< std::size_t > &counts_failed)
 
- Public Member Functions inherited from art::Observer
 ~Observer () noexcept
 
 Observer (Observer const &)=delete
 
 Observer (Observer &&)=delete
 
Observeroperator= (Observer const &)=delete
 
Observeroperator= (Observer &&)=delete
 
void registerProducts (ProductDescriptions &, ModuleDescription const &)
 
void fillDescriptions (ModuleDescription const &)
 
std::string const & processName () const
 
bool wantAllEvents () const
 
bool wantEvent (Event const &e)
 
fhicl::ParameterSetID selectorConfig () const
 
Handle< TriggerResultsgetTriggerResults (Event const &e) const
 
- Public Member Functions inherited from art::ModuleBase
virtual ~ModuleBase () noexcept
 
 ModuleBase ()
 
ModuleDescription const & moduleDescription () const
 
void setModuleDescription (ModuleDescription const &)
 
std::array< std::vector< ProductInfo >, NumBranchTypes > const & getConsumables () const
 
void sortConsumables (std::string const &current_process_name)
 
template<typename T , BranchType BT>
ViewToken< T > consumesView (InputTag const &tag)
 
template<typename T , BranchType BT>
ViewToken< T > mayConsumeView (InputTag const &tag)
 

Private Member Functions

genie::NtpWriterFetchNtpWriter (const std::string &label)
 
std::ostream * FetchDumpStream (const std::string &label)
 

Private Attributes

Parameters fParams
 
std::vector< std::stringfInputModuleLabels
 label(s) of existing MCTruth/GTruth/MCFlux More...
 
std::string fOutputGHEPFilePattern
 
std::string fDumpFilePattern
 
int fDumpGeniePrintLevel
 
bool fDumpMCTruth
 
bool fDumpGTruth
 
bool fDumpMCFlux
 
bool fSeparateOutputNtpWriters
 
bool fSeparateDumpStreams
 
std::map< std::string, genie::NtpWriter * > fOutputNtpWriters
 
std::map< std::string, std::ostream * > fDumpStreams
 

Additional Inherited Members

- Protected Member Functions inherited from art::Observer
 Observer (fhicl::ParameterSet const &config)
 
 Observer (std::vector< std::string > const &paths, fhicl::ParameterSet const &config)
 
detail::ProcessAndEventSelectorsprocessAndEventSelectors ()
 
- Protected Member Functions inherited from art::ModuleBase
ConsumesCollectorconsumesCollector ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > consumes (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > mayConsume (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 

Detailed Description

Definition at line 100 of file GenieOutput_module.cc.

Member Typedef Documentation

Definition at line 105 of file GenieOutput_module.cc.

Constructor & Destructor Documentation

evg::GenieOutput::GenieOutput ( const Parameters params)
explicit

Definition at line 169 of file GenieOutput_module.cc.

170  : EDAnalyzer(params)
171  , fParams(params)
173  , fSeparateDumpStreams(false)
174 {
175  // trigger early initialization of PDG database & message service
177 
178  fInputModuleLabels = fParams().inputModuleLabels();
179  fOutputGHEPFilePattern = fParams().outputGHEPFilePattern();
180  fDumpFilePattern = fParams().dumpFilePattern();
181  fDumpGeniePrintLevel = fParams().dumpGeniePrintLevel();
182 
184  ( fOutputGHEPFilePattern.find("%l") != std::string::npos );
186  ( fDumpFilePattern.find("%l") != std::string::npos );
187 
188  fDumpMCTruth = fParams().dumpMCTruth();
189  fDumpGTruth = fParams().dumpGTruth();
190  fDumpMCFlux = fParams().dumpMCFlux();
191 
192  /*
193  mf::LogInfo("GenieOutput") << "##### Dump options "
194  << fDumpMCTruth << " "
195  << fDumpGTruth << " "
196  << fDumpMCFlux << " " ;
197  */
198 
199 }
std::vector< std::string > fInputModuleLabels
label(s) of existing MCTruth/GTruth/MCFlux
std::string fDumpFilePattern
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:27
static PDGLibrary * Instance(void)
Definition: PDGLibrary.cxx:43
std::string fOutputGHEPFilePattern
evg::GenieOutput::~GenieOutput ( )

Definition at line 201 of file GenieOutput_module.cc.

202 {
203 
204  // release resources
206  fOutputNtpWriters.begin();
207  for ( ; mitro != fOutputNtpWriters.end(); ++mitro ) {
208  std::string label = mitro->first;
209  genie::NtpWriter* ntpw = mitro->second;
210  if ( ntpw ) {
211  // close out the file
212  ntpw->Save();
213  delete ntpw;
214  }
215  mitro->second = 0;
216  }
217 
219  for ( ; mitrd != fDumpStreams.end(); ++mitrd ) {
220  std::string label = mitrd->first;
221  std::ofstream* fout = dynamic_cast<std::ofstream*>(mitrd->second);
222  if ( fout ) {
223  fout->flush();
224  fout->close();
225  delete fout;
226  }
227  mitrd->second = 0;
228  }
229 }
intermediate_table::iterator iterator
std::string string
Definition: nybbler.cc:12
std::map< std::string, genie::NtpWriter * > fOutputNtpWriters
std::map< std::string, std::ostream * > fDumpStreams
void Save(void)
get the even tree
Definition: NtpWriter.cxx:237
A utility class to facilitate creating the GENIE MC Ntuple from the output GENIE GHEP event records...
Definition: NtpWriter.h:40
evg::GenieOutput::GenieOutput ( GenieOutput const &  )
delete
evg::GenieOutput::GenieOutput ( GenieOutput &&  )
delete

Member Function Documentation

void evg::GenieOutput::analyze ( art::Event const &  e)
overridevirtual

Implements art::EDAnalyzer.

Definition at line 231 of file GenieOutput_module.cc.

232 {
233  //std::cerr << "evg::GenieOutput::analyze " << std::endl;
234 
236 
237  bool flag = true;
238  int indx = -1;
239  while ( ( flag = mcitr.Next() ) ) {
240  ++indx;
241  std::string label = mcitr.GetLabel();
242  const simb::MCTruth* pmctruth = mcitr.GetMCTruth();
243  const simb::GTruth* pgtruth = mcitr.GetGTruth();
244  const simb::MCFlux* pmcflux = mcitr.GetMCFlux();
245 
246  static int ievt = -1; // ! bah!
247  ++ievt;
248 
249  static const simb::GTruth nullGTruth;
250  if ( ! pgtruth ) {
251  mf::LogInfo("GenieOutput") << "##### no GTruth ";
252  pgtruth = &nullGTruth;
253  }
254 
255  genie::EventRecord* grec = evgb::RetrieveGHEP(*pmctruth,*pgtruth);
256 
257  genie::NtpWriter* ntpWriter = FetchNtpWriter(label);
258  if ( ntpWriter ) {
259  // check ownership! (might need copy)
260  ntpWriter->AddEventRecord(ievt,grec);
261  }
262 
263  std::ostream* osdump = FetchDumpStream(label);
264  if ( osdump ) {
265  *osdump
266  << " ** Event: GenieOutput_module " << ievt
267  << *grec;
268  osdump->flush();
269  }
270 
271  if ( fDumpMCTruth || fDumpGTruth || fDumpMCFlux ) {
272  std::ostringstream dumpSimBaseObj;
273  dumpSimBaseObj << " after Next() " << indx << " " << flag
274  << std::endl;;
275  if ( fDumpMCTruth ) {
276  if ( pmctruth ) dumpSimBaseObj << *pmctruth << std::endl;
277  else dumpSimBaseObj << "no simb::MCTruth available" << std::endl;
278  }
279  if ( fDumpGTruth ) {
280  if ( pgtruth ) {
281  dumpSimBaseObj << *pgtruth << std::endl;
282  //dumpSimBaseObj << "sorry no operator<< exists for simb::GTruth"
283  // << " - someone should write one" << std::endl;
284  } else dumpSimBaseObj << "no simb::GTruth available" << std::endl;
285  }
286  if ( fDumpMCFlux ) {
287  if ( pmcflux ) dumpSimBaseObj << *pmcflux << std::endl;
288  else dumpSimBaseObj << "no simb::MCFlux available" << std::endl;
289  }
290  mf::LogInfo("GenieOutput") << dumpSimBaseObj.str();
291  }
292 
293  delete grec; // don't leak stuff
294  } // loop over MCTruthAndFriends
295 
296 }
std::vector< std::string > fInputModuleLabels
label(s) of existing MCTruth/GTruth/MCFlux
std::string string
Definition: nybbler.cc:12
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
genie::EventRecord * RetrieveGHEP(const simb::MCTruth &truth, const simb::GTruth &gtruth, bool useFirstTrajPosition=true)
return genie::EventRecord pointer; callee takes possession
Definition: GENIE2ART.cxx:455
void AddEventRecord(int ievent, const EventRecord *ev_rec)
save the event tree
Definition: NtpWriter.cxx:70
Generated Event Record. It is a GHepRecord object that can accept / be visited by EventRecordVisitorI...
Definition: EventRecord.h:38
genie::NtpWriter * FetchNtpWriter(const std::string &label)
A utility class to facilitate creating the GENIE MC Ntuple from the output GENIE GHEP event records...
Definition: NtpWriter.h:40
std::ostream * FetchDumpStream(const std::string &label)
TCEvent evt
Definition: DataStructs.cxx:7
Event generator information.
Definition: MCTruth.h:32
QTextStream & endl(QTextStream &s)
std::ostream * evg::GenieOutput::FetchDumpStream ( const std::string label)
private

Definition at line 330 of file GenieOutput_module.cc.

330  {
331  if (fDumpGeniePrintLevel < 0 ) return 0;
333 
334  std::ostream* osret = 0;
335  if ( fSeparateDumpStreams ) osret = fDumpStreams[label];
336  else osret = fDumpStreams["*"];
337 
338  if ( osret ) return osret; // already openned
339 
340  // nope?? okay
341 
342  if ( fDumpFilePattern == "" ||
343  fDumpFilePattern == "--" ||
344  fDumpFilePattern == "cout" ||
345  fDumpFilePattern == "std::cout" ) {
346  // standardize so we don't check all these again
347  fDumpFilePattern = "std::cout";
348  osret = &(std::cout);
349  } else {
350  std::string finalFileName = fDumpFilePattern;
351  if ( fSeparateDumpStreams ) {
352  size_t posl = finalFileName.find("%l");
353  if ( posl != std::string::npos ) {
354  finalFileName.replace(posl,2,label);
355  }
356  }
357  osret = new std::ofstream(finalFileName.c_str(),
358  std::ios_base::trunc|std::ios_base::out);
359 
360  }
361  if ( fSeparateDumpStreams ) fDumpStreams[label] = osret;
362  else fDumpStreams["*"] = osret;
363 
364  return osret;
365 
366 }
static void SetPrintLevel(int print_level)
Definition: GHepRecord.cxx:992
std::string string
Definition: nybbler.cc:12
std::string fDumpFilePattern
std::map< std::string, std::ostream * > fDumpStreams
genie::NtpWriter * evg::GenieOutput::FetchNtpWriter ( const std::string label)
private

Definition at line 298 of file GenieOutput_module.cc.

298  {
299 
300  if ( fOutputGHEPFilePattern == "" ) return 0;
301 
302  genie::NtpWriter* ntpwret = 0;
304  else ntpwret = fOutputNtpWriters["*"];
305 
306  if ( ntpwret ) return ntpwret; // already openned
307 
308  // nope?? okay
309 
310  std::string finalFileName = fOutputGHEPFilePattern;
312  size_t posl = finalFileName.find("%l");
313  if ( posl != std::string::npos ) {
314  finalFileName.replace(posl,2,label);
315  }
316  }
317  ntpwret = new genie::NtpWriter(genie::kNFGHEP,0);
318  ntpwret->CustomizeFilename(finalFileName);
319  ntpwret->Initialize();
320 
322  else fOutputNtpWriters["*"] = ntpwret;
323 
324  return ntpwret;
325 
326 
327 }
void CustomizeFilename(string filename)
Definition: NtpWriter.cxx:141
std::string string
Definition: nybbler.cc:12
std::map< std::string, genie::NtpWriter * > fOutputNtpWriters
void Initialize(void)
add event
Definition: NtpWriter.cxx:96
A utility class to facilitate creating the GENIE MC Ntuple from the output GENIE GHEP event records...
Definition: NtpWriter.h:40
std::string fOutputGHEPFilePattern
GenieOutput& evg::GenieOutput::operator= ( GenieOutput const &  )
delete
GenieOutput& evg::GenieOutput::operator= ( GenieOutput &&  )
delete

Member Data Documentation

std::string evg::GenieOutput::fDumpFilePattern
private

Definition at line 151 of file GenieOutput_module.cc.

int evg::GenieOutput::fDumpGeniePrintLevel
private

Definition at line 152 of file GenieOutput_module.cc.

bool evg::GenieOutput::fDumpGTruth
private

Definition at line 155 of file GenieOutput_module.cc.

bool evg::GenieOutput::fDumpMCFlux
private

Definition at line 156 of file GenieOutput_module.cc.

bool evg::GenieOutput::fDumpMCTruth
private

Definition at line 154 of file GenieOutput_module.cc.

std::map<std::string,std::ostream*> evg::GenieOutput::fDumpStreams
private

Definition at line 162 of file GenieOutput_module.cc.

std::vector<std::string> evg::GenieOutput::fInputModuleLabels
private

label(s) of existing MCTruth/GTruth/MCFlux

Definition at line 149 of file GenieOutput_module.cc.

std::string evg::GenieOutput::fOutputGHEPFilePattern
private

Definition at line 150 of file GenieOutput_module.cc.

std::map<std::string,genie::NtpWriter*> evg::GenieOutput::fOutputNtpWriters
private

Definition at line 161 of file GenieOutput_module.cc.

Parameters evg::GenieOutput::fParams
private

Definition at line 147 of file GenieOutput_module.cc.

bool evg::GenieOutput::fSeparateDumpStreams
private

Definition at line 159 of file GenieOutput_module.cc.

bool evg::GenieOutput::fSeparateOutputNtpWriters
private

Definition at line 158 of file GenieOutput_module.cc.


The documentation for this class was generated from the following file: