CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
BeamSpotWrite2DB.cc
Go to the documentation of this file.
1 
14 // C++ standard
15 #include <string>
16 // CMS
20 
22 
27 
29 {
30 
31  fasciiFileName = iConfig.getUntrackedParameter<std::string>("OutputFileName");
32 
33  fasciiFile.open(fasciiFileName.c_str());
34 
35 }
36 
37 
39 {
40 }
41 
42 
43 void
45 {
46 }
47 
48 
49 
50 void
52 {
53 }
54 
55 void
57 
58  std::cout << " Read beam spot data from text file: " << fasciiFileName << std::endl;
59  std::cout << " please see plugins/BeamSpotWrite2DB.cc for format of text file." << std::endl;
60  /*
61  std::cout << " Content of the file is expected to have this format with the first column as a keyword:" << std::endl;
62  std::cout << " x\n y\n z\n sigmaZ\n dxdz\n dydz\n beamWidthX\n beamWidthY" << std::endl;
63  for (int i =0; i<7; i++) {
64  for (int j=0; j<7; j++ ) {
65 
66  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;
67  }
68  }
69  */
70 
71  // extract from file
72  double x,y,z,sigmaZ,dxdz,dydz,beamWidthX,beamWidthY,emittanceX,emittanceY,betastar;
73  std::string tag;
74  double cov[7][7];
75  int type;
76 
77  fasciiFile >> tag >> type;
78  fasciiFile >> tag >> x;
79  fasciiFile >> tag >> y;
80  fasciiFile >> tag >> z;
81  fasciiFile >> tag >> sigmaZ;
82  fasciiFile >> tag >> dxdz;
83  fasciiFile >> tag >> dydz;
84  fasciiFile >> tag >> beamWidthX;
85  fasciiFile >> tag >> beamWidthY;
86  fasciiFile >> tag >> cov[0][0] >> cov[0][1] >> cov[0][2]>> cov[0][3] >> cov[0][4]>> cov[0][5] >> cov[0][6];
87  fasciiFile >> tag >> cov[1][0] >> cov[1][1] >> cov[1][2] >> cov[1][3]>> cov[1][4] >> cov[1][5]>> cov[1][6];
88  fasciiFile >> tag >> cov[2][0] >> cov[2][1] >> cov[2][2] >> cov[2][3]>> cov[2][4] >> cov[2][5]>> cov[2][6];
89  fasciiFile >> tag >> cov[3][0] >> cov[3][1] >> cov[3][2] >> cov[3][3]>> cov[3][4] >> cov[3][5]>> cov[3][6];
90  fasciiFile >> tag >> cov[4][0] >> cov[4][1] >> cov[4][2] >> cov[4][3]>> cov[4][4] >> cov[4][5]>> cov[4][6];
91  fasciiFile >> tag >> cov[5][0] >> cov[5][1] >> cov[5][2] >> cov[5][3]>> cov[5][4] >> cov[5][5]>> cov[5][6];
92  fasciiFile >> tag >> cov[6][0] >> cov[6][1] >> cov[6][2] >> cov[6][3]>> cov[6][4] >> cov[6][5]>> cov[6][6];
93  fasciiFile >> tag >> emittanceX;
94  fasciiFile >> tag >> emittanceY;
95  fasciiFile >> tag >> betastar;
96 
97  BeamSpotObjects *abeam = new BeamSpotObjects();
98 
99  abeam->SetType(type);
100  abeam->SetPosition(x,y,z);
101  abeam->SetSigmaZ(sigmaZ);
102  abeam->Setdxdz(dxdz);
103  abeam->Setdydz(dydz);
104  abeam->SetBeamWidthX(beamWidthX);
105  abeam->SetBeamWidthY(beamWidthY);
106  abeam->SetEmittanceX( emittanceX );
107  abeam->SetEmittanceY( emittanceY );
108  abeam->SetBetaStar( betastar );
109 
110  for (int i=0; i<7; ++i) {
111  for (int j=0; j<7; ++j) {
112  abeam->SetCovariance(i,j,cov[i][j]);
113  }
114  }
115 
116  std::cout << " write results to DB..." << std::endl;
117 
119  if( poolDbService.isAvailable() ) {
120  std::cout << "poolDBService available"<<std::endl;
121  if ( poolDbService->isNewTagRequest( "BeamSpotObjectsRcd" ) ) {
122  std::cout << "new tag requested" << std::endl;
123  poolDbService->createNewIOV<BeamSpotObjects>( abeam, poolDbService->beginOfTime(),poolDbService->endOfTime(),
124  "BeamSpotObjectsRcd" );
125  }
126  else {
127  std::cout << "no new tag requested" << std::endl;
128  poolDbService->appendSinceTime<BeamSpotObjects>( abeam, poolDbService->currentTime(),
129  "BeamSpotObjectsRcd" );
130  }
131 
132  }
133 
134  std::cout << "[BeamSpotWrite2DB] endJob done \n" << std::endl;
135 }
136 
137 //define this as a plug-in
type
Definition: HCALResponse.h:22
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
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
double double double z
virtual void beginJob()
void appendSinceTime(T *payloadObj, cond::Time_t sinceTime, const std::string &recordName, bool withlogging=false)
int iEvent
Definition: GenABIO.cc:243
virtual void endJob()
bool isNewTagRequest(const std::string &recordName)
void SetEmittanceX(double val)
set emittance
bool isAvailable() const
Definition: Service.h:47
int j
Definition: DBlmapReader.cc:9
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
tuple cout
Definition: gather_cfg.py:121
BeamSpotWrite2DB(const edm::ParameterSet &)
virtual void analyze(const edm::Event &, const edm::EventSetup &)
x
Definition: VDTMath.h:216
void SetPosition(double x, double y, double z)
set XYZ position