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 
33 
34 #include <xercesc/parsers/XercesDOMParser.hpp>
35 #include <xercesc/dom/DOM.hpp>
36 #include <xercesc/sax/HandlerBase.hpp>
37 #include <xercesc/util/XMLString.hpp>
38 #include <xercesc/util/PlatformUtils.hpp>
39 
40 #include <memory>
41 #include <sstream>
42 
43 //#define DEBUG 1
44 
45 //----------------------------------------------------------------------------------------------------
46 
47 using namespace std;
48 
53 public:
54  static const std::string tagVFAT;
55  static const std::string tagChannel;
57 
59  static const std::string tagArm;
60 
62  static const std::string tagRPStation;
63  static const std::string tagRPPot;
64  static const std::string tagRPPlane;
65 
67  static const std::string tagChip1;
68  static const std::string tagChip2;
69 
72  static const std::string tagDiamondCh;
73 
76  static const std::string tagSampicCh;
79 
81  ~TotemDAQMappingESSourceXML() override;
82 
83  edm::ESProducts<std::unique_ptr<TotemDAQMapping>, std::unique_ptr<TotemAnalysisMask>> produce(const TotemReadoutRcd &);
84 
85 private:
86  unsigned int verbosity;
87 
89  string subSystemName;
90 
91  //subdetector id for sampic
92  unsigned int sampicSubDetId;
93 
95  std::vector<std::string> mappingFileNames;
96 
97  struct ConfigBlock {
100 
102  std::vector<std::string> mappingFileNames;
103 
105  std::vector<std::string> maskFileNames;
106  };
107 
108  vector<ConfigBlock> configuration;
109 
111  unsigned int currentBlock;
112 
115 
117  enum NodeType {
132  nTotemTimingCh
133  };
134 
136  enum ParseType { pMapping, pMask };
137 
139  void ParseXML(ParseType,
140  const string &file,
141  const std::unique_ptr<TotemDAQMapping> &,
142  const std::unique_ptr<TotemAnalysisMask> &);
143 
145  void ParseTreeRP(ParseType,
146  xercesc::DOMNode *,
147  NodeType,
148  unsigned int parentID,
149  const std::unique_ptr<TotemDAQMapping> &,
150  const std::unique_ptr<TotemAnalysisMask> &);
151 
153  void ParseTreeDiamond(ParseType,
154  xercesc::DOMNode *,
155  NodeType,
156  unsigned int parentID,
157  const std::unique_ptr<TotemDAQMapping> &,
158  const std::unique_ptr<TotemAnalysisMask> &);
159 
161  void ParseTreeTotemTiming(ParseType,
162  xercesc::DOMNode *,
163  NodeType,
164  unsigned int parentID,
165  const std::unique_ptr<TotemDAQMapping> &,
166  const std::unique_ptr<TotemAnalysisMask> &);
167 
168 private:
170  string CompleteFileName(const string &fn);
171 
173  bool Test(xercesc::DOMNode *node, const std::string &name) {
174  return !(name.compare(cms::xerces::toString(node->getNodeName())));
175  }
176 
178  NodeType GetNodeType(xercesc::DOMNode *);
179 
181  string GetNodeContent(xercesc::DOMNode *parent) { return string(cms::xerces::toString(parent->getTextContent())); }
182 
184  string GetNodeValue(xercesc::DOMNode *node) { return cms::xerces::toString(node->getNodeValue()); }
185 
187  TotemFramePosition ChipFramePosition(xercesc::DOMNode *chipnode);
188 
189  void GetChannels(xercesc::DOMNode *n, std::set<unsigned char> &channels);
190 
192  return ((type == nArm) || (type == nRPStation) || (type == nRPPot) || (type == nRPPlane) || (type == nChip));
193  }
194 
196  return ((type == nArm) || (type == nRPStation) || (type == nRPPot) || (type == nDiamondPlane) ||
197  (type == nDiamondCh));
198  }
199 
201  return ((type == nArm) || (type == nRPStation) || (type == nRPPot) || (type == nSampicBoard) ||
202  (type == nSampicChannel) || (type == nTotemTimingPlane) || (type == nTotemTimingCh));
203  }
204 
205  bool CommonNode(NodeType type) { return ((type == nChip) || (type == nArm)); }
206 
207 protected:
209  void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &,
210  const edm::IOVSyncValue &,
211  edm::ValidityInterval &) override;
212 };
213 
214 //----------------------------------------------------------------------------------------------------
215 
216 using namespace std;
217 using namespace edm;
218 using namespace xercesc;
219 
220 const string TotemDAQMappingESSourceXML::tagVFAT = "vfat";
221 const string TotemDAQMappingESSourceXML::tagChannel = "channel";
222 const string TotemDAQMappingESSourceXML::tagAnalysisMask = "analysisMask";
223 
224 // common XML position tags
225 const string TotemDAQMappingESSourceXML::tagArm = "arm";
226 
227 // common XML Chip tags
228 const string TotemDAQMappingESSourceXML::tagChip1 = "vfat";
229 const string TotemDAQMappingESSourceXML::tagChip2 = "test_vfat";
230 
231 // specific RP XML tags
232 const string TotemDAQMappingESSourceXML::tagRPStation = "station";
233 const string TotemDAQMappingESSourceXML::tagRPPot = "rp_detector_set";
234 const string TotemDAQMappingESSourceXML::tagRPPlane = "rp_plane";
235 
236 // specific tags for diamond
237 const string TotemDAQMappingESSourceXML::tagDiamondPlane = "rp_plane_diamond";
238 const string TotemDAQMappingESSourceXML::tagDiamondCh = "diamond_channel";
239 
240 // specific tags for totem timing
241 const string TotemDAQMappingESSourceXML::tagSampicBoard = "rp_sampic_board";
242 const string TotemDAQMappingESSourceXML::tagSampicCh = "rp_sampic_channel";
243 const string TotemDAQMappingESSourceXML::tagTotemTimingCh = "timing_channel";
244 const string TotemDAQMappingESSourceXML::tagTotemTimingPlane = "timing_plane";
245 
246 //----------------------------------------------------------------------------------------------------
247 
249  : verbosity(conf.getUntrackedParameter<unsigned int>("verbosity", 0)),
250  subSystemName(conf.getUntrackedParameter<string>("subSystem")),
251  sampicSubDetId(conf.getParameter<unsigned int>("sampicSubDetId")),
252  currentBlock(0),
253  currentBlockValid(false) {
254  for (const auto &it : conf.getParameter<vector<ParameterSet>>("configuration")) {
255  ConfigBlock b;
256  b.validityRange = it.getParameter<EventRange>("validityRange");
257  b.mappingFileNames = it.getParameter<vector<string>>("mappingFileNames");
258  b.maskFileNames = it.getParameter<vector<string>>("maskFileNames");
259  configuration.push_back(b);
260  }
261 
263  findingRecord<TotemReadoutRcd>();
264 }
265 
266 //----------------------------------------------------------------------------------------------------
267 
269  const edm::IOVSyncValue &iosv,
270  edm::ValidityInterval &oValidity) {
271  LogVerbatim("TotemDAQMappingESSourceXML") << ">> TotemDAQMappingESSourceXML::setIntervalFor(" << key.name() << ")";
272 
273  LogVerbatim("TotemDAQMappingESSourceXML")
274  << " run=" << iosv.eventID().run() << ", event=" << iosv.eventID().event();
275 
276  currentBlockValid = false;
277  for (unsigned int idx = 0; idx < configuration.size(); ++idx) {
278  const auto &bl = configuration[idx];
279 
280  edm::EventRange range = bl.validityRange;
281 
282  // If "<run>:min" is specified in python config, it is translated into event <run>:0:1.
283  // However, the truly minimal event id often found in data is <run>:0:0. Therefore the
284  // adjustment below is needed.
285  if (range.startEventID().luminosityBlock() == 0 && range.startEventID().event() == 1)
286  range = edm::EventRange(edm::EventID(range.startEventID().run(), 0, 0), range.endEventID());
287 
288  if (edm::contains(range, iosv.eventID())) {
289  currentBlockValid = true;
290  currentBlock = idx;
291 
292  const IOVSyncValue begin(range.startEventID());
293  const IOVSyncValue end(range.endEventID());
294  oValidity = edm::ValidityInterval(begin, end);
295 
296  LogVerbatim("TotemDAQMappingESSourceXML") << " block found: index=" << currentBlock << ", interval=("
297  << range.startEventID() << " - " << range.endEventID() << ")";
298 
299  return;
300  }
301  }
302 
303  if (!currentBlockValid) {
304  throw cms::Exception("TotemDAQMappingESSourceXML::setIntervalFor")
305  << "No configuration for event " << iosv.eventID();
306  }
307 }
308 
309 //----------------------------------------------------------------------------------------------------
310 
312 
313 //----------------------------------------------------------------------------------------------------
314 
316  FileInPath fip(fn);
317  return fip.fullPath();
318 }
319 
320 //----------------------------------------------------------------------------------------------------
321 
322 edm::ESProducts<std::unique_ptr<TotemDAQMapping>, std::unique_ptr<TotemAnalysisMask>>
325 
326  auto mapping = std::make_unique<TotemDAQMapping>();
327  auto mask = std::make_unique<TotemAnalysisMask>();
328 
329  // initialize Xerces
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
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 
761  vfatInfo.symbolicID.symbolicID = TotemTimingDetId(ArmNum,
762  StationNum,
763  RpNum,
764  0,
766  sampicSubDetId); //Dynamical: it is encoded in the frame
767 
768  mapping->insert(framepos, vfatInfo);
769 
770  continue;
771  }
772 
773  unsigned int childId;
774  if (pType == pMapping && type == nSampicBoard)
775  childId = parentID * 100 + id;
776  else
777  childId = parentID * 10 + id;
778 
779  ParseTreeTotemTiming(pType, n, type, childId, mapping, mask);
780  }
781 }
782 
783 //----------------------------------------------------------------------------------------------------
784 
787  unsigned char attributeFlag = 0;
788 
789  DOMNamedNodeMap *attr = chipnode->getAttributes();
790  for (unsigned int j = 0; j < attr->getLength(); j++) {
791  DOMNode *a = attr->item(j);
792  if (fp.setXMLAttribute(
793  cms::xerces::toString(a->getNodeName()), cms::xerces::toString(a->getNodeValue()), attributeFlag) > 1) {
794  throw cms::Exception("TotemDAQMappingESSourceXML")
795  << "Unrecognized tag `" << cms::xerces::toString(a->getNodeName()) << "' or incompatible value `"
796  << cms::xerces::toString(a->getNodeValue()) << "'.";
797  }
798  }
799 
800  if (!fp.checkXMLAttributeFlag(attributeFlag)) {
801  throw cms::Exception("TotemDAQMappingESSourceXML")
802  << "Wrong/incomplete DAQ channel specification (attributeFlag = " << attributeFlag << ").";
803  }
804 
805  return fp;
806 }
807 
808 //----------------------------------------------------------------------------------------------------
809 
811  // common node types
812  if (Test(n, tagArm))
813  return nArm;
814  if (Test(n, tagChip1))
815  return nChip;
816  if (Test(n, tagChip2))
817  return nChip;
818 
819  // RP node types
820  if (Test(n, tagRPStation))
821  return nRPStation;
822  if (Test(n, tagRPPot))
823  return nRPPot;
824  if (Test(n, tagRPPlane))
825  return nRPPlane;
826 
827  //diamond specifics
828  if (Test(n, tagDiamondCh))
829  return nDiamondCh;
830  if (Test(n, tagDiamondPlane))
831  return nDiamondPlane;
832 
833  //totem timing specifics
834  if (Test(n, tagSampicBoard))
835  return nSampicBoard;
836  if (Test(n, tagSampicCh))
837  return nSampicChannel;
838  if (Test(n, tagTotemTimingCh))
839  return nTotemTimingCh;
840  if (Test(n, tagTotemTimingPlane))
841  return nTotemTimingPlane;
842 
843  // for backward compatibility
844  if (Test(n, "trigger_vfat"))
845  return nSkip;
846 
847  throw cms::Exception("TotemDAQMappingESSourceXML::GetNodeType")
848  << "Unknown tag `" << cms::xerces::toString(n->getNodeName()) << "'.\n";
849 }
850 
851 //----------------------------------------------------------------------------------------------------
852 
853 void TotemDAQMappingESSourceXML::GetChannels(xercesc::DOMNode *n, set<unsigned char> &channels) {
854  DOMNodeList *children = n->getChildNodes();
855  for (unsigned int i = 0; i < children->getLength(); i++) {
856  DOMNode *n = children->item(i);
857  if (n->getNodeType() != DOMNode::ELEMENT_NODE || !Test(n, "channel"))
858  continue;
859 
860  DOMNamedNodeMap *attr = n->getAttributes();
861  bool idSet = false;
862  for (unsigned int j = 0; j < attr->getLength(); j++) {
863  DOMNode *a = attr->item(j);
864 
865  if (!strcmp(cms::xerces::toString(a->getNodeName()).c_str(), "id")) {
866  unsigned int id = 0;
867  sscanf(cms::xerces::toString(a->getNodeValue()).c_str(), "%u", &id);
868  channels.insert(id);
869  idSet = true;
870  break;
871  }
872  }
873 
874  if (!idSet) {
875  throw cms::Exception("TotemDAQMappingESSourceXML::GetChannels") << "Channel tags must have an `id' attribute.";
876  }
877  }
878 }
879 
880 //----------------------------------------------------------------------------------------------------
881 
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.
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
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
static const std::string tagChip1
COMMON Chip XML tags.
string subSystemName
label of the CTPPS sub-system
constexpr uint32_t mask
Definition: gpuClustering.h:24
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &) override
sets infinite validity of this data
std::string toString(XMLCh const *toTranscode)
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
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:91
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 ...