Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bulk generation of screenshots #10706

Merged
merged 2 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class DataSource
void operator=(DataSource const&) = delete;

virtual std::vector<std::pair<VisualisationEvent, EVisualisationGroup>> getVisualisationList(int no, float minTime, float maxTime, float range) = 0;
virtual void rollToNext(){};
virtual bool rollToNext() { return false; };
virtual void changeDataFolder(std::string /*newFolder*/){};
virtual void saveCurrentEvent(std::string /*targetFolder*/){};
virtual int getRunNumber() const { return 0; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class DataSourceOnline : public DataSource
bool refresh() override; // recompute

std::vector<std::pair<VisualisationEvent, EVisualisationGroup>> getVisualisationList(int no, float minTime, float maxTime, float range) override;
void rollToNext() override { mFileWatcher.rollToNext(); };
bool rollToNext() override { return mFileWatcher.rollToNext(); };
void changeDataFolder(std::string newFolder) override { mFileWatcher.changeFolder(newFolder); };
void saveCurrentEvent(std::string targetFolder) override { mFileWatcher.saveCurrentFileToFolder(targetFolder); };
int getRunNumber() const override { return this->mRunNumber; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class FileWatcher
void setLast();
void setNext();
void setPrev();
void rollToNext(); ///< round robin next item
bool rollToNext(); ///< round robin next item, returns True if restart from beginning happened
bool refresh(); ///< reads folder content, updates current if points to not existing file
std::string currentItem() const; ///< name of the file (without path) but guards replaced with file names
void setCurrentItem(int no); ///< sets using index
Expand Down
6 changes: 4 additions & 2 deletions EventVisualisation/Base/src/FileWatcher.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,18 @@ string FileWatcher::currentItem() const
return this->mCurrentFile;
}

void FileWatcher::rollToNext()
bool FileWatcher::rollToNext()
{
if (this->mFiles.size() == 2) { // only guards on the list
return; // nothing to do
return true; // nothing to do, but means we stay at the beginning
}
this->setNext();
if (this->mCurrentFile == mEndGuard) {
this->setFirst();
this->setNext();
return true; // we stay at the beginning
}
return false;
}

void FileWatcher::setFirst()
Expand Down
1 change: 1 addition & 0 deletions EventVisualisation/DataConverter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ o2_add_library(EventVisualisationDataConverter
src/VisualisationEventSerializer.cxx
src/VisualisationEventJSONSerializer.cxx
src/VisualisationEventROOTSerializer.cxx
src/Statistic.cxx
PUBLIC_LINK_LIBRARIES RapidJSON::RapidJSON
O2::ReconstructionDataFormats
O2::DataFormatsParameters
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// 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_STATISTIC_H
#define O2EVE_STATISTIC_H

#include <string>
#include "ReconstructionDataFormats/GlobalTrackID.h"
#include "rapidjson/document.h"

namespace o2
{
namespace event_visualisation
{
class VisualisationEvent;

const std::string gDetectorSources[o2::dataformats::GlobalTrackID::NSources] = {
"ITS", // standalone detectors
"TPC",
"TRD",
"TOF",
"PHS", // FIXME Not sure PHS ... FDD should be kept here, at the moment
"CPV", // they are here for completeness
"EMC",
"HMP",
"MFT",
"MCH",
"MID",
"ZDC",
"FT0",
"FV0",
"FDD",
"ITSTPC", // 2-detector tracks
"TPCTOF",
"TPCTRD",
"MFTMCH",
"ITSTPCTRD", // 3-detector tracks
"ITSTPCTOF",
"TPCTRDTOF",
"MFTMCHMID",
"ITSTPCTRDTOF", // full barrel track
"ITSAB", // ITS AfterBurner tracklets
"CTP",
//
"MCHMID"};

class Statistic
{
public:
rapidjson::Document tree;
rapidjson::Document::AllocatorType* allocator;

Statistic();
void save(std::string fileName);

void toFile(const VisualisationEvent::Statistic& statistic);
};

} // namespace event_visualisation
} // namespace o2

#endif // O2EVE_STATISTIC_H
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ class VisualisationEvent
VisualisationEvent();
VisualisationEvent(const VisualisationEvent& source, EVisualisationGroup filter, float minTime, float maxTime);

struct Statistic {
int mTrackCount[o2::dataformats::GlobalTrackID::NSources];
};
void computeStatistic();
static const Statistic& getStatistic() { return mLastStatistic; }

/// constructor parametrisation (Value Object) for VisualisationEvent class
///
/// Simplifies passing parameters to constructor of VisualisationEvent
Expand Down Expand Up @@ -200,6 +206,7 @@ class VisualisationEvent
void setPrimaryVertex(std::size_t pv) { this->mPrimaryVertex = pv; }

private:
static Statistic mLastStatistic; /// last
int mClMask; /// clusters requested during aquisition
int mTrkMask; /// tracks requested during aquisition
o2::header::DataHeader::RunNumberType mRunNumber; /// run number
Expand Down
62 changes: 62 additions & 0 deletions EventVisualisation/DataConverter/src/Statistic.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// 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 Statistic.cxx
/// \brief JSON statistic serialization
/// \author [email protected]

#include "EventVisualisationDataConverter/VisualisationEvent.h"
#include "EventVisualisationDataConverter/Statistic.h"
#include <fairlogger/Logger.h>
#include <iostream>
#include <iomanip>
#include <limits>

#include "rapidjson/document.h"
#include "rapidjson/writer.h"
#include "rapidjson/prettywriter.h"
#include "rapidjson/stringbuffer.h"
#include "EventVisualisationDataConverter/VisualisationEventJSONSerializer.h"
#include <fairlogger/Logger.h>

using namespace rapidjson;

namespace o2::event_visualisation
{

Statistic::Statistic() : tree(rapidjson::kObjectType)
{
allocator = &tree.GetAllocator();
}
void Statistic::save(std::string fileName)
{
// stringify
rapidjson::StringBuffer buffer;
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buffer);
tree.Accept(writer);
std::string json = std::string(buffer.GetString(), buffer.GetSize());

std::ofstream out(fileName);
out << json;
out.close();
}

void Statistic::toFile(const VisualisationEvent::Statistic& statistic)
{
Value trackCount(kObjectType);
for (int v = 0; v < o2::dataformats::GlobalTrackID::NSources; v++) {
rapidjson::Value key(gDetectorSources[v].c_str(), gDetectorSources[v].length(), *allocator);
trackCount.AddMember(key, rapidjson::Value().SetInt(statistic.mTrackCount[v]), *allocator);
}
tree.AddMember("trackCounts", trackCount, *allocator);
}
} // namespace o2::event_visualisation
12 changes: 12 additions & 0 deletions EventVisualisation/DataConverter/src/VisualisationEvent.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,16 @@ void VisualisationEvent::afterLoading()
}
}

