CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/RecoVertex/BeamSpotProducer/plugins/BeamSpotWrite2DB.cc

Go to the documentation of this file.
00001 
00014 // C++ standard
00015 #include <string>
00016 // CMS
00017 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00018 #include "RecoVertex/BeamSpotProducer/interface/BeamSpotWrite2DB.h"
00019 #include "RecoVertex/BeamSpotProducer/interface/BSFitter.h"
00020 
00021 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00022 
00023 #include "FWCore/Framework/interface/MakerMacros.h"
00024 #include "FWCore/ServiceRegistry/interface/Service.h"
00025 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
00026 #include "CondFormats/BeamSpotObjects/interface/BeamSpotObjects.h"
00027 
00028 BeamSpotWrite2DB::BeamSpotWrite2DB(const edm::ParameterSet& iConfig)
00029 {
00030 
00031   fasciiFileName = iConfig.getUntrackedParameter<std::string>("OutputFileName");
00032   
00033   fasciiFile.open(fasciiFileName.c_str());
00034   
00035 }
00036 
00037 
00038 BeamSpotWrite2DB::~BeamSpotWrite2DB()
00039 {
00040 }
00041 
00042 
00043 void
00044 BeamSpotWrite2DB::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00045 {
00046 }
00047 
00048 
00049 
00050 void 
00051 BeamSpotWrite2DB::beginJob()
00052 {
00053 }
00054 
00055 void 
00056 BeamSpotWrite2DB::endJob() {
00057 
00058         std::cout << " Read beam spot data from text file: " << fasciiFileName << std::endl;
00059         std::cout << " please see plugins/BeamSpotWrite2DB.cc for format of text file." << std::endl;
00060         /*
00061         std::cout << " Content of the file is expected to have this format with the first column as a keyword:" << std::endl;
00062         std::cout << " x\n y\n z\n sigmaZ\n dxdz\n dydz\n beamWidthX\n beamWidthY" << std::endl;
00063         for (int i =0; i<7; i++) {
00064                 for (int j=0; j<7; j++ ) {
00065                         
00066                         std::cout << " cov["<<i<<"]["<<j<<"] cov["<<i<<"]["<<j<<"] cov["<<i<<"]["<<j<<"] cov["<<i<<"]["<<j<<"] cov["<<i<<"]["<<j<<"] cov["<<j<<"]["<<j<<"] cov["<<i<<"]["<<j<<"]" << std::endl;
00067                 }
00068         }
00069         */
00070         
00071         // extract from file
00072         double x,y,z,sigmaZ,dxdz,dydz,beamWidthX,beamWidthY,emittanceX,emittanceY,betastar;
00073         std::string tag;
00074         double cov[7][7];
00075         int type;
00076 
00077         fasciiFile >> tag >> type;
00078         fasciiFile >> tag >> x;
00079         fasciiFile >> tag >> y;
00080         fasciiFile >> tag >> z;
00081         fasciiFile >> tag >> sigmaZ;
00082         fasciiFile >> tag >> dxdz;
00083         fasciiFile >> tag >> dydz;
00084         fasciiFile >> tag >> beamWidthX;
00085         fasciiFile >> tag >> beamWidthY;
00086         fasciiFile >> tag >> cov[0][0] >> cov[0][1] >> cov[0][2]>> cov[0][3] >> cov[0][4]>> cov[0][5] >> cov[0][6];
00087         fasciiFile >> tag >> cov[1][0] >> cov[1][1] >> cov[1][2] >> cov[1][3]>> cov[1][4] >> cov[1][5]>> cov[1][6];
00088         fasciiFile >> tag >> cov[2][0]  >> cov[2][1] >> cov[2][2] >> cov[2][3]>> cov[2][4] >> cov[2][5]>> cov[2][6];
00089         fasciiFile >> tag >> cov[3][0]  >> cov[3][1] >> cov[3][2] >> cov[3][3]>> cov[3][4] >> cov[3][5]>> cov[3][6];
00090         fasciiFile >> tag >> cov[4][0] >> cov[4][1] >> cov[4][2] >> cov[4][3]>> cov[4][4] >> cov[4][5]>> cov[4][6];
00091         fasciiFile >> tag >> cov[5][0] >> cov[5][1] >> cov[5][2] >> cov[5][3]>> cov[5][4] >> cov[5][5]>> cov[5][6];
00092         fasciiFile >> tag >> cov[6][0] >> cov[6][1] >> cov[6][2] >> cov[6][3]>> cov[6][4] >> cov[6][5]>> cov[6][6];
00093         fasciiFile >> tag >> emittanceX;
00094         fasciiFile >> tag >> emittanceY;
00095         fasciiFile >> tag >> betastar;
00096         
00097         BeamSpotObjects *abeam = new BeamSpotObjects();
00098         
00099         abeam->SetType(type);
00100         abeam->SetPosition(x,y,z);
00101         abeam->SetSigmaZ(sigmaZ);
00102         abeam->Setdxdz(dxdz);
00103         abeam->Setdydz(dydz);
00104         abeam->SetBeamWidthX(beamWidthX);
00105         abeam->SetBeamWidthY(beamWidthY);
00106         abeam->SetEmittanceX( emittanceX );
00107         abeam->SetEmittanceY( emittanceY );
00108         abeam->SetBetaStar( betastar );
00109         
00110         for (int i=0; i<7; ++i) {
00111           for (int j=0; j<7; ++j) {
00112             abeam->SetCovariance(i,j,cov[i][j]);
00113           }
00114         }
00115 
00116         std::cout << " write results to DB..." << std::endl;
00117 
00118         edm::Service<cond::service::PoolDBOutputService> poolDbService;
00119         if( poolDbService.isAvailable() ) {
00120           std::cout << "poolDBService available"<<std::endl;
00121           if ( poolDbService->isNewTagRequest( "BeamSpotObjectsRcd" ) ) {
00122             std::cout << "new tag requested" << std::endl;
00123             poolDbService->createNewIOV<BeamSpotObjects>( abeam, poolDbService->beginOfTime(),poolDbService->endOfTime(),
00124                                                                   "BeamSpotObjectsRcd"  );
00125           }
00126           else {
00127             std::cout << "no new tag requested" << std::endl;
00128             poolDbService->appendSinceTime<BeamSpotObjects>( abeam, poolDbService->currentTime(),
00129                                                              "BeamSpotObjectsRcd" );
00130           }
00131           
00132         }
00133 
00134         std::cout << "[BeamSpotWrite2DB] endJob done \n" << std::endl;
00135 }
00136 
00137 //define this as a plug-in
00138 DEFINE_FWK_MODULE(BeamSpotWrite2DB);