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

added functionality to ETC #161

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions documentation/api/event_tree.event_tree_collection.md
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ Returns None if the provided ID is a root of any of the trees in ETC.

---

<a href="../../th2_data_services/event_tree/event_tree_collection.py#L737"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../../th2_data_services/event_tree/event_tree_collection.py#L767"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `get_parentless_tree_collection`

Expand Down Expand Up @@ -656,7 +656,7 @@ Loads missed events and finish tree building.

**Args:**

- <b>`preprocessor`</b>: the function that will be executed for each recovered event before store.
- <b>`preprocessor`</b>: the function that will be executed for each recovered event before store.

---

Expand Down
71 changes: 71 additions & 0 deletions tests/test_TH_4085.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
"""
The data tested on looks as follows:

a2321a5b-f883-11ec-8225-52540095fac0
--a261010a-f883-11ec-8c42-52540095fac0
----bd118950-f883-11ec-bb81-b900dc34ec7b
------bdbae8c1-f883-11ec-bb81-b900dc34ec7b
"""
WARNINGNAME = "PROBLEM CASE"

# TODO
# Remake to work with new version of ETC

# data_source = HTTPProvider5DataSource("http://10.100.66.114:31787/")
#
# events: Data = data_source.command(
# commands.GetEventsById(['30491fae-f885-11ec-bf0f-bd5660c0cda6',
# '4c118cfc-f885-11ec-bf0f-bd5660c0cda6'])
# )
#
#
# def testcase1():
# '''
# Case 1
# 2nd and 4th generation in data present
# Warning case
# '''
# events: Data = data_source.command(
# commands.GetEventsById(['a261010a-f883-11ec-8c42-52540095fac0',
# 'bdbae8c1-f883-11ec-bb81-b900dc34ec7b'])
# )
#
# with warnings.catch_warnings(record=True) as w:
# ETC = EventsTreeCollectionProvider5(events, data_source=data_source)
#
# assert [warning for warning in w if str(warning.message) == WARNINGNAME]
#
#
# def testcase2():
# '''
# Case 2
# 3nd and 4th generation in data present
# Not a warning case
# '''
# events: Data = data_source.command(
# commands.GetEventsById(['bd118950-f883-11ec-bb81-b900dc34ec7b',
# 'bdbae8c1-f883-11ec-bb81-b900dc34ec7b'])
# )
#
# with warnings.catch_warnings(record=True) as w:
# ETC = EventsTreeCollectionProvider5(events, data_source=data_source)
#
# assert [warning for warning in w if
# str(warning.message) == WARNINGNAME] == []
#
#
# def testcase3():
# '''
# Case 3
# root and 4th generation in data present
# Warning case
# '''
# events: Data = data_source.command(
# commands.GetEventsById(['a2321a5b-f883-11ec-8225-52540095fac0',
# 'bdbae8c1-f883-11ec-bb81-b900dc34ec7b'])
# )
#
# with warnings.catch_warnings(record=True) as w:
# ETC = EventsTreeCollectionProvider5(events, data_source=data_source)
#
# assert [warning for warning in w if str(warning.message) == WARNINGNAME]
38 changes: 34 additions & 4 deletions th2_data_services/event_tree/event_tree_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -709,29 +709,59 @@ def recover_unknown_events(self, preprocessor=None) -> None:
"""Loads missed events and finish tree building.

Args:
preprocessor: the function that will be executed for each recovered event before store.
preprocessor: the function that will be executed for each recovered
event before store.

"""
previous_detached_events = list(self._detached_parent_ids())

warning_4085 = False
original_roots_ids = set(self.get_roots_ids())
# FIXME
# original_detached = self._detached_events().copy()

while previous_detached_events:
events = self._driver.get_events_by_id_from_source(ids=self._detached_parent_ids())
if preprocessor is not None:
events = preprocessor(events)

for event in events:
if not self._driver.get_event_name(event) == self._driver.stub_event_name():
parentEventId = self._driver.get_parent_event_id(event)
# FIXME
# if parentEventId in original_roots_ids:
# warning_4085 = True
# for detached in original_detached:
# if original_detached[detached][0]["eventId"] == parentEventId:
# warning_4085 = True
self.append_event(event)

dp_ids = list(self._detached_parent_ids())
if previous_detached_events == dp_ids:
# If previous_detached_events == current, it means that we cannot recover some data.
# So break iteration to escape recursive exception.
w = (
"previous_detached_events == dp_ids. "
"It means that we cannot recover some data. "
"So break iteration to escape recursive exception."
)
warnings.warn(w)
break
else:
previous_detached_events = dp_ids

if self._detached_nodes:
w = "The collection were built with detached events because there are no some events in the source"
w = (
"The collection were built with detached events because there "
"are no some events in the source"
)
warnings.warn(w)

if warning_4085:
w = (
"Data stream has L0 and L2 events but not L1.\n"
"If the data stream has L0 and L2 it also should has L1.1 "
"because it exists between L0 and L2.\n"
"Possible reason: L1.1 is excluded by filter."
)
warnings.warn(w)

def get_parentless_tree_collection(self) -> "EventTreeCollection":
Expand Down
Loading