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 90 of file RPAlignmentCorrectionsDataSequence.h.

Constructor & Destructor Documentation

RPAlignmentCorrectionsDataSequence::RPAlignmentCorrectionsDataSequence ( )
inline

Definition at line 93 of file RPAlignmentCorrectionsDataSequence.h.

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

Definition at line 95 of file RPAlignmentCorrectionsDataSequence.h.

96  {
98  }
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

inserts a set of corrections with validity interval [first, last]

Definition at line 101 of file RPAlignmentCorrectionsDataSequence.h.

References MillePedeFileConverter_cfg::fileName, edm::eventsetup::heterocontainer::insert(), hiDetachedTripletStep_cff::precise, AlCaHLTBitMon_QueryRunRegistry::string, and TimeValidityInterval::TimeValidityInterval().

102  {
103  insert(std::pair<TimeValidityInterval, RPAlignmentCorrectionsData>(TimeValidityInterval(first, last), corr));
104  }
Validity interval in timestamps.
bool insert(Storage &iStorage, ItemType *iItem, const IdTag &iIdTag)
Definition: HCMethods.h:49
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 69 of file RPAlignmentCorrectionsDataSequence.cc.

References a, class-composition::children, Exception, plotBeamSpotDB::first, RPAlignmentCorrectionsMethods::GetCorrectionsData(), i, spu::inf(), edm::eventsetup::heterocontainer::insert(), j, plotBeamSpotDB::last, python.rootplot.argparse::message, gen::n, createfilelist::parser, fetchall_from_DQM_v2::release, TimeValidityInterval::SetInfinite(), AlCaHLTBitMon_QueryRunRegistry::string, and TimeValidityInterval::UNIXStringToValue().

70 {
71  // prepend CMSSW src dir
72  char *cmsswPath = getenv("CMSSW_BASE");
73  size_t start = fileName.find_first_not_of(" ");
74  string fn = fileName.substr(start);
75  if (cmsswPath && fn[0] != '/' && fn.find("./") != 0)
76  fn = string(cmsswPath) + string("/src/") + fn;
77 
78  // load DOM tree first the file
79  try
80  {
81  XMLPlatformUtils::Initialize();
82  }
83  catch (const XMLException& toCatch)
84  {
85  char* message = XMLString::transcode(toCatch.getMessage());
86  throw cms::Exception("RPAlignmentCorrectionsDataSequence") << "An XMLException caught with message: " << message << ".\n";
87  XMLString::release(&message);
88  }
89 
90  XercesDOMParser* parser = new XercesDOMParser();
91  parser->setValidationScheme(XercesDOMParser::Val_Always);
92  parser->setDoNamespaces(true);
93 
94  try
95  {
96  parser->parse(fn.c_str());
97  }
98  catch (...)
99  {
100  throw cms::Exception("RPAlignmentCorrectionsDataSequence") << "Cannot parse file `" << fn << "' (exception)." << endl;
101  }
102 
103  if (!parser)
104  throw cms::Exception("RPAlignmentCorrectionsDataSequence") << "Cannot parse file `" << fn << "' (parser = NULL)." << endl;
105 
106  DOMDocument* xmlDoc = parser->getDocument();
107 
108  if (!xmlDoc)
109  throw cms::Exception("RPAlignmentCorrectionsDataSequence") << "Cannot parse file `" << fn << "' (xmlDoc = NULL)." << endl;
110 
111  DOMElement* elementRoot = xmlDoc->getDocumentElement();
112  if (!elementRoot)
113  throw cms::Exception("RPAlignmentCorrectionsDataSequence") << "File `" << fn << "' is empty." << endl;
114 
115  // extract useful information form the DOM tree
116  DOMNodeList *children = elementRoot->getChildNodes();
117  for (unsigned int i = 0; i < children->getLength(); i++)
118  {
119  DOMNode *n = children->item(i);
120  if (n->getNodeType() != DOMNode::ELEMENT_NODE)
121  continue;
122 
123  // check node type
124  unsigned char nodeType = 0;
125  if (!strcmp(XMLString::transcode(n->getNodeName()), "TimeInterval")) nodeType = 1;
126  if (!strcmp(XMLString::transcode(n->getNodeName()), "det")) nodeType = 2;
127  if (!strcmp(XMLString::transcode(n->getNodeName()), "rp")) nodeType = 3;
128 
129  if (!nodeType)
130  throw cms::Exception("RPAlignmentCorrectionsDataSequence") << "Unknown node `" << XMLString::transcode(n->getNodeName()) << "'.";
131 
132  // old style - no TimeInterval block?
133  if (nodeType == 2 || nodeType == 3)
134  {
135  //printf(">> RPAlignmentCorrectionsDataSequence::LoadXMLFile > WARNING:\n\tIn file `%s' no TimeInterval given, assuming one block of infinite validity.\n", fileName.c_str());
136 
138  inf.SetInfinite();
139  insert(pair<TimeValidityInterval, RPAlignmentCorrectionsData>(inf, RPAlignmentCorrectionsMethods::GetCorrectionsData(elementRoot)));
140  break;
141  }
142 
143  // get attributes
144  TimeValue_t first=0, last=0;
145  bool first_set = false, last_set = false;
146  DOMNamedNodeMap* attr = n->getAttributes();
147  for (unsigned int j = 0; j < attr->getLength(); j++)
148  {
149  DOMNode *a = attr->item(j);
150 
151  if (!strcmp(XMLString::transcode(a->getNodeName()), "first"))
152  {
153  first_set = true;
154  first = TimeValidityInterval::UNIXStringToValue(XMLString::transcode(a->getNodeValue()));
155  } else if (!strcmp(XMLString::transcode(a->getNodeName()), "last"))
156  {
157  last_set = true;
158  last = TimeValidityInterval::UNIXStringToValue(XMLString::transcode(a->getNodeValue()));
159  } else
160  edm::LogProblem("RPAlignmentCorrectionsDataSequence") << ">> RPAlignmentCorrectionsDataSequence::LoadXMLFile > Warning: unknown attribute `"
161  << XMLString::transcode(a->getNodeName()) << "'.";
162  }
163 
164  // interval of validity must be set
165  if (!first_set || !last_set)
166  throw cms::Exception("RPAlignmentCorrectionsDataSequence") << "TimeInterval tag must have `first' and `last' attributes set.";
167 
168  TimeValidityInterval tvi(first, last);
169 
170  // process data
172 
173  // save result
174  insert(pair<TimeValidityInterval, RPAlignmentCorrectionsData>(tvi, corrections));
175  }
176 
177  XMLPlatformUtils::Terminate();
178 }
Definition: start.py:1
int i
Definition: DBlmapReader.cc:9
Validity interval in timestamps.
static RPAlignmentCorrectionsData GetCorrectionsData(xercesc::DOMNode *)
static edm::TimeValue_t UNIXStringToValue(const std::string &s)
int j
Definition: DBlmapReader.cc:9
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...
double a
Definition: hdecay.h:121
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 182 of file RPAlignmentCorrectionsDataSequence.cc.

