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