Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef CondTools_Hcal_BoostIODBReader_h
0002 #define CondTools_Hcal_BoostIODBReader_h
0003 
0004 // -*- C++ -*-
0005 //
0006 // Package:    CondTools/Hcal
0007 // Class:      BoostIODBReader
0008 //
0009 /**\class BoostIODBReader BoostIODBReader.h CondTools/Hcal/interface/BoostIODBReader.h
0010 
0011  Description: reads an object from a database and puts it into a file using boost I/O
0012 
0013  Implementation:
0014      [Notes on implementation]
0015 */
0016 //
0017 // Original Author:  Igor Volobouev
0018 //         Created:  Fri Apr 25 18:17:13 CDT 2014
0019 //
0020 //
0021 
0022 #include <string>
0023 #include <fstream>
0024 #include <cassert>
0025 
0026 #include "CondFormats/Serialization/interface/eos/portable_oarchive.hpp"
0027 
0028 #include "FWCore/Framework/interface/Frameworkfwd.h"
0029 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0030 #include "FWCore/Framework/interface/Event.h"
0031 #include "FWCore/Framework/interface/EventSetup.h"
0032 
0033 #include "FWCore/Utilities/interface/Exception.h"
0034 
0035 #include "FWCore/ServiceRegistry/interface/Service.h"
0036 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0037 
0038 //
0039 // class declaration
0040 //
0041 template <class DataType, class RecordType>
0042 class BoostIODBReader : public edm::one::EDAnalyzer<> {
0043 public:
0044   typedef DataType data_type;
0045   typedef RecordType record_type;
0046 
0047   explicit BoostIODBReader(const edm::ParameterSet&);
0048   inline ~BoostIODBReader() override {}
0049 
0050 private:
0051   void analyze(const edm::Event&, const edm::EventSetup&) override;
0052 
0053   const std::string outputFile_;
0054   const edm::ESGetToken<DataType, RecordType> tok_;
0055 };
0056 
0057 template <class DataType, class RecordType>
0058 BoostIODBReader<DataType, RecordType>::BoostIODBReader(const edm::ParameterSet& ps)
0059     : outputFile_(ps.getParameter<std::string>("outputFile")), tok_(esConsumes<DataType, RecordType>()) {}
0060 
0061 template <class DataType, class RecordType>
0062 void BoostIODBReader<DataType, RecordType>::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0063   const DataType* p = &iSetup.getData(tok_);
0064 
0065   std::ofstream of(outputFile_.c_str(), std::ios_base::binary);
0066   if (!of.is_open())
0067     throw cms::Exception("InvalidArgument") << "Failed to open file \"" << outputFile_ << '"' << std::endl;
0068 
0069   eos::portable_oarchive ar(of);
0070   ar&* p;
0071 }
0072 
0073 #endif  // CondTools_Hcal_BoostIODBReader_h