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 
27 
34 
35 #include <xercesc/parsers/XercesDOMParser.hpp>
36 #include <xercesc/dom/DOM.hpp>
37 #include <xercesc/sax/HandlerBase.hpp>
38 #include <xercesc/util/XMLString.hpp>
39 #include <xercesc/util/PlatformUtils.hpp>
40 
41 #include <memory>
42 #include <sstream>
43 
44 //#define DEBUG 1
45 
46 //----------------------------------------------------------------------------------------------------
47 
48 using namespace std;
49 
54 public:
55  static const std::string tagVFAT;
56  static const std::string tagChannel;
58 
60  static const std::string tagArm;
61 
63  static const std::string tagRPStation;
64  static const std::string tagRPPot;
65  static const std::string tagRPPlane;
66 
68  static const std::string tagChip1;
69  static const std::string tagChip2;
70 
73  static const std::string tagDiamondCh;
74 
77  static const std::string tagSampicCh;
80 
84 
86  ~TotemDAQMappingESSourceXML() override;
87 
88  edm::ESProducts<std::unique_ptr<TotemDAQMapping>, std::unique_ptr<TotemAnalysisMask>> produce(const TotemReadoutRcd &);
89 
90 private:
91  unsigned int verbosity;
92 
94  string subSystemName;
95 
96  //subdetector id for sampic
97  unsigned int sampicSubDetId;
98 
100  std::vector<std::string> mappingFileNames;
101 
102  struct ConfigBlock {
105 
107  std::vector<std::string> mappingFileNames;
108 
110  std::vector<std::string> maskFileNames;
111  };
112 
113  vector<ConfigBlock> configuration;
114 
116  unsigned int currentBlock;
117 
120 
122  enum NodeType {
139  nTotemT2Tile
140  };
141 
143  enum ParseType { pMapping, pMask };
144 
146  void ParseXML(ParseType,
147  const string &file,
148  const std::unique_ptr<TotemDAQMapping> &,
149  const std::unique_ptr<TotemAnalysisMask> &);
150 
152  void ParseTreeRP(ParseType,
153  xercesc::DOMNode *,
154  NodeType,
155  unsigned int parentID,
156  const std::unique_ptr<TotemDAQMapping> &,
157  const std::unique_ptr<TotemAnalysisMask> &);
158 
160  void ParseTreeDiamond(ParseType,
161  xercesc::DOMNode *,
162  NodeType,
163  unsigned int parentID,
164  const std::unique_ptr<TotemDAQMapping> &,
165  const std::unique_ptr<TotemAnalysisMask> &);
166 
168  void ParseTreeTotemTiming(ParseType,
169  xercesc::DOMNode *,
170  NodeType,
171  unsigned int parentID,
172  const std::unique_ptr<TotemDAQMapping> &,
173  const std::unique_ptr<TotemAnalysisMask> &);
174 
176  void ParseTreeTotemT2(ParseType,
177  xercesc::DOMNode *,
178  NodeType,
179  unsigned int parentID,
180  const std::unique_ptr<TotemDAQMapping> &,
181  const std::unique_ptr<TotemAnalysisMask> &);
182 
183 private:
185  string CompleteFileName(const string &fn);
186 
188  bool Test(xercesc::DOMNode *node, const std::string &name) {
189  return !(name.compare(cms::xerces::toString(node->getNodeName())));
190  }
191 
193  NodeType GetNodeType(xercesc::DOMNode *);
194 
196  string GetNodeContent(xercesc::DOMNode *parent) { return string(cms::xerces::toString(parent->getTextContent())); }
197 
199  string GetNodeValue(xercesc::DOMNode *node) { return cms::xerces::toString(node->getNodeValue()); }
200 
202  TotemFramePosition ChipFramePosition(xercesc::DOMNode *chipnode);
203 
204  void GetChannels(xercesc::DOMNode *n, std::set<unsigned char> &channels);
205 
207  return ((type == nArm) || (type == nRPStation) || (type == nRPPot) || (type == nRPPlane) || (type == nChip));
208  }
209 
211  return ((type == nArm) || (type == nRPStation) || (type == nRPPot) || (type == nDiamondPlane) ||
212  (type == nDiamondCh));
213  }
214 
216  return ((type == nArm) || (type == nRPStation) || (type == nRPPot) || (type == nSampicBoard) ||
217  (type == nSampicChannel) || (type == nTotemTimingPlane) || (type == nTotemTimingCh));
218  }
219 
220  bool TotemT2Node(NodeType type) { return type == nArm || type == nTotemT2Plane || type == nTotemT2Tile; }
221 
222  bool CommonNode(NodeType type) { return ((type == nChip) || (type == nArm)); }
223 
224 protected:
226  void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &,
227  const edm::IOVSyncValue &,
228  edm::ValidityInterval &) override;
229 };
230 
231 //----------------------------------------------------------------------------------------------------
232 
233 using namespace std;
234 using namespace edm;
235 using namespace xercesc;
236 
237 const string TotemDAQMappingESSourceXML::tagVFAT = "vfat";
238 const string TotemDAQMappingESSourceXML::tagChannel = "channel";
239 const string TotemDAQMappingESSourceXML::tagAnalysisMask = "analysisMask";
240 
241 // common XML position tags
242 const string TotemDAQMappingESSourceXML::tagArm = "arm";
243 
244 // common XML Chip tags
245 const string TotemDAQMappingESSourceXML::tagChip1 = "vfat";
246 const string TotemDAQMappingESSourceXML::tagChip2 = "test_vfat";
247 
248 // specific RP XML tags
249 const string TotemDAQMappingESSourceXML::tagRPStation = "station";
250 const string TotemDAQMappingESSourceXML::tagRPPot = "rp_detector_set";
251 const string TotemDAQMappingESSourceXML::tagRPPlane = "rp_plane";
252 
253 // specific tags for diamond
254 const string TotemDAQMappingESSourceXML::tagDiamondPlane = "rp_plane_diamond";
255 const string TotemDAQMappingESSourceXML::tagDiamondCh = "diamond_channel";
256 
257 // specific tags for totem timing
258 const string TotemDAQMappingESSourceXML::tagSampicBoard = "rp_sampic_board";
259 const string TotemDAQMappingESSourceXML::tagSampicCh = "rp_sampic_channel";
260 const string TotemDAQMappingESSourceXML::tagTotemTimingCh = "timing_channel";
261 const string TotemDAQMappingESSourceXML::tagTotemTimingPlane = "timing_plane";
262 
263 // specific tags for TOTEM nT2
264 const string TotemDAQMappingESSourceXML::tagTotemT2Plane = "nt2_plane";
265 const string TotemDAQMappingESSourceXML::tagTotemT2Tile = "nt2_tile";
266 
267 //----------------------------------------------------------------------------------------------------
268 
270  : verbosity(conf.getUntrackedParameter<unsigned int>("verbosity", 0)),
271  subSystemName(conf.getUntrackedParameter<string>("subSystem")),
272  sampicSubDetId(conf.getParameter<unsigned int>("sampicSubDetId")),
273  currentBlock(0),
274  currentBlockValid(false) {
275  for (const auto &it : conf.getParameter<vector<ParameterSet>>("configuration")) {
276  ConfigBlock b;
277  b.validityRange = it.getParameter<EventRange>("validityRange");
278  b.mappingFileNames = it.getParameter<vector<string>>("mappingFileNames");
279  b.maskFileNames = it.getParameter<vector<string>>("maskFileNames");
280  configuration.push_back(b);
281  }
282 
284  findingRecord<TotemReadoutRcd>();
285 }
286 
287 //----------------------------------------------------------------------------------------------------
288 
290  const edm::IOVSyncValue &iosv,
291  edm::ValidityInterval &oValidity) {
292  LogVerbatim("TotemDAQMappingESSourceXML") << ">> TotemDAQMappingESSourceXML::setIntervalFor(" << key.name() << ")";
293 
294  LogVerbatim("TotemDAQMappingESSourceXML")
295  << " run=" << iosv.eventID().run() << ", event=" << iosv.eventID().event();
296 
297  currentBlockValid = false;
298  for (unsigned int idx = 0; idx < configuration.size(); ++idx) {
299  const auto &bl = configuration[idx];
300 
301  edm::EventRange range = bl.validityRange;
302 
303  // If "<run>:min" is specified in python config, it is translated into event <run>:0:1.
304  // However, the truly minimal event id often found in data is <run>:0:0. Therefore the
305  // adjustment below is needed.
306  if (range.startEventID().luminosityBlock() == 0 && range.startEventID().event() == 1)
307  range = edm::EventRange(edm::EventID(range.startEventID().run(), 0, 0), range.endEventID());
308 
309  if (edm::contains(range, iosv.eventID())) {
310  currentBlockValid = true;
311  currentBlock = idx;
312 
313  const IOVSyncValue begin(range.startEventID());
314  const IOVSyncValue end(range.endEventID());
315  oValidity = edm::ValidityInterval(begin, end);
316 
317  LogVerbatim("TotemDAQMappingESSourceXML") << " block found: index=" << currentBlock << ", interval=("
318  << range.startEventID() << " - " << range.endEventID() << ")";
319 
320  return;
321  }
322  }
323 
324  if (!currentBlockValid) {
325  throw cms::Exception("TotemDAQMappingESSourceXML::setIntervalFor")
326  << "No configuration for event " << iosv.eventID();
327  }
328 }
329 
330 //----------------------------------------------------------------------------------------------------
331 
333 
334 //----------------------------------------------------------------------------------------------------
335 
337  FileInPath fip(fn);
338  return fip.fullPath();
339 }
340 
341 //----------------------------------------------------------------------------------------------------
342 
343 edm::ESProducts<std::unique_ptr<TotemDAQMapping>, std::unique_ptr<TotemAnalysisMask>>
346 
347  auto mapping = std::make_unique<TotemDAQMapping>();
348  auto mask = std::make_unique<TotemAnalysisMask>();
349 
350  // initialize Xerces
352 
353  // load mapping files
354  for (const auto &fn : configuration[currentBlock].mappingFileNames)
356 
357  // load mask files
358  for (const auto &fn : configuration[currentBlock].maskFileNames)
360 
361  // release Xerces
363 
364  // commit the products
366 }
367 
368 //----------------------------------------------------------------------------------------------------
369 
371  const string &file,
372  const std::unique_ptr<TotemDAQMapping> &mapping,
373  const std::unique_ptr<TotemAnalysisMask> &mask) {
374  unique_ptr<XercesDOMParser> parser(new XercesDOMParser());
375  parser->parse(file.c_str());
376 
377  DOMDocument *domDoc = parser->getDocument();
378 
379  if (!domDoc)
380  throw cms::Exception("TotemDAQMappingESSourceXML::ParseXML")
381  << "Cannot parse file `" << file << "' (domDoc = NULL).";
382 
383  DOMElement *elementRoot = domDoc->getDocumentElement();
384 
385  if (!elementRoot)
386  throw cms::Exception("TotemDAQMappingESSourceXML::ParseXML") << "File `" << file << "' is empty.";
387 
388  ParseTreeRP(pType, elementRoot, nTop, 0, mapping, mask);
389 
390  ParseTreeDiamond(pType, elementRoot, nTop, 0, mapping, mask);
391 
392  ParseTreeTotemTiming(pType, elementRoot, nTop, 0, mapping, mask);
393 
394  ParseTreeTotemT2(pType, elementRoot, nTop, 0, mapping, mask);
395 }
396 
397 //-----------------------------------------------------------------------------------------------------------
398 
400  xercesc::DOMNode *parent,
401  NodeType parentType,
402  unsigned int parentID,
403  const std::unique_ptr<TotemDAQMapping> &mapping,
404  const std::unique_ptr<TotemAnalysisMask> &mask) {
405 #ifdef DEBUG
406  printf(">> TotemDAQMappingESSourceXML::ParseTreeRP(%s, %u, %u)\n",
407  cms::xerces::toString(parent->getNodeName()),
408  parentType,
409  parentID);
410 #endif
411 
412  DOMNodeList *children = parent->getChildNodes();
413 
414  for (unsigned int i = 0; i < children->getLength(); i++) {
415  DOMNode *n = children->item(i);
416  if (n->getNodeType() != DOMNode::ELEMENT_NODE)
417  continue;
418 
420 
421 #ifdef DEBUG
422  printf("\tname = %s, type = %u\n", cms::xerces::toString(n->getNodeName()), type);
423 #endif
424 
425  // structure control
426  if (!RPNode(type))
427  continue;
428 
429  NodeType expectedParentType;
430  switch (type) {
431  case nArm:
432  expectedParentType = nTop;
433  break;
434  case nRPStation:
435  expectedParentType = nArm;
436  break;
437  case nRPPot:
438  expectedParentType = nRPStation;
439  break;
440  case nRPPlane:
441  expectedParentType = nRPPot;
442  break;
443  case nChip:
444  expectedParentType = nRPPlane;
445  break;
446  case nChannel:
447  expectedParentType = nChip;
448  break;
449  default:
450  expectedParentType = nUnknown;
451  break;
452  }
453 
454  if (expectedParentType != parentType) {
455  throw cms::Exception("TotemDAQMappingESSourceXML")
456  << "Node " << cms::xerces::toString(n->getNodeName()) << " not allowed within "
457  << cms::xerces::toString(parent->getNodeName()) << " block.\n";
458  }
459 
460  // parse tag attributes
461  unsigned int id = 0, hw_id = 0;
462  bool id_set = false, hw_id_set = false;
463  bool fullMask = false;
464  DOMNamedNodeMap *attr = n->getAttributes();
465 
466  for (unsigned int j = 0; j < attr->getLength(); j++) {
467  DOMNode *a = attr->item(j);
468 
469  if (!strcmp(cms::xerces::toString(a->getNodeName()).c_str(), "id")) {
470  sscanf(cms::xerces::toString(a->getNodeValue()).c_str(), "%u", &id);
471  id_set = true;
472  }
473 
474  if (!strcmp(cms::xerces::toString(a->getNodeName()).c_str(), "hw_id")) {
475  sscanf(cms::xerces::toString(a->getNodeValue()).c_str(), "%x", &hw_id);
476  hw_id_set = true;
477  }
478 
479  if (!strcmp(cms::xerces::toString(a->getNodeName()).c_str(), "full_mask"))
480  fullMask = (strcmp(cms::xerces::toString(a->getNodeValue()).c_str(), "no") != 0);
481  }
482 
483  // content control
484  if (!id_set)
485  throw cms::Exception("TotemDAQMappingESSourceXML::ParseTreeRP")
486  << "id not given for element `" << cms::xerces::toString(n->getNodeName()) << "'";
487 
488  if (!hw_id_set && type == nChip && pType == pMapping)
489  throw cms::Exception("TotemDAQMappingESSourceXML::ParseTreeRP")
490  << "hw_id not given for element `" << cms::xerces::toString(n->getNodeName()) << "'";
491 
492  if (type == nRPPlane && id > 9)
493  throw cms::Exception("TotemDAQMappingESSourceXML::ParseTreeRP")
494  << "Plane IDs range from 0 to 9. id = " << id << " is invalid.";
495 
496 #ifdef DEBUG
497  printf("\tID found: 0x%x\n", id);
498 #endif
499 
500  // store mapping data
501  if (pType == pMapping && type == nChip) {
502  const TotemFramePosition &framepos = ChipFramePosition(n);
503  TotemVFATInfo vfatInfo;
504  vfatInfo.hwID = hw_id;
505 
506  const unsigned int armIdx = (parentID / 1000) % 10;
507  const unsigned int stIdx = (parentID / 100) % 10;
508  const unsigned int rpIdx = (parentID / 10) % 10;
509  const unsigned int plIdx = parentID % 10;
510 
511  vfatInfo.symbolicID.symbolicID = TotemRPDetId(armIdx, stIdx, rpIdx, plIdx, id);
512 
513  mapping->insert(framepos, vfatInfo);
514 
515  continue;
516  }
517 
518  // store mask data
519  if (pType == pMask && type == nChip) {
520  const unsigned int armIdx = (parentID / 1000) % 10;
521  const unsigned int stIdx = (parentID / 100) % 10;
522  const unsigned int rpIdx = (parentID / 10) % 10;
523  const unsigned int plIdx = parentID % 10;
524 
525  TotemSymbID symbId;
526  symbId.symbolicID = TotemRPDetId(armIdx, stIdx, rpIdx, plIdx, id);
527 
529  am.fullMask = fullMask;
531 
532  mask->insert(symbId, am);
533 
534  continue;
535  }
536 
537  // recursion (deeper in the tree)
538  ParseTreeRP(pType, n, type, parentID * 10 + id, mapping, mask);
539  }
540 }
541 
542 //----------------------------------------------------------------------------------------------------
543 
545  xercesc::DOMNode *parent,
546  NodeType parentType,
547  unsigned int parentID,
548  const std::unique_ptr<TotemDAQMapping> &mapping,
549  const std::unique_ptr<TotemAnalysisMask> &mask) {
550 #ifdef DEBUG
551  printf(">> TotemDAQMappingESSourceXML::ParseTreeDiamond(%s, %u, %u)\n",
552  cms::xerces::toString(parent->getNodeName()),
553  parentType,
554  parentID);
555 #endif
556 
557  DOMNodeList *children = parent->getChildNodes();
558 
559  for (unsigned int i = 0; i < children->getLength(); i++) {
560  DOMNode *n = children->item(i);
561  if (n->getNodeType() != DOMNode::ELEMENT_NODE)
562  continue;
563 
565 #ifdef DEBUG
566  printf("\tname = %s, type = %u\n", cms::xerces::toString(n->getNodeName()), type);
567 #endif
568 
569  // structure control
570  if (!DiamondNode(type))
571  continue;
572 
573  NodeType expectedParentType;
574  switch (type) {
575  case nArm:
576  expectedParentType = nTop;
577  break;
578  case nRPStation:
579  expectedParentType = nArm;
580  break;
581  case nRPPot:
582  expectedParentType = nRPStation;
583  break;
584  case nDiamondPlane:
585  expectedParentType = nRPPot;
586  break;
587  case nDiamondCh:
588  expectedParentType = nDiamondPlane;
589  break;
590  default:
591  expectedParentType = nUnknown;
592  break;
593  }
594 
595  if (expectedParentType != parentType) {
596  throw cms::Exception("TotemDAQMappingESSourceXML")
597  << "Node " << cms::xerces::toString(n->getNodeName()) << " not allowed within "
598  << cms::xerces::toString(parent->getNodeName()) << " block.\n";
599  }
600 
601  // parse tag attributes
602  unsigned int id = 0, hw_id = 0;
603  bool id_set = false, hw_id_set = false;
604  DOMNamedNodeMap *attr = n->getAttributes();
605 
606  for (unsigned int j = 0; j < attr->getLength(); j++) {
607  DOMNode *a = attr->item(j);
608 
609  if (!strcmp(cms::xerces::toString(a->getNodeName()).c_str(), "id")) {
610  sscanf(cms::xerces::toString(a->getNodeValue()).c_str(), "%u", &id);
611  id_set = true;
612  }
613 
614  if (!strcmp(cms::xerces::toString(a->getNodeName()).c_str(), "hw_id")) {
615  sscanf(cms::xerces::toString(a->getNodeValue()).c_str(), "%x", &hw_id);
616  hw_id_set = true;
617  }
618  }
619 
620  // content control
621  if (!id_set)
622  throw cms::Exception("TotemDAQMappingESSourceXML::ParseTreeDiamond")
623  << "id not given for element `" << cms::xerces::toString(n->getNodeName()) << "'";
624 
625  if (!hw_id_set && type == nDiamondCh && pType == pMapping)
626  throw cms::Exception("TotemDAQMappingESSourceXML::ParseTreeDiamond")
627  << "hw_id not given for element `" << cms::xerces::toString(n->getNodeName()) << "'";
628 
629  if (type == nDiamondPlane && id > 3)
630  throw cms::Exception("TotemDAQMappingESSourceXML::ParseTreeDiamond")
631  << "Plane IDs range from 0 to 3. id = " << id << " is invalid.";
632 
633 #ifdef DEBUG
634  printf("\tID found: 0x%x\n", id);
635 #endif
636 
637  // store mapping data
638  if (pType == pMapping && type == nDiamondCh) {
639  const TotemFramePosition &framepos = ChipFramePosition(n);
640 
641  TotemVFATInfo vfatInfo;
642  vfatInfo.hwID = hw_id;
643 
644  if (type == nDiamondCh) {
645  unsigned int ArmNum = (parentID / 10000) % 10;
646  unsigned int StationNum = (parentID / 1000) % 10;
647  unsigned int RpNum = (parentID / 100) % 10;
648  unsigned int PlaneNum = (parentID % 100);
649 
650  vfatInfo.symbolicID.symbolicID = CTPPSDiamondDetId(ArmNum, StationNum, RpNum, PlaneNum, id);
651  }
652 
653  mapping->insert(framepos, vfatInfo);
654 
655  continue;
656  }
657 
658  unsigned int childId;
659  if (pType == pMapping && type == nDiamondPlane)
660  childId = parentID * 100 + id;
661  else
662  childId = parentID * 10 + id;
663 
664  ParseTreeDiamond(pType, n, type, childId, mapping, mask);
665  }
666 }
667 
668 //----------------------------------------------------------------------------------------------------
669 
671  xercesc::DOMNode *parent,
672  NodeType parentType,
673  unsigned int parentID,
674  const std::unique_ptr<TotemDAQMapping> &mapping,
675  const std::unique_ptr<TotemAnalysisMask> &mask) {
676  DOMNodeList *children = parent->getChildNodes();
677 
678  // Fill map hwId -> TotemTimingPlaneChannelPair
679  for (unsigned int i = 0; i < children->getLength(); i++) {
680  DOMNode *child = children->item(i);
681  if ((child->getNodeType() != DOMNode::ELEMENT_NODE) || (GetNodeType(child) != nTotemTimingCh))
682  continue;
683 
684  int plane = -1;
685  DOMNamedNodeMap *attr = parent->getAttributes();
686  for (unsigned int j = 0; j < attr->getLength(); j++) {
687  DOMNode *a = attr->item(j);
688 
689  if (!strcmp(cms::xerces::toString(a->getNodeName()).c_str(), "id"))
690  sscanf(cms::xerces::toString(a->getNodeValue()).c_str(), "%d", &plane);
691  }
692 
693  int channel = -1;
694  unsigned int hwId = 0;
695  attr = child->getAttributes();
696  for (unsigned int j = 0; j < attr->getLength(); j++) {
697  DOMNode *a = attr->item(j);
698 
699  if (!strcmp(cms::xerces::toString(a->getNodeName()).c_str(), "id"))
700  sscanf(cms::xerces::toString(a->getNodeValue()).c_str(), "%d", &channel);
701  if (!strcmp(cms::xerces::toString(a->getNodeName()).c_str(), "hwId"))
702  sscanf(cms::xerces::toString(a->getNodeValue()).c_str(), "%x", &hwId);
703  }
704 
705  mapping->totemTimingChannelMap[(uint8_t)hwId] = TotemDAQMapping::TotemTimingPlaneChannelPair(plane, channel);
706  }
707 
708  for (unsigned int i = 0; i < children->getLength(); i++) {
709  DOMNode *n = children->item(i);
710  if (n->getNodeType() != DOMNode::ELEMENT_NODE)
711  continue;
712 
714 
715  // structure control
716  if (!TotemTimingNode(type))
717  continue;
718 
719  NodeType expectedParentType;
720  switch (type) {
721  case nArm:
722  expectedParentType = nTop;
723  break;
724  case nRPStation:
725  expectedParentType = nArm;
726  break;
727  case nRPPot:
728  expectedParentType = nRPStation;
729  break;
730  case nSampicBoard:
731  expectedParentType = nRPPot;
732  break;
733  case nSampicChannel:
734  expectedParentType = nSampicBoard;
735  break;
736  case nTotemTimingPlane:
737  expectedParentType = nRPPot;
738  break;
739  case nTotemTimingCh:
740  expectedParentType = nTotemTimingPlane;
741  break;
742  default:
743  expectedParentType = nUnknown;
744  break;
745  }
746 
747  if (expectedParentType != parentType) {
748  throw cms::Exception("TotemDAQMappingESSourceXML")
749  << "Node " << cms::xerces::toString(n->getNodeName()) << " not allowed within "
750  << cms::xerces::toString(parent->getNodeName()) << " block.\n";
751  }
752 
753  // parse tag attributes
754  unsigned int id = 0;
755  bool id_set = false;
756  DOMNamedNodeMap *attr = n->getAttributes();
757 
758  for (unsigned int j = 0; j < attr->getLength(); j++) {
759  DOMNode *a = attr->item(j);
760 
761  if (!strcmp(cms::xerces::toString(a->getNodeName()).c_str(), "id")) {
762  sscanf(cms::xerces::toString(a->getNodeValue()).c_str(), "%u", &id);
763  id_set = true;
764  }
765  }
766 
767  // content control
768  if (!id_set)
769  throw cms::Exception("TotemDAQMappingESSourceXML::ParseTreeTotemTiming")
770  << "id not given for element `" << cms::xerces::toString(n->getNodeName()) << "'";
771  if (type == nSampicBoard && id > 5)
772  throw cms::Exception("TotemDAQMappingESSourceXML::ParseTreeTotemTiming")
773  << "SampicBoard IDs range from 0 to 5. id = " << id << " is invalid.";
774 
775  // store mapping data
776  if (pType == pMapping && type == nSampicChannel) {
777  const TotemFramePosition &framepos = ChipFramePosition(n);
778 
779  TotemVFATInfo vfatInfo;
780  unsigned int ArmNum = (parentID / 10000) % 10;
781  unsigned int StationNum = (parentID / 1000) % 10;
782  unsigned int RpNum = (parentID / 100) % 10;
783 
784  vfatInfo.symbolicID.symbolicID = TotemTimingDetId(ArmNum,
785  StationNum,
786  RpNum,
787  0,
789  sampicSubDetId); //Dynamical: it is encoded in the frame
790 
791  mapping->insert(framepos, vfatInfo);
792 
793  continue;
794  }
795 
796  unsigned int childId;
797  if (pType == pMapping && type == nSampicBoard)
798  childId = parentID * 100 + id;
799  else
800  childId = parentID * 10 + id;
801 
802  ParseTreeTotemTiming(pType, n, type, childId, mapping, mask);
803  }
804 }
805 
806 //----------------------------------------------------------------------------------------------------
807 
809  xercesc::DOMNode *parent,
810  NodeType parentType,
811  unsigned int parentID,
812  const std::unique_ptr<TotemDAQMapping> &mapping,
813  const std::unique_ptr<TotemAnalysisMask> &mask) {
814  DOMNodeList *children = parent->getChildNodes();
815 
816  for (unsigned int i = 0; i < children->getLength(); i++) {
817  DOMNode *child = children->item(i);
818  if (child->getNodeType() != DOMNode::ELEMENT_NODE)
819  continue;
820 
822 
823  // structure control
824  if (!TotemT2Node(type))
825  continue;
826 
827  NodeType expectedParentType;
828  switch (type) {
829  case nArm:
830  expectedParentType = nTop;
831  break;
832  case nTotemT2Plane:
833  expectedParentType = nArm;
834  break;
835  case nTotemT2Tile:
836  expectedParentType = nTotemT2Plane;
837  break;
838  default:
839  expectedParentType = nUnknown;
840  break;
841  }
842 
843  if (expectedParentType != parentType) {
844  throw cms::Exception("TotemDAQMappingESSourceXML")
845  << "Node " << cms::xerces::toString(child->getNodeName()) << " not allowed within "
846  << cms::xerces::toString(parent->getNodeName()) << " block.\n";
847  }
848 
849  unsigned int id = 0;
850  bool id_set = false;
851  DOMNamedNodeMap *attr = child->getAttributes();
852 
853  for (unsigned int j = 0; j < attr->getLength(); j++) {
854  DOMNode *a = attr->item(j);
855  if (!strcmp(cms::xerces::toString(a->getNodeName()).c_str(), "id")) {
856  sscanf(cms::xerces::toString(a->getNodeValue()).c_str(), "%u", &id);
857  id_set = true;
858  }
859  }
860  if (pType == pMapping && type == nTotemT2Tile) {
861  // parse tag attributes
862  unsigned int hw_id = 0;
863  bool hw_id_set = false;
864  DOMNamedNodeMap *attr = child->getAttributes();
865 
866  for (unsigned int j = 0; j < attr->getLength(); j++) {
867  DOMNode *a = attr->item(j);
868  if (!strcmp(cms::xerces::toString(a->getNodeName()).c_str(), "hwId")) {
869  sscanf(cms::xerces::toString(a->getNodeValue()).c_str(), "%u", &hw_id);
870  hw_id_set = true;
871  }
872  }
873 
874  // content control
875  if (!id_set)
876  throw cms::Exception("TotemDAQMappingESSourceXML::ParseTreeTotemT2")
877  << "id not given for element `" << cms::xerces::toString(child->getNodeName()) << "'";
878  if (!hw_id_set)
879  throw cms::Exception("TotemDAQMappingESSourceXML::ParseTreeTotemT2")
880  << "hwId not given for element `" << cms::xerces::toString(child->getNodeName()) << "'";
881 
882  // store mapping data
883  const TotemFramePosition &framepos = ChipFramePosition(child);
884  TotemVFATInfo vfatInfo;
885  unsigned int arm = parentID / 10, plane = parentID % 10;
886  vfatInfo.symbolicID.symbolicID = TotemT2DetId(arm, plane, id);
887 
888  mapping->insert(framepos, vfatInfo);
889 
890  continue;
891  }
892  // follow tree recursively
893  ParseTreeTotemT2(pType, child, type, parentID * 10 + id, mapping, mask);
894  }
895 }
896 
897 //----------------------------------------------------------------------------------------------------
898 
901  unsigned char attributeFlag = 0;
902 
903  DOMNamedNodeMap *attr = chipnode->getAttributes();
904  for (unsigned int j = 0; j < attr->getLength(); j++) {
905  DOMNode *a = attr->item(j);
906  if (fp.setXMLAttribute(
907  cms::xerces::toString(a->getNodeName()), cms::xerces::toString(a->getNodeValue()), attributeFlag) > 1) {
908  throw cms::Exception("TotemDAQMappingESSourceXML")
909  << "Unrecognized tag `" << cms::xerces::toString(a->getNodeName()) << "' or incompatible value `"
910  << cms::xerces::toString(a->getNodeValue()) << "'.";
911  }
912  }
913 
914  if (!fp.checkXMLAttributeFlag(attributeFlag)) {
915  throw cms::Exception("TotemDAQMappingESSourceXML")
916  << "Wrong/incomplete DAQ channel specification (attributeFlag = " << attributeFlag << ").";
917  }
918 
919  return fp;
920 }
921 
922 //----------------------------------------------------------------------------------------------------
923 
925  // common node types
926  if (Test(n, tagArm))
927  return nArm;
928  if (Test(n, tagChip1))
929  return nChip;
930  if (Test(n, tagChip2))
931  return nChip;
932 
933  // RP node types
934  if (Test(n, tagRPStation))
935  return nRPStation;
936  if (Test(n, tagRPPot))
937  return nRPPot;
938  if (Test(n, tagRPPlane))
939  return nRPPlane;
940 
941  //diamond specifics
942  if (Test(n, tagDiamondCh))
943  return nDiamondCh;
944  if (Test(n, tagDiamondPlane))
945  return nDiamondPlane;
946 
947  //totem timing specifics
948  if (Test(n, tagSampicBoard))
949  return nSampicBoard;
950  if (Test(n, tagSampicCh))
951  return nSampicChannel;
952  if (Test(n, tagTotemTimingCh))
953  return nTotemTimingCh;
954  if (Test(n, tagTotemTimingPlane))
955  return nTotemTimingPlane;
956 
957  // TOTEM nT2 specifics
958  if (Test(n, tagTotemT2Plane))
959  return nTotemT2Plane;
960  if (Test(n, tagTotemT2Tile))
961  return nTotemT2Tile;
962 
963  // for backward compatibility
964  if (Test(n, "trigger_vfat"))
965  return nSkip;
966 
967  throw cms::Exception("TotemDAQMappingESSourceXML::GetNodeType")
968  << "Unknown tag `" << cms::xerces::toString(n->getNodeName()) << "'.\n";
969 }
970 
971 //----------------------------------------------------------------------------------------------------
972 
973 void TotemDAQMappingESSourceXML::GetChannels(xercesc::DOMNode *n, set<unsigned char> &channels) {
974  DOMNodeList *children = n->getChildNodes();
975  for (unsigned int i = 0; i < children->getLength(); i++) {
976  DOMNode *n = children->item(i);
977  if (n->getNodeType() != DOMNode::ELEMENT_NODE || !Test(n, "channel"))
978  continue;
979 
980  DOMNamedNodeMap *attr = n->getAttributes();
981  bool idSet = false;
982  for (unsigned int j = 0; j < attr->getLength(); j++) {
983  DOMNode *a = attr->item(j);
984 
985  if (!strcmp(cms::xerces::toString(a->getNodeName()).c_str(), "id")) {
986  unsigned int id = 0;
987  sscanf(cms::xerces::toString(a->getNodeValue()).c_str(), "%u", &id);
988  channels.insert(id);
989  idSet = true;
990  break;
991  }
992  }
993 
994  if (!idSet) {
995  throw cms::Exception("TotemDAQMappingESSourceXML::GetChannels") << "Channel tags must have an `id' attribute.";
996  }
997  }
998 }
999 
1000 //----------------------------------------------------------------------------------------------------
1001 
Detector ID class for TOTEM Si strip detectors.
Definition: TotemRPDetId.h:30
Log< level::Info, true > LogVerbatim
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:163
Contains data on masked channels of a VFAT.
static const std::string tagChannel
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
string GetNodeContent(xercesc::DOMNode *parent)
returns the content of the node
bool contains(EventRange const &lh, EventID const &rh)
Definition: EventRange.cc:37
Loads TotemDAQMapping and TotemAnalysisMask from two XML files.
Detector ID class for Totem T2 detectors. Bits [19:31] : Base CTPPSDetId class attributes Bits [16:18...
Definition: TotemT2DetId.h:25
static const std::string tagDiamondPlane
diamond specific tags
edm::ESProducts< std::unique_ptr< TotemDAQMapping >, std::unique_ptr< TotemAnalysisMask > > produce(const TotemReadoutRcd &)
std::string fullPath() const
Definition: FileInPath.cc:161
ESProducts< std::remove_reference_t< TArgs >... > products(TArgs &&... args)
Definition: ESProducts.h:128
edm::EventRange validityRange
validity interval
void xercesTerminate()
Definition: Xerces.cc:23
static const std::string tagTotemT2Tile
EventSetup record for TOTEM readout-related information.
bool currentBlockValid
flag whether the &#39;currentBlock&#39; index is valid
NodeType
enumeration of XML node types
std::pair< Time_t, Time_t > ValidityInterval
Definition: Time.h:17
TotemSymbID symbolicID
the symbolic id
static const std::string tagSampicCh
NodeType GetNodeType(xercesc::DOMNode *)
determines node type
void xercesInitialize()
Definition: Xerces.cc:18
assert(be >=bs)
std::vector< std::string > mappingFileNames
the mapping files
void ParseTreeTotemT2(ParseType, xercesc::DOMNode *, NodeType, unsigned int parentID, const std::unique_ptr< TotemDAQMapping > &, const std::unique_ptr< TotemAnalysisMask > &)
recursive method to extract nT2-related information from the DOM tree
static const std::string tagChip1
COMMON Chip XML tags.
string subSystemName
label of the CTPPS sub-system
constexpr uint32_t mask
Definition: gpuClustering.h:26
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &) override
sets infinite validity of this data
std::string toString(XMLCh const *toTranscode)
static const std::string tagTotemT2Plane
TOTEM nT2 specific tags.
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
Symbolic ID describing an entity of a TOTEM subdetector.
Definition: TotemSymbId.h:17
static const std::string tagTotemTimingPlane
static const std::string tagDiamondCh
static const std::string tagRPStation
RP XML tags.
TotemFramePosition ChipFramePosition(xercesc::DOMNode *chipnode)
extracts VFAT&#39;s DAQ channel from XML attributes
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
std::vector< std::string > maskFileNames
the mask files
bool fullMask
whether all channels of the VFAT shall be masked
unsigned int symbolicID
chip ID, raw integer representation of DetId class
Definition: TotemSymbId.h:20
const int verbosity
Hw Id mapping for Totem Timing (dynamical mapping in Sampic)
RunNumber_t run() const
Definition: EventID.h:38
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
Definition: SourceFactory.h:92
static const std::string tagArm
Common position tags.
unsigned int hwID
the hardware ID (16 bit)
void ParseXML(ParseType, const string &file, const std::unique_ptr< TotemDAQMapping > &, const std::unique_ptr< TotemAnalysisMask > &)
parses XML file
TotemDAQMappingESSourceXML(const edm::ParameterSet &)
double b
Definition: hdecay.h:118
string GetNodeValue(xercesc::DOMNode *node)
returns the value of the node
const EventID & eventID() const
Definition: IOVSyncValue.h:40
ParseType
whether to parse a mapping of a mask XML
bool Test(xercesc::DOMNode *node, const std::string &name)
returns true iff the node is of the given name
HLT enums.
static const std::string tagAnalysisMask
double a
Definition: hdecay.h:119
std::set< unsigned char > maskedChannels
list of channels to be masked
unsigned int currentBlock
index of the current block in &#39;configuration&#39; array
static const std::string tagSampicBoard
totem timing specific tags
Detector ID class for CTPPS Timing Diamond detectors. Bits [19:31] : Assigend in CTPPSDetId Calss Bit...
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
static const std::string tagRPPlane
std::vector< std::string > mappingFileNames
the mapping files
static const std::string tagTotemTimingCh
void GetChannels(xercesc::DOMNode *n, std::set< unsigned char > &channels)
Contains mappind data related to a VFAT.
def move(src, dest)
Definition: eostools.py:511
EventNumber_t event() const
Definition: EventID.h:40
string CompleteFileName(const string &fn)
adds the path prefix, if needed
Detector ID class for CTPPS Totem Timing detectors. Bits [19:31] : Assigend in CTPPSDetId Calss Bits ...