Skip to content

Commit 2c225ce

Browse files
julekmshahor02
authored andcommitted
implementation of active watching folder for files with tracks
1 parent 7f043b3 commit 2c225ce

18 files changed

Lines changed: 562 additions & 88 deletions

EventVisualisation/Base/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ o2_add_library(EventVisualisationBase
1313
src/DataInterpreter.cxx
1414
src/DataReader.cxx
1515
src/DataSourceOffline.cxx
16+
src/DataSourceOnline.cxx
1617
src/GeometryManager.cxx
18+
src/FileWatcher.cxx
1719
PUBLIC_LINK_LIBRARIES ROOT::Eve
1820
O2::CCDB
1921
O2::EventVisualisationDataConverter
20-
O2::DetectorsBase
21-
22+
O2::DetectorsBase
2223
)

EventVisualisation/Base/include/EventVisualisationBase/DataSource.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
#define ALICE_O2_EVENTVISUALISATION_BASE_DATASOURCE_H
1818

1919
#include <EventVisualisationBase/VisualisationConstants.h>
20+
#include <EventVisualisationBase/DataReader.h>
2021
#include <EventVisualisationDataConverter/VisualisationEvent.h>
22+
#include <utility>
2123

2224
class TObject;
2325

@@ -29,9 +31,10 @@ namespace event_visualisation
2931
class DataSource
3032
{
3133
public:
32-
virtual VisualisationEvent getEventData(int /*no*/, EVisualisationGroup /*purpose*/, EVisualisationDataType dataType) = 0;
33-
virtual int GetEventCount() { return 0; };
34-
34+
virtual Int_t getCurrentEvent() { return 0; };
35+
virtual void setCurrentEvent(Int_t /*currentEvent*/){};
36+
virtual int getEventCount() { return 0; };
37+
virtual bool refresh() { return false; }; // recompute
3538
DataSource() = default;
3639

3740
/// Default destructor
@@ -42,6 +45,9 @@ class DataSource
4245

4346
/// Deleted assignemt operator
4447
void operator=(DataSource const&) = delete;
48+
49+
virtual std::vector<std::pair<VisualisationEvent, std::string>> getVisualisationList(int no) = 0;
50+
virtual void registerDetector(DataReader* /*reader*/, EVisualisationGroup /*type*/){};
4551
};
4652

4753
} // namespace event_visualisation

EventVisualisation/Base/include/EventVisualisationBase/DataSourceOffline.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,26 @@ namespace event_visualisation
2929
class DataSourceOffline : public DataSource
3030
{
3131
protected:
32-
static DataReader* instance[EVisualisationGroup::NvisualisationGroups];
32+
Int_t mCurrentEvent = 0;
33+
DataReader* mDataReaders[EVisualisationGroup::NvisualisationGroups];
34+
VisualisationEvent getEventData(int no, EVisualisationGroup purpose, EVisualisationDataType dataType);
3335

3436
public:
35-
DataSourceOffline() = default;
37+
DataSourceOffline();
3638

3739
~DataSourceOffline() override = default;
3840
DataSourceOffline(DataSourceOffline const&) = delete;
41+
void setCurrentEvent(Int_t currentEvent) override;
42+
Int_t getCurrentEvent() override;
3943

4044
/// Deleted assigment operator
4145
void operator=(DataSourceOffline const&) = delete;
4246

43-
int GetEventCount() override;
47+
int getEventCount() override;
4448

45-
void registerReader(DataReader* reader, EVisualisationGroup purpose)
46-
{
47-
instance[purpose] = reader;
48-
}
49+
void registerReader(DataReader* reader, EVisualisationGroup type);
4950

50-
VisualisationEvent getEventData(int no, EVisualisationGroup purpose, EVisualisationDataType dataType) override;
51+
std::vector<std::pair<VisualisationEvent, std::string>> getVisualisationList(int no) override;
5152
};
5253