VisualisationEvent::Statistic VisualisationEvent::mLastStatistic;

void VisualisationEvent::computeStatistic()
{
for (int i = 0; i < o2::dataformats::GlobalTrackID::NSources; i++) {
mLastStatistic.mTrackCount[i] = 0;
}
for (auto track : this->getTracksSpan()) {
mLastStatistic.mTrackCount[track.getSource()]++;
}
}

} // namespace o2
1 change: 1 addition & 0 deletions EventVisualisation/Detectors/src/DataReaderJSON.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ VisualisationEvent DataReaderJSON::getEvent(std::string fileName)
VisualisationEvent vEvent;
auto serializer = VisualisationEventSerializer::getInstance(std::filesystem::path(fileName).extension());
serializer->fromFile(vEvent, fileName);
vEvent.computeStatistic();
return vEvent;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class EventManager final : public TEveEventManager, public TQObject
bool mShowDate = true;
bool getShowDate() const { return mShowDate; }
void setShowDate(bool value) { this->mShowDate = value; }
void createVisualisationSettings(rapidjson::Document& tree, rapidjson::Document::AllocatorType& allocator);

private:
struct VizSettings {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class EventManagerFrame : public TGMainFrame
TGNumberEntryField*& minEntry, const TString& minToolTip,
TGNumberEntryField*& maxEntry, const TString& maxToolTip);
void createOutreachScreenshot();
void createManualScreenshot();

protected:
o2::event_visualisation::EventManager* mEventManager; // Model object.
Expand All @@ -94,7 +95,7 @@ class EventManagerFrame : public TGMainFrame

void setRunMode(EventManagerFrame::RunMode runMode, Bool_t emit = kTRUE);

EventManagerFrame(o2::event_visualisation::EventManager& eventManager);
EventManagerFrame(o2::event_visualisation::EventManager& eventManager, EventManagerFrame::DisplayMode displayMode);
~EventManagerFrame() override;
ClassDefOverride(EventManagerFrame, 0); // GUI window for AliEveEventManager.

