From 3fb89280115b9f2f0e36fb2ddda57f00d42e10ae Mon Sep 17 00:00:00 2001 From: Julian Myrcha Date: Fri, 6 May 2022 14:06:18 +0200 Subject: [PATCH 1/3] o2-eve: calorimeters display, fixes in json serialisation --- .../DataConverter/CMakeLists.txt | 3 + .../VisualisationCalo.h | 118 ++++++ .../VisualisationCluster.h | 6 +- .../VisualisationConstants.h | 23 +- .../VisualisationEvent.h | 61 +++- .../VisualisationEventJSONSerializer.h | 58 +++ .../VisualisationEventSerializer.h | 44 +++ .../VisualisationTrack.h | 13 +- .../DataConverter/src/VisualisationCalo.cxx | 51 +++ .../src/VisualisationCluster.cxx | 28 -- .../DataConverter/src/VisualisationEvent.cxx | 145 +------- .../src/VisualisationEventJSONSerializer.cxx | 341 ++++++++++++++++++ .../src/VisualisationEventSerializer.cxx | 38 ++ .../DataConverter/src/VisualisationTrack.cxx | 86 ----- .../Detectors/src/DataReaderJSON.cxx | 3 +- .../EventVisualisationView/EventManager.h | 2 + EventVisualisation/View/src/EventManager.cxx | 38 +- EventVisualisation/View/src/Initializer.cxx | 25 +- EventVisualisation/View/src/MultiView.cxx | 4 +- EventVisualisation/Workflow/CMakeLists.txt | 4 + .../Workflow/src/EveWorkflowHelper.cxx | 3 +- .../Workflow/src/O2DPLDisplay.cxx | 5 + 22 files changed, 813 insertions(+), 286 deletions(-) create mode 100644 EventVisualisation/DataConverter/include/EventVisualisationDataConverter/VisualisationCalo.h create mode 100644 EventVisualisation/DataConverter/include/EventVisualisationDataConverter/VisualisationEventJSONSerializer.h create mode 100644 EventVisualisation/DataConverter/include/EventVisualisationDataConverter/VisualisationEventSerializer.h create mode 100644 EventVisualisation/DataConverter/src/VisualisationCalo.cxx create mode 100644 EventVisualisation/DataConverter/src/VisualisationEventJSONSerializer.cxx create mode 100644 EventVisualisation/DataConverter/src/VisualisationEventSerializer.cxx diff --git a/EventVisualisation/DataConverter/CMakeLists.txt b/EventVisualisation/DataConverter/CMakeLists.txt index 3495ebab84022..cc7501c0d0ac8 100644 --- a/EventVisualisation/DataConverter/CMakeLists.txt +++ b/EventVisualisation/DataConverter/CMakeLists.txt @@ -13,6 +13,9 @@ o2_add_library(EventVisualisationDataConverter SOURCES src/VisualisationEvent.cxx src/VisualisationTrack.cxx src/VisualisationCluster.cxx + src/VisualisationCalo.cxx + src/VisualisationEventSerializer.cxx + src/VisualisationEventJSONSerializer.cxx PUBLIC_LINK_LIBRARIES RapidJSON::RapidJSON O2::ReconstructionDataFormats ) diff --git a/EventVisualisation/DataConverter/include/EventVisualisationDataConverter/VisualisationCalo.h b/EventVisualisation/DataConverter/include/EventVisualisationDataConverter/VisualisationCalo.h new file mode 100644 index 0000000000000..1d79897e57942 --- /dev/null +++ b/EventVisualisation/DataConverter/include/EventVisualisationDataConverter/VisualisationCalo.h @@ -0,0 +1,118 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +/// +/// \file VisualisationCalo.h +/// \author Julian Myrcha +/// + +#ifndef O2EVE_VISUALISATIONCALO_H +#define O2EVE_VISUALISATIONCALO_H + +#include "rapidjson/document.h" +#include "ReconstructionDataFormats/GlobalTrackID.h" + +namespace o2 +{ +namespace event_visualisation +{ +class VisualisationCalo +{ + friend class VisualisationEventJSONSerializer; + friend class VisualisationEventROOTSerializer; + + public: + // Default constructor + VisualisationCalo(); + + /// constructor parametrisation (Value Object) for VisualisationCalo class + /// + /// Simplifies passing parameters to constructor of VisualisationCalo + /// by providing their names + struct VisualisationCaloVO { + float time = 0; + float energy = 0.0f; + float phi = 0; + float eta = 0; + int PID = 0; + std::string gid = ""; + o2::dataformats::GlobalTrackID::Source source; + }; + // Constructor with properties initialisation + VisualisationCalo(const VisualisationCaloVO& vo); + + VisualisationCalo(const VisualisationCalo& src); + + // Energy getter + float getEnergy() const + { + return mEnergy; + } + + // Time getter + float getTime() const + { + return mTime; + } + + // PID (particle identification code) getter + int getPID() const + { + return mPID; + } + + // GID getter + std::string getGIDAsString() const + { + return mGID; + } + + // Source Getter + o2::dataformats::GlobalTrackID::Source getSource() const + { + return mSource; + } + + // Phi getter + float getPhi() const + { + return mPhi; + } + + // Theta getter + float getEta() const + { + return mEta; + } + + private: + // Set coordinates of the beginning of the track + void addStartCoordinates(const float xyz[3]); + + float mTime; /// time + float mEnergy; /// Energy of the particle + + int mPID; /// PDG code of the particle + std::string mGID; /// String representation of gid + + float mStartCoordinates[3]; /// Vector of track's start coordinates + + float mEta; /// An angle from Z-axis to the radius vector pointing to the particle + float mPhi; /// An angle from X-axis to the radius vector pointing to the particle + + // std::vector mChildrenIDs; /// Unique IDs of children particles + o2::dataformats::GlobalTrackID::Source mSource; /// data source of the track (debug) +}; + +} // namespace event_visualisation +} // namespace o2 + +#endif // O2EVE_VISUALISATIONCALO_H diff --git a/EventVisualisation/DataConverter/include/EventVisualisationDataConverter/VisualisationCluster.h b/EventVisualisation/DataConverter/include/EventVisualisationDataConverter/VisualisationCluster.h index 60e059f241fe6..f70dc8cefd0b1 100644 --- a/EventVisualisation/DataConverter/include/EventVisualisationDataConverter/VisualisationCluster.h +++ b/EventVisualisation/DataConverter/include/EventVisualisationDataConverter/VisualisationCluster.h @@ -36,10 +36,10 @@ namespace event_visualisation class VisualisationCluster { - public: - VisualisationCluster(rapidjson::Value& tree); - rapidjson::Value jsonTree(rapidjson::Document::AllocatorType& allocator); + friend class VisualisationEventJSONSerializer; + friend class VisualisationEventROOTSerializer; + public: // Default constructor VisualisationCluster(float XYZ[], float time); diff --git a/EventVisualisation/DataConverter/include/EventVisualisationDataConverter/VisualisationConstants.h b/EventVisualisation/DataConverter/include/EventVisualisationDataConverter/VisualisationConstants.h index fb1bf679a1996..d1d2ff4cfdfd6 100644 --- a/EventVisualisation/DataConverter/include/EventVisualisationDataConverter/VisualisationConstants.h +++ b/EventVisualisation/DataConverter/include/EventVisualisationDataConverter/VisualisationConstants.h @@ -33,6 +33,9 @@ enum EVisualisationGroup { MFT, MCH, MID, + EMC, + PHS, + CPV, NvisualisationGroups }; @@ -43,7 +46,10 @@ const std::string gVisualisationGroupName[NvisualisationGroups] = { "TOF", "MFT", "MCH", - "MID"}; + "MID", + "EMC", + "PHS", + "CPV"}; const bool R3Visualisation[NvisualisationGroups] = { true, //"ITS", @@ -52,18 +58,23 @@ const bool R3Visualisation[NvisualisationGroups] = { true, //"TOF", true, // "MFT" true, //"MCH", - true //"MID", + true, //"MID", + true, //"EMC", + true, //"PHS", + true, // "CPV" }; enum EVisualisationDataType { - Clusters, ///< Reconstructed clusters (RecPoints) - Tracks, ///< Event Summary Data - NdataTypes ///< number of supported data types + Clusters, ///< Reconstructed clusters (RecPoints) + Tracks, ///< Event Summary Data + Calorimeters, ///< Calorimeters + NdataTypes ///< number of supported data types }; const std::string gDataTypeNames[NdataTypes] = { "Clusters", - "Tracks"}; + "Tracks", + "Calorimeters"}; } // namespace event_visualisation } // namespace o2 diff --git a/EventVisualisation/DataConverter/include/EventVisualisationDataConverter/VisualisationEvent.h b/EventVisualisation/DataConverter/include/EventVisualisationDataConverter/VisualisationEvent.h index 21f881f24d7a5..1b7336fb0ffef 100644 --- a/EventVisualisation/DataConverter/include/EventVisualisationDataConverter/VisualisationEvent.h +++ b/EventVisualisation/DataConverter/include/EventVisualisationDataConverter/VisualisationEvent.h @@ -21,9 +21,11 @@ #include "EventVisualisationDataConverter/VisualisationTrack.h" #include "EventVisualisationDataConverter/VisualisationCluster.h" +#include "EventVisualisationDataConverter/VisualisationCalo.h" #include "EventVisualisationDataConverter/VisualisationConstants.h" #include #include +#include namespace o2 { @@ -39,19 +41,17 @@ namespace event_visualisation class VisualisationEvent { + friend class VisualisationEventJSONSerializer; + friend class VisualisationEventROOTSerializer; + public: struct GIDVisualisation { bool contains[o2::dataformats::GlobalTrackID::NSources][o2::event_visualisation::EVisualisationGroup::NvisualisationGroups]; }; static GIDVisualisation mVis; - std::string toJson(); - void fromJson(std::string json); - bool fromFile(std::string fileName); VisualisationEvent(); VisualisationEvent(std::string fileName); VisualisationEvent(const VisualisationEvent& source, EVisualisationGroup filter, float minTime, float maxTime); - void toFile(std::string fileName); - static std::string fileNameIndexed(const std::string fileName, const int index); /// constructor parametrisation (Value Object) for VisualisationEvent class /// @@ -105,6 +105,26 @@ class VisualisationEvent return mTracks.size(); } + gsl::span getClustersSpan() const + { + return mClusters; + } + + gsl::span getTracksSpan() const + { + return mTracks; + } + + gsl::span getCalorimetersSpan() const + { + return mCalo; + } + + size_t getCaloCount() const + { + return mCalo.size(); + } + // Returns number of tracks with ITS contribution (including standalone) size_t getITSTrackCount() const { @@ -118,6 +138,7 @@ class VisualisationEvent { mTracks.clear(); mClusters.clear(); + mCalo.clear(); } const VisualisationCluster& getCluster(int i) const { return mClusters[i]; }; @@ -125,31 +146,51 @@ class VisualisationEvent void setWorkflowVersion(float workflowVersion) { this->mWorkflowVersion = workflowVersion; } void setWorkflowParameters(const std::string& workflowParameters) { this->mWorkflowParameters = workflowParameters; } - o2::header::DataHeader::RunNumberType getRunNumber() const { return this->mRunNumber; } - void setRunNumber(o2::header::DataHeader::RunNumberType runNumber) { this->mRunNumber = runNumber; } - std::string getCollisionTime() const { return this->mCollisionTime; } void setCollisionTime(std::string collisionTime) { this->mCollisionTime = collisionTime; } float getMinTimeOfTracks() const { return this->mMinTimeOfTracks; } float getMaxTimeOfTracks() const { return this->mMaxTimeOfTracks; } /// maximum time of tracks in the event + bool isEmpty() const { return getTrackCount() == 0 && getClusterCount() == 0; } + + int getClMask() const { return mClMask;} + void setClMask(int value) { mClMask = value;} + + int getTrkMask() const { return mTrkMask;} + void setTrkMask(int value) { mTrkMask = value;} + + o2::header::DataHeader::RunNumberType getRunNumber() const { return this->mRunNumber; } + void setRunNumber(o2::header::DataHeader::RunNumberType runNumber) { this->mRunNumber = runNumber; } + + o2::header::DataHeader::TFCounterType getTfCounter() const { return this->mTfCounter; } + void setTfCounter(o2::header::DataHeader::TFCounterType value) { this->mTfCounter = value; } + + o2::header::DataHeader::TForbitType getFirstTForbit() const { return this->mFirstTForbit; } + void setFirstTForbit(o2::header::DataHeader::TForbitType value) { this->mFirstTForbit = value; } + private: + int mClMask; /// clusters requested during aquisition + int mTrkMask; /// tracks requested during aquisition + o2::header::DataHeader::RunNumberType mRunNumber; /// run number + o2::header::DataHeader::TFCounterType mTfCounter; + o2::header::DataHeader::TForbitType mFirstTForbit; + float mMinTimeOfTracks; /// minimum time of tracks in the event float mMaxTimeOfTracks; /// maximum time of tracks in the event float mWorkflowVersion; /// workflow version used to generate this Event std::string mWorkflowParameters; /// workflow parameters used to generate this Event int mEventNumber; /// event number in file - o2::header::DataHeader::RunNumberType mRunNumber; /// run number double mEnergy; /// energy of the collision int mMultiplicity; /// number of particles reconstructed std::string mCollidingSystem; /// colliding system (e.g. proton-proton) std::string mCollisionTime; /// collision timestamp std::vector mTracks; /// an array of visualisation tracks std::vector mClusters; /// an array of visualisation clusters + std::vector mCalo; /// an array of visualisation calorimeters }; } // namespace event_visualisation } // namespace o2 -#endif // ALICE_O2_EVENTVISUALISATION_BASE_VISUALISATIONEVENT_H \ No newline at end of file +#endif // ALICE_O2_EVENTVISUALISATION_BASE_VISUALISATIONEVENT_H diff --git a/EventVisualisation/DataConverter/include/EventVisualisationDataConverter/VisualisationEventJSONSerializer.h b/EventVisualisation/DataConverter/include/EventVisualisationDataConverter/VisualisationEventJSONSerializer.h new file mode 100644 index 0000000000000..a1d8104d518fb --- /dev/null +++ b/EventVisualisation/DataConverter/include/EventVisualisationDataConverter/VisualisationEventJSONSerializer.h @@ -0,0 +1,58 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +/// +/// \file VisualisationEventSerializer.h +/// \author Julian Myrcha +/// + +#ifndef O2EVE_VISUALISATIONEVENTJSONSERIALIZER_H +#define O2EVE_VISUALISATIONEVENTJSONSERIALIZER_H + +#include "EventVisualisationDataConverter/VisualisationEventSerializer.h" +#include "EventVisualisationDataConverter/VisualisationTrack.h" +#include + +namespace o2 +{ +namespace event_visualisation +{ + +class VisualisationEventJSONSerializer : public VisualisationEventSerializer +{ + static int getIntOrDefault(rapidjson::Value& tree, const char *key, int defaultValue=0) ; + + std::string toJson(const VisualisationEvent& event) const; + void fromJson(VisualisationEvent& event, std::string json); + + // create calo from their JSON representation + VisualisationCalo caloFromJSON(rapidjson::Value& tree); + // create JSON representation of the calo + rapidjson::Value jsonTree(const VisualisationCalo& calo, rapidjson::Document::AllocatorType& allocator) const; + + // create cluster from their JSON representation + VisualisationCluster clusterFromJSON(rapidjson::Value& tree); + rapidjson::Value jsonTree(const VisualisationCluster& cluster, rapidjson::Document::AllocatorType& allocator) const; + + // create track from their JSON representation + VisualisationTrack trackFromJSON(rapidjson::Value& tree); + // create JSON representation of the track + rapidjson::Value jsonTree(const VisualisationTrack& track, rapidjson::Document::AllocatorType& allocator) const; + + public: + bool fromFile(VisualisationEvent& event, std::string fileName) override; + void toFile(const VisualisationEvent& event, std::string fileName) override; +}; + +} // namespace event_visualisation +} // namespace o2 + +#endif // O2EVE_VISUALISATIONEVENTJSONSERIALIZER_H diff --git a/EventVisualisation/DataConverter/include/EventVisualisationDataConverter/VisualisationEventSerializer.h b/EventVisualisation/DataConverter/include/EventVisualisationDataConverter/VisualisationEventSerializer.h new file mode 100644 index 0000000000000..8961fad5a87ae --- /dev/null +++ b/EventVisualisation/DataConverter/include/EventVisualisationDataConverter/VisualisationEventSerializer.h @@ -0,0 +1,44 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +/// +/// \file VisualisationEventSerializer.h +/// \author Julian Myrcha +/// +#ifndef O2EVE_VISUALISATIONEVENTSERIALIZER_H +#define O2EVE_VISUALISATIONEVENTSERIALIZER_H + +#include "EventVisualisationDataConverter/VisualisationEvent.h" +#include + +namespace o2 +{ +namespace event_visualisation +{ + +class VisualisationEventSerializer +{ + static VisualisationEventSerializer* instance; + + protected: + VisualisationEventSerializer() = default; + static std::string fileNameIndexed(const std::string fileName, const int index); + + public: + static VisualisationEventSerializer* getInstance() { return instance; } + virtual bool fromFile(VisualisationEvent& event, std::string fileName) = 0; + virtual void toFile(const VisualisationEvent& event, std::string fileName) = 0; +}; + +} // namespace event_visualisation +} // namespace o2 + +#endif // O2EVE_VISUALISATIONEVENTSERIALIZER_H diff --git a/EventVisualisation/DataConverter/include/EventVisualisationDataConverter/VisualisationTrack.h b/EventVisualisation/DataConverter/include/EventVisualisationDataConverter/VisualisationTrack.h index 27eb506fb9065..38db9b9a029f7 100644 --- a/EventVisualisation/DataConverter/include/EventVisualisationDataConverter/VisualisationTrack.h +++ b/EventVisualisation/DataConverter/include/EventVisualisationDataConverter/VisualisationTrack.h @@ -29,6 +29,7 @@ #include #include #include +#include namespace o2 { @@ -43,13 +44,12 @@ namespace event_visualisation class VisualisationTrack { + friend class VisualisationEventJSONSerializer; + friend class VisualisationEventROOTSerializer; + public: // Default constructor VisualisationTrack(); - // create track from their JSON representation - VisualisationTrack(rapidjson::Value& tree); - // create JSON representation of the track - rapidjson::Value jsonTree(rapidjson::Document::AllocatorType& allocator); /// constructor parametrisation (Value Object) for VisualisationTrack class /// @@ -98,6 +98,11 @@ class VisualisationTrack VisualisationCluster& addCluster(float pos[]); const VisualisationCluster& getCluster(int i) const { return mClusters[i]; }; size_t getClusterCount() const { return mClusters.size(); } // Returns number of clusters + gsl::span getClustersSpan() const + { + return mClusters; + } + private: // Set coordinates of the beginning of the track void addStartCoordinates(const float xyz[3]); diff --git a/EventVisualisation/DataConverter/src/VisualisationCalo.cxx b/EventVisualisation/DataConverter/src/VisualisationCalo.cxx new file mode 100644 index 0000000000000..c7545de9a7ff3 --- /dev/null +++ b/EventVisualisation/DataConverter/src/VisualisationCalo.cxx @@ -0,0 +1,51 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +/// +/// \file VisualisationTrack.cxx +/// \author Julian Myrcha +/// + +#include "EventVisualisationDataConverter/VisualisationCalo.h" +#include "FairLogger.h" + +using namespace std; +namespace o2 +{ +namespace event_visualisation +{ + +VisualisationCalo::VisualisationCalo() = default; + +VisualisationCalo::VisualisationCalo(const VisualisationCaloVO& vo) +{ + this->mSource = vo.source; + this->mTime = vo.time; + this->mEnergy = vo.energy; + this->mEta = vo.eta; + this->mPhi = vo.phi; + this->mGID = vo.gid; + this->mPID = vo.PID; +} + +VisualisationCalo::VisualisationCalo(const VisualisationCalo& src) +{ + this->mSource = src.mSource; + this->mTime = src.mTime; + this->mEnergy = src.mEnergy; + this->mEta = src.mEta; + this->mPhi = src.mPhi; + this->mGID = src.mGID; + this->mPID = src.mPID; +} + +} // namespace event_visualisation +} // namespace o2 diff --git a/EventVisualisation/DataConverter/src/VisualisationCluster.cxx b/EventVisualisation/DataConverter/src/VisualisationCluster.cxx index a74ecd743d23d..1a7406e7d573c 100644 --- a/EventVisualisation/DataConverter/src/VisualisationCluster.cxx +++ b/EventVisualisation/DataConverter/src/VisualisationCluster.cxx @@ -37,33 +37,5 @@ void VisualisationCluster::setCoordinates(float xyz[3]) } } -VisualisationCluster::VisualisationCluster(rapidjson::Value& tree) -{ - rapidjson::Value& jsonX = tree["X"]; - rapidjson::Value& jsonY = tree["Y"]; - rapidjson::Value& jsonZ = tree["Z"]; - - this->mCoordinates[0] = jsonX.GetDouble(); - this->mCoordinates[1] = jsonY.GetDouble(); - this->mCoordinates[2] = jsonZ.GetDouble(); - - this->mSource = o2::dataformats::GlobalTrackID::TPC; // temporary -} - -rapidjson::Value VisualisationCluster::jsonTree(rapidjson::MemoryPoolAllocator<>& allocator) -{ - rapidjson::Value tree(rapidjson::kObjectType); - rapidjson::Value jsonX(rapidjson::kNumberType); - rapidjson::Value jsonY(rapidjson::kNumberType); - rapidjson::Value jsonZ(rapidjson::kNumberType); - jsonX.SetDouble(mCoordinates[0]); - jsonY.SetDouble(mCoordinates[1]); - jsonZ.SetDouble(mCoordinates[2]); - tree.AddMember("X", jsonX, allocator); - tree.AddMember("Y", jsonY, allocator); - tree.AddMember("Z", jsonZ, allocator); - return tree; -} - } // namespace event_visualisation } // namespace o2 diff --git a/EventVisualisation/DataConverter/src/VisualisationEvent.cxx b/EventVisualisation/DataConverter/src/VisualisationEvent.cxx index 50c3d819d52d7..b051b0d0b5d7c 100644 --- a/EventVisualisation/DataConverter/src/VisualisationEvent.cxx +++ b/EventVisualisation/DataConverter/src/VisualisationEvent.cxx @@ -13,17 +13,12 @@ /// \file VisualisationEvent.cxx /// \author Jeremi Niedziela /// \author Maciej Grochowicz +/// \author julian.myrcha@cern.ch /// #include "EventVisualisationDataConverter/VisualisationEvent.h" -#include "rapidjson/document.h" -#include "rapidjson/writer.h" -#include "rapidjson/prettywriter.h" -#include "rapidjson/stringbuffer.h" #include -#include -#include #include #include #include "FairLogger.h" @@ -35,7 +30,6 @@ namespace o2 { namespace event_visualisation { -constexpr int JSON_FILE_VERSION = 1; VisualisationEvent::GIDVisualisation VisualisationEvent::mVis = [] { VisualisationEvent::GIDVisualisation res; @@ -59,6 +53,9 @@ VisualisationEvent::GIDVisualisation VisualisationEvent::mVis = [] { } if (filter == o2::event_visualisation::EVisualisationGroup::TRD) { res.contains[o2::dataformats::GlobalTrackID::TRD][filter] = true; + res.contains[o2::dataformats::GlobalTrackID::TPCTRD][filter] = true; + res.contains[o2::dataformats::GlobalTrackID::ITSTPCTRD][filter] = true; + res.contains[o2::dataformats::GlobalTrackID::ITSTPCTRDTOF][filter] = true; } if (filter == o2::event_visualisation::EVisualisationGroup::TOF) { res.contains[o2::dataformats::GlobalTrackID::ITSTPCTRDTOF][filter] = true; @@ -81,6 +78,12 @@ VisualisationEvent::GIDVisualisation VisualisationEvent::mVis = [] { res.contains[o2::dataformats::GlobalTrackID::MFTMCH][filter] = true; res.contains[o2::dataformats::GlobalTrackID::MFTMCHMID][filter] = true; } + if (filter == o2::event_visualisation::EVisualisationGroup::EMC) { + res.contains[o2::dataformats::GlobalTrackID::EMC][filter] = true; + } + if (filter == o2::event_visualisation::EVisualisationGroup::PHS) { + res.contains[o2::dataformats::GlobalTrackID::PHS][filter] = true; + } } return res; }(); @@ -98,49 +101,6 @@ VisualisationEvent::VisualisationEvent(VisualisationEventVO vo) this->mMaxTimeOfTracks = numeric_limits::min(); } -std::string VisualisationEvent::toJson() -{ - Document tree(kObjectType); - Document::AllocatorType& allocator = tree.GetAllocator(); - - // compatibility verification - tree.AddMember("fileVersion", rapidjson::Value().SetInt(JSON_FILE_VERSION), allocator); - tree.AddMember("runNumber", rapidjson::Value().SetInt(this->mRunNumber), allocator); - tree.AddMember("collisionTime", rapidjson::Value().SetString(this->mCollisionTime.c_str(), this->mCollisionTime.size()), allocator); - tree.AddMember("workflowVersion", rapidjson::Value().SetFloat(this->mWorkflowVersion), allocator); - tree.AddMember("workflowParameters", rapidjson::Value().SetString(this->mWorkflowParameters.c_str(), this->mWorkflowParameters.size()), allocator); - // Tracks - tree.AddMember("trackCount", rapidjson::Value().SetInt(this->getTrackCount()), allocator); - - Value jsonTracks(kArrayType); - for (size_t i = 0; i < this->getTrackCount(); i++) { - jsonTracks.PushBack(this->mTracks[i].jsonTree(allocator), allocator); - } - tree.AddMember("mTracks", jsonTracks, allocator); - - // Clusters - rapidjson::Value clusterCount(rapidjson::kNumberType); - clusterCount.SetInt(this->getClusterCount()); - tree.AddMember("clusterCount", clusterCount, allocator); - Value jsonClusters(kArrayType); - for (size_t i = 0; i < this->getClusterCount(); i++) { - jsonClusters.PushBack(this->mClusters[i].jsonTree(allocator), allocator); - } - tree.AddMember("mClusters", jsonClusters, allocator); - - // stringify - rapidjson::StringBuffer buffer; - rapidjson::PrettyWriter writer(buffer); - tree.Accept(writer); - std::string json_str = std::string(buffer.GetString(), buffer.GetSize()); - return json_str; -} - -VisualisationEvent::VisualisationEvent(std::string fileName) -{ - this->fromFile(fileName); -} - VisualisationEvent::VisualisationEvent(const VisualisationEvent& source, EVisualisationGroup filter, float minTime, float maxTime) { for (auto it = source.mTracks.begin(); it != source.mTracks.end(); ++it) { @@ -159,88 +119,11 @@ VisualisationEvent::VisualisationEvent(const VisualisationEvent& source, EVisual this->mClusters.push_back(*it); } } -} - -void VisualisationEvent::fromJson(std::string json) -{ - mTracks.clear(); - mClusters.clear(); - - rapidjson::Document tree; - tree.Parse(json.c_str()); - - auto version = 1; - if (tree.HasMember("fileVersion")) { - rapidjson::Value& jsonFileVersion = tree["fileVersion"]; - version = jsonFileVersion.GetInt(); - } - - o2::header::DataHeader::RunNumberType runNumber = 0; - if (tree.HasMember("runNumber")) { - rapidjson::Value& jsonRunNumber = tree["runNumber"]; - runNumber = jsonRunNumber.GetInt(); - } - this->setRunNumber(runNumber); - - auto collisionTime = "not specified"; - if (tree.HasMember("collisionTime")) { - rapidjson::Value& jsonCollisionTime = tree["collisionTime"]; - collisionTime = jsonCollisionTime.GetString(); - } - this->setCollisionTime(collisionTime); - - rapidjson::Value& trackCount = tree["trackCount"]; - this->mTracks.reserve(trackCount.GetInt()); - rapidjson::Value& jsonTracks = tree["mTracks"]; - for (auto& v : jsonTracks.GetArray()) { - mTracks.emplace_back(v); - } - this->mMinTimeOfTracks = numeric_limits::max(); - this->mMaxTimeOfTracks = numeric_limits::min(); - for (auto& v : this->mTracks) { - this->mMinTimeOfTracks = min(this->mMinTimeOfTracks, v.getTime()); - this->mMaxTimeOfTracks = max(this->mMaxTimeOfTracks, v.getTime()); - } - - rapidjson::Value& clusterCount = tree["clusterCount"]; - this->mClusters.reserve(clusterCount.GetInt()); - rapidjson::Value& jsonClusters = tree["mClusters"]; - for (auto& v : jsonClusters.GetArray()) { - mClusters.emplace_back(v); - } -} - -void VisualisationEvent::toFile(std::string fileName) -{ - std::string json = toJson(); - std::ofstream out(fileName); - out << json; - out.close(); -} - -std::string VisualisationEvent::fileNameIndexed(const std::string fileName, const int index) -{ - std::stringstream buffer; - buffer << fileName << std::setfill('0') << std::setw(3) << index << ".json"; - return buffer.str(); -} - -bool VisualisationEvent::fromFile(std::string fileName) -{ - if (FILE* file = fopen(fileName.c_str(), "r")) { - fclose(file); // file exists - } else { - return false; + for (auto it = source.mCalo.begin(); it != source.mCalo.end(); ++it) { + if (VisualisationEvent::mVis.contains[it->getSource()][filter]) { + this->mCalo.push_back(*it); + } } - std::ifstream inFile; - inFile.open(fileName); - - std::stringstream strStream; - strStream << inFile.rdbuf(); //read the file - inFile.close(); - std::string str = strStream.str(); //str holds the content of the file - fromJson(str); - return true; } VisualisationEvent::VisualisationEvent() diff --git a/EventVisualisation/DataConverter/src/VisualisationEventJSONSerializer.cxx b/EventVisualisation/DataConverter/src/VisualisationEventJSONSerializer.cxx new file mode 100644 index 0000000000000..6a6eb410d4135 --- /dev/null +++ b/EventVisualisation/DataConverter/src/VisualisationEventJSONSerializer.cxx @@ -0,0 +1,341 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +/// +/// \file VisualisationEventJSONSerializer.cxx +/// \brief JSON serialization +/// \author julian.myrcha@cern.ch + +#include "EventVisualisationDataConverter/VisualisationEventJSONSerializer.h" +#include "FairLogger.h" +#include +#include +#include + +#include "rapidjson/document.h" +#include "rapidjson/writer.h" +#include "rapidjson/prettywriter.h" +#include "rapidjson/stringbuffer.h" + +using namespace rapidjson; + +namespace o2 +{ +namespace event_visualisation +{ +constexpr int JSON_FILE_VERSION = 1; + +void VisualisationEventJSONSerializer::toFile(const VisualisationEvent& event, std::string fileName) +{ + std::string json = toJson(event); + std::ofstream out(fileName); + out << json; + out.close(); +} + +bool VisualisationEventJSONSerializer::fromFile(VisualisationEvent& event, std::string fileName) +{ + if (FILE* file = fopen(fileName.c_str(), "r")) { + fclose(file); // file exists + } else { + return false; + } + std::ifstream inFile; + inFile.open(fileName); + + std::stringstream strStream; + strStream << inFile.rdbuf(); // read the file + inFile.close(); + std::string str = strStream.str(); // str holds the content of the file + fromJson(event, str); + return true; +} + +std::string VisualisationEventJSONSerializer::toJson(const VisualisationEvent& event) const +{ + Document tree(kObjectType); + Document::AllocatorType& allocator = tree.GetAllocator(); + + // compatibility verification + tree.AddMember("fileVersion", rapidjson::Value().SetInt(JSON_FILE_VERSION), allocator); + tree.AddMember("runNumber", rapidjson::Value().SetInt(event.mRunNumber), allocator); + tree.AddMember("clMask", rapidjson::Value().SetInt(event.mClMask), allocator); + tree.AddMember("trkMask", rapidjson::Value().SetInt(event.mTrkMask), allocator); + tree.AddMember("tfCounter", rapidjson::Value().SetInt(event.mTfCounter), allocator); + tree.AddMember("firstTForbit", rapidjson::Value().SetInt(event.mFirstTForbit), allocator); + + tree.AddMember("collisionTime", rapidjson::Value().SetString(event.mCollisionTime.c_str(), event.mCollisionTime.size()), allocator); + tree.AddMember("workflowVersion", rapidjson::Value().SetFloat(event.mWorkflowVersion), allocator); + tree.AddMember("workflowParameters", rapidjson::Value().SetString(event.mWorkflowParameters.c_str(), event.mWorkflowParameters.size()), allocator); + // Tracks + tree.AddMember("trackCount", rapidjson::Value().SetInt(event.getTrackCount()), allocator); + + + Value jsonTracks(kArrayType); + for (auto track : event.getTracksSpan()) { + jsonTracks.PushBack(jsonTree(track, allocator), allocator); + } + tree.AddMember("mTracks", jsonTracks, allocator); + + // Clusters + rapidjson::Value clusterCount(rapidjson::kNumberType); + clusterCount.SetInt(event.getClusterCount()); + tree.AddMember("clusterCount", clusterCount, allocator); + Value jsonClusters(kArrayType); + for (auto cluster : event.getClustersSpan()) { + jsonClusters.PushBack(jsonTree(cluster, allocator), allocator); + } + tree.AddMember("mClusters", jsonClusters, allocator); + + // Calorimeters + rapidjson::Value caloCount(rapidjson::kNumberType); + caloCount.SetInt(event.getCaloCount()); + tree.AddMember("caloCount", caloCount, allocator); + Value jsonCalos(kArrayType); + for (auto calo : event.getCalorimetersSpan()) { + jsonCalos.PushBack(jsonTree(calo, allocator), allocator); + } + tree.AddMember("mCalo", jsonCalos, allocator); + + // stringify + rapidjson::StringBuffer buffer; + rapidjson::PrettyWriter writer(buffer); + tree.Accept(writer); + std::string json_str = std::string(buffer.GetString(), buffer.GetSize()); + return json_str; +} + +int VisualisationEventJSONSerializer::getIntOrDefault(rapidjson::Value& tree, const char *key, int defaultValue) { + if (tree.HasMember(key)) { + rapidjson::Value& jsonValue = tree[key]; + return jsonValue.GetInt(); + } + return defaultValue; +} + + +void VisualisationEventJSONSerializer::fromJson(VisualisationEvent& event, std::string json) +{ + event.mTracks.clear(); + event.mClusters.clear(); + event.mCalo.clear(); + + rapidjson::Document tree; + tree.Parse(json.c_str()); + + auto version = 1; + if (tree.HasMember("fileVersion")) { + rapidjson::Value& jsonFileVersion = tree["fileVersion"]; + version = jsonFileVersion.GetInt(); + } + + o2::header::DataHeader::RunNumberType runNumber = 0; + if (tree.HasMember("runNumber")) { + rapidjson::Value& jsonRunNumber = tree["runNumber"]; + runNumber = jsonRunNumber.GetInt(); + } + event.setRunNumber(runNumber); + + event.setClMask(getIntOrDefault(tree, "clMask")); + event.setTrkMask(getIntOrDefault(tree, "trkMask")); + event.setTfCounter(getIntOrDefault(tree, "tfCounter")); + event.setFirstTForbit(getIntOrDefault(tree, "firstTForbit")); + + auto collisionTime = "not specified"; + if (tree.HasMember("collisionTime")) { + rapidjson::Value& jsonCollisionTime = tree["collisionTime"]; + collisionTime = jsonCollisionTime.GetString(); + } + event.setCollisionTime(collisionTime); + + rapidjson::Value& trackCount = tree["trackCount"]; + event.mTracks.reserve(trackCount.GetInt()); + rapidjson::Value& jsonTracks = tree["mTracks"]; + for (auto& v : jsonTracks.GetArray()) { + event.mTracks.emplace_back(trackFromJSON(v)); + } + + if (tree.HasMember("caloCount")) { + rapidjson::Value& caloCount = tree["caloCount"]; + event.mCalo.reserve(caloCount.GetInt()); + rapidjson::Value& jsonCalo = tree["mCalo"]; + for (auto& v : jsonCalo.GetArray()) { + event.mCalo.emplace_back(caloFromJSON(v)); + } + } + + event.mMinTimeOfTracks = std::numeric_limits::max(); + event.mMaxTimeOfTracks = std::numeric_limits::min(); + for (auto& v : event.mTracks) { + event.mMinTimeOfTracks = std::min(event.mMinTimeOfTracks, v.getTime()); + event.mMaxTimeOfTracks = std::max(event.mMaxTimeOfTracks, v.getTime()); + } + + rapidjson::Value& clusterCount = tree["clusterCount"]; + event.mClusters.reserve(clusterCount.GetInt()); + rapidjson::Value& jsonClusters = tree["mClusters"]; + for (auto& v : jsonClusters.GetArray()) { + event.mClusters.emplace_back(clusterFromJSON(v)); + } +} + +VisualisationCluster VisualisationEventJSONSerializer::clusterFromJSON(rapidjson::Value& tree) +{ + float XYZ[3]; + rapidjson::Value& jsonX = tree["X"]; + rapidjson::Value& jsonY = tree["Y"]; + rapidjson::Value& jsonZ = tree["Z"]; + + XYZ[0] = jsonX.GetDouble(); + XYZ[1] = jsonY.GetDouble(); + XYZ[2] = jsonZ.GetDouble(); + + VisualisationCluster cluster(XYZ, 0); + cluster.mSource = o2::dataformats::GlobalTrackID::TPC; // temporary + return cluster; +} + +rapidjson::Value VisualisationEventJSONSerializer::jsonTree(const VisualisationCluster& cluster, MemoryPoolAllocator<>& allocator) const +{ + rapidjson::Value tree(rapidjson::kObjectType); + rapidjson::Value jsonX(rapidjson::kNumberType); + rapidjson::Value jsonY(rapidjson::kNumberType); + rapidjson::Value jsonZ(rapidjson::kNumberType); + jsonX.SetDouble(cluster.mCoordinates[0]); + jsonY.SetDouble(cluster.mCoordinates[1]); + jsonZ.SetDouble(cluster.mCoordinates[2]); + tree.AddMember("X", jsonX, allocator); + tree.AddMember("Y", jsonY, allocator); + tree.AddMember("Z", jsonZ, allocator); + return tree; +} + +VisualisationCalo VisualisationEventJSONSerializer::caloFromJSON(rapidjson::Value& tree) +{ + VisualisationCalo calo; + calo.mSource = (o2::dataformats::GlobalTrackID::Source)tree["source"].GetInt(); + calo.mTime = tree["time"].GetFloat(); + calo.mEnergy = tree["energy"].GetFloat(); + calo.mEta = tree["eta"].GetFloat(); + calo.mPhi = tree["phi"].GetFloat(); + calo.mGID = tree["gid"].GetString(); + calo.mPID = tree["PID"].GetInt(); + return calo; +} + +rapidjson::Value VisualisationEventJSONSerializer::jsonTree(const VisualisationCalo& calo, rapidjson::MemoryPoolAllocator<>& allocator) const +{ + rapidjson::Value tree(rapidjson::kObjectType); + tree.AddMember("source", rapidjson::Value().SetInt(calo.mSource), allocator); + tree.AddMember("time", rapidjson::Value().SetFloat(std::isnan(calo.mTime) ? 0 : calo.mTime), allocator); + tree.AddMember("energy", rapidjson::Value().SetFloat(calo.mEnergy), allocator); + tree.AddMember("eta", rapidjson::Value().SetFloat(std::isnan(calo.mEta) ? 0 : calo.mEta), allocator); + tree.AddMember("phi", rapidjson::Value().SetFloat(std::isnan(calo.mPhi) ? 0 : calo.mPhi), allocator); + + rapidjson::Value gid; + gid.SetString(calo.mGID.c_str(), calo.mGID.size(), allocator); + tree.AddMember("gid", gid, allocator); + + tree.AddMember("PID", rapidjson::Value().SetInt(calo.mPID), allocator); + return tree; +} + +VisualisationTrack VisualisationEventJSONSerializer::trackFromJSON(rapidjson::Value& tree) +{ + VisualisationTrack track; + track.mClusters.clear(); + rapidjson::Value& jsonPolyX = tree["mPolyX"]; + rapidjson::Value& jsonPolyY = tree["mPolyY"]; + rapidjson::Value& jsonPolyZ = tree["mPolyZ"]; + rapidjson::Value& count = tree["count"]; + track.mCharge = 0; + + if (tree.HasMember("source")) { + track.mSource = (o2::dataformats::GlobalTrackID::Source)tree["source"].GetInt(); + } else { + track.mSource = o2::dataformats::GlobalTrackID::TPC; // temporary + } + track.mPID = tree["source"].GetInt(); + track.mTime = tree["time"].GetFloat(); + if (tree.HasMember("gid")) { + track.mGID = tree["gid"].GetString(); + } else { + track.mGID = "track"; + } + track.mPolyX.reserve(count.GetInt()); + track.mPolyY.reserve(count.GetInt()); + track.mPolyZ.reserve(count.GetInt()); + for (auto& v : jsonPolyX.GetArray()) { + track.mPolyX.push_back(v.GetDouble()); + } + for (auto& v : jsonPolyY.GetArray()) { + track.mPolyY.push_back(v.GetDouble()); + } + for (auto& v : jsonPolyZ.GetArray()) { + track.mPolyZ.push_back(v.GetDouble()); + } + if (tree.HasMember("mClusters")) { + rapidjson::Value& jsonClusters = tree["mClusters"]; + auto jsonArray = jsonClusters.GetArray(); + track.mClusters.reserve(jsonArray.Size()); + for (auto& v : jsonClusters.GetArray()) { + track.mClusters.emplace_back(clusterFromJSON(v)); + } + } + return track; +} + +rapidjson::Value VisualisationEventJSONSerializer::jsonTree(const VisualisationTrack& track, rapidjson::Document::AllocatorType& allocator) const +{ + rapidjson::Value tree(rapidjson::kObjectType); + rapidjson::Value jsonPolyX(rapidjson::kArrayType); + rapidjson::Value jsonPolyY(rapidjson::kArrayType); + rapidjson::Value jsonPolyZ(rapidjson::kArrayType); + rapidjson::Value jsonStartCoordinates(rapidjson::kArrayType); + + tree.AddMember("count", rapidjson::Value().SetInt(track.getPointCount()), allocator); + tree.AddMember("source", rapidjson::Value().SetInt(track.mSource), allocator); + rapidjson::Value gid; + gid.SetString(track.mGID.c_str(), track.mGID.size(), allocator); + tree.AddMember("gid", gid, allocator); + tree.AddMember("time", rapidjson::Value().SetFloat(std::isnan(track.mTime) ? 0 : track.mTime), allocator); + tree.AddMember("charge", rapidjson::Value().SetInt(track.mCharge), allocator); + tree.AddMember("theta", rapidjson::Value().SetFloat(std::isnan(track.mTheta) ? 0 : track.mTheta), allocator); + tree.AddMember("phi", rapidjson::Value().SetFloat(std::isnan(track.mPhi) ? 0 : track.mPhi), allocator); + tree.AddMember("eta", rapidjson::Value().SetFloat(std::isnan(track.mEta) ? 0 : track.mEta), allocator); + tree.AddMember("PID", rapidjson::Value().SetInt(track.mPID), allocator); + + jsonStartCoordinates.PushBack((float)track.mStartCoordinates[0], allocator); + jsonStartCoordinates.PushBack((float)track.mStartCoordinates[1], allocator); + jsonStartCoordinates.PushBack((float)track.mStartCoordinates[2], allocator); + tree.AddMember("jsonStartingXYZ", jsonStartCoordinates, allocator); + + for (size_t i = 0; i < track.getPointCount(); i++) { + jsonPolyX.PushBack((float)track.mPolyX[i], allocator); + jsonPolyY.PushBack((float)track.mPolyY[i], allocator); + jsonPolyZ.PushBack((float)track.mPolyZ[i], allocator); + } + tree.AddMember("mPolyX", jsonPolyX, allocator); + tree.AddMember("mPolyY", jsonPolyY, allocator); + tree.AddMember("mPolyZ", jsonPolyZ, allocator); + + rapidjson::Value jsonClusters(rapidjson::kArrayType); + + for (auto cluster : track.getClustersSpan()) { + jsonClusters.PushBack(jsonTree(cluster, allocator), allocator); + } + tree.AddMember("mClusters", jsonClusters, allocator); + + return tree; +} + +} // namespace event_visualisation +} // namespace o2 \ No newline at end of file diff --git a/EventVisualisation/DataConverter/src/VisualisationEventSerializer.cxx b/EventVisualisation/DataConverter/src/VisualisationEventSerializer.cxx new file mode 100644 index 0000000000000..159664f051801 --- /dev/null +++ b/EventVisualisation/DataConverter/src/VisualisationEventSerializer.cxx @@ -0,0 +1,38 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +/// +/// \file VisualisationEventSerializer.cxx +/// \brief Serialization VisualisationEvent +/// \author julian.myrcha@cern.ch + +#include "EventVisualisationDataConverter/VisualisationEventSerializer.h" +#include "EventVisualisationDataConverter/VisualisationEventJSONSerializer.h" +#include "FairLogger.h" +#include +#include + +namespace o2 +{ +namespace event_visualisation +{ + +VisualisationEventSerializer* VisualisationEventSerializer::instance = new VisualisationEventJSONSerializer(); + +std::string VisualisationEventSerializer::fileNameIndexed(const std::string fileName, const int index) +{ + std::stringstream buffer; + buffer << fileName << std::setfill('0') << std::setw(3) << index << ".json"; + return buffer.str(); +} + +} // namespace event_visualisation +} // namespace o2 \ No newline at end of file diff --git a/EventVisualisation/DataConverter/src/VisualisationTrack.cxx b/EventVisualisation/DataConverter/src/VisualisationTrack.cxx index 707147ee06818..45054dead8a2c 100644 --- a/EventVisualisation/DataConverter/src/VisualisationTrack.cxx +++ b/EventVisualisation/DataConverter/src/VisualisationTrack.cxx @@ -73,92 +73,6 @@ void VisualisationTrack::addPolyPoint(float x, float y, float z) mPolyZ.push_back(z); } -VisualisationTrack::VisualisationTrack(rapidjson::Value& tree) -{ - mClusters.clear(); - rapidjson::Value& jsonPolyX = tree["mPolyX"]; - rapidjson::Value& jsonPolyY = tree["mPolyY"]; - rapidjson::Value& jsonPolyZ = tree["mPolyZ"]; - rapidjson::Value& count = tree["count"]; - this->mCharge = 0; - - if (tree.HasMember("source")) { - this->mSource = (o2::dataformats::GlobalTrackID::Source)tree["source"].GetInt(); - } else { - this->mSource = o2::dataformats::GlobalTrackID::TPC; // temporary - } - this->mPID = tree["source"].GetInt(); - this->mTime = tree["time"].GetFloat(); - if (tree.HasMember("gid")) { - this->mGID = tree["gid"].GetString(); - } else { - this->mGID = "track"; - } - this->mPolyX.reserve(count.GetInt()); - this->mPolyY.reserve(count.GetInt()); - this->mPolyZ.reserve(count.GetInt()); - for (auto& v : jsonPolyX.GetArray()) { - mPolyX.push_back(v.GetDouble()); - } - for (auto& v : jsonPolyY.GetArray()) { - mPolyY.push_back(v.GetDouble()); - } - for (auto& v : jsonPolyZ.GetArray()) { - mPolyZ.push_back(v.GetDouble()); - } - if (tree.HasMember("mClusters")) { - rapidjson::Value& jsonClusters = tree["mClusters"]; - auto jsonArray = jsonClusters.GetArray(); - this->mClusters.reserve(jsonArray.Size()); - for (auto& v : jsonClusters.GetArray()) { - mClusters.emplace_back(v); - } - } -} - -rapidjson::Value VisualisationTrack::jsonTree(rapidjson::Document::AllocatorType& allocator) -{ - rapidjson::Value tree(rapidjson::kObjectType); - rapidjson::Value jsonPolyX(rapidjson::kArrayType); - rapidjson::Value jsonPolyY(rapidjson::kArrayType); - rapidjson::Value jsonPolyZ(rapidjson::kArrayType); - rapidjson::Value jsonStartCoordinates(rapidjson::kArrayType); - - tree.AddMember("count", rapidjson::Value().SetInt(this->getPointCount()), allocator); - tree.AddMember("source", rapidjson::Value().SetInt(this->mSource), allocator); - rapidjson::Value gid; - gid.SetString(this->mGID.c_str(), this->mGID.size(), allocator); - tree.AddMember("gid", gid, allocator); - tree.AddMember("time", rapidjson::Value().SetFloat(isnan(this->mTime) ? 0 : this->mTime), allocator); - tree.AddMember("charge", rapidjson::Value().SetInt(this->mCharge), allocator); - tree.AddMember("theta", rapidjson::Value().SetFloat(isnan(this->mTheta) ? 0 : this->mTheta), allocator); - tree.AddMember("phi", rapidjson::Value().SetFloat(isnan(this->mPhi) ? 0 : this->mPhi), allocator); - tree.AddMember("eta", rapidjson::Value().SetFloat(isnan(this->mEta) ? 0 : this->mEta), allocator); - tree.AddMember("PID", rapidjson::Value().SetInt(this->mPID), allocator); - - jsonStartCoordinates.PushBack((float)mStartCoordinates[0], allocator); - jsonStartCoordinates.PushBack((float)mStartCoordinates[1], allocator); - jsonStartCoordinates.PushBack((float)mStartCoordinates[2], allocator); - tree.AddMember("jsonStartingXYZ", jsonStartCoordinates, allocator); - - for (size_t i = 0; i < this->getPointCount(); i++) { - jsonPolyX.PushBack((float)mPolyX[i], allocator); - jsonPolyY.PushBack((float)mPolyY[i], allocator); - jsonPolyZ.PushBack((float)mPolyZ[i], allocator); - } - tree.AddMember("mPolyX", jsonPolyX, allocator); - tree.AddMember("mPolyY", jsonPolyY, allocator); - tree.AddMember("mPolyZ", jsonPolyZ, allocator); - - rapidjson::Value jsonClusters(rapidjson::kArrayType); - for (size_t i = 0; i < this->mClusters.size(); i++) { - jsonClusters.PushBack(this->mClusters[i].jsonTree(allocator), allocator); - } - tree.AddMember("mClusters", jsonClusters, allocator); - - return tree; -} - VisualisationCluster& VisualisationTrack::addCluster(float pos[]) { mClusters.emplace_back(pos, 0); diff --git a/EventVisualisation/Detectors/src/DataReaderJSON.cxx b/EventVisualisation/Detectors/src/DataReaderJSON.cxx index e833864fa7eba..c33304bbec1d7 100644 --- a/EventVisualisation/Detectors/src/DataReaderJSON.cxx +++ b/EventVisualisation/Detectors/src/DataReaderJSON.cxx @@ -15,6 +15,7 @@ /// \author julian.myrcha@cern.ch #include "EventVisualisationDetectors/DataReaderJSON.h" +#include "EventVisualisationDataConverter/VisualisationEventSerializer.h" #include "FairLogger.h" namespace o2 @@ -25,7 +26,7 @@ namespace event_visualisation VisualisationEvent DataReaderJSON::getEvent(std::string fileName) { VisualisationEvent vEvent; - vEvent.fromFile(fileName); + VisualisationEventSerializer::getInstance()->fromFile(vEvent, fileName); return vEvent; } diff --git a/EventVisualisation/View/include/EventVisualisationView/EventManager.h b/EventVisualisation/View/include/EventVisualisationView/EventManager.h index 3abdb76dda9e4..bd02affb6fc0f 100644 --- a/EventVisualisation/View/include/EventVisualisationView/EventManager.h +++ b/EventVisualisation/View/include/EventVisualisationView/EventManager.h @@ -22,6 +22,7 @@ #include "EventVisualisationBase/DataReader.h" #include "CCDB/BasicCCDBManager.h" #include "CCDB/CcdbApi.h" +#include "TEveCaloData.h" #include #include @@ -92,6 +93,7 @@ class EventManager final : public TEveEventManager, public TQObject void operator=(EventManager const&) = delete; void displayVisualisationEvent(VisualisationEvent& event, const std::string& detectorName); + void displayCalorimeters(VisualisationEvent& event); }; } // namespace event_visualisation diff --git a/EventVisualisation/View/src/EventManager.cxx b/EventVisualisation/View/src/EventManager.cxx index 3be8d8b58ac94..3e5e6ed0b324d 100644 --- a/EventVisualisation/View/src/EventManager.cxx +++ b/EventVisualisation/View/src/EventManager.cxx @@ -13,6 +13,8 @@ /// \file EventManager.cxx /// \author Jeremi Niedziela /// \author Julian Myrcha +/// \author Michal Chwesiuk +/// \author Piotr Nowakowski #include "EventVisualisationView/EventManager.h" #include "EventVisualisationView/EventManagerFrame.h" @@ -23,11 +25,11 @@ #include #include -#include #include #include #include #include +#include #include "FairLogger.h" #define elemof(e) (unsigned int)(sizeof(e) / sizeof(e[0])) @@ -75,6 +77,7 @@ void EventManager::displayCurrentEvent() for (int i = 0; i < EVisualisationDataType::NdataTypes; ++i) { MultiView::getInstance()->registerElement(dataTypeLists[i]); } + // displayCalorimeters(displayList[0].first); MultiView::getInstance()->getAnnotation()->SetText(TString::Format("Run: %d", displayList[0].first.getRunNumber())); } @@ -219,8 +222,41 @@ void EventManager::displayVisualisationEvent(VisualisationEvent& event, const st if (clusterCount != 0) { dataTypeLists[EVisualisationDataType::Clusters]->AddElement(point_list); } + LOG(info) << "tracks: " << trackCount << " detector: " << detectorName << ":" << dataTypeLists[EVisualisationDataType::Tracks]->NumChildren(); LOG(info) << "clusters: " << clusterCount << " detector: " << detectorName << ":" << dataTypeLists[EVisualisationDataType::Clusters]->NumChildren(); + + displayCalorimeters(event); +} + +void EventManager::displayCalorimeters(VisualisationEvent& event) +{ + int size = event.getCaloCount(); + if (size > 0) { + auto data = new TEveCaloDataVec(1); + data->IncDenyDestroy(); + data->RefSliceInfo(0).Setup("Data", 0.3, kYellow); + + for (auto calo : event.getCalorimetersSpan()) { + const float dX = 0.173333; + const float dY = 0.104667; + data->AddTower(calo.getEta(), calo.getEta() + dX, calo.getPhi(), calo.getPhi() + dY); + data->FillSlice(0, calo.getEnergy()); + } + + data->DataChanged(); + data->SetAxisFromBins(); + + float barrelRadius = 375; + float endCalPosition = 400; + + auto calo3d = new TEveCalo3D(data); + + calo3d->SetBarrelRadius(barrelRadius); + calo3d->SetEndCapPos(endCalPosition); + + dataTypeLists[EVisualisationDataType::Calorimeters]->AddElement(calo3d); + } } } // namespace event_visualisation diff --git a/EventVisualisation/View/src/Initializer.cxx b/EventVisualisation/View/src/Initializer.cxx index 3b589fd9d08c4..e355e9b0b50ba 100644 --- a/EventVisualisation/View/src/Initializer.cxx +++ b/EventVisualisation/View/src/Initializer.cxx @@ -123,19 +123,18 @@ void Initializer::setupGeometry() string detName = gVisualisationGroupName[det]; LOG(info) << detName; - if (detName == "TPC" || detName == "MCH" || detName == "MID" || detName == "MFT") { // don't load MUON+MFT and AD and standard TPC to R-Phi view - multiView->drawGeometryForDetector(detName, true, false); - } else if (detName == "RPH") { // special TPC geom from R-Phi view - multiView->drawGeometryForDetector(detName, false, true, false); - } else if (detName != "TST") { // default - multiView->drawGeometryForDetector(detName); - } - - const auto geom = multiView->getDetectorGeometry(detName); - const auto show = settings.GetValue((detName + ".draw").c_str(), false); - - if (geom != nullptr) { - geom->SetRnrSelfChildren(show, show); + if (settings.GetValue((detName + ".draw").c_str(), false)) { + if (detName == "TPC" || detName == "MCH" || detName == "MID" || detName == "MFT") { // don't load MUON+MFT and AD and standard TPC to R-Phi view + + multiView->drawGeometryForDetector(detName, true, false); + } else if (detName == "RPH") { // special TPC geom from R-Phi view + + multiView->drawGeometryForDetector(detName, false, true, false); + } else { // default + if (detName != "TST") { + multiView->drawGeometryForDetector(detName); + } + } } } } diff --git a/EventVisualisation/View/src/MultiView.cxx b/EventVisualisation/View/src/MultiView.cxx index 990bde842b17c..1242aee3ae79d 100644 --- a/EventVisualisation/View/src/MultiView.cxx +++ b/EventVisualisation/View/src/MultiView.cxx @@ -77,8 +77,8 @@ MultiView::MultiView() mProjections[ProjectionRphi]->SetProjection(TEveProjection::kPT_RPhi); mProjections[ProjectionZrho]->SetProjection(TEveProjection::kPT_RhoZ); - // open scenes - gEve->GetScenes()->FindListTreeItem(gEve->GetListTree())->SetOpen(true); + gEve->AddToListTree(static_cast(mProjections[ProjectionRphi]), false); + gEve->AddToListTree(static_cast(mProjections[ProjectionZrho]), false); // add axes TEnv settings; diff --git a/EventVisualisation/Workflow/CMakeLists.txt b/EventVisualisation/Workflow/CMakeLists.txt index e1de05e9fab7e..b738183e3f9e5 100644 --- a/EventVisualisation/Workflow/CMakeLists.txt +++ b/EventVisualisation/Workflow/CMakeLists.txt @@ -38,6 +38,8 @@ if(ALIGPU_BUILD_TYPE STREQUAL "O2" O2::ITSMFTWorkflow O2::MFTWorkflow O2::TOFBase + O2::PHOSBase + O2::EMCALBase O2::TOFWorkflowIO O2::TPCReconstruction O2::TPCWorkflow @@ -69,6 +71,8 @@ if(ALIGPU_BUILD_TYPE STREQUAL "O2" O2::ITSMFTWorkflow O2::MFTWorkflow O2::TOFBase + O2::PHOSBase + O2::EMCALBase O2::TOFWorkflowIO O2::TPCReconstruction O2::TPCWorkflow diff --git a/EventVisualisation/Workflow/src/EveWorkflowHelper.cxx b/EventVisualisation/Workflow/src/EveWorkflowHelper.cxx index 250ea58a289de..f461fe4efabd2 100644 --- a/EventVisualisation/Workflow/src/EveWorkflowHelper.cxx +++ b/EventVisualisation/Workflow/src/EveWorkflowHelper.cxx @@ -13,6 +13,7 @@ /// \author julian.myrcha@cern.ch #include +#include "EventVisualisationDataConverter/VisualisationEventSerializer.h" #include "ReconstructionDataFormats/GlobalTrackID.h" #include "EveWorkflow/FileProducer.h" #include "DataFormatsTRD/TrackTRD.h" @@ -184,7 +185,7 @@ void EveWorkflowHelper::save(const std::string& jsonPath, int numberOfFiles, mEvent.setCollisionTime(asciiCreationTime); FileProducer producer(jsonPath, numberOfFiles); - mEvent.toFile(producer.newFileName()); + VisualisationEventSerializer::getInstance()->toFile(mEvent, producer.newFileName()); } std::vector EveWorkflowHelper::getTrackPoints(const o2::track::TrackPar& trc, float minR, float maxR, float maxStep, float minZ, float maxZ) diff --git a/EventVisualisation/Workflow/src/O2DPLDisplay.cxx b/EventVisualisation/Workflow/src/O2DPLDisplay.cxx index 131f83d5ce698..bf99a6e64ea66 100644 --- a/EventVisualisation/Workflow/src/O2DPLDisplay.cxx +++ b/EventVisualisation/Workflow/src/O2DPLDisplay.cxx @@ -126,6 +126,11 @@ void O2DPLDisplaySpec::run(ProcessingContext& pc) } if (save) { + helper.mEvent.setClMask(this->mClMask.to_ulong()); + helper.mEvent.setTrkMask(this->mTrkMask.to_ulong()); + helper.mEvent.setRunNumber(dh->runNumber); + helper.mEvent.setTfCounter(dh->tfCounter); + helper.mEvent.setFirstTForbit(dh->firstTForbit); helper.save(this->mJsonPath, this->mNumberOfFiles, this->mTrkMask, this->mClMask, this->mWorkflowVersion, dh->runNumber, dph->creation); } From d52a951db8e46d4d9d69e352b8931a635b01b998 Mon Sep 17 00:00:00 2001 From: Julian Myrcha Date: Sun, 8 May 2022 16:40:26 +0200 Subject: [PATCH 2/3] reformatting --- .../EventVisualisationDataConverter/VisualisationEvent.h | 8 ++++---- .../VisualisationEventJSONSerializer.h | 2 +- .../src/VisualisationEventJSONSerializer.cxx | 5 ++--- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/EventVisualisation/DataConverter/include/EventVisualisationDataConverter/VisualisationEvent.h b/EventVisualisation/DataConverter/include/EventVisualisationDataConverter/VisualisationEvent.h index 1b7336fb0ffef..57a93d9f239ca 100644 --- a/EventVisualisation/DataConverter/include/EventVisualisationDataConverter/VisualisationEvent.h +++ b/EventVisualisation/DataConverter/include/EventVisualisationDataConverter/VisualisationEvent.h @@ -154,11 +154,11 @@ class VisualisationEvent bool isEmpty() const { return getTrackCount() == 0 && getClusterCount() == 0; } - int getClMask() const { return mClMask;} - void setClMask(int value) { mClMask = value;} + int getClMask() const { return mClMask; } + void setClMask(int value) { mClMask = value; } - int getTrkMask() const { return mTrkMask;} - void setTrkMask(int value) { mTrkMask = value;} + int getTrkMask() const { return mTrkMask; } + void setTrkMask(int value) { mTrkMask = value; } o2::header::DataHeader::RunNumberType getRunNumber() const { return this->mRunNumber; } void setRunNumber(o2::header::DataHeader::RunNumberType runNumber) { this->mRunNumber = runNumber; } diff --git a/EventVisualisation/DataConverter/include/EventVisualisationDataConverter/VisualisationEventJSONSerializer.h b/EventVisualisation/DataConverter/include/EventVisualisationDataConverter/VisualisationEventJSONSerializer.h index a1d8104d518fb..daa568184a7c4 100644 --- a/EventVisualisation/DataConverter/include/EventVisualisationDataConverter/VisualisationEventJSONSerializer.h +++ b/EventVisualisation/DataConverter/include/EventVisualisationDataConverter/VisualisationEventJSONSerializer.h @@ -28,7 +28,7 @@ namespace event_visualisation class VisualisationEventJSONSerializer : public VisualisationEventSerializer { - static int getIntOrDefault(rapidjson::Value& tree, const char *key, int defaultValue=0) ; + static int getIntOrDefault(rapidjson::Value& tree, const char* key, int defaultValue = 0); std::string toJson(const VisualisationEvent& event) const; void fromJson(VisualisationEvent& event, std::string json); diff --git a/EventVisualisation/DataConverter/src/VisualisationEventJSONSerializer.cxx b/EventVisualisation/DataConverter/src/VisualisationEventJSONSerializer.cxx index 6a6eb410d4135..7f2c6e933b67a 100644 --- a/EventVisualisation/DataConverter/src/VisualisationEventJSONSerializer.cxx +++ b/EventVisualisation/DataConverter/src/VisualisationEventJSONSerializer.cxx @@ -78,7 +78,6 @@ std::string VisualisationEventJSONSerializer::toJson(const VisualisationEvent& e // Tracks tree.AddMember("trackCount", rapidjson::Value().SetInt(event.getTrackCount()), allocator); - Value jsonTracks(kArrayType); for (auto track : event.getTracksSpan()) { jsonTracks.PushBack(jsonTree(track, allocator), allocator); @@ -113,7 +112,8 @@ std::string VisualisationEventJSONSerializer::toJson(const VisualisationEvent& e return json_str; } -int VisualisationEventJSONSerializer::getIntOrDefault(rapidjson::Value& tree, const char *key, int defaultValue) { +int VisualisationEventJSONSerializer::getIntOrDefault(rapidjson::Value& tree, const char* key, int defaultValue) +{ if (tree.HasMember(key)) { rapidjson::Value& jsonValue = tree[key]; return jsonValue.GetInt(); @@ -121,7 +121,6 @@ int VisualisationEventJSONSerializer::getIntOrDefault(rapidjson::Value& tree, co return defaultValue; } - void VisualisationEventJSONSerializer::fromJson(VisualisationEvent& event, std::string json) { event.mTracks.clear(); From dc6f8618ee902ed3b3cc8b3089f1015c88756d83 Mon Sep 17 00:00:00 2001 From: Julian Myrcha Date: Sun, 8 May 2022 18:29:39 +0200 Subject: [PATCH 3/3] fixed merge errors --- EventVisualisation/View/src/EventManager.cxx | 1 + EventVisualisation/View/src/Initializer.cxx | 25 ++++++++++---------- EventVisualisation/View/src/MultiView.cxx | 4 ++-- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/EventVisualisation/View/src/EventManager.cxx b/EventVisualisation/View/src/EventManager.cxx index 3e5e6ed0b324d..938062037fd1e 100644 --- a/EventVisualisation/View/src/EventManager.cxx +++ b/EventVisualisation/View/src/EventManager.cxx @@ -25,6 +25,7 @@ #include #include +#include #include #include #include diff --git a/EventVisualisation/View/src/Initializer.cxx b/EventVisualisation/View/src/Initializer.cxx index e355e9b0b50ba..3b589fd9d08c4 100644 --- a/EventVisualisation/View/src/Initializer.cxx +++ b/EventVisualisation/View/src/Initializer.cxx @@ -123,18 +123,19 @@ void Initializer::setupGeometry() string detName = gVisualisationGroupName[det]; LOG(info) << detName; - if (settings.GetValue((detName + ".draw").c_str(), false)) { - if (detName == "TPC" || detName == "MCH" || detName == "MID" || detName == "MFT") { // don't load MUON+MFT and AD and standard TPC to R-Phi view - - multiView->drawGeometryForDetector(detName, true, false); - } else if (detName == "RPH") { // special TPC geom from R-Phi view - - multiView->drawGeometryForDetector(detName, false, true, false); - } else { // default - if (detName != "TST") { - multiView->drawGeometryForDetector(detName); - } - } + if (detName == "TPC" || detName == "MCH" || detName == "MID" || detName == "MFT") { // don't load MUON+MFT and AD and standard TPC to R-Phi view + multiView->drawGeometryForDetector(detName, true, false); + } else if (detName == "RPH") { // special TPC geom from R-Phi view + multiView->drawGeometryForDetector(detName, false, true, false); + } else if (detName != "TST") { // default + multiView->drawGeometryForDetector(detName); + } + + const auto geom = multiView->getDetectorGeometry(detName); + const auto show = settings.GetValue((detName + ".draw").c_str(), false); + + if (geom != nullptr) { + geom->SetRnrSelfChildren(show, show); } } } diff --git a/EventVisualisation/View/src/MultiView.cxx b/EventVisualisation/View/src/MultiView.cxx index 1242aee3ae79d..990bde842b17c 100644 --- a/EventVisualisation/View/src/MultiView.cxx +++ b/EventVisualisation/View/src/MultiView.cxx @@ -77,8 +77,8 @@ MultiView::MultiView() mProjections[ProjectionRphi]->SetProjection(TEveProjection::kPT_RPhi); mProjections[ProjectionZrho]->SetProjection(TEveProjection::kPT_RhoZ); - gEve->AddToListTree(static_cast(mProjections[ProjectionRphi]), false); - gEve->AddToListTree(static_cast(mProjections[ProjectionZrho]), false); + // open scenes + gEve->GetScenes()->FindListTreeItem(gEve->GetListTree())->SetOpen(true); // add axes TEnv settings;