5354
} // namespace event_visualisation
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
/// \file DataSourceOnline.h
12+
/// \brief Grouping reading from file(s)
13+
/// \author julian.myrcha@cern.ch
14+
15+
#ifndef O2EVE_DATASOURCEONLINE_H
16+
#define O2EVE_DATASOURCEONLINE_H
17+
18+
#include <EventVisualisationBase/DataSource.h>
19+
#include <EventVisualisationBase/DataReader.h>
20+
#include <EventVisualisationBase/FileWatcher.h>
21+
22+
class TObject;
23+
24+
namespace o2
25+
{
26+
namespace event_visualisation
27+
{
28+
29+
class DataSourceOnline : public DataSource
30+
{
31+
protected:
32+
FileWatcher mFileWatcher;
33+
34+
public:
35+
DataSourceOnline(const std::string path);
36+
37+
~DataSourceOnline() override = default;
38+
DataSourceOnline(DataSourceOnline const&) = delete;
39+
40+
/// Deleted assigment operator
41+
void operator=(DataSourceOnline const&) = delete;
42+
43+
int getEventCount() override;
44+
void setCurrentEvent(Int_t currentEvent) override;
45+
Int_t getCurrentEvent() override;
46+
47+
bool refresh() override; // recompute
48+
49+
std::vector<std::pair<VisualisationEvent, std::string>> getVisualisationList(int no) override;
50+
};
51+
52+
} // namespace event_visualisation
53+
} // namespace o2
54+
55+
#endif //O2EVE_DATASOURCEONLINE_H
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
/// \file FileWatcher.h
12+
/// \brief Observing folder for created and removed files - preserving current
13+
/// \author julian.myrcha@cern.ch
14+
15+
#ifndef WATCHER_FILEWATCHER_H
16+
#define WATCHER_FILEWATCHER_H
17+
18+
#include <string>
19+
#include <deque>
20+
21+
namespace o2
22+
{
23+
namespace event_visualisation
24+
{
25+
26+
class FileWatcher
27+
{
28+
static const char* mLowGuard; ///< "artificial" file name meaning "on the first" (guard)
29+
static const char* mEndGard; ///< "artificial" file name meaning "on the last" (guard)
30+
std::deque<std::string> mFiles; ///< sorted file list with guards at the beginning and end
31+
std::string nextItem(const std::string& item) const;
32+
std::string prevItem(const std::string& item) const;
33+
static std::deque<std::string> load(const std::string path);
34+
std::string mDataFolder; ///< folder being observed
35+
std::string mCurrentFile; ///< "current" file name
36+
bool currentFileExist();
37+
38+
public:
39+
FileWatcher(const std::string& path);
40+
int getSize() const; ///< include guards (so >=2 )
41+
int getPos() const; ///< include guards -> 0 points to mLowGuard
42+
void setFirst();
43+
void setLast();
44+
void setNext();
45+
void setPrev();
46+
bool refresh(); ///< reads folder content, updates current if points to not existing file
47+
std::string currentItem() const; ///< name of the file (without path) but guards replaced with file names
48+
void setCurrentItem(int no); ///< sets using index
49+
std::string currentFilePath() const; ///< name of the file (with path) but guards replaced with file names
50+
};
51+
52+
} // namespace event_visualisation
53+
} // namespace o2
54+
55+
#endif //WATCHER_FILEWATCHER_H

EventVisualisation/Base/src/DataSourceOffline.cxx

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,35 +28,79 @@
2828
#include <TVector3.h>
2929
#include <TObject.h>
3030

