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