CMS 3D CMS Logo

List of all members | Public Member Functions
RPAlignmentCorrectionsDataSequence Class Reference

Time sequence of alignment corrections. More...

#include <RPAlignmentCorrectionsDataSequence.h>

Inheritance diagram for RPAlignmentCorrectionsDataSequence:

Public Member Functions

void insert (edm::TimeValue_t first, edm::TimeValue_t last, const RPAlignmentCorrectionsData &corr)
 inserts a set of corrections with validity interval [first, last] More...
 
void loadXMLFile (const std::string &fileName)
 loads data from an alignment file More...
 
 RPAlignmentCorrectionsDataSequence ()
 
 RPAlignmentCorrectionsDataSequence (const std::string &fileName)
 
void writeXMLFile (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) const
 saves data to an alignment file More...
 

Detailed Description

Time sequence of alignment corrections.

Definition at line 70 of file RPAlignmentCorrectionsDataSequence.h.

Constructor & Destructor Documentation

RPAlignmentCorrectionsDataSequence::RPAlignmentCorrectionsDataSequence ( )
inline

Definition at line 73 of file RPAlignmentCorrectionsDataSequence.h.

73 {}
RPAlignmentCorrectionsDataSequence::RPAlignmentCorrectionsDataSequence ( const std::string &  fileName)
inline

Definition at line 74 of file RPAlignmentCorrectionsDataSequence.h.

74 { loadXMLFile( fileName ); }
void loadXMLFile(const std::string &fileName)
loads data from an alignment file

Member Function Documentation

void RPAlignmentCorrectionsDataSequence::insert ( edm::TimeValue_t  first,
edm::TimeValue_t  last,
const RPAlignmentCorrectionsData corr 
)
inline
void RPAlignmentCorrectionsDataSequence::loadXMLFile ( const std::string &  fileName)

loads data from an alignment file

STRUCTURE OF ALINGMENT XML FILE

The file has the following structure <xml> <TimeInterval first="..." last="..."> <tag> <tag> ... </TimeInterval> <TimeInterval first="..." last="..."> ... </TimeInterval></xml>

The time intervals are specified by the `first' and `last' UNIX timestamp (boundaries included). If there is only one time interval, the <TimeInterval> tags might be omitted. An infinite validty is assumed in this case.

The tag can be either "det" - the alignment correction is applied to one detector or "rp" - the alignment correction id applied to one RP

Each tag must have an "id" attribute set. In addition the following attributes are recognized: sh_r - shift in readout direction sh_r_e - the uncertainty of sh_r determination sh_x - shift in x sh_x_e - the uncertainty of sh_x determination sh_y - shift in y sh_y_e - the uncertainty of sh_y determination sh_z - shift in z sh_z_e - the uncertainty of sh_z determination rot_z - rotation around z rot_z_e - the uncertainty of rot_z determination

UNITS: shifts are in um, rotations are in mrad.

Definition at line 65 of file RPAlignmentCorrectionsDataSequence.cc.

References class-composition::children, Exception, plotBeamSpotDB::first, RPAlignmentCorrectionsMethods::getCorrectionsData(), mps_fire::i, spu::inf(), edm::eventsetup::heterocontainer::insert(), plotBeamSpotDB::last, createfilelist::parser, TimeValidityInterval::SetInfinite(), AlCaHLTBitMon_QueryRunRegistry::string, cms::xerces::toString(), and TimeValidityInterval::UNIXStringToValue().

