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>();
222 char *cmsswPath = getenv(
"CMSSW_BASE");
223 if (cmsswPath && fn[0] !=
'/' && fn[0] !=
'.')
242 XercesDOMParser*
parser =
new XercesDOMParser();
243 parser->parse(file.c_str());
245 DOMDocument* xmlDoc = parser->getDocument();
248 throw cms::Exception(
"TotemDAQMappingESSourceXML::GetDOMDocument") <<
"Cannot parse file `" << file
249 <<
"' (xmlDoc = NULL)." << endl;
271 XMLPlatformUtils::Initialize();
273 catch (
const XMLException& toCatch)
276 throw cms::Exception(
"TotemDAQMappingESSourceXML") <<
"An XMLException caught with message: " << message <<
".\n";
289 XMLPlatformUtils::Terminate();
298 const boost::shared_ptr<TotemDAQMapping> &mapping,
const boost::shared_ptr<TotemAnalysisMask> &mask)
301 DOMElement* elementRoot = domDoc->getDocumentElement();
304 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseMappingXML") <<
"File `" <<
305 file <<
"' is empty." << endl;
315 unsigned int parentID,
const boost::shared_ptr<TotemDAQMapping>& mapping,
316 const boost::shared_ptr<TotemAnalysisMask>& mask)
319 printf(
">> TotemDAQMappingESSourceXML::ParseTreeRP(%s, %u, %u)\n",
XMLString::transcode(parent->getNodeName()),
320 parentType, parentID);
323 DOMNodeList *children = parent->getChildNodes();
325 for (
unsigned int i = 0;
i < children->getLength();
i++)
327 DOMNode *
n = children->item(
i);
328 if (n->getNodeType() != DOMNode::ELEMENT_NODE)
345 LogPrint(
"TotemDAQMappingESSourceXML") <<
">> TotemDAQMappingESSourceXML::ParseTreeRP > Warning: tag `" <<
tagRPPot
346 <<
"' found in global scope, assuming station ID = 12.";
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();
360 for (
unsigned int j = 0;
j < attr->getLength();
j++)
362 DOMNode *
a = attr->item(
j);
382 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTreeRP") <<
"id not given for element `"
386 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTreeRP") <<
"hw_id not given for element `"
390 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTreeRP") <<
391 "Plane IDs range from 0 to 9. id = " <<
id <<
" is invalid." << endl;
394 printf(
"\tID found: 0x%x\n",
id);
402 vfatInfo.
hwID = hw_id;
417 mapping->insert(framepos, vfatInfo);
433 mask->insert(symbId, am);
439 ParseTreeRP(pType, n, type, parentID * 10 +
id, mapping, mask);
446 unsigned int parentID,
const boost::shared_ptr<TotemDAQMapping>&
data,
447 const boost::shared_ptr<TotemAnalysisMask>& mask)
449 DOMNodeList *children = parent->getChildNodes();
452 printf(
">> ParseTreeT2(parent,parentType,parentID)=(%p, %i, %u)\n", parent, parentType, parentID);
453 printf(
"\tchildren: Numero children: %li\n", children->getLength());
456 for (
unsigned int i = 0;
i < children->getLength();
i++)
458 DOMNode *
n = children->item(
i);
460 if (n->getNodeType() != DOMNode::ELEMENT_NODE)
467 printf(
"\t\tchildren #%i: is a %s, (of type %i) \n",
i,
XMLString::transcode(n->getNodeName()), type);
472 printf(
"Found Unknown tag during T2 reading.. EXIT ");
479 printf(
"Found Non-T2 tag during T2 reading.. EXIT ");
491 unsigned int position_t2 = 0;
493 unsigned int arm=0,ht=0,pl=0,pls=0;
495 bool idSet_t2 =
false;
497 int attribcounter_t2planedescript=0;
498 unsigned int toaddForParentID=0;
501 bool hw_id_set =
false;
503 DOMNamedNodeMap* attr = n->getAttributes();
506 for (
unsigned int j = 0;
j < attr->getLength();
j++) {
507 DOMNode *
a = attr->item(
j);
521 toaddForParentID = position_t2;
530 toaddForParentID=20*id_arm;
537 toaddForParentID=10*id_half;
545 attribcounter_t2planedescript++;
550 attribcounter_t2planedescript++;
555 attribcounter_t2planedescript++;
560 attribcounter_t2planedescript++;
567 attribcounter_t2planedescript++;
572 attribcounter_t2planedescript++;
574 attribcounter_t2planedescript=attribcounter_t2planedescript+20;
592 if (attribcounter_t2planedescript>=(21)) {
596 printf(
"TotemDAQMappingESSourceXML: attribcounter_t2planedescript: %i \n",attribcounter_t2planedescript);
599 if (attribcounter_t2planedescript>=25) {
600 edm::LogVerbatim(
"TotemDAQMappingESSourceXML") <<
"T2-Plane attribute utilezed for parentID: position+info from parent ";
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 ";
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";
618 edm::LogVerbatim(
"TotemDAQMappingESSourceXML")<<
"T2 Plane have parentID: "<<parentID<<
" for its VFATs. Plane Position read: "<<position_t2;
620 if (attribcounter_t2planedescript==21) {
622 ID_t2=parentID+position_t2;
624 toaddForParentID=position_t2;
632 if (attribcounter_t2planedescript>=1) {
635 if(attribcounter_t2planedescript>=5) {
636 int test_position_t2=arm*20+ht*10+pl*2+pls;
639 ID_t2=test_position_t2;
640 cout <<
"ID_t2=test_position_t2: " << ID_t2 << endl;
641 toaddForParentID=test_position_t2;
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;
648 toaddForParentID=ID_t2;
649 edm::LogVerbatim(
"TotemDAQMappingESSourceXML")<<
" Number of T2 plane attributes: "<< attribcounter_t2planedescript<<
" T2-Plane attribute utilezed for parentID: plane 'id' only";
653 edm::LogProblem (
"TotemDAQMappingESSourceXML") <<
"T2 plane not enough specified from its attribute!";
659 if (idSet_t2 ==
false) {
664 if (type ==
nChip && !hw_id_set)
665 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTree") <<
"hw_id not given for VFAT id `" <<
666 ID_t2 <<
"'" << endl;
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.";
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);
683 unsigned int symId=0;
686 symId = parentID * 100 + ID_t2;
691 printf(
"TotemDAQMappingESSourceXML Found T2 special Vfat ChId-SLink-Symb 0x%x - %i - %i \n",
692 ID_t2,position_t2,symId );
699 vfatInfo.
hwID = hw_id;
702 data->insert(framepos, vfatInfo);
706 if (pType ==
pMask) {
718 mask->insert(symbId, vfatMask);
724 ParseTreeT2(pType, n, type, parentID+toaddForParentID, data, mask);
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)
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;
747 unsigned int T1ChannelType = 0;
749 DOMNodeList *children = parent->getChildNodes();
752 printf(
">> ParseTreeT1(parent,parentType,parentID)=(%p, %i, %u)\n", parent, parentType, parentID);
753 printf(
"\tchildren: Numero children: %li\n", children->getLength());
756 for (
unsigned int i = 0;
i < children->getLength();
i++) {
757 DOMNode *
n = children->item(
i);
759 if (n->getNodeType() != DOMNode::ELEMENT_NODE)
766 printf(
"\t\tchildren #%i: is a %s, (of type %i) \n",
i,
XMLString::transcode(n->getNodeName()), type);
771 printf(
"Found Unknown tag during T1 reading.. EXIT ");
778 printf(
"Found Non-T1 tag during T1 reading.. EXIT ");
786 unsigned int ID_t1 = 0;
788 unsigned int VFPOS = 0;
790 unsigned int Gender =0;
793 unsigned int hw_id = 0;
794 bool hw_id_set =
false;
796 bool idSet_t1 =
false;
798 DOMNamedNodeMap* attr = n->getAttributes();
800 bool fullMask =
false;
803 for (
unsigned int j = 0;
j < attr->getLength();
j++) {
805 DOMNode *
a = attr->item(
j);
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;
822 id_arm = id_arm << 9;
824 parentID &= ArmMask_;
833 id_plane = id_plane << 6;
834 PlaneMask_ = ~PlaneMask;
835 parentID &= PlaneMask_;
836 parentID |= id_plane;
844 id_csc = id_csc << 3;
846 parentID &= CSCMask_;
887 if (idSet_t1==
false){
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;
902 symbId.
symbolicID = T1ChannelType + 10 * T1CSC + 100 * T1Plane + 1000 * T1Arm;
907 mask->insert(symbId, am);
914 printf(
"T1 Vfat in detector (parentID): %x || Position %i \n", parentID, VFPOS);
915 printf(
"\t\t\tID_t1 = 0x%x\n", ID_t1);
918 unsigned int symId=0;
923 Gender = Gender << 2;
924 GenderMask_ = ~GenderMask;
926 symId &= GenderMask_;
942 vfatInfo.
hwID = hw_id;
945 mapping->insert(framepos, vfatInfo);
949 ParseTreeT1(pType, n, type, parentID, mapping, mask, T1Arm, T1Plane, T1CSC);
960 unsigned char attributeFlag = 0;
962 DOMNamedNodeMap* attr = chipnode->getAttributes();
963 for (
unsigned int j = 0;
j < attr->getLength();
j++)
965 DOMNode *
a = attr->item(
j);
978 "Wrong/incomplete DAQ channel specification (attributeFlag = " << attributeFlag <<
")." << endl;
1013 throw cms::Exception(
"TotemDAQMappingESSourceXML::GetNodeType") <<
"Unknown tag `"
1021 DOMNodeList *children = n->getChildNodes();
1022 for (
unsigned int i = 0;
i < children->getLength();
i++)
1024 DOMNode *n = children->item(
i);
1025 if (n->getNodeType() != DOMNode::ELEMENT_NODE || !
Test(n,
"channel"))
1028 DOMNamedNodeMap* attr = n->getAttributes();
1030 for (
unsigned int j = 0;
j < attr->getLength();
j++)
1032 DOMNode *
a = attr->item(
j);
1036 unsigned int id = 0;
1038 channels.insert(
id);
1046 throw cms::Exception(
"TotemDAQMappingESSourceXML::GetChannels") <<
1047 "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()
enum TotemSymbID::@179 subSystem
identifies the TOTEM subsystem
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
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.
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'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
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)
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
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
static const std::string tagT1
T1 XML tags.
~TotemDAQMappingESSourceXML()
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