Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-23 04:28:38

0001 // system include files
0002 #include <memory>
0003 #include <sstream>
0004 
0005 // user include files
0006 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008 
0009 #include "FWCore/ServiceRegistry/interface/Service.h"
0010 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0011 
0012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0013 
0014 #include "CondFormats/SiPixelObjects/interface/SiPixelFedCablingMap.h"
0015 #include "CondFormats/SiPixelObjects/interface/SiPixelFedCablingTree.h"
0016 #include "CalibTracker/SiPixelConnectivity/interface/SiPixelFedCablingMapBuilder.h"
0017 
0018 using namespace std;
0019 using namespace edm;
0020 using namespace sipixelobjects;
0021 
0022 class SiPixelFedCablingMapWriter : public edm::one::EDAnalyzer<> {
0023 public:
0024   explicit SiPixelFedCablingMapWriter(const edm::ParameterSet& cfg);
0025   ~SiPixelFedCablingMapWriter();
0026   virtual void beginJob();
0027   virtual void endJob();
0028   virtual void analyze(const edm::Event&, const edm::EventSetup&);
0029 
0030 private:
0031   SiPixelFedCablingTree* cabling;
0032   string record_;
0033   //string pixelToFedAssociator_;
0034   string fileName_;
0035   //bool phase1_;
0036 };
0037 
0038 SiPixelFedCablingMapWriter::SiPixelFedCablingMapWriter(const edm::ParameterSet& cfg)
0039     : record_(cfg.getParameter<std::string>("record")),
0040       //pixelToFedAssociator_(cfg.getUntrackedParameter<std::string>("associator","PixelToFEDAssociateFromAscii")),
0041       //phase1_(cfg.getUntrackedParameter<bool>("phase1",false)),
0042       fileName_(cfg.getUntrackedParameter<std::string>("fileName", "pixelToLNK.ascii")) {
0043   stringstream out;
0044   out << " record:          " << record_ << endl;
0045   out << " input file name " << fileName_ << endl;
0046   //out << " phase " << phase1_ << endl;
0047   LogInfo("initialisation: ") << out.str();
0048 
0049   //::putenv(const_cast<char*>(std::string("CORAL_AUTH_USER=me").c_str()));
0050   //::putenv(const_cast<char*>(std::string("CORAL_AUTH_PASSWORD=none").c_str()));
0051 }
0052 
0053 SiPixelFedCablingMapWriter::~SiPixelFedCablingMapWriter() = default;
0054 
0055 void SiPixelFedCablingMapWriter::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0056   static int first(1);
0057   if (1 == first) {
0058     first = 0;
0059     //std::cout << "-------HERE-----------" << endl;
0060     //cabling = SiPixelFedCablingMapBuilder(pixelToFedAssociator_).produce(iSetup);
0061     //cabling = SiPixelFedCablingMapBuilder(fileName_,phase1_).produce(iSetup);
0062     cabling = SiPixelFedCablingMapBuilder(consumesCollector(), fileName_).produce(iSetup);
0063     //std::cout << "-------Print Map ----------- DOES NOT WORK for phase1 " << endl;
0064     edm::LogInfo("PRINTING MAP (Does not work for phase1: ") << cabling->print(3);
0065   }
0066 }
0067 
0068 void SiPixelFedCablingMapWriter::beginJob() {}
0069 
0070 void SiPixelFedCablingMapWriter::endJob() {
0071   SiPixelFedCablingMap result(cabling);
0072   LogInfo("Now NEW writing to DB");
0073   edm::Service<cond::service::PoolDBOutputService> mydbservice;
0074   if (!mydbservice.isAvailable()) {
0075     edm::LogInfo("db service unavailable");
0076     //std::cout<<"db service unavailable"<<std::endl;
0077     return;
0078   } else {
0079     //std::cout<<"OK"<<std::endl;
0080     edm::LogInfo("Writing finished ");
0081   }
0082 
0083   try {
0084     if (mydbservice->isNewTagRequest(record_)) {
0085       mydbservice->createOneIOV<SiPixelFedCablingMap>(result, mydbservice->beginOfTime(), record_);
0086     } else {
0087       mydbservice->appendOneIOV<SiPixelFedCablingMap>(result, mydbservice->currentTime(), record_);
0088     }
0089   } catch (std::exception& e) {
0090     LogError("std::exception:  ") << e.what();
0091   } catch (...) {
0092     LogError("Unknown error caught ");
0093   }
0094   LogInfo("... all done, end");
0095 }
0096 
0097 //define this as a plug-in
0098 #include "FWCore/Framework/interface/MakerMacros.h"
0099 DEFINE_FWK_MODULE(SiPixelFedCablingMapWriter);