Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:32:43

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/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::EDAnalyzer {
0025 public:
0026   explicit testReadMVAComputerCondDB(const edm::ParameterSet& params);
0027 
0028   virtual void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup);
0029 
0030   virtual void endJob();
0031 };
0032 
0033 testReadMVAComputerCondDB::testReadMVAComputerCondDB(const edm::ParameterSet& params) {}
0034 
0035 void testReadMVAComputerCondDB::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0036   edm::ESHandle<Calibration::MVAComputerContainer> calib;
0037   iSetup.get<BTauGenericMVAJetTagComputerRcd>().get(calib);
0038   MVAComputer computer(&calib.product()->find("test"));
0039 
0040   Variable::Value values[] = {
0041       Variable::Value("toast", 4.4), Variable::Value("toast", 4.5), Variable::Value("test", 4.6),
0042       Variable::Value("toast", 4.7), Variable::Value("test", 4.8),  Variable::Value("normal", 4.9),
0043       Variable::Value("toast", 4.4), Variable::Value("toast", 4.5), Variable::Value("test", 4.6),
0044       Variable::Value("toast", 4.7), Variable::Value("test", 4.8),  Variable::Value("normal", 4.9),
0045       Variable::Value("toast", 4.4), Variable::Value("toast", 4.5), Variable::Value("test", 4.6),
0046       Variable::Value("toast", 4.7), Variable::Value("test", 4.8),  Variable::Value("normal", 4.9),
0047       Variable::Value("toast", 4.4), Variable::Value("toast", 4.5), Variable::Value("test", 4.6),
0048       Variable::Value("toast", 4.7), Variable::Value("test", 4.8),  Variable::Value("normal", 4.9)};
0049 
0050   unsigned int i = 0;
0051   uint64_t n = 0;
0052   struct timeval start;
0053   gettimeofday(&start, 0);
0054   for (;;) {
0055     computer.eval(values, values + 6);
0056     n++;
0057     if (++i == 1000) {
0058       i = 0;
0059       struct timeval now;
0060       gettimeofday(&now, NULL);
0061       if (now.tv_sec < start.tv_sec + 5)
0062         continue;
0063       if (now.tv_sec > start.tv_sec + 5)
0064         break;
0065       if (now.tv_usec >= start.tv_usec)
0066         break;
0067     }
0068   }
0069 
0070   std::cout << "Did " << n << " computationss in five seconds." << std::endl;
0071 }
0072 
0073 void testReadMVAComputerCondDB::endJob() {}
0074 
0075 // define this as a plug-in
0076 DEFINE_FWK_MODULE(testReadMVAComputerCondDB);