31+
#define elemof(e) (unsigned int)(sizeof(e) / sizeof(e[0]))
32+
3133
namespace o2
3234
{
3335
namespace event_visualisation
3436
{
3537

36-
DataReader* DataSourceOffline::instance[EVisualisationGroup::NvisualisationGroups];
37-
3838
VisualisationEvent DataSourceOffline::getEventData(int no, EVisualisationGroup purpose, EVisualisationDataType dataType)
3939
{
40-
if (instance[purpose] == nullptr) {
40+
if (mDataReaders[purpose] == nullptr) {
4141
return VisualisationEvent({.eventNumber = -1,
4242
.runNumber = -1,
4343
.energy = -1,
4444
.multiplicity = -1,
4545
.collidingSystem = "",
4646
.timeStamp = 0});
4747
}
48-
return instance[purpose]->getEvent(no, dataType);
48+
return mDataReaders[purpose]->getEvent(no, dataType);
4949
}
5050

51-
int DataSourceOffline::GetEventCount()
51+
int DataSourceOffline::getEventCount()
5252
{
5353
for (int i = 0; i < EVisualisationGroup::NvisualisationGroups; i++) {
54-
if (instance[i] != nullptr) {
55-
return instance[i]->GetEventCount();
54+
if (mDataReaders[i] != nullptr) {
55+
return mDataReaders[i]->GetEventCount();
5656
}
5757
}
5858
return 1;
5959
};
6060

61+
void DataSourceOffline::setCurrentEvent(Int_t currentEvent)
62+
{
63+
this->mCurrentEvent = currentEvent;
64+
}
65+
66+
std::vector<std::pair<VisualisationEvent, std::string>> DataSourceOffline::getVisualisationList(int no)
67+
{
68+
std::vector<std::pair<VisualisationEvent, std::string>> res;
69+
for (int i = 0; i < EVisualisationGroup::NvisualisationGroups; ++i) {
70+
DataReader* reader = mDataReaders[i];
71+
if (reader) {
72+
for (int dataType = 0; dataType < EVisualisationDataType::NdataTypes; ++dataType) {
73+
VisualisationEvent event = getEventData(no, (EVisualisationGroup)i, (EVisualisationDataType)dataType);
74+
res.push_back(std::make_pair(event, gVisualisationGroupName[i]));
75+
}
76+
}
77+
}
78+
79+
return res;
80+
}
81+
82+
DataSourceOffline::DataSourceOffline()
83+
{
84+
for (unsigned int i = 0; i < elemof(mDataReaders); i++) {
85+
mDataReaders[i] = nullptr;
86+
}
87+
for (int i = 0; i < EVisualisationGroup::NvisualisationGroups; i++) {
88+
if (mDataReaders[i] != nullptr) {
89+
mDataReaders[i]->open();
90+
this->registerReader(mDataReaders[i], static_cast<EVisualisationGroup>(i));
91+
}
92+
}
93+
}
94+
95+
void DataSourceOffline::registerReader(DataReader* reader, EVisualisationGroup type)
96+
{
97+
mDataReaders[type] = reader;
98+
}
99+
100+
Int_t DataSourceOffline::getCurrentEvent()
101+
{
102+
return this->mCurrentEvent;
103+
}
104+
61105
} // namespace event_visualisation
62106
} // namespace o2
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
/// \file DataSourceOnline.h
12+
/// \brief Grouping reading from file(s)
13+
/// \author julian.myrcha@cern.ch
14+
15+
#include <EventVisualisationBase/DataSourceOnline.h>
16+
17+
#include <TSystem.h>
18+
#include <TEveTreeTools.h>
19+
#include <TEveTrack.h>
20+
#include <TEveManager.h>
21+
#include <TFile.h>
22+
#include <TPRegexp.h>
23+
#include <TEveTrackPropagator.h>
24+
#include <TEveVSD.h>
25+
#include <TObject.h>
26+
27+
namespace o2
28+
{
29+
namespace event_visualisation
30+
{
31+
32+
std::vector<std::pair<VisualisationEvent, std::string>> DataSourceOnline::getVisualisationList(int no)
33+
{
34+
std::vector<std::pair<VisualisationEvent, std::string>> res;
35+
if (no < getEventCount()) {
36+
assert(no >= 0);
37+
VisualisationEvent vEvent;
38+
mFileWatcher.setCurrentItem(no);
39+
vEvent.fromFile(mFileWatcher.currentFilePath());
40+
res.push_back(std::make_pair(vEvent, gVisualisationGroupName[EVisualisationGroup::TPC]));
41+
}
42+
return res;
43+
}
44+
45+
DataSourceOnline::DataSourceOnline(const std::string path) : mFileWatcher(path)
46+
{
47+
}
48+
49+
int DataSourceOnline::getEventCount()
50+
{
51+
return this->mFileWatcher.getSize();
52+
}
53+
54+
void DataSourceOnline::setCurrentEvent(Int_t currentEvent)
55+
{
56+
this->mFileWatcher.setCurrentItem(currentEvent);
57+
}
58+
59+
bool DataSourceOnline::refresh()
60+
{
61+
return this->mFileWatcher.refresh();
62+
}
63+
64+
Int_t DataSourceOnline::getCurrentEvent()
65+
{
66+
return mFileWatcher.getPos();
67+
}
68+
69+
} // namespace event_visualisation
70+
} // namespace o2

0 commit comments

Comments
 (0)