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; }
optutl::VariableMapCont::stringValue
std::string & stringValue(std::string key)
Definition: VariableMapCont.cc:163
fwlite::EventContainer::~EventContainer
~EventContainer() override
Definition: EventContainer.cc:59
fwlite::EventContainer::m_maxWanted
int m_maxWanted
Definition: EventContainer.h:129
optutl::VariableMapCont::kStringVector
Definition: VariableMapCont.h:69
optutl::VariableMapCont::hasOption
OptionType hasOption(std::string key)
Definition: VariableMapCont.h:100
fwlite
Definition: TFileDirectory.h:16
fwlite::EventContainer::operator++
const EventContainer & operator++() override
Definition: EventContainer.cc:102
gather_cfg.cout
cout
Definition: gather_cfg.py:144
operator<<
ostream & operator<<(ostream &o_stream, const EventContainer &rhs)
Definition: EventContainer.cc:137
cms::cuda::assert
assert(be >=bs)
writedatasetfile.parser
parser
Definition: writedatasetfile.py:7
fwlite::MultiChainEvent
Definition: MultiChainEvent.h:50
fwlite::EventBase::toBegin
virtual EventBase const & toBegin()=0
fwlite::EventContainer::toBegin
const EventContainer & toBegin() override
Definition: EventContainer.cc:113
fwlite::EventContainer::m_outputName
std::string m_outputName
Definition: EventContainer.h:127
dout.h
TH1Store::hist
TH1 * hist(const std::string &name)
optutl::CommandLineParser::argVec
const SVec argVec() const
Definition: CommandLineParser.h:46
MultiChainEvent.h
fwlite::EventContainer::m_eventsSeen
int m_eventsSeen
Definition: EventContainer.h:128
fwlite::EventContainer::sm_autoloaderCalled
static bool sm_autoloaderCalled
Definition: EventContainer.h:137
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition: GlobalPosition_Frontier_DevDB_cff.py:11
fwlite::EventBase::getByLabel
virtual bool getByLabel(std::type_info const &, char const *, char const *, char const *, void *) const =0
fwlite::EventContainer::m_eventBasePtr
fwlite::EventBase * m_eventBasePtr
Definition: EventContainer.h:125
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
fwlite::EventContainer::add
void add(TH1 *histPtr, const std::string &directory="")
Definition: EventContainer.cc:76
fwlite::EventContainer::m_outputEvery
int m_outputEvery
Definition: EventContainer.h:130
FWLiteEnabler::enable
static void enable()
enable automatic library loading
Definition: FWLiteEnabler.cc:46
EventContainer.h
fwlite::EventContainer
Definition: EventContainer.h:21
fwlite::EventBase::getBranchNameFor
virtual const std::string getBranchNameFor(std::type_info const &, char const *, char const *, char const *) const =0
optutl::CommandLineParser::_finishDefaultOptions
void _finishDefaultOptions(std::string tag="")
Definition: CommandLineParser.cc:583
fwlite::EventContainer::getByLabel
bool getByLabel(const std::type_info &iInfo, const char *iModuleLabel, const char *iProductInstanceLabel, const char *iProcessLabel, void *oData) const override
Definition: EventContainer.cc:85
fwlite::EventContainer::parser
optutl::CommandLineParser & parser()
Definition: EventContainer.cc:78
fwlite::EventBase::atEnd
virtual bool atEnd() const =0
fwlite::EventContainer::m_parserPtr
optutl::CommandLineParser * m_parserPtr
Definition: EventContainer.h:131
std
Definition: JetResolutionObject.h:76
fwlite::EventContainer::getBranchNameFor
const std::string getBranchNameFor(const std::type_info &iInfo, const char *iModuleLabel, const char *iProductInstanceLabel, const char *iProcessLabel) const override
Definition: EventContainer.cc:94
TH1Store::write
void write(const std::string &filename, const SVec &argsVec=kEmptyVec, const SVec &inputFilesVec=kEmptyVec) const
optutl::VariableMapCont::SVec
std::vector< std::string > SVec
Definition: VariableMapCont.h:21
createBeamHaloJobs.directory
string directory
Definition: createBeamHaloJobs.py:211
fwlite::EventContainer::atEnd
bool atEnd() const override
Definition: EventContainer.cc:124
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
optutl::VariableMapCont::stringVector
SVec & stringVector(std::string key)
Definition: VariableMapCont.cc:203
TH1Store::add
void add(TH1 *histPtr, const std::string &directory="")
Definition: TH1Store.cc:30
fwlite::EventContainer::hist
TH1 * hist(const std::string &name)
fwlite::EventContainer::m_histStore
TH1Store m_histStore
Definition: EventContainer.h:126
optutl::VariableMapCont::integerValue
int & integerValue(std::string key)
Definition: VariableMapCont.cc:143
fwlite::ChainEvent
Definition: ChainEvent.h:46
FWLiteEnabler.h
optutl::VariableMapCont::boolValue
bool & boolValue(std::string key)
Definition: VariableMapCont.cc:173
optutl::CommandLineParser
Definition: CommandLineParser.h:10