CMS 3D CMS Logo

TotemDAQMappingESSourceXML.cc
Go to the documentation of this file.
1 /****************************************************************************
2 *
3 * This is a part of TOTEM offline software.
4 * Authors:
5 * Maciej Wróbel (wroblisko@gmail.com)
6 * Jan Kašpar (jan.kaspar@cern.ch)
7 * Marcin Borratynski (mborratynski@gmail.com)
8 * Seyed Mohsen Etesami (setesami@cern.ch)
9 * Laurent Forthomme
10 ****************************************************************************/
11 
22 
26 
32 
33 #include <xercesc/parsers/XercesDOMParser.hpp>
34 #include <xercesc/dom/DOM.hpp>
35 #include <xercesc/sax/HandlerBase.hpp>
36 #include <xercesc/util/XMLString.hpp>
37 #include <xercesc/util/PlatformUtils.hpp>
38 
39 #include <memory>
40 #include <sstream>
41 
42 //#define DEBUG 1
43 
44 //----------------------------------------------------------------------------------------------------
45 
46 using namespace std;
47 
52 public:
53  static const std::string tagVFAT;
54  static const std::string tagChannel;
56 
58  static const std::string tagArm;
59 
61  static const std::string tagRPStation;
62  static const std::string tagRPPot;
63  static const std::string tagRPPlane;
64 
66  static const std::string tagChip1;
67  static const std::string tagChip2;
68 
71  static const std::string tagDiamondCh;
72 
75  static const std::string tagSampicCh;
78 
80  ~TotemDAQMappingESSourceXML() override;
81 
82  edm::ESProducts<std::unique_ptr<TotemDAQMapping>, std::unique_ptr<TotemAnalysisMask>> produce(const TotemReadoutRcd &);
83 
84 private:
85  unsigned int verbosity;
86 
88  string subSystemName;
89 
91  std::vector<std::string> mappingFileNames;
92 
93  struct ConfigBlock {
96 
98  std::vector<std::string> mappingFileNames;
99 
101  std::vector<std::string> maskFileNames;
102  };
103 
104  vector<ConfigBlock> configuration;
105 
107  unsigned int currentBlock;
108 
111 
113  enum NodeType {
128  nTotemTimingCh
129  };
130 
132  enum ParseType { pMapping, pMask };
133 
135  void ParseXML(ParseType,
136  const string &file,
137  const std::unique_ptr<TotemDAQMapping> &,
138  const std::unique_ptr<TotemAnalysisMask> &);
139 
141  void ParseTreeRP(ParseType,
142  xercesc::DOMNode *,
143  NodeType,
144  unsigned int parentID,
145  const std::unique_ptr<TotemDAQMapping> &,
146  const std::unique_ptr<TotemAnalysisMask> &);
147 
149  void ParseTreeDiamond(ParseType,
150  xercesc::DOMNode *,
151  NodeType,
152  unsigned int parentID,
153  const std::unique_ptr<TotemDAQMapping> &,
154  const std::unique_ptr<TotemAnalysisMask> &);
155 
157  void ParseTreeTotemTiming(ParseType,
158  xercesc::DOMNode *,
159  NodeType,
160  unsigned int parentID,
161  const std::unique_ptr<TotemDAQMapping> &,
162  const std::unique_ptr<TotemAnalysisMask> &);
163 
164 private:
166  string CompleteFileName(const string &fn);
167 
169  bool Test(xercesc::DOMNode *node, const std::string &name) {
170  return !(name.compare(cms::xerces::toString(node->getNodeName())));
171  }
172 
174  NodeType GetNodeType(xercesc::DOMNode *);
175 
177  string GetNodeContent(xercesc::DOMNode *parent) { return string(cms::xerces::toString(parent->getTextContent())); }
178 
180  string GetNodeValue(xercesc::DOMNode *node) { return cms::xerces::toString(node->getNodeValue()); }
181 
183  TotemFramePosition ChipFramePosition(xercesc::DOMNode *chipnode);
184 
185  void GetChannels(xercesc::DOMNode *n, std::set<unsigned char> &channels);
186 
188  return ((type == nArm) || (type == nRPStation) || (type == nRPPot) || (type == nRPPlane) || (type == nChip));
189  }
190 
192  return ((type == nArm) || (type == nRPStation) || (type == nRPPot) || (type == nDiamondPlane) ||
193  (type == nDiamondCh));
194  }
195 
197  return ((type == nArm) || (type == nRPStation) || (type == nRPPot) || (type == nSampicBoard) ||
198  (type == nSampicChannel) || (type == nTotemTimingPlane) || (type == nTotemTimingCh));
199  }
200 
201  bool CommonNode(NodeType type) { return ((type == nChip) || (type == nArm)); }
202 
203 protected:
205  void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &,
206  const edm::IOVSyncValue &,
207  edm::ValidityInterval &) override;
208 };
209 
210 //----------------------------------------------------------------------------------------------------
211 
212 using namespace std;
213 using namespace edm;
214 using namespace xercesc;
215 
216 const string TotemDAQMappingESSourceXML::tagVFAT = "vfat";
217 const string TotemDAQMappingESSourceXML::tagChannel = "channel";
218 const string TotemDAQMappingESSourceXML::tagAnalysisMask = "analysisMask";
219 
220 // common XML position tags
221 const string TotemDAQMappingESSourceXML::tagArm = "arm";
222 
223 // common XML Chip tags
224 const string TotemDAQMappingESSourceXML::tagChip1 = "vfat";
225 const string TotemDAQMappingESSourceXML::tagChip2 = "test_vfat";
226 
227 // specific RP XML tags
228 const string TotemDAQMappingESSourceXML::tagRPStation = "station";
229 const string TotemDAQMappingESSourceXML::tagRPPot = "rp_detector_set";
230 const string TotemDAQMappingESSourceXML::tagRPPlane = "rp_plane";
231 
232 // specific tags for diamond
233 const string TotemDAQMappingESSourceXML::tagDiamondPlane = "rp_plane_diamond";
234 const string TotemDAQMappingESSourceXML::tagDiamondCh = "diamond_channel";
235 
236 // specific tags for totem timing
237 const string TotemDAQMappingESSourceXML::tagSampicBoard = "rp_sampic_board";
238 const string TotemDAQMappingESSourceXML::tagSampicCh = "rp_sampic_channel";
239 const string TotemDAQMappingESSourceXML::tagTotemTimingCh = "timing_channel";
240 const string TotemDAQMappingESSourceXML::tagTotemTimingPlane = "timing_plane";
241 
242 //----------------------------------------------------------------------------------------------------
243 
245  : verbosity(conf.getUntrackedParameter<unsigned int>("verbosity", 0)),
246  subSystemName(conf.getUntrackedParameter<string>("subSystem")),
247  currentBlock(0),
248  currentBlockValid(false) {
249  for (const auto &it : conf.getParameter<vector<ParameterSet>>("configuration")) {
250  ConfigBlock b;
251  b.validityRange = it.getParameter<EventRange>("validityRange");
252  b.mappingFileNames = it.getParameter<vector<string>>("mappingFileNames");
253  b.maskFileNames = it.getParameter<vector<string>>("maskFileNames");
254  configuration.push_back(b);
255  }
256 
258  findingRecord<TotemReadoutRcd>();
259 }
260 
261 //----------------------------------------------------------------------------------------------------
262 
264  const edm::IOVSyncValue &iosv,
265  edm::ValidityInterval &oValidity) {
266  LogVerbatim("TotemDAQMappingESSourceXML") << ">> TotemDAQMappingESSourceXML::setIntervalFor(" << key.name() << ")";
267 
268  LogVerbatim("TotemDAQMappingESSourceXML")
269  << " run=" << iosv.eventID().run() << ", event=" << iosv.eventID().event();
270 
271  currentBlockValid = false;
272  for (unsigned int idx = 0; idx < configuration.size(); ++idx) {
273  const auto &bl = configuration[idx];
274 
275  edm::EventRange range = bl.validityRange;
276 
277  // If "<run>:min" is specified in python config, it is translated into event <run>:0:1.
278  // However, the truly minimal event id often found in data is <run>:0:0. Therefore the
279  // adjustment below is needed.
280  if (range.startEventID().luminosityBlock() == 0 && range.startEventID().event() == 1)
281  range = edm::EventRange(edm::EventID(range.startEventID().run(), 0, 0), range.endEventID());
282 
283  if (edm::contains(range, iosv.eventID())) {
284  currentBlockValid = true;
285  currentBlock = idx;
286 
287  const IOVSyncValue begin(range.startEventID());
288  const IOVSyncValue end(range.endEventID());
289  oValidity = edm::ValidityInterval(begin, end);
290 
291  LogVerbatim("TotemDAQMappingESSourceXML") << " block found: index=" << currentBlock << ", interval=("
292  << range.startEventID() << " - " << range.endEventID() << ")";
293 
294  return;
295  }
296  }
297 
298  if (!currentBlockValid) {
299  throw cms::Exception("TotemDAQMappingESSourceXML::setIntervalFor")
300  << "No configuration for event " << iosv.eventID();
301  }
302 }
303 
304 //----------------------------------------------------------------------------------------------------
305 
307 
308 //----------------------------------------------------------------------------------------------------
309 
311  FileInPath fip(fn);
312  return fip.fullPath();
313 }
314 
315 //----------------------------------------------------------------------------------------------------
316 
317 edm::ESProducts<std::unique_ptr<TotemDAQMapping>, std::unique_ptr<TotemAnalysisMask>>
320 
321  auto mapping = std::make_unique<TotemDAQMapping>();
322  auto mask = std::make_unique<TotemAnalysisMask>();
323 
324  // initialize Xerces
325  try {
326  XMLPlatformUtils::Initialize();
327  } catch (const XMLException &toCatch) {
328  throw cms::Exception("TotemDAQMappingESSourceXML")
329  << "An XMLException caught with message: " << cms::xerces::toString(toCatch.getMessage()) << ".\n";
330  }
331 
332  // load mapping files
333  for (const auto &fn : configuration[currentBlock].mappingFileNames)
335 
336  // load mask files
337  for (const auto &fn : configuration[currentBlock].maskFileNames)
339 
340  // release Xerces
341  XMLPlatformUtils::Terminate();
342 
343  // commit the products
345 }
346 
347 //----------------------------------------------------------------------------------------------------
348 
350  const string &file,
351  const std::unique_ptr<TotemDAQMapping> &mapping,
352  const std::unique_ptr<TotemAnalysisMask> &mask) {
353  unique_ptr<XercesDOMParser> parser(new XercesDOMParser());
354  parser->parse(file.c_str());
355 
356  DOMDocument *domDoc = parser->getDocument();
357 
358  if (!domDoc)
359  throw cms::Exception("TotemDAQMappingESSourceXML::ParseXML")
360  << "Cannot parse file `" << file << "' (domDoc = NULL).";
361 
362  DOMElement *elementRoot = domDoc->getDocumentElement();
363 
364  if (!elementRoot)
365  throw cms::Exception("TotemDAQMappingESSourceXML::ParseXML") << "File `" << file << "' is empty.";
366 
367  ParseTreeRP(pType, elementRoot, nTop, 0, mapping, mask);
368 
369  ParseTreeDiamond(pType, elementRoot, nTop, 0, mapping, mask);
370 
371  ParseTreeTotemTiming(pType, elementRoot, nTop, 0, mapping, mask);
372 }
373 
374 //-----------------------------------------------------------------------------------------------------------
375 
377  xercesc::DOMNode *parent,
378  NodeType parentType,
379  unsigned int parentID,
380  const std::unique_ptr<TotemDAQMapping> &mapping,
381  const std::unique_ptr<TotemAnalysisMask> &mask) {
382 #ifdef DEBUG
383  printf(">> TotemDAQMappingESSourceXML::ParseTreeRP(%s, %u, %u)\n",
384  cms::xerces::toString(parent->getNodeName()),
385  parentType,
386  parentID);
387 #endif
388 
389  DOMNodeList *children = parent->getChildNodes();
390 
391  for (unsigned int i = 0; i < children->getLength(); i++) {
392  DOMNode *n = children->item(i);
393  if (n->getNodeType() != DOMNode::ELEMENT_NODE)
394  continue;
395 
397 
398 #ifdef DEBUG
399  printf("\tname = %s, type = %u\n", cms::xerces::toString(n->getNodeName()), type);
400 #endif
401 
402  // structure control
403  if (!RPNode(type))
404  continue;
405 
406  NodeType expectedParentType;
407  switch (type) {
408  case nArm:
409  expectedParentType = nTop;
410  break;
411  case nRPStation:
412  expectedParentType = nArm;
413  break;
414  case nRPPot:
415  expectedParentType = nRPStation;
416  break;
417  case nRPPlane:
418  expectedParentType = nRPPot;
419  break;
420  case nChip:
421  expectedParentType = nRPPlane;
422  break;
423  case nChannel:
424  expectedParentType = nChip;
425  break;
426  default:
427  expectedParentType = nUnknown;
428  break;
429  }
430 
431  if (expectedParentType != parentType) {
432  throw cms::Exception("TotemDAQMappingESSourceXML")
433  << "Node " << cms::xerces::toString(n->getNodeName()) << " not allowed within "
434  << cms::xerces::toString(parent->getNodeName()) << " block.\n";
435  }
436 
437  // parse tag attributes
438  unsigned int id = 0, hw_id = 0;
439  bool id_set = false, hw_id_set = false;
440  bool fullMask = false;
441  DOMNamedNodeMap *attr = n->getAttributes();
442 
443  for (unsigned int j = 0; j < attr->getLength(); j++) {
444  DOMNode *a = attr->item(j);
445 
446  if (!strcmp(cms::xerces::toString(a->getNodeName()).c_str(), "id")) {
447  sscanf(cms::xerces::toString(a->getNodeValue()).c_str(), "%u", &id);
448  id_set = true;
449  }
450 
451  if (!strcmp(cms::xerces::toString(a->getNodeName()).c_str(), "hw_id")) {
452  sscanf(cms::xerces::toString(a->getNodeValue()).c_str(), "%x", &hw_id);
453  hw_id_set = true;
454  }
455 
456  if (!strcmp(cms::xerces::toString(a->getNodeName()).c_str(), "full_mask"))
457  fullMask = (strcmp(cms::xerces::toString(a->getNodeValue()).c_str(), "no") != 0);
458  }
459 
460  // content control
461  if (!id_set)
462  throw cms::Exception("TotemDAQMappingESSourceXML::ParseTreeRP")
463  << "id not given for element `" << cms::xerces::toString(n->getNodeName()) << "'";
464 
465  if (!hw_id_set && type == nChip && pType == pMapping)
466  throw cms::Exception("TotemDAQMappingESSourceXML::ParseTreeRP")
467  << "hw_id not given for element `" << cms::xerces::toString(n->getNodeName()) << "'";
468 
469  if (type == nRPPlane && id > 9)
470  throw cms::Exception("TotemDAQMappingESSourceXML::ParseTreeRP")
471  << "Plane IDs range from 0 to 9. id = " << id << " is invalid.";
472 
473 #ifdef DEBUG
474  printf("\tID found: 0x%x\n", id);
475 #endif
476 
477  // store mapping data
478  if (pType == pMapping && type == nChip) {
479  const TotemFramePosition &framepos = ChipFramePosition(n);
480  TotemVFATInfo vfatInfo;
481  vfatInfo.hwID = hw_id;
482 
483  const unsigned int armIdx = (parentID / 1000) % 10;
484  const unsigned int stIdx = (parentID / 100) % 10;
485  const unsigned int rpIdx = (parentID / 10) % 10;
486  const unsigned int plIdx = parentID % 10;
487 
488  vfatInfo.symbolicID.symbolicID = TotemRPDetId(armIdx, stIdx, rpIdx, plIdx, id);
489 
490  mapping->insert(framepos, vfatInfo);
491 
492  continue;
493  }
494 
495  // store mask data
496  if (pType == pMask && type == nChip) {
497  const unsigned int armIdx = (parentID / 1000) % 10;
498  const unsigned int stIdx = (parentID / 100) % 10;
499  const unsigned int rpIdx = (parentID / 10) % 10;
500  const unsigned int plIdx = parentID % 10;
501 
502  TotemSymbID symbId;
503  symbId.symbolicID = TotemRPDetId(armIdx, stIdx, rpIdx, plIdx, id);
504 
506  am.fullMask = fullMask;
508 
509  mask->insert(symbId, am);
510 
511  continue;
512  }
513 
514  // recursion (deeper in the tree)
515  ParseTreeRP(pType, n, type, parentID * 10 + id, mapping, mask);
516  }
517 }
518 
519 //----------------------------------------------------------------------------------------------------
520 
522  xercesc::DOMNode *parent,
523  NodeType parentType,
524  unsigned int parentID,
525  const std::unique_ptr<TotemDAQMapping> &mapping,
526  const std::unique_ptr<TotemAnalysisMask> &mask) {
527 #ifdef DEBUG
528  printf(">> TotemDAQMappingESSourceXML::ParseTreeDiamond(%s, %u, %u)\n",
529  cms::xerces::toString(parent->getNodeName()),
530  parentType,
531  parentID);
532 #endif
533 
534  DOMNodeList *children = parent->getChildNodes();
535 
536  for (unsigned int i = 0; i < children->getLength(); i++) {
537  DOMNode *n = children->item(i);
538  if (n->getNodeType() != DOMNode::ELEMENT_NODE)
539  continue;
540 
542 #ifdef DEBUG
543  printf("\tname = %s, type = %u\n", cms::xerces::toString(n->getNodeName()), type);
544 #endif
545 
546  // structure control
547  if (!DiamondNode(type))
548  continue;
549 
550  NodeType expectedParentType;
551  switch (type) {
552  case nArm:
553  expectedParentType = nTop;
554  break;
555  case nRPStation:
556  expectedParentType = nArm;
557  break;
558  case nRPPot:
559  expectedParentType = nRPStation;
560  break;
561  case nDiamondPlane:
562  expectedParentType = nRPPot;
563  break;
564  case nDiamondCh:
565  expectedParentType = nDiamondPlane;
566  break;
567  default:
568  expectedParentType = nUnknown;
569  break;
570  }
571 
572  if (expectedParentType != parentType) {
573  throw cms::Exception("TotemDAQMappingESSourceXML")
574  << "Node " << cms::xerces::toString(n->getNodeName()) << " not allowed within "
575  << cms::xerces::toString(parent->getNodeName()) << " block.\n";
576  }
577 
578  // parse tag attributes
579  unsigned int id = 0, hw_id = 0;
580  bool id_set = false, hw_id_set = false;
581  DOMNamedNodeMap *attr = n->getAttributes();
582 
583  for (unsigned int j = 0; j < attr->getLength(); j++) {
584  DOMNode *a = attr->item(j);
585 
586  if (!strcmp(cms::xerces::toString(a->getNodeName()).c_str(), "id")) {
587  sscanf(cms::xerces::toString(a->getNodeValue()).c_str(), "%u", &id);
588  id_set = true;
589  }
590 
591  if (!strcmp(cms::xerces::toString(a->getNodeName()).c_str(), "hw_id")) {
592  sscanf(cms::xerces::toString(a->getNodeValue()).c_str(), "%x", &hw_id);
593  hw_id_set = true;
594  }
595  }
596 
597  // content control
598  if (!id_set)
599  throw cms::Exception("TotemDAQMappingESSourceXML::ParseTreeDiamond")
600  << "id not given for element `" << cms::xerces::toString(n->getNodeName()) << "'";
601 
602  if (!hw_id_set && type == nDiamondCh && pType == pMapping)
603  throw cms::Exception("TotemDAQMappingESSourceXML::ParseTreeDiamond")
604  << "hw_id not given for element `" << cms::xerces::toString(n->getNodeName()) << "'";
605 
606  if (type == nDiamondPlane && id > 3)
607  throw cms::Exception("TotemDAQMappingESSourceXML::ParseTreeDiamond")
608  << "Plane IDs range from 0 to 3. id = " << id << " is invalid.";
609 
610 #ifdef DEBUG
611  printf("\tID found: 0x%x\n", id);
612 #endif
613 
614  // store mapping data
615  if (pType == pMapping && type == nDiamondCh) {
616  const TotemFramePosition &framepos = ChipFramePosition(n);
617 
618  TotemVFATInfo vfatInfo;
619  vfatInfo.hwID = hw_id;
620 
621  if (type == nDiamondCh) {
622  unsigned int ArmNum = (parentID / 10000) % 10;
623  unsigned int StationNum = (parentID / 1000) % 10;
624  unsigned int RpNum = (parentID / 100) % 10;
625  unsigned int PlaneNum = (parentID % 100);
626 
627  vfatInfo.symbolicID.symbolicID = CTPPSDiamondDetId(ArmNum, StationNum, RpNum, PlaneNum, id);
628  }
629 
630  mapping->insert(framepos, vfatInfo);
631 
632  continue;
633  }
634 
635  unsigned int childId;
636  if (pType == pMapping && type == nDiamondPlane)
637  childId = parentID * 100 + id;
638  else
639  childId = parentID * 10 + id;
640 
641  ParseTreeDiamond(pType, n, type, childId, mapping, mask);
642  }
643 }
644 
645 //----------------------------------------------------------------------------------------------------
646 
648  xercesc::DOMNode *parent,
649  NodeType parentType,
650  unsigned int parentID,
651  const std::unique_ptr<TotemDAQMapping> &mapping,
652  const std::unique_ptr<TotemAnalysisMask> &mask) {
653  DOMNodeList *children = parent->getChildNodes();
654 
655  // Fill map hwId -> TotemTimingPlaneChannelPair
656  for (unsigned int i = 0; i < children->getLength(); i++) {
657  DOMNode *child = children->item(i);
658  if ((child->getNodeType() != DOMNode::ELEMENT_NODE) || (GetNodeType(child) != nTotemTimingCh))
659  continue;
660 
661  int plane = -1;
662  DOMNamedNodeMap *attr = parent->getAttributes();
663  for (unsigned int j = 0; j < attr->getLength(); j++) {
664  DOMNode *a = attr->item(j);
665 
666  if (!strcmp(cms::xerces::toString(a->getNodeName()).c_str(), "id"))
667  sscanf(cms::xerces::toString(a->getNodeValue()).c_str(), "%d", &plane);
668  }
669 
670  int channel = -1;
671  unsigned int hwId = 0;
672  attr = child->getAttributes();
673  for (unsigned int j = 0; j < attr->getLength(); j++) {
674  DOMNode *a = attr->item(j);
675 
676  if (!strcmp(cms::xerces::toString(a->getNodeName()).c_str(), "id"))
677  sscanf(cms::xerces::toString(a->getNodeValue()).c_str(), "%d", &channel);
678  if (!strcmp(cms::xerces::toString(a->getNodeName()).c_str(), "hwId"))
679  sscanf(cms::xerces::toString(a->getNodeValue()).c_str(), "%x", &hwId);
680  }
681 
682  mapping->totemTimingChannelMap[(uint8_t)hwId] = TotemDAQMapping::TotemTimingPlaneChannelPair(plane, channel);
683  }
684 
685  for (unsigned int i = 0; i < children->getLength(); i++) {
686  DOMNode *n = children->item(i);
687  if (n->getNodeType() != DOMNode::ELEMENT_NODE)
688  continue;
689 
691 
692  // structure control
693  if (!TotemTimingNode(type))
694  continue;
695 
696  NodeType expectedParentType;
697  switch (type) {
698  case nArm:
699  expectedParentType = nTop;
700  break;
701  case nRPStation:
702  expectedParentType = nArm;
703  break;
704  case nRPPot:
705  expectedParentType = nRPStation;
706  break;
707  case nSampicBoard:
708  expectedParentType = nRPPot;
709  break;
710  case nSampicChannel:
711  expectedParentType = nSampicBoard;
712  break;
713  case nTotemTimingPlane:
714  expectedParentType = nRPPot;
715  break;
716  case nTotemTimingCh:
717  expectedParentType = nTotemTimingPlane;
718  break;
719  default:
720  expectedParentType = nUnknown;
721  break;
722  }
723 
724  if (expectedParentType != parentType) {
725  throw cms::Exception("TotemDAQMappingESSourceXML")
726  << "Node " << cms::xerces::toString(n->getNodeName()) << " not allowed within "
727  << cms::xerces::toString(parent->getNodeName()) << " block.\n";
728  }
729 
730  // parse tag attributes
731  unsigned int id = 0;
732  bool id_set = false;
733  DOMNamedNodeMap *attr = n->getAttributes();
734 
735  for (unsigned int j = 0; j < attr->getLength(); j++) {
736  DOMNode *a = attr->item(j);
737 
738  if (!strcmp(cms::xerces::toString(a->getNodeName()).c_str(), "id")) {
739  sscanf(cms::xerces::toString(a->getNodeValue()).c_str(), "%u", &id);
740  id_set = true;
741  }
742  }
743 
744  // content control
745  if (!id_set)
746  throw cms::Exception("TotemDAQMappingESSourceXML::ParseTreeTotemTiming")
747  << "id not given for element `" << cms::xerces::toString(n->getNodeName()) << "'";
748  if (type == nSampicBoard && id > 5)
749  throw cms::Exception("TotemDAQMappingESSourceXML::ParseTreeTotemTiming")
750  << "SampicBoard IDs range from 0 to 5. id = " << id << " is invalid.";
751 
752  // store mapping data
753  if (pType == pMapping && type == nSampicChannel) {
754  const TotemFramePosition &framepos = ChipFramePosition(n);
755 
756  TotemVFATInfo vfatInfo;
757  unsigned int ArmNum = (parentID / 10000) % 10;
758  unsigned int StationNum = (parentID / 1000) % 10;
759  unsigned int RpNum = (parentID / 100) % 10;
760 
762  ArmNum, StationNum, RpNum, 0, TotemTimingDetId::ID_NOT_SET); //Dynamical: it is encoded in the frame
763 
764  mapping->insert(framepos, vfatInfo);
765 
766  continue;
767  }
768 
769  unsigned int childId;
770  if (pType == pMapping && type == nSampicBoard)
771  childId = parentID * 100 + id;
772  else
773  childId = parentID * 10 + id;
774 
775  ParseTreeTotemTiming(pType, n, type, childId, mapping, mask);
776  }
777 }
778 
779 //----------------------------------------------------------------------------------------------------
780 
783  unsigned char attributeFlag = 0;
784 
785  DOMNamedNodeMap *attr = chipnode->getAttributes();
786  for (unsigned int j = 0; j < attr->getLength(); j++) {
787  DOMNode *a = attr->item(j);
788  if (fp.setXMLAttribute(
789  cms::xerces::toString(a->getNodeName()), cms::xerces::toString(a->getNodeValue()), attributeFlag) > 1) {
790  throw cms::Exception("TotemDAQMappingESSourceXML")
791  << "Unrecognized tag `" << cms::xerces::toString(a->getNodeName()) << "' or incompatible value `"
792  << cms::xerces::toString(a->getNodeValue()) << "'.";
793  }
794  }
795 
796  if (!fp.checkXMLAttributeFlag(attributeFlag)) {
797  throw cms::Exception("TotemDAQMappingESSourceXML")
798  << "Wrong/incomplete DAQ channel specification (attributeFlag = " << attributeFlag << ").";
799  }
800 
801  return fp;
802 }
803 
804 //----------------------------------------------------------------------------------------------------
805 
807  // common node types
808  if (Test(n, tagArm))
809  return nArm;
810  if (Test(n, tagChip1))
811  return nChip;
812  if (Test(n, tagChip2))
813  return nChip;
814 
815  // RP node types
816  if (Test(n, tagRPStation))
817  return nRPStation;
818  if (Test(n, tagRPPot))
819  return nRPPot;
820  if (Test(n, tagRPPlane))
821  return nRPPlane;
822 
823  //diamond specifics
824  if (Test(n, tagDiamondCh))
825  return nDiamondCh;
826  if (Test(n, tagDiamondPlane))
827  return nDiamondPlane;
828 
829  //totem timing specifics
830  if (Test(n, tagSampicBoard))
831  return nSampicBoard;
832  if (Test(n, tagSampicCh))
833  return nSampicChannel;
834  if (Test(n, tagTotemTimingCh))
835  return nTotemTimingCh;
836  if (Test(n, tagTotemTimingPlane))
837  return nTotemTimingPlane;
838 
839  // for backward compatibility
840  if (Test(n, "trigger_vfat"))
841  return nSkip;
842 
843  throw cms::Exception("TotemDAQMappingESSourceXML::GetNodeType")
844  << "Unknown tag `" << cms::xerces::toString(n->getNodeName()) << "'.\n";
845 }
846 
847 //----------------------------------------------------------------------------------------------------
848 
849 void TotemDAQMappingESSourceXML::GetChannels(xercesc::DOMNode *n, set<unsigned char> &channels) {
850  DOMNodeList *children = n->getChildNodes();
851  for (unsigned int i = 0; i < children->getLength(); i++) {
852  DOMNode *n = children->item(i);
853  if (n->getNodeType() != DOMNode::ELEMENT_NODE || !Test(n, "channel"))
854  continue;
855 
856  DOMNamedNodeMap *attr = n->getAttributes();
857  bool idSet = false;
858  for (unsigned int j = 0; j < attr->getLength(); j++) {
859  DOMNode *a = attr->item(j);
860 
861  if (!strcmp(cms::xerces::toString(a->getNodeName()).c_str(), "id")) {
862  unsigned int id = 0;
863  sscanf(cms::xerces::toString(a->getNodeValue()).c_str(), "%u", &id);
864  channels.insert(id);
865  idSet = true;
866  break;
867  }
868  }
869 
870  if (!idSet) {
871  throw cms::Exception("TotemDAQMappingESSourceXML::GetChannels") << "Channel tags must have an `id' attribute.";
872  }
873  }
874 }
875 
876 //----------------------------------------------------------------------------------------------------
877 
TotemDAQMappingESSourceXML::ParseTreeTotemTiming
void ParseTreeTotemTiming(ParseType, xercesc::DOMNode *, NodeType, unsigned int parentID, const std::unique_ptr< TotemDAQMapping > &, const std::unique_ptr< TotemAnalysisMask > &)
recursive method to extract RP-related information from the DOM tree
Definition: TotemDAQMappingESSourceXML.cc:647
TotemDAQMappingESSourceXML::subSystemName
string subSystemName
label of the CTPPS sub-system
Definition: TotemDAQMappingESSourceXML.cc:88
HIPAlignmentAlgorithm_cfi.verbosity
verbosity
Definition: HIPAlignmentAlgorithm_cfi.py:7
XercesStrUtils.h
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
TotemReadoutRcd.h
TotemDAQMappingESSourceXML::tagSampicCh
static const std::string tagSampicCh
Definition: TotemDAQMappingESSourceXML.cc:75
TotemDAQMappingESSourceXML::tagDiamondCh
static const std::string tagDiamondCh
Definition: TotemDAQMappingESSourceXML.cc:71
mps_fire.i
i
Definition: mps_fire.py:355
TotemDAQMappingESSourceXML::ParseTreeDiamond
void ParseTreeDiamond(ParseType, xercesc::DOMNode *, NodeType, unsigned int parentID, const std::unique_ptr< TotemDAQMapping > &, const std::unique_ptr< TotemAnalysisMask > &)
recursive method to extract RP-related information from the DOM tree
Definition: TotemDAQMappingESSourceXML.cc:521
MessageLogger.h
funct::false
false
Definition: Factorize.h:34
TotemDAQMappingESSourceXML::configuration
vector< ConfigBlock > configuration
Definition: TotemDAQMappingESSourceXML.cc:104
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
TotemVFATAnalysisMask::fullMask
bool fullMask
whether all channels of the VFAT shall be masked
Definition: TotemAnalysisMask.h:33
TotemTimingDetId::ID_NOT_SET
Definition: TotemTimingDetId.h:32
TotemDAQMappingESSourceXML::NodeType
NodeType
enumeration of XML node types
Definition: TotemDAQMappingESSourceXML.cc:113
ESHandle.h
TotemDAQMappingESSourceXML::GetNodeType
NodeType GetNodeType(xercesc::DOMNode *)
determines node type
Definition: TotemDAQMappingESSourceXML.cc:806
TotemDAQMappingESSourceXML::tagAnalysisMask
static const std::string tagAnalysisMask
Definition: TotemDAQMappingESSourceXML.cc:55
edm
HLT enums.
Definition: AlignableModifier.h:19
class-composition.children
children
Definition: class-composition.py:88
TotemDAQMapping.h
TotemDAQMappingESSourceXML::ConfigBlock
Definition: TotemDAQMappingESSourceXML.cc:93
TotemDAQMappingESSourceXML::ConfigBlock::maskFileNames
std::vector< std::string > maskFileNames
the mask files
Definition: TotemDAQMappingESSourceXML.cc:101
edm::ESProducer::setWhatProduced
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:138
TotemDAQMappingESSourceXML::TotemDAQMappingESSourceXML
TotemDAQMappingESSourceXML(const edm::ParameterSet &)
Definition: TotemDAQMappingESSourceXML.cc:244
edm::ValidityInterval
Definition: ValidityInterval.h:28
ESProducer.h
TotemDAQMappingESSourceXML::~TotemDAQMappingESSourceXML
~TotemDAQMappingESSourceXML() override
Definition: TotemDAQMappingESSourceXML.cc:306
cms::cuda::assert
assert(be >=bs)
writedatasetfile.parser
parser
Definition: writedatasetfile.py:7
edm::ESProducts
Definition: ESProducts.h:105
personalPlayback.fp
fp
Definition: personalPlayback.py:523
TotemReadoutRcd
EventSetup record for TOTEM readout-related information.
Definition: TotemReadoutRcd.h:16
TotemDAQMappingESSourceXML::tagChip2
static const std::string tagChip2
Definition: TotemDAQMappingESSourceXML.cc:67
training_settings.idx
idx
Definition: training_settings.py:16
TotemDAQMappingESSourceXML::GetChannels
void GetChannels(xercesc::DOMNode *n, std::set< unsigned char > &channels)
Definition: TotemDAQMappingESSourceXML.cc:849
edm::EventSetupRecordIntervalFinder
Definition: EventSetupRecordIntervalFinder.h:33
TotemDAQMappingESSourceXML::verbosity
unsigned int verbosity
Definition: TotemDAQMappingESSourceXML.cc:85
edm::eventsetup::EventSetupRecordKey
Definition: EventSetupRecordKey.h:30
TotemDAQMappingESSourceXML::tagVFAT
static const std::string tagVFAT
Definition: TotemDAQMappingESSourceXML.cc:53
TotemDAQMappingESSourceXML::nSampicChannel
Definition: TotemDAQMappingESSourceXML.cc:126
TotemDAQMappingESSourceXML::nTop
Definition: TotemDAQMappingESSourceXML.cc:116
edm::es::products
ESProducts< std::remove_reference_t< TArgs >... > products(TArgs &&... args)
Definition: ESProducts.h:128
TotemVFATInfo
Contains mappind data related to a VFAT.
Definition: TotemDAQMapping.h:23
end
#define end
Definition: vmac.h:39
TotemDAQMappingESSourceXML::CompleteFileName
string CompleteFileName(const string &fn)
adds the path prefix, if needed
Definition: TotemDAQMappingESSourceXML.cc:310
TotemDAQMappingESSourceXML::GetNodeValue
string GetNodeValue(xercesc::DOMNode *node)
returns the value of the node
Definition: TotemDAQMappingESSourceXML.cc:180
TotemDAQMappingESSourceXML::RPNode
bool RPNode(NodeType type)
Definition: TotemDAQMappingESSourceXML.cc:187
edm::FileInPath
Definition: FileInPath.h:64
MakerMacros.h
cms::xerces::toString
std::string toString(XMLCh const *toTranscode)
Definition: XercesStrUtils.h:34
TotemDAQMappingESSourceXML::nSkip
Definition: TotemDAQMappingESSourceXML.cc:115
TotemDAQMappingESSourceXML::currentBlock
unsigned int currentBlock
index of the current block in 'configuration' array
Definition: TotemDAQMappingESSourceXML.cc:107
TotemDAQMappingESSourceXML::nDiamondPlane
Definition: TotemDAQMappingESSourceXML.cc:121
TotemDAQMappingESSourceXML::ParseTreeRP
void ParseTreeRP(ParseType, xercesc::DOMNode *, NodeType, unsigned int parentID, const std::unique_ptr< TotemDAQMapping > &, const std::unique_ptr< TotemAnalysisMask > &)
recursive method to extract RP-related information from the DOM tree
Definition: TotemDAQMappingESSourceXML.cc:376
TotemTimingDetId.h
TotemDAQMappingESSourceXML::tagTotemTimingCh
static const std::string tagTotemTimingCh
Definition: TotemDAQMappingESSourceXML.cc:76
TotemDAQMappingESSourceXML::tagRPPot
static const std::string tagRPPot
Definition: TotemDAQMappingESSourceXML.cc:62
TotemDAQMappingESSourceXML
Loads TotemDAQMapping and TotemAnalysisMask from two XML files.
Definition: TotemDAQMappingESSourceXML.cc:51
ctppsRawToDigi_cff.maskFileNames
maskFileNames
Definition: ctppsRawToDigi_cff.py:16
TotemDAQMappingESSourceXML::tagDiamondPlane
static const std::string tagDiamondPlane
diamond specific tags
Definition: TotemDAQMappingESSourceXML.cc:70
TotemAnalysisMask.h
TotemDAQMappingESSourceXML::pMapping
Definition: TotemDAQMappingESSourceXML.cc:132
TotemDAQMapping::TotemTimingPlaneChannelPair
Hw Id mapping for Totem Timing (dynamical mapping in Sampic)
Definition: TotemDAQMapping.h:44
TotemDAQMappingESSourceXML::tagChip1
static const std::string tagChip1
COMMON Chip XML tags.
Definition: TotemDAQMappingESSourceXML.cc:66
b
double b
Definition: hdecay.h:118
TotemDAQMappingESSourceXML::tagSampicBoard
static const std::string tagSampicBoard
totem timing specific tags
Definition: TotemDAQMappingESSourceXML.cc:74
edm::IOVSyncValue
Definition: IOVSyncValue.h:31
edm::EventID::run
RunNumber_t run() const
Definition: EventID.h:38
DEFINE_FWK_EVENTSETUP_SOURCE
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
Definition: SourceFactory.h:91
EventSetupRecordIntervalFinder.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
ESProducts.h
TotemDAQMappingESSourceXML::ConfigBlock::mappingFileNames
std::vector< std::string > mappingFileNames
the mapping files
Definition: TotemDAQMappingESSourceXML.cc:98
TotemTimingDetId
Detector ID class for CTPPS Totem Timing detectors. Bits [19:31] : Assigend in CTPPSDetId Calss Bits ...
Definition: TotemTimingDetId.h:26
CTPPSDiamondDetId.h
TotemDAQMappingESSourceXML::nChannel
Definition: TotemDAQMappingESSourceXML.cc:124
SourceFactory.h
TotemDAQMappingESSourceXML::GetNodeContent
string GetNodeContent(xercesc::DOMNode *parent)
returns the content of the node
Definition: TotemDAQMappingESSourceXML.cc:177
TotemDAQMappingESSourceXML::setIntervalFor
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &) override
sets infinite validity of this data
Definition: TotemDAQMappingESSourceXML.cc:263
edm::IOVSyncValue::eventID
const EventID & eventID() const
Definition: IOVSyncValue.h:40
TotemDAQMappingESSourceXML::nRPStation
Definition: TotemDAQMappingESSourceXML.cc:118
CTPPSDiamondDetId
Detector ID class for CTPPS Timing Diamond detectors. Bits [19:31] : Assigend in CTPPSDetId Calss Bit...
Definition: CTPPSDiamondDetId.h:24
edm::ParameterSet
Definition: ParameterSet.h:36
a
double a
Definition: hdecay.h:119
TotemSymbID
Symbolic ID describing an entity of a TOTEM subdetector.
Definition: TotemSymbId.h:16
TotemDAQMappingESSourceXML::currentBlockValid
bool currentBlockValid
flag whether the 'currentBlock' index is valid
Definition: TotemDAQMappingESSourceXML.cc:110
TotemSymbID::symbolicID
unsigned int symbolicID
chip ID, raw integer representation of DetId class
Definition: TotemSymbId.h:24
TotemDAQMappingESSourceXML::ConfigBlock::validityRange
edm::EventRange validityRange
validity interval
Definition: TotemDAQMappingESSourceXML.cc:95
TotemFramePosition
Definition: TotemFramePosition.h:31
TotemDAQMappingESSourceXML::produce
edm::ESProducts< std::unique_ptr< TotemDAQMapping >, std::unique_ptr< TotemAnalysisMask > > produce(const TotemReadoutRcd &)
Definition: TotemDAQMappingESSourceXML.cc:318
TotemDAQMappingESSourceXML::tagChannel
static const std::string tagChannel
Definition: TotemDAQMappingESSourceXML.cc:54
edm::EventID::event
EventNumber_t event() const
Definition: EventID.h:40
TotemFramePosition.h
createfilelist.int
int
Definition: createfilelist.py:10
TotemDAQMappingESSourceXML::tagRPPlane
static const std::string tagRPPlane
Definition: TotemDAQMappingESSourceXML.cc:63
FrontierConditions_GlobalTag_cff.file
file
Definition: FrontierConditions_GlobalTag_cff.py:13
TotemDAQMappingESSourceXML::pMask
Definition: TotemDAQMappingESSourceXML.cc:132
edm::LogVerbatim
Definition: MessageLogger.h:297
TotemDAQMappingESSourceXML::CommonNode
bool CommonNode(NodeType type)
Definition: TotemDAQMappingESSourceXML.cc:201
TotemDAQMappingESSourceXML::nChip
Definition: TotemDAQMappingESSourceXML.cc:122
edm::contains
bool contains(EventRange const &lh, EventID const &rh)
Definition: EventRange.cc:37
TotemDAQMappingESSourceXML::tagTotemTimingPlane
static const std::string tagTotemTimingPlane
Definition: TotemDAQMappingESSourceXML.cc:77
hlx_dqm_sourceclient_cfi.subSystemName
subSystemName
Definition: hlx_dqm_sourceclient_cfi.py:15
TotemDAQMappingESSourceXML::nUnknown
Definition: TotemDAQMappingESSourceXML.cc:114
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
TotemDAQMappingESSourceXML::ParseXML
void ParseXML(ParseType, const string &file, const std::unique_ptr< TotemDAQMapping > &, const std::unique_ptr< TotemAnalysisMask > &)
parses XML file
Definition: TotemDAQMappingESSourceXML.cc:349
ModuleFactory.h
TotemDAQMappingESSourceXML::mappingFileNames
std::vector< std::string > mappingFileNames
the mapping files
Definition: TotemDAQMappingESSourceXML.cc:91
cond::ValidityInterval
std::pair< Time_t, Time_t > ValidityInterval
Definition: Time.h:17
type
type
Definition: HCALResponse.h:21
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
TotemVFATInfo::hwID
unsigned int hwID
the hardware ID (16 bit)
Definition: TotemDAQMapping.h:35
TotemDAQMappingESSourceXML::nTotemTimingPlane
Definition: TotemDAQMappingESSourceXML.cc:127
TotemDAQMappingESSourceXML::nDiamondCh
Definition: TotemDAQMappingESSourceXML.cc:123
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:31
TotemDAQMappingESSourceXML::nRPPlane
Definition: TotemDAQMappingESSourceXML.cc:120
TotemDAQMappingESSourceXML::tagRPStation
static const std::string tagRPStation
RP XML tags.
Definition: TotemDAQMappingESSourceXML.cc:61
Exception
Definition: hltDiff.cc:246
ewkTauDQM_cfi.channels
channels
Definition: ewkTauDQM_cfi.py:14
TotemDAQMappingESSourceXML::ChipFramePosition
TotemFramePosition ChipFramePosition(xercesc::DOMNode *chipnode)
extracts VFAT's DAQ channel from XML attributes
Definition: TotemDAQMappingESSourceXML.cc:781
TotemDAQMappingESSourceXML::nTotemTimingCh
Definition: TotemDAQMappingESSourceXML.cc:128
TotemRPDetId.h
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
personalPlayback.fn
fn
Definition: personalPlayback.py:515
TotemDAQMappingESSourceXML::DiamondNode
bool DiamondNode(NodeType type)
Definition: TotemDAQMappingESSourceXML.cc:191
TotemDAQMappingESSourceXML::nSampicBoard
Definition: TotemDAQMappingESSourceXML.cc:125
edm::ESProducer
Definition: ESProducer.h:101
TotemDAQMappingESSourceXML::tagArm
static const std::string tagArm
Common position tags.
Definition: TotemDAQMappingESSourceXML.cc:58
TotemDAQMappingESSourceXML::TotemTimingNode
bool TotemTimingNode(NodeType type)
Definition: TotemDAQMappingESSourceXML.cc:196
ParameterSet.h
TotemVFATInfo::symbolicID
TotemSymbID symbolicID
the symbolic id
Definition: TotemDAQMapping.h:32
TotemDAQMappingESSourceXML::ParseType
ParseType
whether to parse a mapping of a mask XML
Definition: TotemDAQMappingESSourceXML.cc:132
TotemDAQMappingESSourceXML::Test
bool Test(xercesc::DOMNode *node, const std::string &name)
returns true iff the node is of the given name
Definition: TotemDAQMappingESSourceXML.cc:169
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
edm::EventID
Definition: EventID.h:31
edm::EventRange
Definition: EventRange.h:31
child
Definition: simpleInheritance.h:11
crabWrapper.key
key
Definition: crabWrapper.py:19
TotemDAQMappingESSourceXML::nRPPot
Definition: TotemDAQMappingESSourceXML.cc:119
taus_updatedMVAIds_cff.mapping
mapping
Definition: taus_updatedMVAIds_cff.py:28
class-composition.parent
parent
Definition: class-composition.py:88
TotemRPDetId
Detector ID class for TOTEM Si strip detectors.
Definition: TotemRPDetId.h:29
begin
#define begin
Definition: vmac.h:32
TotemVFATAnalysisMask
Contains data on masked channels of a VFAT.
Definition: TotemAnalysisMask.h:22
edm::FileInPath::fullPath
std::string fullPath() const
Definition: FileInPath.cc:163
TotemDAQMappingESSourceXML::nArm
Definition: TotemDAQMappingESSourceXML.cc:117
TotemVFATAnalysisMask::maskedChannels
std::set< unsigned char > maskedChannels
list of channels to be masked
Definition: TotemAnalysisMask.h:36