Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:19:12

0001 
0002 #include <iostream>
0003 
0004 #include "IOPool/Streamer/test/StreamThingAnalyzer.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 
0007 #include "FWCore/Framework/interface/Event.h"
0008 #include "FWCore/Framework/interface/ModuleLabelMatch.h"
0009 #include "DataFormats/Common/interface/Handle.h"
0010 #include "FWCore/Framework/interface/MakerMacros.h"
0011 // #include "FWCore/MessageLogger/interface/MessageLogger.h"
0012 
0013 #include <iostream>
0014 #include <algorithm>
0015 #include <numeric>
0016 #include <iterator>
0017 
0018 using namespace edmtestprod;
0019 
0020 namespace edmtest_thing {
0021   StreamThingAnalyzer::StreamThingAnalyzer(edm::ParameterSet const& ps)
0022       : name_(ps.getParameter<std::string>("product_to_get")),
0023         total_(),
0024         out_("gennums.txt"),
0025         inChecksumFile_(ps.getUntrackedParameter<std::string>("inChecksum", "")),
0026         outChecksumFile_(ps.getUntrackedParameter<std::string>("outChecksum", "")),
0027         cnt_(),
0028         getterUsingLabel_(edm::ModuleLabelMatch(name_), this) {
0029     callWhenNewProductsRegistered(getterUsingLabel_);
0030     if (!out_) {
0031       std::cerr << "cannot open file gennums.txt" << std::endl;
0032       abort();
0033     }
0034     out_ << "event instance value" << std::endl;
0035 
0036     //LogDebug("StreamThing") << "ctor completing"; // << std::endl;
0037     //edm::LogInfo("stuff") << "again, ctor completing";
0038   }
0039 
0040   StreamThingAnalyzer::~StreamThingAnalyzer() { std::cout << "\nSTREAMTHING_CHECKSUM " << total_ << "\n" << std::endl; }
0041 
0042   void StreamThingAnalyzer::endJob() {
0043     edm::LogInfo("StreamThingAnalyzer") << "STREAMTHING_CHECKSUM " << total_;
0044     if (!outChecksumFile_.empty()) {
0045       edm::LogInfo("StreamThingAnalyzer") << "Writing checksum to " << outChecksumFile_;
0046       std::ofstream outChecksum(outChecksumFile_);
0047       outChecksum << total_;
0048     } else if (!inChecksumFile_.empty()) {
0049       edm::LogInfo("StreamThingAnalyzer") << "Reading checksum from " << inChecksumFile_;
0050       int totalIn = 0;
0051       std::ifstream inChecksum(inChecksumFile_);
0052       inChecksum >> totalIn;
0053       if (totalIn != total_)
0054         throw cms::Exception("StreamThingAnalyzer")
0055             << "Checksum mismatch input: " << totalIn << " compared to: " << total_;
0056     }
0057   }
0058 
0059   void StreamThingAnalyzer::analyze(edm::Event const& e, edm::EventSetup const&) {
0060     typedef std::vector<edm::Handle<WriteThis> > ProdList;
0061     ProdList prod;
0062     getterUsingLabel_.fillHandles(e, prod);
0063     ProdList::iterator i(prod.begin()), end(prod.end());
0064     for (; i != end; ++i)
0065       total_ = accumulate((*i)->data_.begin(), (*i)->data_.end(), total_);
0066       //std::cout << tot << std::endl;
0067 
0068 #if 0
0069     for(i = prod.begin();i != end; ++i) {
0070       std::vector<int>::const_iterator ii((*i)->data_.begin()),
0071          ib((*i)->data_.end());
0072       for(; ii != ib; ++ii) {
0073              out_ << cnt_ << " " << i->id() << " " << *ii << "\n" ;
0074       }
0075     }
0076 #endif
0077 
0078     ++cnt_;
0079   }
0080 }  // namespace edmtest_thing
0081 
0082 using edmtest_thing::StreamThingAnalyzer;
0083 DEFINE_FWK_MODULE(StreamThingAnalyzer);