References begin, end, Exception, TimeValidityInterval::ValueToUNIXString(), and RPAlignmentCorrectionsMethods::WriteXMLBlock().

184 {
185  FILE *rf = fopen(fileName.c_str(), "w");
186  if (!rf)
187  throw cms::Exception("RPAlignmentCorrectionsDataSequence::WriteXMLFile") << "Cannot open file `" << fileName
188  << "' to save alignments." << endl;
189 
190  fprintf(rf, "<!--\nShifts in um, rotations in mrad.\n\nFor more details see RPAlignmentCorrections::LoadXMLFile in\n");
191  fprintf(rf, "Alignment/RPDataFormats/src/RPAlignmentCorrectionsDataSequence.cc\n-->\n\n");
192  fprintf(rf, "<xml DocumentType=\"AlignmentSequenceDescription\">\n");
193 
194  // write all time blocks
195  for (const_iterator it = this->begin(); it != this->end(); ++it)
196  {
197  fprintf(rf, "\t<TimeInterval first=\"%s\" last=\"%s\">",
198  TimeValidityInterval::ValueToUNIXString(it->first.first).c_str(),
199  TimeValidityInterval::ValueToUNIXString(it->first.last).c_str()
200  );
201 
202  RPAlignmentCorrectionsMethods::WriteXMLBlock(it->second, rf, precise, wrErrors, wrSh_r, wrSh_xy, wrSh_z, wrRot_z );
203  fprintf(rf, "\t</TimeInterval>\n");
204  }
205 
206  fprintf(rf, "</xml>\n");
207  fclose(rf);
208 }
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
static std::string ValueToUNIXString(const edm::TimeValue_t &v)
#define end
Definition: vmac.h:37
#define begin
Definition: vmac.h:30