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