CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Static Public Member Functions
RPAlignmentCorrectionsMethods Class Reference

#include <RPAlignmentCorrectionsMethods.h>

Public Member Functions

 RPAlignmentCorrectionsMethods ()
 

Static Public Member Functions

static RPAlignmentCorrectionsData GetCorrectionsData (xercesc::DOMNode *)
 
static RPAlignmentCorrectionsData GetCorrectionsDataFromFile (const std::string &fileName)
 
static void WriteXML (const RPAlignmentCorrectionData &data, FILE *f, bool precise, bool wrErrors, bool wrSh_r, bool wrSh_xy, bool wrSh_z, bool wrRot_z)
 
static void WriteXMLBlock (const RPAlignmentCorrectionsData &, FILE *, bool precise=false, bool wrErrors=true, bool wrSh_r=true, bool wrSh_xy=true, bool wrSh_z=true, bool wrRot_z=true)
 writes a block of corrections into a file More...
 
static void WriteXMLFile (const RPAlignmentCorrectionsData &, const std::string &fileName, bool precise=false, bool wrErrors=true, bool wrSh_r=true, bool wrSh_xy=true, bool wrSh_z=true, bool wrRot_z=true)
 writes corrections into a single XML file More...
 

Detailed Description

Definition at line 26 of file RPAlignmentCorrectionsMethods.h.

Constructor & Destructor Documentation

RPAlignmentCorrectionsMethods::RPAlignmentCorrectionsMethods ( )
inline

Definition at line 30 of file RPAlignmentCorrectionsMethods.h.

30 {}

Member Function Documentation

RPAlignmentCorrectionsData RPAlignmentCorrectionsMethods::GetCorrectionsData ( xercesc::DOMNode *  )
static

Definition at line 86 of file RPAlignmentCorrectionsMethods.cc.

References a, Exception, i, j, gen::n, and XERCES_CPP_NAMESPACE_USE::transcode().

Referenced by RPAlignmentCorrectionsDataSequence::LoadXMLFile().

87 {
88  DOMNodeList *children = root->getChildNodes();
89  for (unsigned int i = 0; i < children->getLength(); i++) {
90  DOMNode *n = children->item(i);
91  if (n->getNodeType() != DOMNode::ELEMENT_NODE)
92  continue;
93 
94  // check node type
95  unsigned char nodeType = 0;
96  if (!strcmp(XMLString::transcode(n->getNodeName()), "det")) nodeType = 1;
97  if (!strcmp(XMLString::transcode(n->getNodeName()), "rp")) nodeType = 2;
98 
99  if (!nodeType)
100  throw cms::Exception("RPAlignmentCorrectionsMethods") << "Unknown node `" << XMLString::transcode(n->getNodeName()) << "'.";
101 
102  // check children
103  if (n->getChildNodes()->getLength() > 0)
104  edm::LogProblem("RPAlignmentCorrectionsMethods") << ">> RPAlignmentCorrectionsMethods::LoadXMLFile > Warning: tag `" <<
105  XMLString::transcode(n->getNodeName()) << "' has " << n->getChildNodes()->getLength() <<
106  " children nodes - they will be all ignored.";
107 
108  // default values
109  double sh_r = 0., sh_x = 0., sh_y = 0., sh_z = 0., rot_z = 0.;
110  double sh_r_e = 0., sh_x_e = 0., sh_y_e = 0., sh_z_e = 0., rot_z_e = 0.;
111 // unsigned int id = 0;
112  bool idSet = false;
113 
114  // get attributes
115  DOMNamedNodeMap* attr = n->getAttributes();
116  for (unsigned int j = 0; j < attr->getLength(); j++) {
117  DOMNode *a = attr->item(j);
118 
119  //printf("\t%s\n", XMLString::transcode(a->getNodeName()));
120 
121  if (!strcmp(XMLString::transcode(a->getNodeName()), "id")) {
122 // id = atoi(XMLString::transcode(a->getNodeValue()));
123  idSet = true;
124  } else if (!strcmp(XMLString::transcode(a->getNodeName()), "sh_r"))
125  sh_r = atof(XMLString::transcode(a->getNodeValue()));
126  else if (!strcmp(XMLString::transcode(a->getNodeName()), "sh_r_e"))
127  sh_r_e = atof(XMLString::transcode(a->getNodeValue()));
128  else if (!strcmp(XMLString::transcode(a->getNodeName()), "sh_x"))
129  sh_x = atof(XMLString::transcode(a->getNodeValue()));
130  else if (!strcmp(XMLString::transcode(a->getNodeName()), "sh_x_e"))
131  sh_x_e = atof(XMLString::transcode(a->getNodeValue()));
132  else if (!strcmp(XMLString::transcode(a->getNodeName()), "sh_y"))
133  sh_y = atof(XMLString::transcode(a->getNodeValue()));
134  else if (!strcmp(XMLString::transcode(a->getNodeName()), "sh_y_e"))
135  sh_y_e = atof(XMLString::transcode(a->getNodeValue()));
136  else if (!strcmp(XMLString::transcode(a->getNodeName()), "sh_z"))
137  sh_z = atof(XMLString::transcode(a->getNodeValue()));
138  else if (!strcmp(XMLString::transcode(a->getNodeName()), "sh_z_e"))
139  sh_z_e = atof(XMLString::transcode(a->getNodeValue()));
140  else if (!strcmp(XMLString::transcode(a->getNodeName()), "rot_z"))
141  rot_z = atof(XMLString::transcode(a->getNodeValue()));
142  else if (!strcmp(XMLString::transcode(a->getNodeName()), "rot_z_e"))
143  rot_z_e = atof(XMLString::transcode(a->getNodeValue()));
144  else
145  edm::LogProblem("RPAlignmentCorrectionsMethods") << ">> RPAlignmentCorrectionsMethods::LoadXMLFile > Warning: unknown attribute `"
146  << XMLString::transcode(a->getNodeName()) << "'.";
147  }
148 
149  // id must be set
150  if (!idSet)
151  throw cms::Exception("RPAlignmentCorrectionsMethods") << "Id not set for tag `" << XMLString::transcode(n->getNodeName()) << "'.";
152 
153  // build alignment
154  RPAlignmentCorrectionData a(sh_r*1E-3, sh_r_e*1E-3, sh_x*1E-3, sh_x_e*1E-3, sh_y*1E-3, sh_y_e*1E-3,
155  sh_z*1E-3, sh_z_e*1E-3, rot_z*1E-3, rot_z_e*1E-3);
156 
157  //printf("id = %u\n", id);
158 
159 // // add the alignment to the right list
160 // if (nodeType == 1)
161 // AddSensorCorrection(id, a, true);
162 // else
163 // AddRPCorrection(id, a, true);
164 
165 
166  }
168 
169 }
int i
Definition: DBlmapReader.cc:9
XMLCh * transcode(const T &fInput)
int j
Definition: DBlmapReader.cc:9
Alignment correction or result of alignment procedure for a single RP sensor. Within the geometry des...
Container for RP alignment corrections. The corrections are stored on two levels - RP and sensor...
double a
Definition: hdecay.h:121
RPAlignmentCorrectionsData RPAlignmentCorrectionsMethods::GetCorrectionsDataFromFile ( const std::string &  fileName)
static

