File indexing completed on 2024-04-06 12:23:23
0001
0002 #include <iostream>
0003 #include <fstream>
0004 #include <iomanip>
0005 #include <cassert>
0006
0007 #include "FWCore/FWLite/interface/FWLiteEnabler.h"
0008 #include "PhysicsTools/FWLite/interface/EventContainer.h"
0009 #include "PhysicsTools/FWLite/interface/dout.h"
0010 #include "DataFormats/FWLite/interface/MultiChainEvent.h"
0011
0012 #include "TH1.h"
0013
0014 using namespace std;
0015 using namespace fwlite;
0016
0017
0018
0019
0020
0021 bool EventContainer::sm_autoloaderCalled = false;
0022
0023 EventContainer::EventContainer(optutl::CommandLineParser& parser, FuncPtr funcPtr)
0024 : m_eventsSeen(0), m_maxWanted(0), m_parserPtr(nullptr) {
0025
0026 string tag;
0027 if (funcPtr) {
0028 (*funcPtr)(tag);
0029 }
0030
0031
0032 parser._finishDefaultOptions(tag);
0033
0034
0035 if (!sm_autoloaderCalled) {
0036 FWLiteEnabler::enable();
0037 sm_autoloaderCalled = true;
0038 }
0039
0040 const optutl::CommandLineParser::SVec& secondaryInputFiles = parser.stringVector("secondaryInputFiles");
0041 if (!secondaryInputFiles.empty()) {
0042 m_eventBasePtr = new fwlite::MultiChainEvent(
0043 parser.stringVector("inputFiles"), secondaryInputFiles, parser.boolValue("orderedSecondaryFiles"));
0044 } else {
0045 m_eventBasePtr = new fwlite::ChainEvent(parser.stringVector("inputFiles"));
0046 }
0047
0048
0049 m_outputName = parser.stringValue("outputFile");
0050 m_maxWanted = parser.integerValue("maxEvents");
0051 m_outputEvery = parser.integerValue("outputEvery");
0052
0053
0054 m_parserPtr = &parser;
0055
0056
0057 }
0058
0059 EventContainer::~EventContainer() {
0060
0061
0062 if (!m_eventBasePtr) {
0063 return;
0064 }
0065
0066 cout << "EventContainer Summary: Processed " << m_eventsSeen << " events." << endl;
0067 optutl::CommandLineParser& parser = this->parser();
0068 if (optutl::CommandLineParser::kStringVector == parser.hasOption("inputFiles")) {
0069 m_histStore.write(m_outputName, parser.argVec(), parser.stringVector("inputFiles"));
0070 } else {
0071 m_histStore.write(m_outputName, parser.argVec());
0072 }
0073 delete m_eventBasePtr;
0074 }
0075
0076 void EventContainer::add(TH1* histPtr, const string& directory) { m_histStore.add(histPtr, directory); }
0077
0078 optutl::CommandLineParser& EventContainer::parser() {
0079 assert(m_parserPtr);
0080 return *m_parserPtr;
0081 }
0082
0083 TH1* EventContainer::hist(const string& name) { return m_histStore.hist(name); }
0084
0085 bool EventContainer::getByLabel(const std::type_info& iInfo,
0086 const char* iModuleLabel,
0087 const char* iProductInstanceLabel,
0088 const char* iProcessLabel,
0089 void* oData) const {
0090 assert(m_eventBasePtr);
0091 return m_eventBasePtr->getByLabel(iInfo, iModuleLabel, iProductInstanceLabel, iProcessLabel, oData);
0092 }
0093
0094 const std::string EventContainer::getBranchNameFor(const std::type_info& iInfo,
0095 const char* iModuleLabel,
0096 const char* iProductInstanceLabel,
0097 const char* iProcessLabel) const {
0098 assert(m_eventBasePtr);
0099 return m_eventBasePtr->getBranchNameFor(iInfo, iModuleLabel, iProductInstanceLabel, iProcessLabel);
0100 }
0101
0102 const EventContainer& EventContainer::operator++() {
0103 assert(m_eventBasePtr);
0104
0105 m_eventBasePtr->operator++();
0106 ++m_eventsSeen;
0107 if (m_outputEvery && m_eventsSeen % m_outputEvery == 0) {
0108 cout << "Processing Event: " << m_eventsSeen << endl;
0109 }
0110 return *this;
0111 }
0112
0113 const EventContainer& EventContainer::toBegin() {
0114 assert(m_eventBasePtr);
0115 m_eventsSeen = 0;
0116 m_eventBasePtr->toBegin();
0117
0118
0119
0120
0121 return *this;
0122 }
0123
0124 bool EventContainer::atEnd() const {
0125 assert(m_eventBasePtr);
0126
0127
0128 if (m_maxWanted && m_eventsSeen >= m_maxWanted) {
0129
0130 return true;
0131 }
0132
0133 return m_eventBasePtr->atEnd();
0134 }
0135
0136
0137 ostream& operator<<(ostream& o_stream, const EventContainer& rhs) { return o_stream; }