test
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, RPAlignmentCorrectionsData::AddRPCorrection(), RPAlignmentCorrectionsData::AddSensorCorrection(), Exception, i, j, gen::n, mps_fire::result, and XERCES_CPP_NAMESPACE_USE::transcode().

Referenced by RPAlignmentCorrectionsDataSequence::LoadXMLFile().

87 {
88 
90 
91  DOMNodeList *children = root->getChildNodes();
92  for (unsigned int i = 0; i < children->getLength(); i++) {
93  DOMNode *n = children->item(i);
94  if (n->getNodeType() != DOMNode::ELEMENT_NODE)
95  continue;
96 
97  // check node type
98  unsigned char nodeType = 0;
99  if (!strcmp(XMLString::transcode(n->getNodeName()), "det")) nodeType = 1;
100  if (!strcmp(XMLString::transcode(n->getNodeName()), "rp")) nodeType = 2;
101 
102  if (!nodeType)
103  throw cms::Exception("RPAlignmentCorrectionsMethods") << "Unknown node `" << XMLString::transcode(n->getNodeName()) << "'.";
104 
105  // check children
106  if (n->getChildNodes()->getLength() > 0)
107  {
108  edm::LogProblem("RPAlignmentCorrectionsMethods") << ">> RPAlignmentCorrectionsMethods::LoadXMLFile > Warning: tag `" <<
109  XMLString::transcode(n->getNodeName()) << "' has " << n->getChildNodes()->getLength() <<
110  " children nodes - they will be all ignored.";
111  }
112 
113  // default values
114  double sh_r = 0., sh_x = 0., sh_y = 0., sh_z = 0., rot_z = 0.;
115  double sh_r_e = 0., sh_x_e = 0., sh_y_e = 0., sh_z_e = 0., rot_z_e = 0.;
116  unsigned int id = 0;
117  bool idSet = false;
118 
119  // get attributes
120  DOMNamedNodeMap* attr = n->getAttributes();
121  for (unsigned int j = 0; j < attr->getLength(); j++) {
122  DOMNode *a = attr->item(j);
123 
124  //printf("\t%s\n", XMLString::transcode(a->getNodeName()));
125 
126  if (!strcmp(XMLString::transcode(a->getNodeName()), "id")) {
127  id = atoi(XMLString::transcode(a->getNodeValue()));
128  idSet = true;
129  } else if (!strcmp(XMLString::transcode(a->getNodeName()), "sh_r"))
130  sh_r = atof(XMLString::transcode(a->getNodeValue()));
131  else if (!strcmp(XMLString::transcode(a->getNodeName()), "sh_r_e"))
132  sh_r_e = atof(XMLString::transcode(a->getNodeValue()));
133  else if (!strcmp(XMLString::transcode(a->getNodeName()), "sh_x"))
134  sh_x = atof(XMLString::transcode(a->getNodeValue()));
135  else if (!strcmp(XMLString::transcode(a->getNodeName()), "sh_x_e"))
136  sh_x_e = atof(XMLString::transcode(a->getNodeValue()));
137  else if (!strcmp(XMLString::transcode(a->getNodeName()), "sh_y"))
138  sh_y = atof(XMLString::transcode(a->getNodeValue()));
139  else if (!strcmp(XMLString::transcode(a->getNodeName()), "sh_y_e"))
140  sh_y_e = atof(XMLString::transcode(a->getNodeValue()));
141  else if (!strcmp(XMLString::transcode(a->getNodeName()), "sh_z"))
142  sh_z = atof(XMLString::transcode(a->getNodeValue()));
143  else if (!strcmp(XMLString::transcode(a->getNodeName()), "sh_z_e"))
144  sh_z_e = atof(XMLString::transcode(a->getNodeValue()));
145  else if (!strcmp(XMLString::transcode(a->getNodeName()), "rot_z"))
146  rot_z = atof(XMLString::transcode(a->getNodeValue()));
147  else if (!strcmp(XMLString::transcode(a->getNodeName()), "rot_z_e"))
148  rot_z_e = atof(XMLString::transcode(a->getNodeValue()));
149  else
150  edm::LogProblem("RPAlignmentCorrectionsMethods") << ">> RPAlignmentCorrectionsMethods::LoadXMLFile > Warning: unknown attribute `"
151  << XMLString::transcode(a->getNodeName()) << "'.";
152  }
153 
154  // id must be set
155  if (!idSet)
156  throw cms::Exception("RPAlignmentCorrectionsMethods") << "Id not set for tag `" << XMLString::transcode(n->getNodeName()) << "'.";
157 
158  // build alignment
159  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,
160  sh_z*1E-3, sh_z_e*1E-3, rot_z*1E-3, rot_z_e*1E-3);
161 
162  // add the alignment to the right list
163  if (nodeType == 1)
164  result.AddSensorCorrection(id, a, true);
165  else
166  result.AddRPCorrection(id, a, true);
167 
168 
169  }
170  return result;
171 
172 }
int i
Definition: DBlmapReader.cc:9
tuple result
Definition: mps_fire.py:83
void AddRPCorrection(unsigned int, const RPAlignmentCorrectionData &, bool sumErrors=true, bool addShR=true, bool addShZ=true, bool addRotZ=true)
void AddSensorCorrection(unsigned int, const RPAlignmentCorrectionData &, bool sumErrors=true, bool addShR=true, bool addShZ=true, bool addRotZ=true)
adds (merges) a RP correction on top of the current value
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 183 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.

