25 #include <xercesc/parsers/XercesDOMParser.hpp> 26 #include <xercesc/sax/HandlerBase.hpp> 27 #include <xercesc/util/XMLString.hpp> 28 #include <xercesc/util/PlatformUtils.hpp> 83 size_t sep_pos = str.find(
":");
115 XMLPlatformUtils::Initialize();
116 }
catch (
const XMLException& toCatch ) {
120 auto parser = std::make_unique<XercesDOMParser>();
121 parser->setValidationScheme( XercesDOMParser::Val_Always );
122 parser->setDoNamespaces(
true );
123 parser->parse( fileName.c_str() );
126 throw cms::Exception(
"CTPPSRPAlignmentCorrectionsMethods") <<
"Cannot parse file `" << fileName <<
"' (parser = NULL).";
128 DOMDocument* xmlDoc = parser->getDocument();
131 throw cms::Exception(
"CTPPSRPAlignmentCorrectionsMethods") <<
"Cannot parse file `" << fileName <<
"' (xmlDoc = NULL).";
133 DOMElement* elementRoot = xmlDoc->getDocumentElement();
135 throw cms::Exception(
"CTPPSRPAlignmentCorrectionsMethods") <<
"File `" << fileName <<
"' is empty.";
138 DOMNodeList*
children = elementRoot->getChildNodes();
139 for (
unsigned int i = 0;
i < children->getLength();
i++ )
141 DOMNode* node = children->item(
i );
142 if ( node->getNodeType() != DOMNode::ELEMENT_NODE )
148 unsigned char nodeType = 0;
149 if ( node_name ==
"iov" ) nodeType = 1;
150 else if ( node_name ==
"det" ) nodeType = 2;
151 else if ( node_name ==
"rp" ) nodeType = 3;
154 throw cms::Exception(
"CTPPSRPAlignmentCorrectionsMethods") <<
"Unknown node `" << node_name <<
"'.";
157 if ( nodeType == 2 || nodeType == 3 )
166 bool first_set =
false, last_set =
false;
167 DOMNamedNodeMap* attrs = node->getAttributes();
168 for (
unsigned int j = 0; j < attrs->getLength(); j++ )
170 const DOMNode* attr = attrs->item( j );
173 if ( attr_name ==
"first" )
178 else if ( attr_name ==
"last" ) {
183 edm::LogProblem(
"CTPPSRPAlignmentCorrectionsMethods") <<
">> CTPPSRPAlignmentCorrectionsDataSequence::loadFromXML > Warning: unknown attribute `" 184 << attr_name <<
"'.";
188 if ( !first_set || !last_set )
189 throw cms::Exception(
"CTPPSRPAlignmentCorrectionsMethods") <<
"iov tag must have `first' and `last' attributes set.";
200 XMLPlatformUtils::Terminate();
213 DOMNodeList *
children = root->getChildNodes();
214 for (
unsigned int i = 0;
i < children->getLength();
i++ )
216 DOMNode *node = children->item(
i );
217 if ( node->getNodeType() != DOMNode::ELEMENT_NODE )
223 unsigned char nodeType = 0;
224 if ( node_name ==
"det" ) nodeType = 1;
225 else if ( node_name ==
"rp" ) nodeType = 2;
231 if ( node->getChildNodes()->getLength() > 0 )
233 edm::LogProblem(
"CTPPSRPAlignmentCorrectionsMethods") <<
"LoadXMLFile > Warning: tag `" <<
234 cms::xerces::toString( node->getNodeName() ) <<
"' has " << node->getChildNodes()->getLength() <<
" children nodes - they will be all ignored.";
238 double sh_x = 0., sh_y = 0., sh_z = 0., rot_x = 0., rot_y = 0., rot_z = 0.;
239 double sh_x_e = 0., sh_y_e = 0., sh_z_e = 0., rot_x_e = 0., rot_y_e = 0., rot_z_e = 0.;
244 DOMNamedNodeMap* attr = node->getAttributes();
245 for (
unsigned int j = 0; j < attr->getLength(); j++ )
247 DOMNode *
a = attr->item( j );
250 if ( node_name ==
"id" )
268 edm::LogProblem(
"CTPPSRPAlignmentCorrectionsMethods") <<
">> CTPPSRPAlignmentCorrectionsMethods::getCorrectionsData > Warning: unknown attribute `" 278 sh_x*1
e-3, sh_x_e*1
e-3,
279 sh_y*1
e-3, sh_y_e*1
e-3,
280 sh_z*1
e-3, sh_z_e*1
e-3,
281 rot_x*1
e-3, rot_x_e*1
e-3,
282 rot_y*1
e-3, rot_y_e*1
e-3,
283 rot_z*1
e-3, rot_z_e*1
e-3
300 bool wrSh_xy,
bool wrSh_z,
bool wrRot_xy,
bool wrRot_z )
302 FILE* rf = fopen( fileName.c_str(),
"w" );
304 throw cms::Exception(
"CTPPSRPAlignmentCorrectionsMethods") <<
"Cannot open file `" << fileName <<
"' to save alignments.";
306 fprintf( rf,
"<!-- Shifts in um, rotations in mrad. -->\n" );
307 fprintf( rf,
"<xml DocumentType=\"AlignmentDescription\">\n" );
310 for (
const auto &
p : data )
312 fprintf( rf,
"\t<iov first=\"%s\" last=\"%s\">\n",
317 writeXMLBlock(
p.second, rf, precise, wrErrors, wrSh_xy, wrSh_z, wrRot_xy, wrRot_z );
319 fprintf( rf,
"\t</iov>\n" );
322 fprintf( rf,
"</xml>\n" );
328 bool wrSh_xy,
bool wrSh_z,
bool wrRot_xy,
bool wrRot_z )
331 unsigned int prevRP = 0;
332 std::set<unsigned int> writtenRPs;
337 for (
auto it = sensors.begin(); it != sensors.end(); ++it)
344 if (firstRP || prevRP != rpId)
350 fprintf(rf,
"\t<!-- RP %3u -->\n", decRPId);
352 auto rit = rps.find(rpId);
353 if (rit != rps.end())
355 fprintf(rf,
"\t<rp id=\"%u\" ", rit->first);
356 writeXML( rit->second , rf, precise, wrErrors, wrSh_xy, wrSh_z, wrRot_xy, wrRot_z );
358 writtenRPs.insert(rpId);
364 unsigned int planeIdx = 1000;
368 fprintf(rf,
"\t<!-- plane %u --> ", planeIdx);
371 fprintf(rf,
"<det id=\"%u\"", it->first);
372 writeXML(it->second, rf, precise, wrErrors, wrSh_xy, wrSh_z, wrRot_xy, wrRot_z);
377 for (
auto it = rps.begin(); it != rps.end(); ++it)
379 std::set<unsigned int>::iterator wit = writtenRPs.find(it->first);
380 if (wit == writtenRPs.end())
389 fprintf(rf,
"\t<!-- RP %3u -->\n", decRPId);
391 fprintf(rf,
"\t<rp id=\"%u\" ", it->first);
392 writeXML(it->second, rf, precise, wrErrors, wrSh_xy, wrSh_z, wrRot_xy, wrRot_z);
400 #define WRITE(q, tag, dig, lim) \ 402 fprintf(f, " " tag "=\"%.15E\"", q*1E3);\ 404 if (fabs(q*1E3) < lim && q != 0) \ 405 fprintf(f, " " tag "=\"%+8.1E\"", q*1E3);\ 407 fprintf(f, " " tag "=\"%+8." #dig "f\"", q*1E3); 413 bool wrSh_xy,
bool wrSh_z,
bool wrRot_xy,
bool wrRot_z )
void addSensorCorrection(unsigned int, const CTPPSRPAlignmentCorrectionData &, bool sumErrors=true, bool addSh=true, bool addRot=true)
adds (merges) a RP correction on top of the current value
Detector ID class for TOTEM Si strip detectors.
static edm::IOVSyncValue stringToIOVValue(const std::string &)
const EventID & eventID() const
Time sequence of alignment corrections. I/O methods have been factored out to: CondFormats/CTPPSReado...
double getRotXUnc() const
static const IOVSyncValue & endOfTime()
double toDouble(XMLCh const *toTranscode)
LuminosityBlockNumber_t luminosityBlock() const
#define WRITE(q, tag, dig, lim)
static CTPPSRPAlignmentCorrectionsDataSequence loadFromXML(const std::string &fileName)
loads sequence of alignment corrections from XML file
std::string toString(XMLCh const *toTranscode)
static const IOVSyncValue & beginOfTime()
static std::string iovValueToString(const edm::IOVSyncValue &)
unsigned int toUInt(XMLCh const *toTranscode)
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
const mapType & getRPMap() const
returns the map of RP alignment corrections
CTPPSDetId getRPId() const
double getRotYUnc() const
void addRPCorrection(unsigned int, const CTPPSRPAlignmentCorrectionData &, bool sumErrors=true, bool addSh=true, bool addRot=true)
const mapType & getSensorMap() const
returns the map of sensor alignment corrections
void insert(const edm::ValidityInterval &iov, const CTPPSRPAlignmentCorrectionsData &data)
Base class for CTPPS detector IDs.
Container for CTPPS RP alignment corrections. The corrections are stored on two levels - RP and senso...
static void writeXMLBlock(const CTPPSRPAlignmentCorrectionsData &, FILE *, bool precise=false, bool wrErrors=true, bool wrSh_xy=true, bool wrSh_z=false, bool wrRot_xy=false, bool wrRot_z=true)
writes a block of corrections into a file
char data[epos_bytes_allocation]
static void writeToXML(const CTPPSRPAlignmentCorrectionsDataSequence &seq, const std::string &fileName, bool precise=false, bool wrErrors=true, bool wrSh_xy=true, bool wrSh_z=false, bool wrRot_xy=false, bool wrRot_z=true)
writes sequence of alignment corrections into a single XML file
double getRotZUnc() const
Detector ID class for CTPPS Timing Diamond detectors. Bits [19:31] : Assigend in CTPPSDetId Calss Bit...
static void writeXML(const CTPPSRPAlignmentCorrectionData &data, FILE *f, bool precise, bool wrErrors, bool wrSh_xy, bool wrSh_z, bool wrRot_xy, bool wrRot_z)
writes data of a correction in XML format
static CTPPSRPAlignmentCorrectionsData getCorrectionsData(xercesc::DOMNode *)
load corrections data corresponding to one IOV
Alignment correction for an element of the CT-PPS detector. Within the geometry description, every sensor (more generally every element) is given its translation and rotation. These two quantities shall be understood in local-to-global coordinate transform. That is, if r_l is a point in local coordinate system and x_g in global, then it holds.