CMS 3D CMS Logo

EventContainer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 #include <iostream>
3 #include <fstream>
4 #include <iomanip>
5 #include <cassert>
6 
11 
12 #include "TH1.h"
13 
14 using namespace std;
15 using namespace fwlite;
16 
18 // Static Member Data Declaration //
20 
21 bool EventContainer::sm_autoloaderCalled = false;
22 
23 EventContainer::EventContainer(optutl::CommandLineParser& parser, FuncPtr funcPtr)
24  : m_eventsSeen(0), m_maxWanted(0), m_parserPtr(nullptr) {
25  // get the user-defined tag
26  string tag;
27  if (funcPtr) {
28  (*funcPtr)(tag);
29  }
30 
31  // finish defaultt options and create fwlite::Event
33 
34  // Call the autoloader if not already called.
35  if (!sm_autoloaderCalled) {
37  sm_autoloaderCalled = true;
38  }
39 
40  const optutl::CommandLineParser::SVec& secondaryInputFiles = parser.stringVector("secondaryInputFiles");
41  if (!secondaryInputFiles.empty()) {
43  parser.stringVector("inputFiles"), secondaryInputFiles, parser.boolValue("orderedSecondaryFiles"));
44  } else {
46  }
47 
48  // get whatever other info you want
49  m_outputName = parser.stringValue("outputFile");
50  m_maxWanted = parser.integerValue("maxEvents");
51  m_outputEvery = parser.integerValue("outputEvery");
52 
53  // remember my parser
55 
56  // TH1::AddDirectory(false);
57 }
58 
60  // if the pointer is non-zero, then we should run the standard
61  // destructor. If it is zero, then we should do nothing
62  if (!m_eventBasePtr) {
63  return;
64  }
65  // If we're still here, let's get to work.
66  cout << "EventContainer Summary: Processed " << m_eventsSeen << " events." << endl;
68  if (optutl::CommandLineParser::kStringVector == parser.hasOption("inputFiles")) {
70  } else {
72  }
73  delete m_eventBasePtr;
74 }
75 
76 void EventContainer::add(TH1* histPtr, const string& directory) { m_histStore.add(histPtr, directory); }
77 
80  return *m_parserPtr;
81 }
82 
83 TH1* EventContainer::hist(const string& name) { return m_histStore.hist(name); }
84 
85 bool EventContainer::getByLabel(const std::type_info& iInfo,
86  const char* iModuleLabel,
87  const char* iProductInstanceLabel,
88  const char* iProcessLabel,
89  void* oData) const {
91  return m_eventBasePtr->getByLabel(iInfo, iModuleLabel, iProductInstanceLabel, iProcessLabel, oData);
92 }
93 
94 const std::string EventContainer::getBranchNameFor(const std::type_info& iInfo,
95  const char* iModuleLabel,
96  const char* iProductInstanceLabel,
97  const char* iProcessLabel) const {
99  return m_eventBasePtr->getBranchNameFor(iInfo, iModuleLabel, iProductInstanceLabel, iProcessLabel);
100 }
101 
104 
105  m_eventBasePtr->operator++();
106  ++m_eventsSeen;
107  if (m_outputEvery && m_eventsSeen % m_outputEvery == 0) {
108  cout << "Processing Event: " << m_eventsSeen << endl;
109  }
110  return *this;
111 }
112 
115  m_eventsSeen = 0;
117 
118  // If we're going to skip over any events, do it here.
119 
120  // O.k. We should be good to go.
121  return *this;
122 }
123 
124 bool EventContainer::atEnd() const {
126  // first check to see that we haven't already processed the maxinum
127  // number of events that we asked for.
129  // we're done
130  return true;
131  }
132 
133  return m_eventBasePtr->atEnd();
134 }
135 
136 // friends
137 ostream& operator<<(ostream& o_stream, const EventContainer& rhs) { return o_stream; }
void _finishDefaultOptions(std::string tag="")
const EventContainer & operator++() override
void add(TH1 *histPtr, const std::string &directory="")
Definition: TH1Store.cc:30
std::string & stringValue(std::string key)
const EventContainer & toBegin() override
ostream & operator<<(ostream &o_stream, const EventContainer &rhs)
virtual std::string const getBranchNameFor(std::type_info const &, char const *, char const *, char const *) const =0
static bool sm_autoloaderCalled
std::vector< std::string > SVec
assert(be >=bs)
virtual bool getByLabel(std::type_info const &, char const *, char const *, char const *, void *) const =0
int & integerValue(std::string key)
fwlite::EventBase * m_eventBasePtr
static void enable()
enable automatic library loading
bool atEnd() const override
void write(const std::string &filename, const SVec &argsVec=kEmptyVec, const SVec &inputFilesVec=kEmptyVec) const
void add(TH1 *histPtr, const std::string &directory="")
bool getByLabel(const std::type_info &iInfo, const char *iModuleLabel, const char *iProductInstanceLabel, const char *iProcessLabel, void *oData) const override
optutl::CommandLineParser * m_parserPtr
SVec & stringVector(std::string key)
bool & boolValue(std::string key)
const SVec argVec() const
virtual bool atEnd() const =0
const std::string getBranchNameFor(const std::type_info &iInfo, const char *iModuleLabel, const char *iProductInstanceLabel, const char *iProcessLabel) const override
TH1 * hist(const std::string &name)
TH1 * hist(const std::string &name)
virtual EventBase const & toBegin()=0
optutl::CommandLineParser & parser()
OptionType hasOption(std::string key)