Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-27 09:20:25

0001 /**
0002  *  @file   PandoraSDK/include/Persistency/XmlFileWriter.h
0003  *
0004  *  @brief  Header file for the xml file writer class.
0005  *
0006  *  $Log: $
0007  */
0008 #ifndef PANDORA_XML_FILE_WRITER_H
0009 #define PANDORA_XML_FILE_WRITER_H 1
0010 
0011 #include "Pandora/Pandora.h"
0012 
0013 #include "Objects/CartesianVector.h"
0014 #include "Objects/TrackState.h"
0015 
0016 #include "Persistency/FileWriter.h"
0017 
0018 #include "Xml/tinyxml.h"
0019 
0020 namespace pandora
0021 {
0022 
0023 /**
0024  *  @brief  XmlFileWriter class
0025  */
0026 class XmlFileWriter : public FileWriter
0027 {
0028 public:
0029     /**
0030      *  @brief  Constructor
0031      *
0032      *  @param  algorithm the pandora instance to be used alongside the file writer
0033      *  @param  fileName the name of the output file
0034      *  @param  fileMode the mode for file writing
0035      *  @param  majorVersion the major version of the output file
0036      *  @param  minorVersion the minor version of the output file
0037      */
0038     XmlFileWriter(const pandora::Pandora &pandora, const std::string &fileName, const FileMode fileMode = APPEND,
0039         const unsigned int majorVersion = 1, const unsigned int minorVersion = 0);
0040 
0041     /**
0042      *  @brief  Destructor
0043      */
0044     ~XmlFileWriter();
0045 
0046     /**
0047      *  @brief  Write a variable to the file
0048      *
0049      *  @param  xmlKey the xml key
0050      */
0051     template <typename T>
0052     StatusCode WriteVariable(const std::string &xmlKey, const T &t);
0053 
0054     StatusCode WriteGlobalHeader();
0055 
0056 private:
0057     StatusCode WriteHeader(const ContainerId containerId);
0058     StatusCode WriteFooter();
0059     StatusCode WriteVersion();
0060     StatusCode WriteSubDetector(const SubDetector *const pSubDetector);
0061     StatusCode WriteLArTPC(const LArTPC *const pLArTPC);
0062     StatusCode WriteDetectorGap(const DetectorGap *const pDetectorGap);
0063     StatusCode WriteCaloHit(const CaloHit *const pCaloHit);
0064     StatusCode WriteTrack(const Track *const pTrack);
0065     StatusCode WriteMCParticle(const MCParticle *const pMCParticle);
0066     StatusCode WriteRelationship(const RelationshipId relationshipId, const void *address1, const void *address2, const float weight);
0067     StatusCode WriteEventInformation();
0068 
0069     TiXmlDocument *m_pXmlDocument;        ///< The xml document
0070     TiXmlElement *m_pContainerXmlElement; ///< The container xml element
0071     TiXmlElement *m_pCurrentXmlElement;   ///< The current xml element
0072 };
0073 
0074 //------------------------------------------------------------------------------------------------------------------------------------------
0075 
0076 template <typename T>
0077 inline StatusCode XmlFileWriter::WriteVariable(const std::string &xmlKey, const T &t)
0078 {
0079     if (!m_pCurrentXmlElement)
0080         return STATUS_CODE_FAILURE;
0081 
0082     TiXmlElement *const pTiXmlElement = new TiXmlElement(xmlKey);
0083     pTiXmlElement->LinkEndChild(new TiXmlText(TypeToStringPrecision(t)));
0084     m_pCurrentXmlElement->LinkEndChild(pTiXmlElement);
0085 
0086     return STATUS_CODE_SUCCESS;
0087 }
0088 
0089 template <>
0090 inline StatusCode XmlFileWriter::WriteVariable(const std::string &xmlKey, const CartesianVector &t)
0091 {
0092     return this->WriteVariable(
0093         xmlKey, TypeToStringPrecision(t.GetX()) + " " + TypeToStringPrecision(t.GetY()) + " " + TypeToStringPrecision(t.GetZ()));
0094 }
0095 
0096 template <>
0097 inline StatusCode XmlFileWriter::WriteVariable(const std::string &xmlKey, const TrackState &t)
0098 {
0099     return this->WriteVariable(xmlKey,
0100         TypeToStringPrecision(t.GetPosition().GetX()) + " " + TypeToStringPrecision(t.GetPosition().GetY()) + " " +
0101             TypeToStringPrecision(t.GetPosition().GetZ()) + " " + TypeToStringPrecision(t.GetMomentum().GetX()) + " " +
0102             TypeToStringPrecision(t.GetMomentum().GetY()) + " " + TypeToStringPrecision(t.GetMomentum().GetZ()));
0103 }
0104 
0105 } // namespace pandora
0106 
0107 #endif // #ifndef PANDORA_XML_FILE_WRITER_H