Expand Down Expand Up @@ -123,7 +124,7 @@ class EventManagerFrame : public TGMainFrame
void DoTimeFrameSliderChanged();

public: // static functions
static TString getSourceDirectory(EventManagerFrame::RunMode runMode);
static TString getSourceDirectory(EventManagerFrame::RunMode runMode, EventManagerFrame::DisplayMode displayMode);
static RunMode decipherRunMode(TString name, RunMode defaultRun = SyntheticRun);
static TString getRunTypeString(EventManagerFrame::RunMode runMode);
};
Expand Down
22 changes: 13 additions & 9 deletions EventVisualisation/View/include/EventVisualisationView/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class Options
std::string mImageFolder; // -i './'
long mMemoryLimit; // -m 1500 (MB) = 1.5GB
bool mHideDplGUI; // -hg
bool mGenerateScreenshots; // -gs
bool mSequential;
std::string mAODConverterPath; // -a 'o2-eve-aodconverter'

// helper methods
Expand All @@ -49,15 +51,17 @@ class Options
bool processCommandLine(int argc, char* argv[]);

// get access methods
bool json() { return this->mJSON; }
bool online() { return this->mOnline; }
std::string dataFolder() { return this->mDataFolder; }
std::string imageFolder() { return this->mImageFolder; }
std::string savedDataFolder() { return this->mSavedDataFolder; }
std::string fileName() { return this->mFileName; }
bool randomTracks() { return this->mRandomTracks; }
long memoryLimit() { return this->mMemoryLimit; }
bool hideDplGUI() { return this->mHideDplGUI; }
bool sequential() const { return this->mSequential; }
bool json() const { return this->mJSON; }
bool online() const { return this->mOnline; }
std::string dataFolder() const { return this->mDataFolder; }
std::string imageFolder() const { return this->mImageFolder; }
std::string savedDataFolder() const { return this->mSavedDataFolder; }
std::string fileName() const { return this->mFileName; }
bool randomTracks() const { return this->mRandomTracks; }
long memoryLimit() const { return this->mMemoryLimit; }
bool hideDplGUI() const { return this->mHideDplGUI; }
bool generateScreenshots() const { return this->mGenerateScreenshots; }
std::string AODConverterPath() { return this->mAODConverterPath; }
};

Expand Down
34 changes: 19 additions & 15 deletions EventVisualisation/View/src/EventManager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,25 @@ void EventManager::displayCalorimeters(VisualisationEvent& event, const std::str
}

void EventManager::saveVisualisationSettings()
{
ofstream settings(TEMP_SETTINGS_PATH);

if (settings.good()) {
Document d;
d.SetObject();
auto& allocator = d.GetAllocator();

createVisualisationSettings(d, allocator);

StringBuffer strbuf;
Writer<StringBuffer> writer(strbuf);
d.Accept(writer);

settings << strbuf.GetString();
}
}

void EventManager::createVisualisationSettings(rapidjson::Document& d, rapidjson::Document::AllocatorType& allocator)
{
const auto& tracks = *dataTypeLists[EVisualisationDataType::Tracks];

Expand Down Expand Up @@ -401,13 +420,6 @@ void EventManager::saveVisualisationSettings()
}
}

ofstream settings(TEMP_SETTINGS_PATH);

if (settings.good()) {
Document d;
d.SetObject();
auto& allocator = d.GetAllocator();

auto jsonArray = [](const auto& array, auto& allocator) {
Value arr(kArrayType);

Expand Down Expand Up @@ -443,20 +455,12 @@ void EventManager::saveVisualisationSettings()
} else if (camera.IsPerspective()) {
obj.AddMember("fov", dynamic_cast<TGLPerspectiveCamera&>(camera).GetFOV(), allocator);
}

return obj;
};

d.AddMember("camera3d", jsonCamera(MultiView::View3d, allocator), allocator);
d.AddMember("cameraRphi", jsonCamera(MultiView::ViewRphi, allocator), allocator);
d.AddMember("cameraZY", jsonCamera(MultiView::ViewZY, allocator), allocator);

StringBuffer strbuf;
Writer<StringBuffer> writer(strbuf);
d.Accept(writer);

settings << strbuf.GetString();
}
}

void EventManager::restoreVisualisationSettings()
Expand Down
Loading