Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-27 09:14:59

0001 /**
0002  * @file LCContent/LCObjects/include/LCTrack.h
0003  *
0004  * @brief Header file for LC Track class
0005  *
0006  */
0007 
0008 #ifndef LC_TRACK_H
0009 #define LC_TRACK_H 1
0010 
0011 #include "Api/PandoraApi.h"
0012 #include "Objects/Track.h"
0013 
0014 #include "Pandora/ObjectCreation.h"
0015 #include "Pandora/PandoraObjectFactories.h"
0016 
0017 #include "Persistency/BinaryFileReader.h"
0018 #include "Persistency/BinaryFileWriter.h"
0019 #include "Persistency/XmlFileReader.h"
0020 #include "Persistency/XmlFileWriter.h"
0021 
0022 namespace lc_content {
0023 
0024 typedef std::vector<pandora::InputTrackState> LCInputTrackStates;
0025 typedef std::vector<pandora::TrackState> LCTrackStates;
0026 
0027 /**
0028  *  @brief  LCTrack Parameters, allow multiple track states at the calorimeter
0029  */
0030 class LCTrackParameters : public object_creation::Track::Parameters {
0031 public:
0032   LCInputTrackStates m_trackStates; ///< Vector of TrackStates
0033 };
0034 
0035 /**
0036  *  @brief  LCTrack extension of the Track class for LC-content
0037  */
0038 class LCTrack : public object_creation::Track::Object {
0039 
0040 public:
0041   LCTrack(const LCTrackParameters& parameters);
0042   virtual ~LCTrack() {};
0043 
0044   const LCTrackStates& GetTrackStates() const;
0045 
0046 protected:
0047   LCTrackStates m_trackStates;
0048 };
0049 
0050 /**
0051  *  @brief  LCTrackFactory responsible for LCTrack creation
0052  */
0053 class LCTrackFactory
0054     : public pandora::ObjectFactory<object_creation::Track::Parameters, object_creation::Track::Object> {
0055 public:
0056   /**
0057    *  @brief  Create new parameters instance on the heap (memory-management to be controlled by user)
0058    *
0059    *  @return the address of the new parameters instance
0060    */
0061   Parameters* NewParameters() const;
0062 
0063   /**
0064    *  @brief  Read any additional (derived class only) object parameters from file using the specified file reader
0065    *
0066    *  @param  parameters the parameters to pass in constructor
0067    *  @param  fileReader the file reader, used to extract any additional parameters from file
0068    */
0069   pandora::StatusCode Read(Parameters&, pandora::FileReader&) const;
0070 
0071   /**
0072    *  @brief  Persist any additional (derived class only) object parameters using the specified file writer
0073    *
0074    *  @param  pObject the address of the object to persist
0075    *  @param  fileWriter the file writer
0076    */
0077   pandora::StatusCode Write(const Object* const, pandora::FileWriter&) const;
0078 
0079   /**
0080    *  @brief  Create an object with the given parameters
0081    *
0082    *  @param  parameters the parameters to pass in constructor
0083    *  @param  pObject to receive the address of the object created
0084    */
0085   pandora::StatusCode Create(const Parameters& parameters, const Object*& pObject) const;
0086 };
0087 
0088 //------------------------------------------------------------------------------------------------------------------------------------------
0089 //------------------------------------------------------------------------------------------------------------------------------------------
0090 
0091 inline LCTrack::LCTrack(const LCTrackParameters& parameters)
0092     : object_creation::Track::Object(parameters), m_trackStates() {
0093   for (auto const& inputTrackState : parameters.m_trackStates) {
0094     m_trackStates.push_back(inputTrackState.Get());
0095   }
0096 }
0097 
0098 //------------------------------------------------------------------------------------------------------------------------------------------
0099 
0100 inline const LCTrackStates& LCTrack::GetTrackStates() const { return m_trackStates; }
0101 
0102 //------------------------------------------------------------------------------------------------------------------------------------------
0103 //------------------------------------------------------------------------------------------------------------------------------------------
0104 
0105 inline LCTrackFactory::Parameters* LCTrackFactory::NewParameters() const { return (new LCTrackParameters); }
0106 
0107 //------------------------------------------------------------------------------------------------------------------------------------------
0108 
0109 inline pandora::StatusCode LCTrackFactory::Create(const Parameters& parameters, const Object*& pObject) const {
0110   const LCTrackParameters& lcTrackParameters(dynamic_cast<const LCTrackParameters&>(parameters));
0111   pObject = new LCTrack(lcTrackParameters);
0112 
0113   return pandora::STATUS_CODE_SUCCESS;
0114 }
0115 
0116 //------------------------------------------------------------------------------------------------------------------------------------------
0117 
0118 inline pandora::StatusCode LCTrackFactory::Read(Parameters& parameters, pandora::FileReader& fileReader) const {
0119   // ATTN: To receive this call-back must have already set file reader track factory to this factory
0120   LCInputTrackStates trackStates;
0121   int nTrackStates;
0122   if (pandora::BINARY == fileReader.GetFileType()) {
0123     pandora::BinaryFileReader& binaryFileReader(dynamic_cast<pandora::BinaryFileReader&>(fileReader));
0124     PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, binaryFileReader.ReadVariable(nTrackStates));
0125     for (int i = 0; i < nTrackStates; ++i) {
0126       pandora::TrackState trackState(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
0127       PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, binaryFileReader.ReadVariable(trackState));
0128       trackStates.push_back(pandora::InputTrackState(trackState));
0129     }
0130   } else if (pandora::XML == fileReader.GetFileType()) {
0131     pandora::XmlFileReader& xmlFileReader(dynamic_cast<pandora::XmlFileReader&>(fileReader));
0132     PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=,
0133                              xmlFileReader.ReadVariable("NumberOfTrackStates", nTrackStates));
0134     for (int i = 0; i < nTrackStates; ++i) {
0135       pandora::TrackState trackState(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
0136       std::stringstream trackStateName;
0137       trackStateName << "TrackState" << i;
0138       PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=,
0139                                xmlFileReader.ReadVariable(trackStateName.str(), trackState));
0140       trackStates.push_back(pandora::InputTrackState(trackState));
0141     }
0142   } else {
0143     return pandora::STATUS_CODE_INVALID_PARAMETER;
0144   }
0145 
0146   LCTrackParameters& lcTrackParameters(dynamic_cast<LCTrackParameters&>(parameters));
0147   lcTrackParameters.m_trackStates = trackStates;
0148 
0149   return pandora::STATUS_CODE_SUCCESS;
0150 }
0151 
0152 //------------------------------------------------------------------------------------------------------------------------------------------
0153 
0154 inline pandora::StatusCode LCTrackFactory::Write(const Object* const pObject, pandora::FileWriter& fileWriter) const {
0155   // ATTN: To receive this call-back must have already set file writer track factory to this factory
0156   const LCTrack* const pLCTrack(dynamic_cast<const LCTrack*>(pObject));
0157 
0158   if (!pLCTrack)
0159     return pandora::STATUS_CODE_INVALID_PARAMETER;
0160 
0161   const LCTrackStates& trackStates = pLCTrack->GetTrackStates();
0162   int nTrackStates = trackStates.size();
0163 
0164   if (pandora::BINARY == fileWriter.GetFileType()) {
0165     pandora::BinaryFileWriter& binaryFileWriter(dynamic_cast<pandora::BinaryFileWriter&>(fileWriter));
0166     PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, binaryFileWriter.WriteVariable(nTrackStates));
0167     for (auto const& trackState : trackStates) {
0168       PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, binaryFileWriter.WriteVariable(trackState));
0169     }
0170   } else if (pandora::XML == fileWriter.GetFileType()) {
0171     pandora::XmlFileWriter& xmlFileWriter(dynamic_cast<pandora::XmlFileWriter&>(fileWriter));
0172     PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=,
0173                              xmlFileWriter.WriteVariable("NumberOfTrackStates", nTrackStates));
0174     int trackStateCounter = 0;
0175     for (auto const& trackState : trackStates) {
0176       std::stringstream trackStateName;
0177       trackStateName << "TrackState" << trackStateCounter;
0178       PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=,
0179                                xmlFileWriter.WriteVariable(trackStateName.str(), trackState));
0180       ++trackStateCounter;
0181     }
0182   } else {
0183     return pandora::STATUS_CODE_INVALID_PARAMETER;
0184   }
0185 
0186   return pandora::STATUS_CODE_SUCCESS;
0187 }
0188 
0189 } // namespace lc_content
0190 
0191 #endif // LC_TRACK_H