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>
107 nT2,
nT2Half, nT2Det, nT1, nT1Arm, nT1Plane, nT1CSC, nT1ChannelType, nChannel };
113 void ParseXML(ParseType,
const string &
file,
const boost::shared_ptr<TotemDAQMapping>&,
const boost::shared_ptr<TotemAnalysisMask>&);
116 void ParseTreeRP(ParseType, xercesc::DOMNode *, NodeType,
unsigned int parentID,
117 const boost::shared_ptr<TotemDAQMapping>&,
const boost::shared_ptr<TotemAnalysisMask>&);
120 void ParseTreeT1(ParseType, xercesc::DOMNode *, NodeType,
unsigned int parentID,
121 const boost::shared_ptr<TotemDAQMapping>&,
const boost::shared_ptr<TotemAnalysisMask>&,
122 unsigned int T1Arm,
unsigned int T1Plane,
unsigned int T1CSC);
125 void ParseTreeT2(ParseType, xercesc::DOMNode *, NodeType,
unsigned int parentID,
126 const boost::shared_ptr<TotemDAQMapping>&,
const boost::shared_ptr<TotemAnalysisMask>&);
130 string CompleteFileName(
const string &
fn);
139 NodeType GetNodeType(xercesc::DOMNode *);
156 void GetChannels(xercesc::DOMNode *
n, std::set<unsigned char> &channels);
160 return ((type == nArm)||(type == nRPStation)||(type == nRPPot)||(type == nRPPlane)||(type == nChip)||(type == nTriggerVFAT));
165 return ((type==nT2)||(type==nT2Det)|| (type==nT2Half));
170 return ((type==nT1)||(type==nT1Arm)|| (type==nT1Plane) || (type==nT1CSC) || (type==nT1ChannelType));
175 return ((type==nChip)||(type==nArm));
187 using namespace xercesc;
221 verbosity(conf.getUntrackedParameter<unsigned int>(
"verbosity", 0)),
223 currentBlockValid(
false)
225 for (
const auto it : conf.
getParameter<vector<ParameterSet>>(
"configuration"))
230 b.
maskFileNames = it.getParameter< vector<string> >(
"maskFileNames");
235 findingRecord<TotemReadoutRcd>();
244 <<
">> TotemDAQMappingESSourceXML::setIntervalFor(" << key.
name() <<
")";
255 EventID startEventID = bl.validityRange.startEventID();
256 if (startEventID ==
EventID(1, 0, 1))
257 startEventID =
EventID(1, 0, 0);
259 if (startEventID <= iosv.
eventID() && iosv.
eventID() <= bl.validityRange.endEventID())
270 <<
", interval=(" << startEventID <<
" - " << bl.validityRange.endEventID() <<
")";
278 throw cms::Exception(
"TotemDAQMappingESSourceXML::setIntervalFor") <<
279 "No configuration for event " << iosv.
eventID();
310 XMLPlatformUtils::Initialize();
312 catch (
const XMLException& toCatch)
315 throw cms::Exception(
"TotemDAQMappingESSourceXML") <<
"An XMLException caught with message: " << message <<
".\n";
328 XMLPlatformUtils::Terminate();
337 const boost::shared_ptr<TotemDAQMapping> &mapping,
const boost::shared_ptr<TotemAnalysisMask> &mask)
339 unique_ptr<XercesDOMParser>
parser(
new XercesDOMParser());
340 parser->parse(file.c_str());
342 DOMDocument* domDoc = parser->getDocument();
345 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseXML") <<
"Cannot parse file `" << file
346 <<
"' (domDoc = NULL)." << endl;
348 DOMElement* elementRoot = domDoc->getDocumentElement();
351 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseXML") <<
"File `" <<
352 file <<
"' is empty." << endl;
362 unsigned int parentID,
const boost::shared_ptr<TotemDAQMapping>& mapping,
363 const boost::shared_ptr<TotemAnalysisMask>& mask)
366 printf(
">> TotemDAQMappingESSourceXML::ParseTreeRP(%s, %u, %u)\n",
XMLString::transcode(parent->getNodeName()),
367 parentType, parentID);
370 DOMNodeList *children = parent->getChildNodes();
372 for (
unsigned int i = 0;
i < children->getLength();
i++)
374 DOMNode *
n = children->item(
i);
375 if (n->getNodeType() != DOMNode::ELEMENT_NODE)
392 LogPrint(
"TotemDAQMappingESSourceXML") <<
">> TotemDAQMappingESSourceXML::ParseTreeRP > Warning: tag `" <<
tagRPPot
393 <<
"' found in global scope, assuming station ID = 12.";
402 unsigned int id = 0, hw_id = 0;
403 bool id_set =
false, hw_id_set =
false;
404 bool fullMask =
false;
405 DOMNamedNodeMap* attr = n->getAttributes();
407 for (
unsigned int j = 0;
j < attr->getLength();
j++)
409 DOMNode *
a = attr->item(
j);
429 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTreeRP") <<
"id not given for element `"
433 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTreeRP") <<
"hw_id not given for element `"
437 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTreeRP") <<
438 "Plane IDs range from 0 to 9. id = " <<
id <<
" is invalid." << endl;
441 printf(
"\tID found: 0x%x\n",
id);
449 vfatInfo.
hwID = hw_id;
464 mapping->insert(framepos, vfatInfo);
480 mask->insert(symbId, am);
486 ParseTreeRP(pType, n, type, parentID * 10 +
id, mapping, mask);
493 unsigned int parentID,
const boost::shared_ptr<TotemDAQMapping>&
data,
494 const boost::shared_ptr<TotemAnalysisMask>& mask)
496 DOMNodeList *children = parent->getChildNodes();
499 printf(
">> ParseTreeT2(parent,parentType,parentID)=(%p, %i, %u)\n", parent, parentType, parentID);
500 printf(
"\tchildren: Numero children: %li\n", children->getLength());
503 for (
unsigned int i = 0;
i < children->getLength();
i++)
505 DOMNode *
n = children->item(
i);
507 if (n->getNodeType() != DOMNode::ELEMENT_NODE)
514 printf(
"\t\tchildren #%i: is a %s, (of type %i) \n",
i,
XMLString::transcode(n->getNodeName()), type);
519 printf(
"Found Unknown tag during T2 reading.. EXIT ");
526 printf(
"Found Non-T2 tag during T2 reading.. EXIT ");
538 unsigned int position_t2 = 0;
540 unsigned int arm=0,ht=0,pl=0,pls=0;
542 bool idSet_t2 =
false;
544 int attribcounter_t2planedescript=0;
545 unsigned int toaddForParentID=0;
548 bool hw_id_set =
false;
550 DOMNamedNodeMap* attr = n->getAttributes();
553 for (
unsigned int j = 0;
j < attr->getLength();
j++) {
554 DOMNode *
a = attr->item(
j);
568 toaddForParentID = position_t2;
577 toaddForParentID=20*id_arm;
584 toaddForParentID=10*id_half;
592 attribcounter_t2planedescript++;
597 attribcounter_t2planedescript++;
602 attribcounter_t2planedescript++;
607 attribcounter_t2planedescript++;
614 attribcounter_t2planedescript++;
619 attribcounter_t2planedescript++;
621 attribcounter_t2planedescript=attribcounter_t2planedescript+20;
639 if (attribcounter_t2planedescript>=(21)) {
643 printf(
"TotemDAQMappingESSourceXML: attribcounter_t2planedescript: %i \n",attribcounter_t2planedescript);
646 if (attribcounter_t2planedescript>=25) {
647 edm::LogVerbatim(
"TotemDAQMappingESSourceXML") <<
"T2-Plane attribute utilezed for parentID: position+info from parent ";
650 unsigned int test_position_t2=arm*20+ht*10+pl*2+pls;
651 unsigned int testHS=pl*2+pls;
652 if(testHS!=position_t2) {
653 edm::LogPrint(
"TotemDAQMappingESSourceXML") <<
"T2 Xml inconsistence in pl-pls attributes and position. Only 'position attribute' taken ";
657 ID_t2=parentID+position_t2;
658 cout <<
"attribcounter_t2planedescript>=(25), ID_t2: " << ID_t2 << endl;
659 toaddForParentID=position_t2;
660 if (ID_t2!=(
int)test_position_t2)
661 edm::LogPrint(
"TotemDAQMappingESSourceXML") <<
"T2 Xml inconsistence in plane attributes and xml parents structure. Plane attributes ignored";
665 edm::LogVerbatim(
"TotemDAQMappingESSourceXML")<<
"T2 Plane have parentID: "<<parentID<<
" for its VFATs. Plane Position read: "<<position_t2;
667 if (attribcounter_t2planedescript==21) {
669 ID_t2=parentID+position_t2;
671 toaddForParentID=position_t2;
679 if (attribcounter_t2planedescript>=1) {
682 if(attribcounter_t2planedescript>=5) {
683 int test_position_t2=arm*20+ht*10+pl*2+pls;
686 ID_t2=test_position_t2;
687 cout <<
"ID_t2=test_position_t2: " << ID_t2 << endl;
688 toaddForParentID=test_position_t2;
690 if ((
int)parentID!=ID_t2) {
691 edm::LogPrint(
"TotemDAQMappingESSourceXML") <<
"T2 Inconsistence between plane 'id' and position from attributes. Id ignored";
692 edm::LogPrint(
"TotemDAQMappingESSourceXML") <<
" T2-Parent = "<<parentID;
695 toaddForParentID=ID_t2;
696 edm::LogVerbatim(
"TotemDAQMappingESSourceXML")<<
" Number of T2 plane attributes: "<< attribcounter_t2planedescript<<
" T2-Plane attribute utilezed for parentID: plane 'id' only";
700 edm::LogProblem (
"TotemDAQMappingESSourceXML") <<
"T2 plane not enough specified from its attribute!";
706 if (idSet_t2 ==
false) {
711 if (type ==
nChip && !hw_id_set)
712 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTree") <<
"hw_id not given for VFAT id `" <<
713 ID_t2 <<
"'" << endl;
715 if (type ==
nT2Det && position_t2 > 39) {
716 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTree") <<
"Plane position_t2 range from 0 to 39. position_t2 = " << position_t2 <<
" is invalid." << endl;
717 edm::LogProblem (
"TotemDAQMappingESSourceXML") <<
"Plane position_t2 range from 0 to 39. position_t2 = "<<position_t2<<
" is invalid.";
726 printf(
"T2 Vfat in plane (parentID): %i || GeomPosition %i \n", parentID, ID_t2);
727 printf(
"\t\t\tID_t2 = 0x%x\n", hw_id);
728 printf(
"\t\t\tpos = %i\n", position_t2);
730 unsigned int symId=0;
733 symId = parentID * 100 + ID_t2;
738 printf(
"TotemDAQMappingESSourceXML Found T2 special Vfat ChId-SLink-Symb 0x%x - %i - %i \n",
739 ID_t2,position_t2,symId );
746 vfatInfo.
hwID = hw_id;
749 data->insert(framepos, vfatInfo);
753 if (pType ==
pMask) {
765 mask->insert(symbId, vfatMask);
771 ParseTreeT2(pType, n, type, parentID+toaddForParentID, data, mask);
779 unsigned int parentID,
const boost::shared_ptr<TotemDAQMapping>& mapping,
780 const boost::shared_ptr<TotemAnalysisMask>& mask,
unsigned int T1Arm,
unsigned int T1Plane,
unsigned int T1CSC)
782 const int ArmMask = 0x0200;
783 const int PlaneMask = 0x01c0;
784 const int CSCMask = 0x0038;
785 const int GenderMask = 0x0004;
786 const int VFnMask = 0x0003;
794 unsigned int T1ChannelType = 0;
796 DOMNodeList *children = parent->getChildNodes();
799 printf(
">> ParseTreeT1(parent,parentType,parentID)=(%p, %i, %u)\n", parent, parentType, parentID);
800 printf(
"\tchildren: Numero children: %li\n", children->getLength());
803 for (
unsigned int i = 0;
i < children->getLength();
i++) {
804 DOMNode *
n = children->item(
i);
806 if (n->getNodeType() != DOMNode::ELEMENT_NODE)
813 printf(
"\t\tchildren #%i: is a %s, (of type %i) \n",
i,
XMLString::transcode(n->getNodeName()), type);
818 printf(
"Found Unknown tag during T1 reading.. EXIT ");
825 printf(
"Found Non-T1 tag during T1 reading.. EXIT ");
833 unsigned int ID_t1 = 0;
835 unsigned int VFPOS = 0;
837 unsigned int Gender =0;
840 unsigned int hw_id = 0;
841 bool hw_id_set =
false;
843 bool idSet_t1 =
false;
845 DOMNamedNodeMap* attr = n->getAttributes();
847 bool fullMask =
false;
850 for (
unsigned int j = 0;
j < attr->getLength();
j++) {
852 DOMNode *
a = attr->item(
j);
864 if (id_arm != 0 && id_arm != 1) {
865 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTree") <<
"T1 id_arm neither 0 nor 1. Problem parsing XML file." <<
XMLString::transcode(n->getNodeName()) << endl;
869 id_arm = id_arm << 9;
871 parentID &= ArmMask_;
880 id_plane = id_plane << 6;
881 PlaneMask_ = ~PlaneMask;
882 parentID &= PlaneMask_;
883 parentID |= id_plane;
891 id_csc = id_csc << 3;
893 parentID &= CSCMask_;
934 if (idSet_t1==
false){
939 if (type ==
nChip && !hw_id_set)
940 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTreeT1") <<
941 "hw_id not set for T1 VFAT id " << ID_t1 <<
"." << endl;
949 symbId.
symbolicID = T1ChannelType + 10 * T1CSC + 100 * T1Plane + 1000 * T1Arm;
954 mask->insert(symbId, am);
961 printf(
"T1 Vfat in detector (parentID): %x || Position %i \n", parentID, VFPOS);
962 printf(
"\t\t\tID_t1 = 0x%x\n", ID_t1);
965 unsigned int symId=0;
970 Gender = Gender << 2;
971 GenderMask_ = ~GenderMask;
973 symId &= GenderMask_;
989 vfatInfo.
hwID = hw_id;
992 mapping->insert(framepos, vfatInfo);
996 ParseTreeT1(pType, n, type, parentID, mapping, mask, T1Arm, T1Plane, T1CSC);
1007 unsigned char attributeFlag = 0;
1009 DOMNamedNodeMap* attr = chipnode->getAttributes();
1010 for (
unsigned int j = 0;
j < attr->getLength();
j++)
1012 DOMNode *
a = attr->item(
j);
1025 "Wrong/incomplete DAQ channel specification (attributeFlag = " << attributeFlag <<
")." << endl;
1060 throw cms::Exception(
"TotemDAQMappingESSourceXML::GetNodeType") <<
"Unknown tag `"
1068 DOMNodeList *children = n->getChildNodes();
1069 for (
unsigned int i = 0;
i < children->getLength();
i++)
1071 DOMNode *n = children->item(
i);
1072 if (n->getNodeType() != DOMNode::ELEMENT_NODE || !
Test(n,
"channel"))
1075 DOMNamedNodeMap* attr = n->getAttributes();
1077 for (
unsigned int j = 0;
j < attr->getLength();
j++)
1079 DOMNode *
a = attr->item(
j);
1083 unsigned int id = 0;
1085 channels.insert(
id);
1093 throw cms::Exception(
"TotemDAQMappingESSourceXML::GetChannels") <<
1094 "Channel tags must have an `id' attribute.";
T getParameter(std::string const &) const
EventNumber_t event() const
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
const EventID & eventID() const
edm::EventRange validityRange
validity interval
bool RPNode(NodeType type)
EventSetup record for TOTEM readout-related information.
bool currentBlockValid
flag whether the 'currentBlock' index is valid
static const std::string tagT1Arm
NodeType
enumeration of XML node types
std::pair< Time_t, Time_t > ValidityInterval
TotemSymbID symbolicID
the symbolic id
static const std::string tagT2Half
void ParseXML(ParseType, const string &file, const boost::shared_ptr< TotemDAQMapping > &, const boost::shared_ptr< TotemAnalysisMask > &)
parses XML file
NodeType GetNodeType(xercesc::DOMNode *)
determines node type
static const std::string tagVFAT
static const std::string tagChip1
COMMON Chip XML tags.
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
vector< ConfigBlock > configuration
enum TotemVFATInfo::@83 type
is data of coincidence-chip VFAT
Symbolic ID describing an entity of a TOTEM subdetector.
ESProducts< T, S > products(const T &i1, const S &i2)
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
const char * name() const
std::vector< std::string > maskFileNames
the mask files
bool fullMask
whether all channels of the VFAT shall be masked
bool T1Node(NodeType type)
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
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.
tuple idx
DEBUGGING if hasattr(process,"trackMonIterativeTracking2012"): print "trackMonIterativeTracking2012 D...
unsigned int hwID
the hardware ID (16 bit)
void ParseTreeT1(ParseType, xercesc::DOMNode *, NodeType, unsigned int parentID, const boost::shared_ptr< TotemDAQMapping > &, const boost::shared_ptr< TotemAnalysisMask > &, unsigned int T1Arm, unsigned int T1Plane, unsigned int T1CSC)
recursive method to extract RP-related information from the DOM tree
TotemDAQMappingESSourceXML(const edm::ParameterSet &)
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
unsigned int currentBlock
index of the current block in 'configuration' array
static const std::string tagRPPot
static const std::string tagRPPlane
std::vector< std::string > mappingFileNames
the mapping files
volatile std::atomic< bool > shutdown_flag false
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