test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 *
9 ****************************************************************************/
10 
21 
26 
27 #include <xercesc/parsers/XercesDOMParser.hpp>
28 #include <xercesc/dom/DOM.hpp>
29 #include <xercesc/sax/HandlerBase.hpp>
30 #include <xercesc/util/XMLString.hpp>
31 #include <xercesc/util/PlatformUtils.hpp>
32 
33 #include <memory>
34 #include <sstream>
35 
36 //#define DEBUG 1
37 
38 //----------------------------------------------------------------------------------------------------
39 
40 using namespace std;
41 
46 {
47 public:
48  static const std::string tagVFAT;
49  static const std::string tagChannel;
51 
53  static const std::string tagArm;
54 
56  static const std::string tagRPStation;
57  static const std::string tagRPPot;
58  static const std::string tagRPPlane;
59 
61  static const std::string tagT2;
62  static const std::string tagT2Half;
63  static const std::string tagT2detector;
64 
66  static const std::string tagT1;
67  static const std::string tagT1Arm;
68  static const std::string tagT1Plane;
69  static const std::string tagT1CSC;
71 
73  static const std::string tagChip1;
74  static const std::string tagChip2;
76 
79 
80  edm::ESProducts< boost::shared_ptr<TotemDAQMapping>, boost::shared_ptr<TotemAnalysisMask> > produce( const TotemReadoutRcd & );
81 
82 private:
83  unsigned int verbosity;
84 
85  struct ConfigBlock
86  {
89 
91  std::vector<std::string> mappingFileNames;
92 
94  std::vector<std::string> maskFileNames;
95  };
96 
97  vector<ConfigBlock> configuration;
98 
100  unsigned int currentBlock;
101 
104 
106  enum NodeType { nUnknown, nTop, nArm, nRPStation, nRPPot, nRPPlane, nChip, nTriggerVFAT,
107  nT2, nT2Half, nT2Det, nT1, nT1Arm, nT1Plane, nT1CSC, nT1ChannelType, nChannel };
108 
110  enum ParseType { pMapping, pMask };
111 
113  void ParseXML(ParseType, const string &file, const boost::shared_ptr<TotemDAQMapping>&, const boost::shared_ptr<TotemAnalysisMask>&);
114 
116  void ParseTreeRP(ParseType, xercesc::DOMNode *, NodeType, unsigned int parentID,
117  const boost::shared_ptr<TotemDAQMapping>&, const boost::shared_ptr<TotemAnalysisMask>&);
118 
120  void ParseTreeT1(ParseType, xercesc::DOMNode *, NodeType, unsigned int parentID,
121  const boost::shared_ptr<TotemDAQMapping>&, const boost::shared_ptr<TotemAnalysisMask>&,
122  unsigned int T1Arm, unsigned int T1Plane, unsigned int T1CSC);
123 
125  void ParseTreeT2(ParseType, xercesc::DOMNode *, NodeType, unsigned int parentID,
126  const boost::shared_ptr<TotemDAQMapping>&, const boost::shared_ptr<TotemAnalysisMask>&);
127 
128 private:
130  string CompleteFileName(const string &fn);
131 
133  bool Test(xercesc::DOMNode *node, const std::string &name)
134  {
135  return !(name.compare(xercesc::XMLString::transcode(node->getNodeName())));
136  }
137 
139  NodeType GetNodeType(xercesc::DOMNode *);
140 
142  string GetNodeContent(xercesc::DOMNode *parent)
143  {
144  return string(xercesc::XMLString::transcode(parent->getTextContent()));
145  }
146 
148  string GetNodeValue(xercesc::DOMNode *node)
149  {
150  return string(xercesc::XMLString::transcode(node->getNodeValue()));
151  }
152 
154  TotemFramePosition ChipFramePosition(xercesc::DOMNode *chipnode);
155 
156  void GetChannels(xercesc::DOMNode *n, std::set<unsigned char> &channels);
157 
159  {
160  return ((type == nArm)||(type == nRPStation)||(type == nRPPot)||(type == nRPPlane)||(type == nChip)||(type == nTriggerVFAT));
161  }
162 
164  {
165  return ((type==nT2)||(type==nT2Det)|| (type==nT2Half));
166  }
167 
169  {
170  return ((type==nT1)||(type==nT1Arm)|| (type==nT1Plane) || (type==nT1CSC) || (type==nT1ChannelType));
171  }
172 
174  {
175  return ((type==nChip)||(type==nArm));
176  }
177 
178 protected:
180  virtual void setIntervalFor(const edm::eventsetup::EventSetupRecordKey&, const edm::IOVSyncValue&, edm::ValidityInterval&);
181 };
182 
183 //----------------------------------------------------------------------------------------------------
184 
185 using namespace std;
186 using namespace edm;
187 using namespace xercesc;
188 
189 const string TotemDAQMappingESSourceXML::tagVFAT="vfat";
190 const string TotemDAQMappingESSourceXML::tagChannel="channel";
191 const string TotemDAQMappingESSourceXML::tagAnalysisMask="analysisMask";
192 
193 // common XML position tags
194 const string TotemDAQMappingESSourceXML::tagArm = "arm";
195 
196 // common XML Chip tags
197 const string TotemDAQMappingESSourceXML::tagChip1 = "vfat";
198 const string TotemDAQMappingESSourceXML::tagChip2 = "test_vfat";
199 const string TotemDAQMappingESSourceXML::tagTriggerVFAT1 = "trigger_vfat";
200 
201 // specific RP XML tags
202 const string TotemDAQMappingESSourceXML::tagRPStation = "station";
203 const string TotemDAQMappingESSourceXML::tagRPPot = "rp_detector_set";
204 const string TotemDAQMappingESSourceXML::tagRPPlane = "rp_plane";
205 
206 // specific T2 XML tags
207 const string TotemDAQMappingESSourceXML::tagT2="t2_detector_set";
208 const string TotemDAQMappingESSourceXML::tagT2detector="t2_detector";
209 const string TotemDAQMappingESSourceXML::tagT2Half="t2_half";
210 
211 // specific T1 XML tags
212 const string TotemDAQMappingESSourceXML::tagT1="t1_detector_set";
213 const string TotemDAQMappingESSourceXML::tagT1Arm="t1_arm";
214 const string TotemDAQMappingESSourceXML::tagT1Plane="t1_plane";
215 const string TotemDAQMappingESSourceXML::tagT1CSC="t1_csc";
216 const string TotemDAQMappingESSourceXML::tagT1ChannelType="t1_channel_type";
217 
218 //----------------------------------------------------------------------------------------------------
219 
221  verbosity(conf.getUntrackedParameter<unsigned int>("verbosity", 0)),
222  currentBlock(0),
223  currentBlockValid(false)
224 {
225  for (const auto it : conf.getParameter<vector<ParameterSet>>("configuration"))
226  {
227  ConfigBlock b;
228  b.validityRange = it.getParameter<EventRange>("validityRange");
229  b.mappingFileNames = it.getParameter< vector<string> >("mappingFileNames");
230  b.maskFileNames = it.getParameter< vector<string> >("maskFileNames");
231  configuration.push_back(b);
232  }
233 
234  setWhatProduced(this);
235  findingRecord<TotemReadoutRcd>();
236 }
237 
238 //----------------------------------------------------------------------------------------------------
239 
241  const edm::IOVSyncValue& iosv, edm::ValidityInterval& oValidity)
242 {
243  LogVerbatim("TotemDAQMappingESSourceXML")
244  << ">> TotemDAQMappingESSourceXML::setIntervalFor(" << key.name() << ")";
245 
246  LogVerbatim("TotemDAQMappingESSourceXML")
247  << " run=" << iosv.eventID().run() << ", event=" << iosv.eventID().event();
248 
249  currentBlockValid = false;
250  for (unsigned int idx = 0; idx < configuration.size(); ++idx)
251  {
252  const auto &bl = configuration[idx];
253 
254  // event id "1:min" has a special meaning and is translated to a truly minimal event id (1:0:0)
255  EventID startEventID = bl.validityRange.startEventID();
256  if (startEventID == EventID(1, 0, 1))
257  startEventID = EventID(1, 0, 0);
258 
259  if (startEventID <= iosv.eventID() && iosv.eventID() <= bl.validityRange.endEventID())
260  {
261  currentBlockValid = true;
262  currentBlock = idx;
263 
264  const IOVSyncValue begin(startEventID);
265  const IOVSyncValue end(bl.validityRange.endEventID());
266  oValidity = ValidityInterval(begin, end);
267 
268  LogVerbatim("TotemDAQMappingESSourceXML")
269  << " block found: index=" << currentBlock
270  << ", interval=(" << startEventID << " - " << bl.validityRange.endEventID() << ")";
271 
272  return;
273  }
274  }
275 
276  if (!currentBlockValid)
277  {
278  throw cms::Exception("TotemDAQMappingESSourceXML::setIntervalFor") <<
279  "No configuration for event " << iosv.eventID();
280  }
281 }
282 
283 //----------------------------------------------------------------------------------------------------
284 
286 {
287 }
288 
289 //----------------------------------------------------------------------------------------------------
290 
292 {
293  FileInPath fip(fn);
294  return fip.fullPath();
295 }
296 
297 //----------------------------------------------------------------------------------------------------
298 
299 edm::ESProducts< boost::shared_ptr<TotemDAQMapping>, boost::shared_ptr<TotemAnalysisMask> >
301 {
303 
304  boost::shared_ptr<TotemDAQMapping> mapping(new TotemDAQMapping());
305  boost::shared_ptr<TotemAnalysisMask> mask(new TotemAnalysisMask());
306 
307  // initialize Xerces
308  try
309  {
310  XMLPlatformUtils::Initialize();
311  }
312  catch (const XMLException& toCatch)
313  {
314  char* message = XMLString::transcode(toCatch.getMessage());
315  throw cms::Exception("TotemDAQMappingESSourceXML") << "An XMLException caught with message: " << message << ".\n";
316  XMLString::release(&message);
317  }
318 
319  // load mapping files
320  for (const auto &fn : configuration[currentBlock].mappingFileNames)
321  ParseXML(pMapping, CompleteFileName(fn), mapping, mask);
322 
323  // load mask files
324  for (const auto &fn : configuration[currentBlock].maskFileNames)
325  ParseXML(pMask, CompleteFileName(fn), mapping, mask);
326 
327  // release Xerces
328  XMLPlatformUtils::Terminate();
329 
330  // commit the products
331  return edm::es::products(mapping, mask);
332 }
333 
334 //----------------------------------------------------------------------------------------------------
335 
337  const boost::shared_ptr<TotemDAQMapping> &mapping, const boost::shared_ptr<TotemAnalysisMask> &mask)
338 {
339  unique_ptr<XercesDOMParser> parser(new XercesDOMParser());
340  parser->parse(file.c_str());
341 
342  DOMDocument* domDoc = parser->getDocument();
343 
344  if (!domDoc)
345  throw cms::Exception("TotemDAQMappingESSourceXML::ParseXML") << "Cannot parse file `" << file
346  << "' (domDoc = NULL)." << endl;
347 
348  DOMElement* elementRoot = domDoc->getDocumentElement();
349 
350  if (!elementRoot)
351  throw cms::Exception("TotemDAQMappingESSourceXML::ParseXML") << "File `" <<
352  file << "' is empty." << endl;
353 
354  ParseTreeRP(pType, elementRoot, nTop, 0, mapping, mask);
355  ParseTreeT2(pType, elementRoot, nTop, 0, mapping, mask);
356  ParseTreeT1(pType, elementRoot, nTop, 0, mapping, mask, 0,0,0);
357 }
358 
359 //-----------------------------------------------------------------------------------------------------------
360 
361 void TotemDAQMappingESSourceXML::ParseTreeRP(ParseType pType, xercesc::DOMNode * parent, NodeType parentType,
362  unsigned int parentID, const boost::shared_ptr<TotemDAQMapping>& mapping,
363  const boost::shared_ptr<TotemAnalysisMask>& mask)
364 {
365 #ifdef DEBUG
366  printf(">> TotemDAQMappingESSourceXML::ParseTreeRP(%s, %u, %u)\n", XMLString::transcode(parent->getNodeName()),
367  parentType, parentID);
368 #endif
369 
370  DOMNodeList *children = parent->getChildNodes();
371 
372  for (unsigned int i = 0; i < children->getLength(); i++)
373  {
374  DOMNode *n = children->item(i);
375  if (n->getNodeType() != DOMNode::ELEMENT_NODE)
376  continue;
377 
379 
380 #ifdef DEBUG
381  printf("\tname = %s, type = %u\n", XMLString::transcode(n->getNodeName()), type);
382 #endif
383 
384  // structure control
385  if (!RPNode(type))
386  continue;
387 
388  if ((type != parentType + 1)&&(parentType != nRPPot || type != nTriggerVFAT))
389  {
390  if (parentType == nTop && type == nRPPot)
391  {
392  LogPrint("TotemDAQMappingESSourceXML") << ">> TotemDAQMappingESSourceXML::ParseTreeRP > Warning: tag `" << tagRPPot
393  << "' found in global scope, assuming station ID = 12.";
394  parentID = 12;
395  } else {
396  throw cms::Exception("TotemDAQMappingESSourceXML") << "Node " << XMLString::transcode(n->getNodeName())
397  << " not allowed within " << XMLString::transcode(parent->getNodeName()) << " block.\n";
398  }
399  }
400 
401  // parse tag attributes
402  unsigned int id = 0, hw_id = 0;
403  bool id_set = false, hw_id_set = false;
404  bool fullMask = false;
405  DOMNamedNodeMap* attr = n->getAttributes();
406 
407  for (unsigned int j = 0; j < attr->getLength(); j++)
408  {
409  DOMNode *a = attr->item(j);
410 
411  if (!strcmp(XMLString::transcode(a->getNodeName()), "id"))
412  {
413  sscanf(XMLString::transcode(a->getNodeValue()), "%u", &id);
414  id_set = true;
415  }
416 
417  if (!strcmp(XMLString::transcode(a->getNodeName()), "hw_id"))
418  {
419  sscanf(XMLString::transcode(a->getNodeValue()), "%x", &hw_id);
420  hw_id_set = true;
421  }
422 
423  if (!strcmp(XMLString::transcode(a->getNodeName()), "full_mask"))
424  fullMask = (strcmp(XMLString::transcode(a->getNodeValue()), "no") != 0);
425  }
426 
427  // content control
428  if (!id_set && type != nTriggerVFAT)
429  throw cms::Exception("TotemDAQMappingESSourceXML::ParseTreeRP") << "id not given for element `"
430  << XMLString::transcode(n->getNodeName()) << "'" << endl;
431 
432  if (!hw_id_set && type == nChip && pType == pMapping)
433  throw cms::Exception("TotemDAQMappingESSourceXML::ParseTreeRP") << "hw_id not given for element `"
434  << XMLString::transcode(n->getNodeName()) << "'" << endl;
435 
436  if (type == nRPPlane && id > 9)
437  throw cms::Exception("TotemDAQMappingESSourceXML::ParseTreeRP") <<
438  "Plane IDs range from 0 to 9. id = " << id << " is invalid." << endl;
439 
440 #ifdef DEBUG
441  printf("\tID found: 0x%x\n", id);
442 #endif
443 
444  // store mapping data
445  if (pType == pMapping && (type == nChip || type == nTriggerVFAT))
446  {
447  const TotemFramePosition &framepos = ChipFramePosition(n);
448  TotemVFATInfo vfatInfo;
449  vfatInfo.hwID = hw_id;
451 
452  if (type == nChip)
453  {
454  vfatInfo.symbolicID.symbolicID = parentID * 10 + id;
455  vfatInfo.type = TotemVFATInfo::data;
456  }
457 
458  if (type == nTriggerVFAT)
459  {
460  vfatInfo.symbolicID.symbolicID = parentID;
461  vfatInfo.type = TotemVFATInfo::CC;
462  }
463 
464  mapping->insert(framepos, vfatInfo);
465 
466  continue;
467  }
468 
469  // store mask data
470  if (pType == pMask && type == nChip)
471  {
472  TotemSymbID symbId;
473  symbId.subSystem = TotemSymbID::RP;
474  symbId.symbolicID = parentID * 10 + id;
475 
477  am.fullMask = fullMask;
479 
480  mask->insert(symbId, am);
481 
482  continue;
483  }
484 
485  // recursion (deeper in the tree)
486  ParseTreeRP(pType, n, type, parentID * 10 + id, mapping, mask);
487  }
488 }
489 
490 //----------------------------------------------------------------------------------------------------
491 
492 void TotemDAQMappingESSourceXML::ParseTreeT2(ParseType pType, xercesc::DOMNode * parent, NodeType parentType,
493  unsigned int parentID, const boost::shared_ptr<TotemDAQMapping>& data,
494  const boost::shared_ptr<TotemAnalysisMask>& mask)
495 {
496  DOMNodeList *children = parent->getChildNodes();
497 
498 #ifdef DEBUG
499  printf(">> ParseTreeT2(parent,parentType,parentID)=(%p, %i, %u)\n", parent, parentType, parentID);
500  printf("\tchildren: Numero children: %li\n", children->getLength());
501 #endif
502 
503  for (unsigned int i = 0; i < children->getLength(); i++)
504  {
505  DOMNode *n = children->item(i);
506 
507  if (n->getNodeType() != DOMNode::ELEMENT_NODE)
508  continue;
509 
510  // get node type for RP or T2
512 
513 #ifdef DEBUG
514  printf("\t\tchildren #%i: is a %s, (of type %i) \n", i, XMLString::transcode(n->getNodeName()), type);
515 #endif
516 
517  if ((type == nUnknown)) {
518 #ifdef DEBUG
519  printf("Found Unknown tag during T2 reading.. EXIT ");
520 #endif
521  continue;
522  }
523 
524  if ((T2Node(type)==false)&&(CommonNode(type)==false)) {
525 #ifdef DEBUG
526  printf("Found Non-T2 tag during T2 reading.. EXIT ");
527  printf("\t The tag is: %s \n", XMLString::transcode(n->getNodeName()));
528 #endif
529  continue;
530  }
531 
532  // get ID_t2 and position
533 
534  // id for T2 plane goes from 0..9; for chip is the 16 bit ID
535  // position_t2 was the S-link for chip and for the plane should be a number compatible with arm,ht,pl,pls or HS position
536  int ID_t2 = 0;
537 
538  unsigned int position_t2 = 0;
539 
540  unsigned int arm=0,ht=0,pl=0,pls=0;
541 
542  bool idSet_t2 = false;
543  //position_t2Set = false;
544  int attribcounter_t2planedescript=0;
545  unsigned int toaddForParentID=0;
546 
547  unsigned hw_id = 0;
548  bool hw_id_set = false;
549 
550  DOMNamedNodeMap* attr = n->getAttributes();
551 
552  // Begin loop for save T2 element attriute
553  for (unsigned int j = 0; j < attr->getLength(); j++) {
554  DOMNode *a = attr->item(j);
555  if (!strcmp(XMLString::transcode(a->getNodeName()), "id")) {
556  sscanf(XMLString::transcode(a->getNodeValue()), "%i", &ID_t2);
557  idSet_t2 = true;
558  }
559 
560  if (!strcmp(XMLString::transcode(a->getNodeName()), "hw_id")) {
561  sscanf(XMLString::transcode(a->getNodeValue()), "%x", &hw_id);
562  hw_id_set = true;
563  }
564 
565  if (!strcmp(XMLString::transcode(a->getNodeName()), "position")) {
566  position_t2 = atoi(XMLString::transcode(a->getNodeValue()));
567  if (pType == pMask)
568  toaddForParentID = position_t2;
569 // position_t2Set = true;
570  }
571 
572  if (type == nArm) {
573  // arm is the top node and should be reset to 0.
574  if (!strcmp(XMLString::transcode(a->getNodeName()), "id")) {
575  parentID=0;
576  unsigned int id_arm = atoi(XMLString::transcode(a->getNodeValue()));
577  toaddForParentID=20*id_arm;
578  }
579  }
580 
581  if (type == nT2Half) {
582  if (!strcmp(XMLString::transcode(a->getNodeName()), "id")) {
583  unsigned int id_half = atoi(XMLString::transcode(a->getNodeValue()));
584  toaddForParentID=10*id_half;
585  }
586  }
587 
588  // This is needed in principle only for the old formats
589  if(type == nT2Det) {
590  if (!strcmp(XMLString::transcode(a->getNodeName()), "arm")) {
591  sscanf(XMLString::transcode(a->getNodeValue()), "%u", &arm);
592  attribcounter_t2planedescript++;
593  }
594 
595  if (!strcmp(XMLString::transcode(a->getNodeName()), "ht")) {
596  sscanf(XMLString::transcode(a->getNodeValue()), "%u", &ht);
597  attribcounter_t2planedescript++;
598  }
599 
600  if (!strcmp(XMLString::transcode(a->getNodeName()), "pl")) {
601  sscanf(XMLString::transcode(a->getNodeValue()), "%u", &pl);
602  attribcounter_t2planedescript++;
603  }
604 
605  if (!strcmp(XMLString::transcode(a->getNodeName()), "pls")) {
606  sscanf(XMLString::transcode(a->getNodeValue()), "%u", &pls);
607  attribcounter_t2planedescript++;
608  }
609 
610  // remember id in monitor goes from 0 -- 39
611  if (!strcmp(XMLString::transcode(a->getNodeName()), "id")) {
612  // Id saved another time ... just to increment attribcounter
613  sscanf(XMLString::transcode(a->getNodeValue()), "%i", &ID_t2);
614  attribcounter_t2planedescript++;
615  }
616 
617  if (!strcmp(XMLString::transcode(a->getNodeName()), "position")) {
618  sscanf(XMLString::transcode(a->getNodeValue()), "%u", &position_t2);
619  attribcounter_t2planedescript++;
620  // Just another indication for further checking. This attribute was not compulsory in monitor.
621  attribcounter_t2planedescript=attribcounter_t2planedescript+20;
622  // 20 is just a "big number"
623  }
624  }
625  }
626 
627  // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
628  // When a plane tag is found, calculate Parent-Id and allows different xml formats:
629  // Provide compatibility with old monitor formats.
630 
631  // Note:
632  // plane position and id foreseen in final ip5 mapping.
633  // plane position NOT foreseen in Monitor.
634 
635  if (pType == pMapping) {
636  if (type == nT2Det) {
637  // Calculate the parent-id from attributes or xml STRUCTURE
638 // position_t2Set = true;
639  if (attribcounter_t2planedescript>=(21)) {
640  // there is already in xml plane the "position" attribute + other attributes. It is assumed to utilize the parent info
641 
642 #ifdef DEBUG
643  printf("TotemDAQMappingESSourceXML: attribcounter_t2planedescript: %i \n",attribcounter_t2planedescript);
644 #endif
645 
646  if (attribcounter_t2planedescript>=25) {
647  edm::LogVerbatim("TotemDAQMappingESSourceXML") << "T2-Plane attribute utilezed for parentID: position+info from parent ";
648  //Plane Seems fully specified
649  //all T2 plane attribute read correctly. Check if it is consitent
650  unsigned int test_position_t2=arm*20+ht*10+pl*2+pls;
651  unsigned int testHS=pl*2+pls;
652  if(testHS!=position_t2) {
653  edm::LogPrint("TotemDAQMappingESSourceXML") <<"T2 Xml inconsistence in pl-pls attributes and position. Only 'position attribute' taken ";
654  }
655 
656  // For plane, ID_t2 should go from 0..39 position_t2 from 0..9
657  ID_t2=parentID+position_t2;
658  cout << "attribcounter_t2planedescript>=(25), ID_t2: " << ID_t2 << endl;
659  toaddForParentID=position_t2;
660  if (ID_t2!=(int)test_position_t2)
661  edm::LogPrint("TotemDAQMappingESSourceXML") <<"T2 Xml inconsistence in plane attributes and xml parents structure. Plane attributes ignored";
662 
663  } else {
664  // Case where arm-ht-pl-pls are NOT specified
665  edm::LogVerbatim("TotemDAQMappingESSourceXML")<<"T2 Plane have parentID: "<<parentID<<" for its VFATs. Plane Position read: "<<position_t2;
666 
667  if (attribcounter_t2planedescript==21) {
668  // You have put in XML only position and not Plane id (the last is obligatory)
669  ID_t2=parentID+position_t2;
670  // cout << "attribcounter_t2planedescript>=(21), ID_t2: " << ID_t2 << endl;
671  toaddForParentID=position_t2;
672  idSet_t2=true;
673  }
674  }
675  } else {
676  // Construct plane position from other attributes cause "position" is not inserted;
677  // Ex- monitor: <t2_detector id="0" z="13871.3" arm="0" ht="0" pl="0" pls="0" >
678 
679  if (attribcounter_t2planedescript>=1) {
680  // Remember, Z attribute is not counted
681 
682  if(attribcounter_t2planedescript>=5) {
683  int test_position_t2=arm*20+ht*10+pl*2+pls;
684 
685  // case for xml from monitor
686  ID_t2=test_position_t2;
687  cout << "ID_t2=test_position_t2: " << ID_t2 << endl;
688  toaddForParentID=test_position_t2;
689 
690  if ((int)parentID!=ID_t2) {
691  edm::LogPrint("TotemDAQMappingESSourceXML") <<"T2 Inconsistence between plane 'id' and position from attributes. Id ignored";
692  edm::LogPrint("TotemDAQMappingESSourceXML") <<" T2-Parent = "<<parentID;
693  }
694  } else {
695  toaddForParentID=ID_t2;
696  edm::LogVerbatim("TotemDAQMappingESSourceXML")<<" Number of T2 plane attributes: "<< attribcounter_t2planedescript<<" T2-Plane attribute utilezed for parentID: plane 'id' only";
697  }
698  } else {
699 // position_t2Set = false;
700  edm::LogProblem ("TotemDAQMappingESSourceXML") << "T2 plane not enough specified from its attribute!";
701  }
702  }
703  }
704 
705  // content control
706  if (idSet_t2 == false) {
707  throw cms::Exception("TotemDAQMappingESSourceXML::ParseTree") << "ID_t2 not given for element `" << XMLString::transcode(n->getNodeName()) << "'" << endl;
708  edm::LogProblem ("TotemDAQMappingESSourceXML") <<"ID_t2 not given for element `"<<XMLString::transcode(n->getNodeName()) << "'";
709  }
710 
711  if (type == nChip && !hw_id_set)
712  throw cms::Exception("TotemDAQMappingESSourceXML::ParseTree") << "hw_id not given for VFAT id `" <<
713  ID_t2 << "'" << endl;
714 
715  if (type == nT2Det && position_t2 > 39) {
716  throw cms::Exception("TotemDAQMappingESSourceXML::ParseTree") << "Plane position_t2 range from 0 to 39. position_t2 = " << position_t2 << " is invalid." << endl;
717  edm::LogProblem ("TotemDAQMappingESSourceXML") <<"Plane position_t2 range from 0 to 39. position_t2 = "<<position_t2<< " is invalid.";
718  }
719  }
720 
721 
722  if (type == nChip) {
723  // save mapping data
724  if (pType == pMapping) {
725 #ifdef DEBUG
726  printf("T2 Vfat in plane (parentID): %i || GeomPosition %i \n", parentID, ID_t2);
727  printf("\t\t\tID_t2 = 0x%x\n", hw_id);
728  printf("\t\t\tpos = %i\n", position_t2);
729 #endif
730  unsigned int symId=0;
731  // Check if it is a special chip
732  if (!tagT2detector.compare(XMLString::transcode((n->getParentNode()->getNodeName()))))
733  symId = parentID * 100 + ID_t2; // same conv = symbplaneNumber*100 +iid used in DQM
734  else {
735  // It is a special VFAT and the special number is set directly in the XML file
736  symId = ID_t2; //17,18,19,20
737 #ifdef DEBUG
738  printf("TotemDAQMappingESSourceXML Found T2 special Vfat ChId-SLink-Symb 0x%x - %i - %i \n",
739  ID_t2,position_t2,symId );
740 #endif
741  }
742 
744  TotemVFATInfo vfatInfo;
745  vfatInfo.symbolicID.symbolicID = symId;
746  vfatInfo.hwID = hw_id;
748  vfatInfo.type = TotemVFATInfo::data;
749  data->insert(framepos, vfatInfo);
750  }
751 
752  // save mask data
753  if (pType == pMask) {
754  TotemVFATAnalysisMask vfatMask;
755  TotemSymbID symbId;
756  symbId.subSystem = TotemSymbID::T2;
757  symbId.symbolicID = 100*parentID+ID_t2;
758 
759  DOMNode *fullMaskNode = attr->getNamedItem(XMLString::transcode("full_mask"));
760  if (fullMaskNode && !GetNodeValue(fullMaskNode).compare("yes"))
761  vfatMask.fullMask = true;
762  else
763  GetChannels(n, vfatMask.maskedChannels);
764 
765  mask->insert(symbId, vfatMask);
766  //cout << "saved mask, ID = " << symbId.symbolicID << ", full mask: " << vfatMask.fullMask << endl;
767  }
768  } else {
769  // Look for the children of n (recursion)
770  // 3° argument=parentId is needed for calculate VFAT-id startintg from the parent plane
771  ParseTreeT2(pType, n, type, parentID+toaddForParentID, data, mask);
772  }
773  } // Go to the next children
774 }
775 
776 //----------------------------------------------------------------------------------------------------
777 
778 void TotemDAQMappingESSourceXML::ParseTreeT1(ParseType pType, xercesc::DOMNode * parent, NodeType parentType,
779  unsigned int parentID, const boost::shared_ptr<TotemDAQMapping>& mapping,
780  const boost::shared_ptr<TotemAnalysisMask>& mask, unsigned int T1Arm, unsigned int T1Plane, unsigned int T1CSC)
781 {
782  const int ArmMask = 0x0200;
783  const int PlaneMask = 0x01c0;
784  const int CSCMask = 0x0038;
785  const int GenderMask = 0x0004;
786  const int VFnMask = 0x0003;
787 
788  int ArmMask_ = 0;
789  int PlaneMask_ = 0;
790  int CSCMask_ = 0;
791  int GenderMask_ = 0;
792  int VFnMask_ = 0;
793 
794  unsigned int T1ChannelType = 0;
795 
796  DOMNodeList *children = parent->getChildNodes();
797 
798 #ifdef DEBUG
799  printf(">> ParseTreeT1(parent,parentType,parentID)=(%p, %i, %u)\n", parent, parentType, parentID);
800  printf("\tchildren: Numero children: %li\n", children->getLength());
801 #endif
802 
803  for (unsigned int i = 0; i < children->getLength(); i++) {
804  DOMNode *n = children->item(i);
805 
806  if (n->getNodeType() != DOMNode::ELEMENT_NODE)
807  continue;
808 
809  // get node type for RP or T2 or T1
811 
812 #ifdef DEBUG
813  printf("\t\tchildren #%i: is a %s, (of type %i) \n", i, XMLString::transcode(n->getNodeName()), type);
814 #endif
815 
816  if ((type == nUnknown)) {
817 #ifdef DEBUG
818  printf("Found Unknown tag during T1 reading.. EXIT ");
819 #endif
820  continue;
821  }
822 
823  if ((T1Node(type)==false)&&(CommonNode(type)==false)) {
824 #ifdef DEBUG
825  printf("Found Non-T1 tag during T1 reading.. EXIT ");
826  printf("\t The tag is: %s \n", XMLString::transcode(n->getNodeName()));
827 #endif
828  continue;
829  }
830 
831  // id for T2 plane goes from 0..9; for chip is the 16 bit ID
832  // for VFATs: (0 or 1 for anodes A0 and A1; 0, 1 or 2 for Cathodes C0,C1,C2)
833  unsigned int ID_t1 = 0;
834 #ifdef DEBUG
835  unsigned int VFPOS = 0;
836 #endif
837  unsigned int Gender =0;
838 
839  // hardware of an id
840  unsigned int hw_id = 0;
841  bool hw_id_set = false;
842 
843  bool idSet_t1 = false;//bool position_t2Set = false;
844 
845  DOMNamedNodeMap* attr = n->getAttributes();
846 
847  bool fullMask = false;
848 
849  // Begin loop for save T1 element attriute ------------------------------------------------------------------
850  for (unsigned int j = 0; j < attr->getLength(); j++) {
851 
852  DOMNode *a = attr->item(j);
853  if (!strcmp(XMLString::transcode(a->getNodeName()), "id")) {
854  sscanf(XMLString::transcode(a->getNodeValue()), "%u", &ID_t1);
855  idSet_t1 = true;
856  }
857 
858  if (type == nT1Arm) {
859  if (!strcmp(XMLString::transcode(a->getNodeName()), "id")) {
860  // arm is the top node and parent ID should be reset to 0.
861  parentID=0;
862  unsigned int id_arm = atoi(XMLString::transcode(a->getNodeValue()));
863  T1Arm = id_arm;
864  if (id_arm != 0 && id_arm != 1) {
865  throw cms::Exception("TotemDAQMappingESSourceXML::ParseTree") << "T1 id_arm neither 0 nor 1. Problem parsing XML file." << XMLString::transcode(n->getNodeName()) << endl;
866  edm::LogProblem ("TotemDAQMappingESSourceXML") <<"T1 id_arm neither 0 nor 1. Problem parsing XML file."<<XMLString::transcode(n->getNodeName()) ;
867  }
868 
869  id_arm = id_arm << 9;
870  ArmMask_ = ~ArmMask;
871  parentID &= ArmMask_;
872  parentID |= id_arm;
873  }
874  }
875 
876  if (type == nT1Plane) {
877  if (!strcmp(XMLString::transcode(a->getNodeName()), "id")) {
878  unsigned int id_plane = atoi(XMLString::transcode(a->getNodeValue()));
879  T1Plane = id_plane;
880  id_plane = id_plane << 6;
881  PlaneMask_ = ~PlaneMask;
882  parentID &= PlaneMask_;
883  parentID |= id_plane;
884  }
885  }
886 
887  if (type == nT1CSC) {
888  if (!strcmp(XMLString::transcode(a->getNodeName()), "id")) {
889  unsigned int id_csc = atoi(XMLString::transcode(a->getNodeValue()));
890  T1CSC = id_csc;
891  id_csc = id_csc << 3;
892  CSCMask_ = ~CSCMask;
893  parentID &= CSCMask_;
894  parentID |= id_csc;
895  }
896  }
897 
898  if (type == nT1ChannelType) {
899  if (!strcmp(XMLString::transcode(a->getNodeName()), "id")) {
900  T1ChannelType = atoi(XMLString::transcode(a->getNodeValue()));
901  }
902  if (!strcmp(XMLString::transcode(a->getNodeName()), "full_mask")) {
903  fullMask = (strcmp(XMLString::transcode(a->getNodeValue()), "no") != 0);
904  }
905  }
906 
907  if(type == nChip) {
908 #ifdef DEBUG
909  if (!strcmp(XMLString::transcode(a->getNodeName()), "position")){
910  VFPOS = atoi(XMLString::transcode(a->getNodeValue()));
911  }
912 #endif
913  if (!strcmp(XMLString::transcode(a->getNodeName()), "polarity")) {
914  if (!strcmp(XMLString::transcode(a->getNodeValue()),"a")) {
915  Gender = 0;
916  } else
917  if (!strcmp(XMLString::transcode(a->getNodeValue()),"c")) {
918  Gender = 1;
919  } else {
920  throw cms::Exception("TotemDAQMappingESSourceXML::ParseTree") << "T1: Neither anode nor cathode vfat : " << XMLString::transcode(n->getNodeName()) << endl;
921  edm::LogProblem ("TotemDAQMappingESSourceXML") <<"T1: Neither anode nor cathode vfat : "<<XMLString::transcode(n->getNodeName());
922  }
923  }
924 
925  if (!strcmp(XMLString::transcode(a->getNodeName()), "hw_id")) {
926  sscanf(XMLString::transcode(a->getNodeValue()), "%x", &hw_id);
927  hw_id_set = true; }
928  }
929  }
930 
931  // content control
932  // Note: each element has an id!! However if the element is a plane, it could be enough to use position 0..9
933 
934  if (idSet_t1==false){
935  throw cms::Exception("TotemDAQMappingESSourceXML::ParseTree") << "ID_t1 not given for element `" << XMLString::transcode(n->getNodeName()) << "'" << endl;
936  edm::LogProblem ("TotemDAQMappingESSourceXML") <<"ID_t1 not given for element `"<<XMLString::transcode(n->getNodeName()) << "'";
937  }
938 
939  if (type == nChip && !hw_id_set)
940  throw cms::Exception("TotemDAQMappingESSourceXML::ParseTreeT1") <<
941  "hw_id not set for T1 VFAT id " << ID_t1 << "." << endl;
942 
943 
944 
945  // save mask data
946  if (type == nT1ChannelType && pType == pMask) {
947  TotemSymbID symbId;
948  symbId.subSystem = TotemSymbID::T1;
949  symbId.symbolicID = T1ChannelType + 10 * T1CSC + 100 * T1Plane + 1000 * T1Arm;
950  //cout << "mask: " << T1Arm << " " << T1Plane << " " << T1CSC << " " <<T1ChannelType << endl;
952  am.fullMask = fullMask;
954  mask->insert(symbId, am);
955  //cout << "saved mask, ID = " << symbId.symbolicID << ", full mask: " << am.fullMask << endl;
956  }
957 
958  // save data
959  if (type == nChip) {
960 #ifdef DEBUG
961  printf("T1 Vfat in detector (parentID): %x || Position %i \n", parentID, VFPOS);
962  printf("\t\t\tID_t1 = 0x%x\n", ID_t1);
963 #endif
964 
965  unsigned int symId=0;
966 
967  // Check if it is a special chip
968  if (!tagT1CSC.compare(XMLString::transcode((n->getParentNode()->getNodeName())))) {
969  symId = parentID;
970  Gender = Gender << 2;
971  GenderMask_ = ~GenderMask;
972 
973  symId &= GenderMask_;
974  symId |= Gender;
975 
976  VFnMask_ = ~VFnMask;
977  symId &= VFnMask_;
978  symId |= ID_t1;
979  } else {
980  // It is a special VFAT ...
981  throw cms::Exception("TotemDAQMappingESSourceXML::ParseTree") << "T1 has no special vfat `" << XMLString::transcode(n->getNodeName()) << "'" << endl;
982  edm::LogProblem ("TotemDAQMappingESSourceXML") <<"T1 has no special vfat `"<<XMLString::transcode(n->getNodeName()) << "'";
983  }
984 
985  // Assign a contanaier for the register of that VFAT with ChipId (Hex)
987  TotemVFATInfo vfatInfo;
988  vfatInfo.symbolicID.symbolicID = symId;
989  vfatInfo.hwID = hw_id;
991  vfatInfo.type = TotemVFATInfo::data;
992  mapping->insert(framepos, vfatInfo);
993  } else {
994  // Look for the children of n (recursion)
995  // 3° argument=parentId is needed for calculate VFAT-id startintg from the parent plane
996  ParseTreeT1(pType, n, type, parentID, mapping, mask, T1Arm, T1Plane, T1CSC);
997  }
998  } // Go to the next children
999 }
1000 
1001 //----------------------------------------------------------------------------------------------------
1002 //----------------------------------------------------------------------------------------------------
1003 
1005 {
1007  unsigned char attributeFlag = 0;
1008 
1009  DOMNamedNodeMap* attr = chipnode->getAttributes();
1010  for (unsigned int j = 0; j < attr->getLength(); j++)
1011  {
1012  DOMNode *a = attr->item(j);
1013  if (fp.setXMLAttribute(XMLString::transcode(a->getNodeName()), XMLString::transcode(a->getNodeValue()), attributeFlag) > 1)
1014  {
1015  throw cms::Exception("TotemDAQMappingESSourceXML") <<
1016  "Unrecognized tag `" << XMLString::transcode(a->getNodeName()) <<
1017  "' or incompatible value `" << XMLString::transcode(a->getNodeValue()) <<
1018  "'." << endl;
1019  }
1020  }
1021 
1022  if (!fp.checkXMLAttributeFlag(attributeFlag))
1023  {
1024  throw cms::Exception("TotemDAQMappingESSourceXML") <<
1025  "Wrong/incomplete DAQ channel specification (attributeFlag = " << attributeFlag << ")." << endl;
1026  }
1027 
1028  return fp;
1029 }
1030 
1031 //----------------------------------------------------------------------------------------------------
1032 
1034 {
1035  // common node types
1036  if (Test(n, tagArm)) return nArm;
1037  if (Test(n, tagChip1)) return nChip;
1038  if (Test(n, tagChip2)) return nChip;
1039  if (Test(n, tagTriggerVFAT1)) return nTriggerVFAT;
1040 
1041  // RP node types
1042  if (Test(n, tagRPStation)) return nRPStation;
1043  if (Test(n, tagRPPot)) return nRPPot;
1044  if (Test(n, tagRPPlane)) return nRPPlane;
1045 
1046  // T2 node types
1047  if (Test(n, tagT2)) return nT2;
1048  if (Test(n, tagT2detector)) return nT2Det;
1049  if (Test(n, tagT2Half)) return nT2Half;
1050 
1051  // T1 node types
1052  if (Test(n, tagT1)) return nT1;
1053  if (Test(n, tagT1Arm)) return nT1Arm;
1054  if (Test(n, tagT1Plane)) return nT1Plane;
1055  if (Test(n, tagT1CSC)) return nT1CSC;
1056  if (Test(n, tagT1ChannelType)) return nT1ChannelType;
1057  if (Test(n, tagChannel)) return nChannel;
1058 
1059 
1060  throw cms::Exception("TotemDAQMappingESSourceXML::GetNodeType") << "Unknown tag `"
1061  << XMLString::transcode(n->getNodeName()) << "'.\n";
1062 }
1063 
1064 //----------------------------------------------------------------------------------------------------
1065 
1066 void TotemDAQMappingESSourceXML::GetChannels(xercesc::DOMNode *n, set<unsigned char> &channels)
1067 {
1068  DOMNodeList *children = n->getChildNodes();
1069  for (unsigned int i = 0; i < children->getLength(); i++)
1070  {
1071  DOMNode *n = children->item(i);
1072  if (n->getNodeType() != DOMNode::ELEMENT_NODE || !Test(n, "channel"))
1073  continue;
1074 
1075  DOMNamedNodeMap* attr = n->getAttributes();
1076  bool idSet = false;
1077  for (unsigned int j = 0; j < attr->getLength(); j++)
1078  {
1079  DOMNode *a = attr->item(j);
1080 
1081  if (!strcmp(XMLString::transcode(a->getNodeName()), "id"))
1082  {
1083  unsigned int id = 0;
1084  sscanf(XMLString::transcode(a->getNodeValue()), "%u", &id);
1085  channels.insert(id);
1086  idSet = true;
1087  break;
1088  }
1089  }
1090 
1091  if (!idSet)
1092  {
1093  throw cms::Exception("TotemDAQMappingESSourceXML::GetChannels") <<
1094  "Channel tags must have an `id' attribute.";
1095  }
1096  }
1097 }
1098 
1099 //----------------------------------------------------------------------------------------------------
1100 
RunNumber_t run() const
Definition: EventID.h:39
type
Definition: HCALResponse.h:21
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
Contains data on masked channels of a VFAT.
static const std::string tagChannel
int i
Definition: DBlmapReader.cc:9
Channel-mask mapping.
string GetNodeContent(xercesc::DOMNode *parent)
returns the content of the node
Loads TotemDAQMapping and TotemAnalysisMask from two XML files.
const EventID & eventID() const
Definition: IOVSyncValue.h:42
edm::EventRange validityRange
validity interval
assert(m_qm.get())
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 tagT2Half
void ParseXML(ParseType, const string &file, const boost::shared_ptr< TotemDAQMapping > &, const boost::shared_ptr< TotemAnalysisMask > &)
parses XML file
NodeType GetNodeType(xercesc::DOMNode *)
determines node type
static const std::string tagChip1
COMMON Chip XML tags.
void setWhatProduced(T *iThis, const es::Label &iLabel=es::Label())
Definition: ESProducer.h:115
static const std::string tagT2
T2 XML tags.
static const std::string tagTriggerVFAT1
static const std::string tagT1ChannelType
enum TotemVFATInfo::@83 type
is data of coincidence-chip VFAT
Symbolic ID describing an entity of a TOTEM subdetector.
Definition: TotemSymbId.h:17
ESProducts< T, S > products(const T &i1, const S &i2)
Definition: ESProducts.h:189
The mapping between FramePosition and VFATInfo.
static const std::string tagT2detector
static const std::string tagRPStation
RP XML tags.
TotemFramePosition ChipFramePosition(xercesc::DOMNode *chipnode)
extracts VFAT&#39;s DAQ channel from XML attributes
XMLCh * transcode(const T &fInput)
void ParseTreeRP(ParseType, xercesc::DOMNode *, NodeType, unsigned int parentID, const boost::shared_ptr< TotemDAQMapping > &, const boost::shared_ptr< TotemAnalysisMask > &)
recursive method to extract RP-related information from the DOM tree
int j
Definition: DBlmapReader.cc:9
std::vector< std::string > maskFileNames
the mask files
bool fullMask
whether all channels of the VFAT shall be masked
#define end
Definition: vmac.h:37
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
unsigned int symbolicID
integer-encoded symbolic ID
Definition: TotemSymbId.h:24
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
Definition: SourceFactory.h:92
static const std::string tagArm
Common position tags.
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
unsigned int hwID
the hardware ID (16 bit)
void ParseTreeT1(ParseType, xercesc::DOMNode *, NodeType, unsigned int parentID, const boost::shared_ptr< TotemDAQMapping > &, const boost::shared_ptr< TotemAnalysisMask > &, unsigned int T1Arm, unsigned int T1Plane, unsigned int T1CSC)
recursive method to extract RP-related information from the DOM tree
TotemDAQMappingESSourceXML(const edm::ParameterSet &)
double b
Definition: hdecay.h:120
edm::ESProducts< boost::shared_ptr< TotemDAQMapping >, boost::shared_ptr< TotemAnalysisMask > > produce(const TotemReadoutRcd &)
void ParseTreeT2(ParseType, xercesc::DOMNode *, NodeType, unsigned int parentID, const boost::shared_ptr< TotemDAQMapping > &, const boost::shared_ptr< TotemAnalysisMask > &)
recursive method to extract RP-related information from the DOM tree
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:30
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
static const std::string tagAnalysisMask
double a
Definition: hdecay.h:121
virtual void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &)
sets infinite validity of this data
std::set< unsigned char > maskedChannels
list of channels to be masked
unsigned int currentBlock
index of the current block in &#39;configuration&#39; array
tuple cout
Definition: gather_cfg.py:145
static const std::string tagRPPlane
std::vector< std::string > mappingFileNames
the mapping files
volatile std::atomic< bool > shutdown_flag false
std::string fullPath() const
Definition: FileInPath.cc:184
static const std::string tagT1
T1 XML tags.
enum TotemSymbID::@84 subSystem
identifies the TOTEM subsystem
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.
static const std::string tagT1Plane
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