66 {
67  // prepend CMSSW src dir
68  const char* cmsswPath = getenv( "CMSSW_BASE" );
69  size_t start = fileName.find_first_not_of( " " );
70  std::string fn = fileName.substr( start );
71  if ( cmsswPath && fn[0] != '/' && fn.find( "./" ) != 0 )
72  fn = std::string( cmsswPath ) + std::string( "/src/" ) + fn;
73 
74  // load DOM tree first the file
75  try {
76  XMLPlatformUtils::Initialize();
77  } catch ( const XMLException& toCatch ) {
78  throw cms::Exception("RPAlignmentCorrectionsDataSequence") << "An XMLException caught with message: " << cms::xerces::toString( toCatch.getMessage() ) << ".";
79  }
80 
81  auto parser = std::make_unique<XercesDOMParser>();
82  parser->setValidationScheme( XercesDOMParser::Val_Always );
83  parser->setDoNamespaces( true );
84  parser->parse( fn.c_str() );
85 
86  if ( !parser )
87  throw cms::Exception("RPAlignmentCorrectionsDataSequence") << "Cannot parse file `" << fn << "' (parser = NULL).";
88 
89  DOMDocument* xmlDoc = parser->getDocument();
90 
91  if ( !xmlDoc )
92  throw cms::Exception("RPAlignmentCorrectionsDataSequence") << "Cannot parse file `" << fn << "' (xmlDoc = NULL).";
93 
94  DOMElement* elementRoot = xmlDoc->getDocumentElement();
95  if ( !elementRoot )
96  throw cms::Exception("RPAlignmentCorrectionsDataSequence") << "File `" << fn << "' is empty.";
97 
98  // extract useful information form the DOM tree
99  DOMNodeList* children = elementRoot->getChildNodes();
100  for ( unsigned int i = 0; i < children->getLength(); i++ ) {
101  DOMNode* node = children->item( i );
102  if ( node->getNodeType() != DOMNode::ELEMENT_NODE ) continue;
103  const std::string node_name = cms::xerces::toString( node->getNodeName() );
104 
105  // check node type
106  unsigned char nodeType = 0;
107  if ( node_name == "TimeInterval" ) nodeType = 1;
108  else if ( node_name == "det" ) nodeType = 2;
109  else if ( node_name == "rp" ) nodeType = 3;
110 
111  if ( nodeType==0 )
112  throw cms::Exception("RPAlignmentCorrectionsDataSequence") << "Unknown node `" << cms::xerces::toString( node->getNodeName() ) << "'.";
113 
114  // old style - no TimeInterval block?
115  if ( nodeType == 2 || nodeType == 3 ) {
116  //edm::LogWarning("RPAlignmentCorrectionsDataSequence::LoadXMLFile") << "In file `" << fn << "' no TimeInterval given, assuming one block of infinite validity.";
118  inf.SetInfinite();
120  break;
121  }
122 
123  // get attributes
124  edm::TimeValue_t first = 0, last = 0;
125  bool first_set = false, last_set = false;
126  DOMNamedNodeMap* attrs = node->getAttributes();
127  for ( unsigned int j = 0; j < attrs->getLength(); j++ ) {
128  const DOMNode* attr = attrs->item( j );
129  const std::string node_name = cms::xerces::toString( node->getNodeName() );
130 
131  if ( node_name == "first" ) {
132  first_set = true;
133  first = TimeValidityInterval::UNIXStringToValue( cms::xerces::toString( attr->getNodeValue() ) );
134  }
135  else if ( node_name == "last" ) {
136  last_set = true;
138  }
139  else
140  edm::LogProblem("RPAlignmentCorrectionsDataSequence") << ">> RPAlignmentCorrectionsDataSequence::LoadXMLFile > Warning: unknown attribute `"
141  << cms::xerces::toString( attr->getNodeName() ) << "'.";
142  }
143 
144  // interval of validity must be set
145  if ( !first_set || !last_set )
146  throw cms::Exception("RPAlignmentCorrectionsDataSequence") << "TimeInterval tag must have `first' and `last' attributes set.";
147 
148  TimeValidityInterval tvi( first, last );
149 
150  // process data
152 
153  // save result
154  std::map<TimeValidityInterval,RPAlignmentCorrectionsData>::insert( std::make_pair( tvi, corrections ) );
155  }
156 
157  XMLPlatformUtils::Terminate();
158 }
Definition: start.py:1
Validity interval in timestamps.
static RPAlignmentCorrectionsData getCorrectionsData(xercesc::DOMNode *)
std::string toString(XMLCh const *toTranscode)
static edm::TimeValue_t UNIXStringToValue(const std::string &s)
bool insert(Storage &iStorage, ItemType *iItem, const IdTag &iIdTag)
Definition: HCMethods.h:49
unsigned long long TimeValue_t
Definition: Timestamp.h:28
int inf(FILE *, FILE *)
Container for RP alignment corrections. The corrections are stored on two levels - RP and sensor...
void RPAlignmentCorrectionsDataSequence::writeXMLFile ( 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 
) const

saves data to an alignment file

Definition at line 163 of file RPAlignmentCorrectionsDataSequence.cc.

References Exception, TimeValidityInterval::ValueToUNIXString(), and RPAlignmentCorrectionsMethods::writeXMLBlock().

164 {
165  FILE *rf = fopen( fileName.c_str(), "w" );
166  if ( !rf )
167  throw cms::Exception("RPAlignmentCorrectionsDataSequence::writeXMLFile") << "Cannot open file `" << fileName
168  << "' to save alignments.";
169 
170  fprintf( rf, "<!--\nShifts in um, rotations in mrad.\n\nFor more details see RPAlignmentCorrections::LoadXMLFile in\n" );
171  fprintf( rf, "Alignment/RPDataFormats/src/RPAlignmentCorrectionsDataSequence.cc\n-->\n\n" );
172  fprintf( rf, "<xml DocumentType=\"AlignmentSequenceDescription\">\n" );
173 
174  // write all time blocks
175  for ( const auto& it : *this ) {
176  fprintf( rf, "\t<TimeInterval first=\"%s\" last=\"%s\">",
177  TimeValidityInterval::ValueToUNIXString( it.first.first ).c_str(),
178  TimeValidityInterval::ValueToUNIXString( it.first.last ).c_str()
179  );
180 
181  RPAlignmentCorrectionsMethods::writeXMLBlock( it.second, rf, precise, wrErrors, wrSh_r, wrSh_xy, wrSh_z, wrRot_z );
182  fprintf( rf, "\t</TimeInterval>\n" );
183  }
184 
185  fprintf( rf, "</xml>\n" );
186  fclose( rf );
187 }
static std::string ValueToUNIXString(const edm::TimeValue_t &v)
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