CMS 3D CMS Logo

BeamSpotWrite2DB.cc
Go to the documentation of this file.
1 
13 // C++ standard
14 #include <string>
15 // CMS
19 
21 
26 
28 {
29 
30  fasciiFileName = iConfig.getUntrackedParameter<std::string>("OutputFileName");
31 
32  fasciiFile.open(fasciiFileName.c_str());
33 
34 }
35 
36 
38 {
39 }
40 
41 
42 void
44 {
45 }
46 
47 
48 
49 void
51 {
52 }
53 
54 void
56 
57  std::cout << " Read beam spot data from text file: " << fasciiFileName << std::endl;
58  std::cout << " please see plugins/BeamSpotWrite2DB.cc for format of text file." << std::endl;
59  /*
60  std::cout << " Content of the file is expected to have this format with the first column as a keyword:" << std::endl;
61  std::cout << " x\n y\n z\n sigmaZ\n dxdz\n dydz\n beamWidthX\n beamWidthY" << std::endl;
62  for (int i =0; i<7; i++) {
63  for (int j=0; j<7; j++ ) {
64 
65  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;
66  }
67  }
68  */
69 
70  // extract from file
71  double x,y,z,sigmaZ,dxdz,dydz,beamWidthX,beamWidthY,emittanceX,emittanceY,betastar;
73  double cov[7][7];
74  int type;
75 
76  fasciiFile >> tag >> type;
77  fasciiFile >> tag >> x;
78  fasciiFile >> tag >> y;
79  fasciiFile >> tag >> z;
80  fasciiFile >> tag >> sigmaZ;
81  fasciiFile >> tag >> dxdz;
82  fasciiFile >> tag >> dydz;
83  fasciiFile >> tag >> beamWidthX;
84  fasciiFile >> tag >> beamWidthY;
85  fasciiFile >> tag >> cov[0][0] >> cov[0][1] >> cov[0][2]>> cov[0][3] >> cov[0][4]>> cov[0][5] >> cov[0][6];
86  fasciiFile >> tag >> cov[1][0] >> cov[1][1] >> cov[1][2] >> cov[1][3]>> cov[1][4] >> cov[1][5]>> cov[1][6];
87  fasciiFile >> tag >> cov[2][0] >> cov[2][1] >> cov[2][2] >> cov[2][3]>> cov[2][4] >> cov[2][5]>> cov[2][6];
88  fasciiFile >> tag >> cov[3][0] >> cov[3][1] >> cov[3][2] >> cov[3][3]>> cov[3][4] >> cov[3][5]>> cov[3][6];
89  fasciiFile >> tag >> cov[4][0] >> cov[4][1] >> cov[4][2] >> cov[4][3]>> cov[4][4] >> cov[4][5]>> cov[4][6];
90  fasciiFile >> tag >> cov[5][0] >> cov[5][1] >> cov[5][2] >> cov[5][3]>> cov[5][4] >> cov[5][5]>> cov[5][6];
91  fasciiFile >> tag >> cov[6][0] >> cov[6][1] >> cov[6][2] >> cov[6][3]>> cov[6][4] >> cov[6][5]>> cov[6][6];
92  fasciiFile >> tag >> emittanceX;
93  fasciiFile >> tag >> emittanceY;
94  fasciiFile >> tag >> betastar;
95 
96  BeamSpotObjects *abeam = new BeamSpotObjects();
97 
98  abeam->SetType(type);
99  abeam->SetPosition(x,y,z);
100  abeam->SetSigmaZ(sigmaZ);
101  abeam->Setdxdz(dxdz);
102  abeam->Setdydz(dydz);
103  abeam->SetBeamWidthX(beamWidthX);
104  abeam->SetBeamWidthY(beamWidthY);
105  abeam->SetEmittanceX( emittanceX );
106  abeam->SetEmittanceY( emittanceY );
107  abeam->SetBetaStar( betastar );
108 
109  for (int i=0; i<7; ++i) {
110  for (int j=0; j<7; ++j) {
111  abeam->SetCovariance(i,j,cov[i][j]);
112  }
113  }
114 
115  std::cout << " write results to DB..." << std::endl;
116 
118  if( poolDbService.isAvailable() ) {
119  std::cout << "poolDBService available"<<std::endl;
120  if ( poolDbService->isNewTagRequest( "BeamSpotObjectsRcd" ) ) {
121  std::cout << "new tag requested" << std::endl;
122  poolDbService->createNewIOV<BeamSpotObjects>( abeam, poolDbService->beginOfTime(),poolDbService->endOfTime(),
123  "BeamSpotObjectsRcd" );
124  }
125  else {
126  std::cout << "no new tag requested" << std::endl;
127  poolDbService->appendSinceTime<BeamSpotObjects>( abeam, poolDbService->currentTime(),
128  "BeamSpotObjectsRcd" );
129  }
130 
131  }
132 
133  std::cout << "[BeamSpotWrite2DB] endJob done \n" << std::endl;
134 }
135 
136 //define this as a plug-in
type
Definition: HCALResponse.h:21
T getUntrackedParameter(std::string const &, T const &) const
std::ifstream fasciiFile
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::string fasciiFileName
void SetSigmaZ(double val)
set sigma Z, RMS bunch length
void SetCovariance(int i, int j, double val)
set i,j element of the full covariance matrix 7x7
void Setdydz(double val)
set dydz slope, crossing angle in XZ
virtual void beginJob()
void appendSinceTime(T *payloadObj, cond::Time_t sinceTime, const std::string &recordName, bool withlogging=false)
int iEvent
Definition: GenABIO.cc:230
virtual void endJob()
bool isNewTagRequest(const std::string &recordName)
void SetEmittanceX(double val)
set emittance
bool isAvailable() const
Definition: Service.h:46
void Setdxdz(double val)
set dxdz slope, crossing angle
void createNewIOV(T *firstPayloadObj, cond::Time_t firstSinceTime, cond::Time_t firstTillTime, const std::string &recordName, bool withlogging=false)
void SetBetaStar(double val)
set beta star
void SetType(int type)
set beam type
void SetEmittanceY(double val)
set emittance
void SetBeamWidthX(double val)
set average transverse beam width X
void SetBeamWidthY(double val)
set average transverse beam width Y
BeamSpotWrite2DB(const edm::ParameterSet &)
virtual void analyze(const edm::Event &, const edm::EventSetup &)
void SetPosition(double x, double y, double z)
set XYZ position