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>
92 enum NodeType {
nUnknown, nTop, nArm, nRPStation, nRPPot, nRPPlane, nChip, nTriggerVFAT,
93 nT2,
nT2Half, nT2Det, nT1, nT1Arm, nT1Plane, nT1CSC, nT1ChannelType, nChannel };
99 void ParseXML(ParseType,
const string &
file,
const boost::shared_ptr<TotemDAQMapping>&,
const boost::shared_ptr<TotemAnalysisMask>&);
102 void ParseTreeRP(ParseType, xercesc::DOMNode *, NodeType,
unsigned int parentID,
103 const boost::shared_ptr<TotemDAQMapping>&,
const boost::shared_ptr<TotemAnalysisMask>&);
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);
111 void ParseTreeT2(ParseType, xercesc::DOMNode *, NodeType,
unsigned int parentID,
112 const boost::shared_ptr<TotemDAQMapping>&,
const boost::shared_ptr<TotemAnalysisMask>&);
116 string CompleteFileName(
const string &
fn);
119 xercesc::DOMDocument* GetDOMDocument(
string file);
128 NodeType GetNodeType(xercesc::DOMNode *);
145 void GetChannels(xercesc::DOMNode *
n, std::set<unsigned char> &channels);
149 return ((type == nArm)||(type == nRPStation)||(type == nRPPot)||(type == nRPPlane)||(type == nChip)||(type == nTriggerVFAT));
154 return ((type==nT2)||(type==nT2Det)|| (type==nT2Half));
159 return ((type==nT1)||(type==nT1Arm)|| (type==nT1Plane) || (type==nT1CSC) || (type==nT1ChannelType));
164 return ((type==nChip)||(type==nArm));
176 using namespace xercesc;
210 verbosity(conf.getUntrackedParameter<unsigned int>(
"verbosity", 0)),
211 mappingFileNames(conf.getUntrackedParameter< vector<
string> >(
"mappingFileNames")),
212 maskFileNames(conf.getUntrackedParameter< vector<
string> >(
"maskFileNames"))
215 findingRecord<TotemReadoutRcd>();
239 XercesDOMParser*
parser =
new XercesDOMParser();
240 parser->parse(file.c_str());
242 DOMDocument* xmlDoc = parser->getDocument();
245 throw cms::Exception(
"TotemDAQMappingESSourceXML::GetDOMDocument") <<
"Cannot parse file `" << file
246 <<
"' (xmlDoc = NULL)." << endl;
268 XMLPlatformUtils::Initialize();
270 catch (
const XMLException& toCatch)
273 throw cms::Exception(
"TotemDAQMappingESSourceXML") <<
"An XMLException caught with message: " << message <<
".\n";
286 XMLPlatformUtils::Terminate();
295 const boost::shared_ptr<TotemDAQMapping> &mapping,
const boost::shared_ptr<TotemAnalysisMask> &mask)
298 DOMElement* elementRoot = domDoc->getDocumentElement();
301 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseMappingXML") <<
"File `" <<
302 file <<
"' is empty." << endl;
312 unsigned int parentID,
const boost::shared_ptr<TotemDAQMapping>& mapping,
313 const boost::shared_ptr<TotemAnalysisMask>& mask)
316 printf(
">> TotemDAQMappingESSourceXML::ParseTreeRP(%s, %u, %u)\n",
XMLString::transcode(parent->getNodeName()),
317 parentType, parentID);
320 DOMNodeList *children = parent->getChildNodes();
322 for (
unsigned int i = 0;
i < children->getLength();
i++)
324 DOMNode *
n = children->item(
i);
325 if (n->getNodeType() != DOMNode::ELEMENT_NODE)
342 LogPrint(
"TotemDAQMappingESSourceXML") <<
">> TotemDAQMappingESSourceXML::ParseTreeRP > Warning: tag `" <<
tagRPPot
343 <<
"' found in global scope, assuming station ID = 12.";
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();
357 for (
unsigned int j = 0;
j < attr->getLength();
j++)
359 DOMNode *
a = attr->item(
j);
379 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTreeRP") <<
"id not given for element `"
383 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTreeRP") <<
"hw_id not given for element `"
387 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTreeRP") <<
388 "Plane IDs range from 0 to 9. id = " <<
id <<
" is invalid." << endl;
391 printf(
"\tID found: 0x%x\n",
id);
399 vfatInfo.
hwID = hw_id;
414 mapping->insert(framepos, vfatInfo);
430 mask->insert(symbId, am);
436 ParseTreeRP(pType, n, type, parentID * 10 +
id, mapping, mask);
443 unsigned int parentID,
const boost::shared_ptr<TotemDAQMapping>&
data,
444 const boost::shared_ptr<TotemAnalysisMask>& mask)
446 DOMNodeList *children = parent->getChildNodes();
449 printf(
">> ParseTreeT2(parent,parentType,parentID)=(%p, %i, %u)\n", parent, parentType, parentID);
450 printf(
"\tchildren: Numero children: %li\n", children->getLength());
453 for (
unsigned int i = 0;
i < children->getLength();
i++)
455 DOMNode *
n = children->item(
i);
457 if (n->getNodeType() != DOMNode::ELEMENT_NODE)
464 printf(
"\t\tchildren #%i: is a %s, (of type %i) \n",
i,
XMLString::transcode(n->getNodeName()), type);
469 printf(
"Found Unknown tag during T2 reading.. EXIT ");
476 printf(
"Found Non-T2 tag during T2 reading.. EXIT ");
488 unsigned int position_t2 = 0;
490 unsigned int arm=0,ht=0,pl=0,pls=0;
492 bool idSet_t2 =
false;
494 int attribcounter_t2planedescript=0;
495 unsigned int toaddForParentID=0;
498 bool hw_id_set =
false;
500 DOMNamedNodeMap* attr = n->getAttributes();
503 for (
unsigned int j = 0;
j < attr->getLength();
j++) {
504 DOMNode *
a = attr->item(
j);
518 toaddForParentID = position_t2;
527 toaddForParentID=20*id_arm;
534 toaddForParentID=10*id_half;
542 attribcounter_t2planedescript++;
547 attribcounter_t2planedescript++;
552 attribcounter_t2planedescript++;
557 attribcounter_t2planedescript++;
564 attribcounter_t2planedescript++;
569 attribcounter_t2planedescript++;
571 attribcounter_t2planedescript=attribcounter_t2planedescript+20;
589 if (attribcounter_t2planedescript>=(21)) {
593 printf(
"TotemDAQMappingESSourceXML: attribcounter_t2planedescript: %i \n",attribcounter_t2planedescript);
596 if (attribcounter_t2planedescript>=25) {
597 edm::LogVerbatim(
"TotemDAQMappingESSourceXML") <<
"T2-Plane attribute utilezed for parentID: position+info from parent ";
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 ";
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";
615 edm::LogVerbatim(
"TotemDAQMappingESSourceXML")<<
"T2 Plane have parentID: "<<parentID<<
" for its VFATs. Plane Position read: "<<position_t2;
617 if (attribcounter_t2planedescript==21) {
619 ID_t2=parentID+position_t2;
621 toaddForParentID=position_t2;
629 if (attribcounter_t2planedescript>=1) {
632 if(attribcounter_t2planedescript>=5) {
633 int test_position_t2=arm*20+ht*10+pl*2+pls;
636 ID_t2=test_position_t2;
637 cout <<
"ID_t2=test_position_t2: " << ID_t2 << endl;
638 toaddForParentID=test_position_t2;
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;
645 toaddForParentID=ID_t2;
646 edm::LogVerbatim(
"TotemDAQMappingESSourceXML")<<
" Number of T2 plane attributes: "<< attribcounter_t2planedescript<<
" T2-Plane attribute utilezed for parentID: plane 'id' only";
650 edm::LogProblem (
"TotemDAQMappingESSourceXML") <<
"T2 plane not enough specified from its attribute!";
656 if (idSet_t2 ==
false) {
661 if (type ==
nChip && !hw_id_set)
662 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTree") <<
"hw_id not given for VFAT id `" <<
663 ID_t2 <<
"'" << endl;
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.";
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);
680 unsigned int symId=0;
683 symId = parentID * 100 + ID_t2;
688 printf(
"TotemDAQMappingESSourceXML Found T2 special Vfat ChId-SLink-Symb 0x%x - %i - %i \n",
689 ID_t2,position_t2,symId );
696 vfatInfo.
hwID = hw_id;
699 data->insert(framepos, vfatInfo);
703 if (pType ==
pMask) {
715 mask->insert(symbId, vfatMask);
721 ParseTreeT2(pType, n, type, parentID+toaddForParentID, data, mask);
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)
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;
744 unsigned int T1ChannelType = 0;
746 DOMNodeList *children = parent->getChildNodes();
749 printf(
">> ParseTreeT1(parent,parentType,parentID)=(%p, %i, %u)\n", parent, parentType, parentID);
750 printf(
"\tchildren: Numero children: %li\n", children->getLength());
753 for (
unsigned int i = 0;
i < children->getLength();
i++) {
754 DOMNode *
n = children->item(
i);
756 if (n->getNodeType() != DOMNode::ELEMENT_NODE)
763 printf(
"\t\tchildren #%i: is a %s, (of type %i) \n",
i,
XMLString::transcode(n->getNodeName()), type);
768 printf(
"Found Unknown tag during T1 reading.. EXIT ");
775 printf(
"Found Non-T1 tag during T1 reading.. EXIT ");
783 unsigned int ID_t1 = 0;
785 unsigned int VFPOS = 0;
787 unsigned int Gender =0;
790 unsigned int hw_id = 0;
791 bool hw_id_set =
false;
793 bool idSet_t1 =
false;
795 DOMNamedNodeMap* attr = n->getAttributes();
797 bool fullMask =
false;
800 for (
unsigned int j = 0;
j < attr->getLength();
j++) {
802 DOMNode *
a = attr->item(
j);
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;
819 id_arm = id_arm << 9;
821 parentID &= ArmMask_;
830 id_plane = id_plane << 6;
831 PlaneMask_ = ~PlaneMask;
832 parentID &= PlaneMask_;
833 parentID |= id_plane;
841 id_csc = id_csc << 3;
843 parentID &= CSCMask_;
884 if (idSet_t1==
false){
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;
899 symbId.
symbolicID = T1ChannelType + 10 * T1CSC + 100 * T1Plane + 1000 * T1Arm;
904 mask->insert(symbId, am);
911 printf(
"T1 Vfat in detector (parentID): %x || Position %i \n", parentID, VFPOS);
912 printf(
"\t\t\tID_t1 = 0x%x\n", ID_t1);
915 unsigned int symId=0;
920 Gender = Gender << 2;
921 GenderMask_ = ~GenderMask;
923 symId &= GenderMask_;
939 vfatInfo.
hwID = hw_id;
942 mapping->insert(framepos, vfatInfo);
946 ParseTreeT1(pType, n, type, parentID, mapping, mask, T1Arm, T1Plane, T1CSC);
957 unsigned char attributeFlag = 0;
959 DOMNamedNodeMap* attr = chipnode->getAttributes();
960 for (
unsigned int j = 0;
j < attr->getLength();
j++)
962 DOMNode *
a = attr->item(
j);
975 "Wrong/incomplete DAQ channel specification (attributeFlag = " << attributeFlag <<
")." << endl;
1010 throw cms::Exception(
"TotemDAQMappingESSourceXML::GetNodeType") <<
"Unknown tag `"
1018 DOMNodeList *children = n->getChildNodes();
1019 for (
unsigned int i = 0;
i < children->getLength();
i++)
1021 DOMNode *n = children->item(
i);
1022 if (n->getNodeType() != DOMNode::ELEMENT_NODE || !
Test(n,
"channel"))
1025 DOMNamedNodeMap* attr = n->getAttributes();
1027 for (
unsigned int j = 0;
j < attr->getLength();
j++)
1029 DOMNode *
a = attr->item(
j);
1033 unsigned int id = 0;
1035 channels.insert(
id);
1043 throw cms::Exception(
"TotemDAQMappingESSourceXML::GetChannels") <<
1044 "Channel tags must have an `id' attribute.";
Contains data on masked channels of a VFAT.
static const std::string tagChannel
bool CommonNode(NodeType type)
string GetNodeContent(xercesc::DOMNode *parent)
returns the content of the node
Loads TotemDAQMapping and TotemAnalysisMask from two XML files.
static const std::string tagT1CSC
xercesc::DOMDocument * GetDOMDocument(string file)
returns the top element from an XML file
bool RPNode(NodeType type)
EventSetup record for TOTEM readout-related information.
static const IOVSyncValue & endOfTime()
static const std::string tagT1Arm
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 tagVFAT
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())
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.
static const IOVSyncValue & beginOfTime()
ESProducts< T, S > products(const T &i1, const S &i2)
tuple TotemDAQMappingESSourceXML
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'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
bool fullMask
whether all channels of the VFAT shall be masked
bool T1Node(NodeType type)
unsigned int symbolicID
integer-encoded symbolic ID
bool T2Node(NodeType type)
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
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]
static const std::string tagAnalysisMask
static const std::string tagChip2
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
static const std::string tagRPPot
static const std::string tagRPPlane
std::string fullPath() const
static const std::string tagT1
T1 XML tags.
~TotemDAQMappingESSourceXML()
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