Definition at line 33 of file RPAlignmentCorrectionsMethods.cc.

References ztail::d, Exception, personalPlayback::fn, python.rootplot.argparse::message, mps_alisetup::parser, fetchall_from_DQM_v2::release, dqm_diff::start, AlCaHLTBitMon_QueryRunRegistry::string, and XERCES_CPP_NAMESPACE_USE::transcode().

34 {
35  printf(">> RPAlignmentCorrectionsMethods::LoadXMLFile(%s)\n", fileName.c_str());
36 
37  // prepend CMSSW src dir
38  char *cmsswPath = getenv("CMSSW_BASE");
39  size_t start = fileName.find_first_not_of(" ");
40  string fn = fileName.substr(start);
41  if (cmsswPath && fn[0] != '/' && fn.find("./") != 0)
42  fn = string(cmsswPath) + string("/src/") + fn;
43 
44  // load DOM tree first the file
45  try {
46  XMLPlatformUtils::Initialize();
47  }
48  catch (const XMLException& toCatch) {
49  char* message = XMLString::transcode(toCatch.getMessage());
50  throw cms::Exception("RPAlignmentCorrectionsMethods") << "An XMLException caught with message: " << message << ".\n";
51  XMLString::release(&message);
52  }
53 
54  XercesDOMParser* parser = new XercesDOMParser();
55  parser->setValidationScheme(XercesDOMParser::Val_Always);
56  parser->setDoNamespaces(true);
57 
58  try {
59  parser->parse(fn.c_str());
60  }
61  catch (...) {
62  throw cms::Exception("RPAlignmentCorrectionsMethods") << "Cannot parse file `" << fn << "' (exception)." << endl;
63  }
64 
65  if (!parser)
66  throw cms::Exception("RPAlignmentCorrectionsMethods") << "Cannot parse file `" << fn << "' (parser = NULL)." << endl;
67 
68  DOMDocument* xmlDoc = parser->getDocument();
69 
70  if (!xmlDoc)
71  throw cms::Exception("RPAlignmentCorrectionsMethods") << "Cannot parse file `" << fn << "' (xmlDoc = NULL)." << endl;
72 
73  DOMElement* elementRoot = xmlDoc->getDocumentElement();
74  if (!elementRoot)
75  throw cms::Exception("RPAlignmentCorrectionsMethods") << "File `" << fn << "' is empty." << endl;
76 
78 
79  XMLPlatformUtils::Terminate();
80 
81  return d;
82 }
tuple start
Check for commandline option errors.
Definition: dqm_diff.py:58
static RPAlignmentCorrectionsData GetCorrectionsData(xercesc::DOMNode *)
tuple d
Definition: ztail.py:151
XMLCh * transcode(const T &fInput)
Container for RP alignment corrections. The corrections are stored on two levels - RP and sensor...
void RPAlignmentCorrectionsMethods::WriteXML ( const RPAlignmentCorrectionData data,
FILE *  f,
bool  precise,
bool  wrErrors,
bool  wrSh_r,
bool  wrSh_xy,
bool  wrSh_z,
bool  wrRot_z 
)
static

