CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DQMXMLFileEventSetupAnalyzer.cc
Go to the documentation of this file.
1 // C++ common header
2 #include <iostream>
3 #include <memory>
4 #include <vector>
5 #include <fstream>
6 
18 
19 namespace edmtest {
21  public:
23  explicit DQMXMLFileEventSetupAnalyzer(int i);
25  void analyze(const edm::Event& event, const edm::EventSetup& setup) override;
26  void beginRun(edm::Run const&, edm::EventSetup const&);
27 
28  private:
30  bool init_;
32  };
33 
35  : fileBlobToken_(
36  esConsumes<edm::Transition::BeginRun>(edm::ESInputTag("", ps.getParameter<std::string>("labelToGet")))),
37  labelToGet_(ps.getParameter<std::string>("labelToGet")) {
38  init_ = false;
39  edm::LogPrint("DQMXMLFileEventSetupAnalyzer")
40  << "DQMXMLFileEventSetupAnalyzer(const edm::ParameterSet &ps)" << std::endl;
41  }
42 
44  init_ = false;
45  edm::LogPrint("DQMXMLFileEventSetupAnalyzer") << "DQMXMLFileEventSetupAnalyzer(int i) " << i << std::endl;
46  }
47 
49  init_ = false;
50  edm::LogPrint("DQMXMLFileEventSetupAnalyzer") << "~DQMXMLFileEventSetupAnalyzer" << std::endl;
51  }
52 
54 
56  edm::LogPrint("DQMXMLFileEventSetupAnalyzer") << "DQMXMLFileEventSetupAnalyzer::beginRun()" << std::endl;
57  if (!init_) {
58  init_ = true;
62  throw cms::Exception("Record not found") << "Record \"DQMXMLFileRcd"
63  << "\" does not exist!" << std::endl;
64  }
65 
66  const auto& rootgeo = &iSetup.getData(fileBlobToken_);
67  edm::LogPrint("DQMXMLFileEventSetupAnalyzer") << "XML FILE IN MEMORY 1 with label " << labelToGet_ << std::endl;
68  std::unique_ptr<std::vector<unsigned char> > tb1((*rootgeo).getUncompressedBlob());
69  //here you can implement the stream for putting the TFile on disk...
70  std::string outfile1("XML1_retrieved.xml");
71  std::ofstream output1(outfile1.c_str());
72  output1.write((const char*)&(*tb1)[0], tb1->size());
73  output1.close();
74 
75  // iSetup.get<DQMXMLFileRcd>().get("XML2_mio",rootgeo);
76  // std::cout<<"ROOT FILE IN MEMORY 2"<<std::endl;
77  // std::unique_ptr<std::vector<unsigned char> > tb2( (*rootgeo).getUncompressedBlob() );
78  // //here you can implement the stream for putting the TFile on disk...
79  // std::string outfile2("XML2_retrieved.xml") ;
80  // std::ofstream output2(outfile2.c_str()) ;
81  // output2.write((const char *)&(*tb2)[0], tb2->size());
82  // output2.close() ;
83  // std::unique_ptr<std::vector<unsigned char> > tb( (*rootgeo).getUncompressedBlob() );
84  }
85  }
86 
88 } // namespace edmtest
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
DQMXMLFileEventSetupAnalyzer(const edm::ParameterSet &pset)
bool getData(T &iHolder) const
Definition: EventSetup.h:128
int iEvent
Definition: GenABIO.cc:224
Transition
Definition: Transition.h:12
Log< level::Warning, true > LogPrint
void analyze(const edm::Event &event, const edm::EventSetup &setup) override
heterocontainer::HCTypeTag TypeTag
const edm::ESGetToken< FileBlob, DQMXMLFileRcd > fileBlobToken_
void beginRun(edm::Run const &, edm::EventSetup const &)
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
Definition: Run.h:45
static HCTypeTag findType(char const *iTypeName)
find a type based on the types name, if not found will return default HCTypeTag
Definition: HCTypeTag.cc:121