185 {
186  if (wrSh_r) {
187  WRITE(data.sh_r, 2, 0.1);
188  if (wrErrors) {
189  WRITE(data.sh_r_e, 2, 0.1);
190  }
191  /*
192  fprintf(f, " sh_r=\"%+8.2f\"", data.sh_r()*1E3);
193  if (wrErrors)
194  if (fabs(data.sh_r_e())*1E3 < 0.1)
195  fprintf(f, " sh_r_e=\"%+8.1E\"", data.sh_r_e()*1E3);
196  else
197  fprintf(f, " sh_r_e=\"%+8.2f\"", data.sh_r_e()*1E3);
198  */
199  }
200 
201  if (wrSh_xy) {
202  WRITE(data.sh_x, 2, 0.1);
203  WRITE(data.sh_y, 2, 0.1);
204  if (wrErrors) {
205  WRITE(data.sh_x_e, 2, 0.1);
206  WRITE(data.sh_y_e, 2, 0.1);
207  }
208  /*
209  fprintf(f, " sh_x=\"%+8.2f\" sh_y=\"%+8.2f\"", data.sh_x()*1E3, data.sh_y()*1E3);
210  if (wrErrors) {
211  if (fabs(data.sh_x_e())*1E3 < 0.1)
212  fprintf(f, " sh_x_e=\"%+8.1E\"", data.sh_x_e()*1E3);
213  else
214  fprintf(f, " sh_x_e=\"%+8.2f\"", data.sh_x_e()*1E3);
215 
216  if (fabs(data.sh_y_e())*1E3 < 0.1)
217  fprintf(f, " sh_y_e=\"%+8.1E\"", data.sh_y_e()*1E3);
218  else
219  fprintf(f, " sh_y_e=\"%+8.2f\"", data.sh_y_e()*1E3);
220  }
221  */
222  }
223 
224  // TODO: add the other 2 rotations
225 
226  if (wrRot_z) {
227  WRITE(data.rot_z, 3, 0.01);
228  if (wrErrors) {
229  WRITE(data.rot_z_e, 3, 0.01);
230  }
231  /*
232  fprintf(f, " rot_z=\"%+8.3f\"", data.rot_z()*1E3);
233  if (wrErrors)
234  if (fabs(data.rot_z_e())*1E3 < 0.01)
235  fprintf(f, " rot_z_e=\"%+8.1E\"", data.rot_z_e()*1E3);
236  else
237  fprintf(f, " rot_z_e=\"%+8.3f\"", data.rot_z_e()*1E3);
238  */
239  }
240 
241  if (wrSh_z) {
242  WRITE(data.sh_z, 2, 0.1);
243  if (wrErrors) {
244  WRITE(data.sh_z_e, 2, 0.1);
245  }
246 
247  /*
248  fprintf(f, " sh_z=\"%+8.2f\"", data.sh_z()*1E3);
249  if (wrErrors)
250  if (fabs(data.sh_z_e())*1E3 < 0.1)
251  fprintf(f, " sh_z_e=\"%+8.1E\"", data.sh_z_e()*1E3);
252  else
253  fprintf(f, " sh_z_e=\"%+8.2f\"", data.sh_z_e()*1E3);
254  */
255  }
256 }
#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 283 of file RPAlignmentCorrectionsMethods.cc.

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