Definition at line 180 of file RPAlignmentCorrectionsMethods.cc.

References RPAlignmentCorrectionData::rot_z(), RPAlignmentCorrectionData::rot_z_e(), RPAlignmentCorrectionData::sh_r(), RPAlignmentCorrectionData::sh_r_e(), RPAlignmentCorrectionData::sh_x(), RPAlignmentCorrectionData::sh_x_e(), RPAlignmentCorrectionData::sh_y(), RPAlignmentCorrectionData::sh_y_e(), RPAlignmentCorrectionData::sh_z(), RPAlignmentCorrectionData::sh_z_e(), and WRITE.

182 {
183  if (wrSh_r) {
184  WRITE(data.sh_r, 2, 0.1);
185  if (wrErrors) {
186  WRITE(data.sh_r_e, 2, 0.1);
187  }
188  /*
189  fprintf(f, " sh_r=\"%+8.2f\"", data.sh_r()*1E3);
190  if (wrErrors)
191  if (fabs(data.sh_r_e())*1E3 < 0.1)
192  fprintf(f, " sh_r_e=\"%+8.1E\"", data.sh_r_e()*1E3);
193  else
194  fprintf(f, " sh_r_e=\"%+8.2f\"", data.sh_r_e()*1E3);
195  */
196  }
197 
198  if (wrSh_xy) {
199  WRITE(data.sh_x, 2, 0.1);
200  WRITE(data.sh_y, 2, 0.1);
201  if (wrErrors) {
202  WRITE(data.sh_x_e, 2, 0.1);
203  WRITE(data.sh_y_e, 2, 0.1);
204  }
205  /*
206  fprintf(f, " sh_x=\"%+8.2f\" sh_y=\"%+8.2f\"", data.sh_x()*1E3, data.sh_y()*1E3);
207  if (wrErrors) {
208  if (fabs(data.sh_x_e())*1E3 < 0.1)
209  fprintf(f, " sh_x_e=\"%+8.1E\"", data.sh_x_e()*1E3);
210  else
211  fprintf(f, " sh_x_e=\"%+8.2f\"", data.sh_x_e()*1E3);
212 
213  if (fabs(data.sh_y_e())*1E3 < 0.1)
214  fprintf(f, " sh_y_e=\"%+8.1E\"", data.sh_y_e()*1E3);
215  else
216  fprintf(f, " sh_y_e=\"%+8.2f\"", data.sh_y_e()*1E3);
217  }
218  */
219  }
220 
221  // TODO: add the other 2 rotations
222 
223  if (wrRot_z) {
224  WRITE(data.rot_z, 3, 0.01);
225  if (wrErrors) {
226  WRITE(data.rot_z_e, 3, 0.01);
227  }
228  /*
229  fprintf(f, " rot_z=\"%+8.3f\"", data.rot_z()*1E3);
230  if (wrErrors)
231  if (fabs(data.rot_z_e())*1E3 < 0.01)
232  fprintf(f, " rot_z_e=\"%+8.1E\"", data.rot_z_e()*1E3);
233  else
234  fprintf(f, " rot_z_e=\"%+8.3f\"", data.rot_z_e()*1E3);
235  */
236  }
237 
238  if (wrSh_z) {
239  WRITE(data.sh_z, 2, 0.1);
240  if (wrErrors) {
241  WRITE(data.sh_z_e, 2, 0.1);
242  }
243 
244  /*
245  fprintf(f, " sh_z=\"%+8.2f\"", data.sh_z()*1E3);
246  if (wrErrors)
247  if (fabs(data.sh_z_e())*1E3 < 0.1)
248  fprintf(f, " sh_z_e=\"%+8.1E\"", data.sh_z_e()*1E3);
249  else
250  fprintf(f, " sh_z_e=\"%+8.2f\"", data.sh_z_e()*1E3);
251  */
252  }
253 }
#define WRITE(q, dig, lim)
void RPAlignmentCorrectionsMethods::WriteXMLBlock ( const RPAlignmentCorrectionsData data,
FILE *  rf,
bool  precise = false,
bool  wrErrors = true,
bool  wrSh_r = true,
bool  wrSh_xy = true,
bool  wrSh_z = true,
bool  wrRot_z = true 
)
static

