77#include " FWCore/Framework/interface/EventSetup.h"
88#include " FWCore/Concurrency/interface/WaitingTaskWithArenaHolder.h"
99#include " FWCore/MessageLogger/interface/MessageLogger.h"
10-
10+ # include < sstream >
1111#include < string>
1212#include < chrono>
13+ #include < fstream>
1314
1415// this is a stream producer because client operations are not multithread-safe in general
1516// it is designed such that the user never has to interact with the client or the acquire() callback directly
@@ -20,17 +21,40 @@ class SonicEDProducer : public edm::stream::EDProducer<edm::ExternalWork, Capabi
2021 typedef typename Client::Input Input;
2122 typedef typename Client::Output Output;
2223 // constructor
23- SonicEDProducer (edm::ParameterSet const & cfg) : client_(cfg.getParameter<edm::ParameterSet>(" Client" )) {}
24+ SonicEDProducer (edm::ParameterSet const & cfg) : client_(cfg.getParameter<edm::ParameterSet>(" Client" )) {
25+ sumLoadTime = 0 ;
26+ numLoadTime = 0 ;
27+ }
28+
2429 // destructor
25- virtual ~SonicEDProducer () {}
30+ ~SonicEDProducer () {
31+ /*
32+ std::stringstream msg;
33+ msg << "Produced by SonicEDProducer" << std::endl;
34+ if (numLoadTime == 0) {
35+ msg << "numLoadTime was 0." << std::endl;
36+ }
37+ else {
38+ msg << "Load time: " << float(sumLoadTime) / numLoadTime << std::endl;
39+ }
40+
41+ writeData(&msg);
42+
43+ std::ofstream file("./data/producer-data.dat");
44+ file << msg.str();
45+ file.close();*/
46+ }
2647
2748 // derived classes use a dedicated acquire() interface that incorporates client_.input()
2849 // (no need to interact with callback holder)
2950 void acquire (edm::Event const & iEvent, edm::EventSetup const & iSetup, edm::WaitingTaskWithArenaHolder holder) override final {
3051 auto t0 = std::chrono::high_resolution_clock::now ();
3152 acquire (iEvent, iSetup, client_.input ());
3253 auto t1 = std::chrono::high_resolution_clock::now ();
33- if (!debugName_.empty ()) edm::LogInfo (debugName_) << " Load time: " << std::chrono::duration_cast<std::chrono::microseconds>(t1 - t0).count ();
54+ if (!debugName_.empty ()) {
55+ sumLoadTime += (unsigned int )std::chrono::duration_cast<std::chrono::microseconds>(t1 - t0).count ();
56+ numLoadTime++;
57+ }
3458 client_.predict (holder);
3559 }
3660 virtual void acquire (edm::Event const & iEvent, edm::EventSetup const & iSetup, Input& iInput) = 0;
@@ -50,6 +74,11 @@ class SonicEDProducer : public edm::stream::EDProducer<edm::ExternalWork, Capabi
5074 // members
5175 Client client_;
5276 std::string debugName_;
77+
78+ private:
79+ virtual void writeData (std::stringstream* msg) {}
80+ unsigned int sumLoadTime;
81+ unsigned int numLoadTime;
5382};
5483
5584#endif
0 commit comments