Referenced by RPAlignmentCorrectionsDataSequence::WriteXMLFile().

285 {
286  bool firstRP = true;
287  unsigned int prevRP = 0;
288  set<unsigned int> writtenRPs;
289 
292 
293  for (RPAlignmentCorrectionsData::mapType::const_iterator it = sensors.begin(); it != sensors.end(); ++it) {
294  // start a RP block
295  unsigned int rp = it->first / 10;
296  if (firstRP || prevRP != rp) {
297  if (!firstRP)
298  fprintf(rf, "\n");
299  firstRP = false;
300 
301  RPAlignmentCorrectionsData::mapType::const_iterator rit = rps.find(rp);
302  if (rit != rps.end()) {
303  fprintf(rf, "\t<rp id=\"%4u\" ", rit->first);
304  WriteXML( rit->second , rf, precise, wrErrors, false, wrSh_xy, wrSh_z, wrRot_z );
305  fprintf(rf, "/>\n");
306  writtenRPs.insert(rp);
307  } else
308  fprintf(rf, "\t<!-- RP %3u -->\n", rp);
309  }
310  prevRP = rp;
311 
312  // write the correction
313  fprintf(rf, "\t<det id=\"%4u\"", it->first);
314  WriteXML(it->second, rf, precise, wrErrors, wrSh_r, wrSh_xy, wrSh_z, wrRot_z);
315  fprintf(rf, "/>\n");
316  }
317 
318  // write remaining RPs
319  for (RPAlignmentCorrectionsData::mapType::const_iterator it = rps.begin(); it != rps.end(); ++it) {
320  set<unsigned int>::iterator wit = writtenRPs.find(it->first);
321  if (wit == writtenRPs.end()) {
322  fprintf(rf, "\t<rp id=\"%4u\" ", it->first);
323  WriteXML(it->second, rf, precise, wrErrors, false, wrSh_xy, wrSh_z, wrRot_z);
324  fprintf(rf, "/>\n");
325  }
326  }
327 }
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 263 of file RPAlignmentCorrectionsMethods.cc.

References Exception.

Referenced by BuildElasticCorrectionsFile::beginRun().

265 {
266  FILE *rf = fopen(fileName.c_str(), "w");
267  if (!rf)
268  throw cms::Exception("RPAlignmentCorrections::WriteXMLFile") << "Cannot open file `" << fileName
269  << "' to save alignments." << endl;
270 
271  fprintf(rf, "<!--\nShifts in um, rotations in mrad.\n\nFor more details see RPAlignmentCorrections::LoadXMLFile in\n");
272  fprintf(rf, "Alignment/RPDataFormats/src/RPAlignmentCorrectionsSequence.cc\n-->\n\n");
273  fprintf(rf, "<xml DocumentType=\"AlignmentDescription\">\n");
274 
275  WriteXMLBlock(data, rf, precise, wrErrors, wrSh_r, wrSh_xy, wrSh_z, wrRot_z);
276 
277  fprintf(rf, "</xml>\n");
278  fclose(rf);
279 }
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