CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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.

References LoadXMLFile().

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 edm::eventsetup::heterocontainer::insert().

Referenced by BuildElasticCorrectionsFile::beginRun().

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 68 of file RPAlignmentCorrectionsDataSequence.cc.

References a, Exception, plotBeamSpotDB::first, personalPlayback::fn, RPAlignmentCorrectionsMethods::GetCorrectionsData(), i, EcalCondDB::inf, edm::eventsetup::heterocontainer::insert(), j, plotBeamSpotDB::last, python.rootplot.argparse::message, gen::n, mps_alisetup::parser, fetchall_from_DQM_v2::release, TimeValidityInterval::SetInfinite(), dqm_diff::start, AlCaHLTBitMon_QueryRunRegistry::string, XERCES_CPP_NAMESPACE_USE::transcode(), and TimeValidityInterval::UNIXStringToValue().

Referenced by RPAlignmentCorrectionsDataSequence().

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

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

Referenced by BuildElasticCorrectionsFile::beginRun().

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