writes a block of corrections into a file

Definition at line 280 of file RPAlignmentCorrectionsMethods.cc.

References RPAlignmentCorrectionsData::GetRPMap(), and RPAlignmentCorrectionsData::GetSensorMap().

Referenced by RPAlignmentCorrectionsDataSequence::WriteXMLFile().

282 {
283  bool firstRP = true;
284  unsigned int prevRP = 0;
285  set<unsigned int> writtenRPs;
286 
289 
290  for (RPAlignmentCorrectionsData::mapType::const_iterator it = sensors.begin(); it != sensors.end(); ++it) {
291  // start a RP block
292  unsigned int rp = it->first / 10;
293  if (firstRP || prevRP != rp) {
294  if (!firstRP)
295  fprintf(rf, "\n");
296  firstRP = false;
297 
298  RPAlignmentCorrectionsData::mapType::const_iterator rit = rps.find(rp);
299  if (rit != rps.end()) {
300  fprintf(rf, "\t<rp id=\"%4u\" ", rit->first);
301  WriteXML( rit->second , rf, precise, wrErrors, false, wrSh_xy, wrSh_z, wrRot_z );
302  fprintf(rf, "/>\n");
303  writtenRPs.insert(rp);
304  } else
305  fprintf(rf, "\t<!-- RP %3u -->\n", rp);
306  }
307  prevRP = rp;
308 
309  // write the correction
310  fprintf(rf, "\t<det id=\"%4u\"", it->first);
311  WriteXML(it->second, rf, precise, wrErrors, wrSh_r, wrSh_xy, wrSh_z, wrRot_z);
312  fprintf(rf, "/>\n");
313  }
314 
315  // write remaining RPs
316  for (RPAlignmentCorrectionsData::mapType::const_iterator it = rps.begin(); it != rps.end(); ++it) {
317  set<unsigned int>::iterator wit = writtenRPs.find(it->first);
318  if (wit == writtenRPs.end()) {
319  fprintf(rf, "\t<rp id=\"%4u\" ", it->first);
320  WriteXML(it->second, rf, precise, wrErrors, false, wrSh_xy, wrSh_z, wrRot_z);
321  fprintf(rf, "/>\n");
322  }
323  }
324 }
std::map< unsigned int, RPAlignmentCorrectionData > mapType
map: element id -&gt; its alignment correction
const mapType & GetSensorMap() const
returns the map of sensor alignment corrections
const mapType & GetRPMap() const
returns the map of RP alignment corrections
static void WriteXML(const RPAlignmentCorrectionData &data, FILE *f, bool precise, bool wrErrors, bool wrSh_r, bool wrSh_xy, bool wrSh_z, bool wrRot_z)
void RPAlignmentCorrectionsMethods::WriteXMLFile ( const RPAlignmentCorrectionsData ,
const std::string &  fileName,
bool  precise = false,
bool  wrErrors = true,
bool  wrSh_r = true,
bool  wrSh_xy = true,
bool  wrSh_z = true,
bool  wrRot_z = true 
)
static

writes corrections into a single XML file

Definition at line 260 of file RPAlignmentCorrectionsMethods.cc.

References Exception.

Referenced by BuildElasticCorrectionsFile::beginRun().

262 {
263  FILE *rf = fopen(fileName.c_str(), "w");
264  if (!rf)
265  throw cms::Exception("RPAlignmentCorrections::WriteXMLFile") << "Cannot open file `" << fileName
266  << "' to save alignments." << endl;
267 
268  fprintf(rf, "<!--\nShifts in um, rotations in mrad.\n\nFor more details see RPAlignmentCorrections::LoadXMLFile in\n");
269  fprintf(rf, "Alignment/RPDataFormats/src/RPAlignmentCorrectionsSequence.cc\n-->\n\n");
270  fprintf(rf, "<xml DocumentType=\"AlignmentDescription\">\n");
271 
272  WriteXMLBlock(data, rf, precise, wrErrors, wrSh_r, wrSh_xy, wrSh_z, wrRot_z);
273 
274  fprintf(rf, "</xml>\n");
275  fclose(rf);
276 }
static void WriteXMLBlock(const RPAlignmentCorrectionsData &, FILE *, bool precise=false, bool wrErrors=true, bool wrSh_r=true, bool wrSh_xy=true, bool wrSh_z=true, bool wrRot_z=true)
writes a block of corrections into a file
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82