Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:23:39

0001 #include <sys/time.h>
0002 #include <stdint.h>
0003 #include <iostream>
0004 
0005 #include "FWCore/Framework/interface/Frameworkfwd.h"
0006 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0007 #include "FWCore/Framework/interface/Event.h"
0008 #include "FWCore/Framework/interface/EventSetup.h"
0009 #include "FWCore/Framework/interface/MakerMacros.h"
0010 #include "FWCore/Framework/interface/ESHandle.h"
0011 
0012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0013 #include "FWCore/Utilities/interface/InputTag.h"
0014 
0015 #include "CondFormats/DataRecord/interface/BTauGenericMVAJetTagComputerRcd.h"
0016 #include "CondFormats/PhysicsToolsObjects/interface/MVAComputer.h"
0017 #include "PhysicsTools/MVAComputer/interface/MVAComputer.h"
0018 
0019 #include "FWCore/Framework/interface/EventSetupRecord.h"
0020 #include "FWCore/Framework/interface/EventSetupRecordKey.h"
0021 
0022 using namespace PhysicsTools;
0023 
0024 class testReadMVAComputerCondDB : public edm::one::EDAnalyzer<> {
0025 public:
0026   explicit testReadMVAComputerCondDB(const edm::ParameterSet& params);
0027 
0028   void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override;
0029 
0030   void endJob() override;
0031 
0032 private:
0033   edm::ESGetToken<Calibration::MVAComputerContainer, BTauGenericMVAJetTagComputerRcd> m_token;
0034 };
0035 
0036 testReadMVAComputerCondDB::testReadMVAComputerCondDB(const edm::ParameterSet& params) : m_token(esConsumes()) {}
0037 
0038 void testReadMVAComputerCondDB::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0039   MVAComputer computer(&iSetup.getData(m_token).find("test"));
0040 
0041   Variable::Value values[] = {
0042       Variable::Value("toast", 4.4), Variable::Value("toast", 4.5), Variable::Value("test", 4.6),
0043       Variable::Value("toast", 4.7), Variable::Value("test", 4.8),  Variable::Value("normal", 4.9),
0044       Variable::Value("toast", 4.4), Variable::Value("toast", 4.5), Variable::Value("test", 4.6),
0045       Variable::Value("toast", 4.7), Variable::Value("test", 4.8),  Variable::Value("normal", 4.9),
0046       Variable::Value("toast", 4.4), Variable::Value("toast", 4.5), Variable::Value("test", 4.6),
0047       Variable::Value("toast", 4.7), Variable::Value("test", 4.8),  Variable::Value("normal", 4.9),
0048       Variable::Value("toast", 4.4), Variable::Value("toast", 4.5), Variable::Value("test", 4.6),
0049       Variable::Value("toast", 4.7), Variable::Value("test", 4.8),  Variable::Value("normal", 4.9)};
0050 
0051   unsigned int i = 0;
0052   uint64_t n = 0;
0053   struct timeval start;
0054   gettimeofday(&start, 0);
0055   for (;;) {
0056     computer.eval(values, values + 6);
0057     n++;
0058     if (++i == 1000) {
0059       i = 0;
0060       struct timeval now;
0061       gettimeofday(&now, NULL);
0062       if (now.tv_sec < start.tv_sec + 5)
0063         continue;
0064       if (now.tv_sec > start.tv_sec + 5)
0065         break;
0066       if (now.tv_usec >= start.tv_usec)
0067         break;
0068     }
0069   }
0070 
0071   std::cout << "Did " << n << " computationss in five seconds." << std::endl;
0072 }
0073 
0074 void testReadMVAComputerCondDB::endJob() {}
0075 
0076 // define this as a plug-in
0077 DEFINE_FWK_MODULE(testReadMVAComputerCondDB);