52 using namespace EVENTSLIB;
58 constexpr
static int invalidID(0);
59 static std::string defaultGroupName(
"Default");
64 : m_pSharedMemManager(
std::make_unique<EVENTSINTERNAL::EventSharedMemManager>(this))
65 , m_iEventIdCounter(invalidID)
66 , m_iGroupIdCounter(invalidID)
67 , m_bDefaultGroupNotCreated(true)
68 , m_DefaultGroupId(invalidID)
77 auto eventInt = findEventINT(eventId);
78 if(eventInt != m_EventsListBySample.end())
80 return Event(eventInt->second);
87 std::multimap<int, EVENTSINTERNAL::EventINT>::const_iterator EventManager::findEventINT(idNum eventId)
const
89 int sample = m_MapIdToSample.at(eventId);
90 auto eventsRange = m_EventsListBySample.equal_range(sample);
91 for(
auto e = eventsRange.first; e != eventsRange.second; ++e)
93 if( e->second.getId() == eventId)
98 return m_EventsListBySample.end();
103 std::unique_ptr<std::vector<Event> >
106 auto pEventsList(allocateOutputContainer<Event>(eventIds.size()));
107 for (
const auto&
id: eventIds)
110 if(event.id != invalidID)
112 pEventsList->push_back(event);
122 auto pEventsList(allocateOutputContainer<Event>(
getNumEvents()));
123 for(
auto& e: m_EventsListBySample)
125 pEventsList->emplace_back(
Event(e.second));
134 size_t numEventsInSample = m_EventsListBySample.count(sample);
135 auto pEventsList(allocateOutputContainer<Event>(numEventsInSample));
137 auto eventsRange = m_EventsListBySample.equal_range(sample);
138 for(
auto e = eventsRange.first; e != eventsRange.second; e++)
140 pEventsList->emplace_back(
Event(e->second));
147 std::unique_ptr<std::vector<Event> >
150 int memoryHint = ((sampleEnd-sampleStart)/1000)+2;
151 auto pEventsList(allocateOutputContainer<Event>(memoryHint));
153 auto eventStart = m_EventsListBySample.lower_bound(sampleStart);
154 auto eventEnd = m_EventsListBySample.upper_bound(sampleEnd);
156 for(
auto e = eventStart; e != eventEnd; e++)
158 pEventsList->emplace_back(
Event(e->second));
165 std::unique_ptr<std::vector<Event> >
168 int memoryHint = ((sampleEnd-sampleStart)/1000)+2;
169 auto pEventsList(allocateOutputContainer<Event>(memoryHint));
171 auto eventStart = m_EventsListBySample.lower_bound(sampleStart);
172 auto eventEnd = m_EventsListBySample.upper_bound(sampleEnd);
174 for(
auto e = eventStart; e != eventEnd; e++)
176 if(e->second.getGroupId() == groupId)
178 pEventsList->emplace_back(
Event(e->second));
186 std::unique_ptr<std::vector<Event> >
189 int memoryHint = (sampleEnd-sampleStart)/200;
190 auto pEventsList(allocateOutputContainer<Event>(memoryHint));
192 auto eventStart = m_EventsListBySample.lower_bound(sampleStart);
193 auto eventEnd = m_EventsListBySample.upper_bound(sampleEnd);
195 for(
auto e = eventStart; e != eventEnd; e++)
197 for(
auto& groupId: groupIdsList)
199 if(e->second.getGroupId() == groupId)
201 pEventsList->emplace_back(
Event(e->second));
210 std::unique_ptr<std::vector<Event> >
213 auto pEventsList(allocateOutputContainer<Event>());
215 for(
const auto& e: m_EventsListBySample)
217 if(e.second.getGroupId() == groupId)
219 pEventsList->emplace_back(
Event(e.second));
229 auto pEventsList(allocateOutputContainer<Event>());
231 for(
const auto& e: m_EventsListBySample)
233 for (
const auto groupId : groupIdsList)
235 if(e.second.getGroupId() == groupId)
237 pEventsList->emplace_back(
Event(e.second));
248 idNum EventManager::generateNewEventId()
250 return ++m_iEventIdCounter;
255 idNum EventManager::generateNewGroupId()
257 return ++m_iGroupIdCounter;
264 return m_EventsListBySample.size();
272 insertEvent(newEvent);
274 if(m_pSharedMemManager->isInit())
276 qDebug() <<
"Sending event to SM: Sample: " << sample;
277 m_pSharedMemManager->addEvent(newEvent.
getSample());
280 return Event(newEvent);
287 createDefaultGroupIfNeeded();
288 return addEvent(sample, m_DefaultGroupId);
296 auto event = findEventINT(eventId);
297 if(event != m_EventsListBySample.end())
302 insertEvent(newEvent);
312 bool eventFound(
false);
313 eventFound = eraseEvent(eventId);
314 if(eventFound && m_pSharedMemManager->isInit())
316 m_pSharedMemManager->deleteEvent(m_MapIdToSample.at(eventId));
323 bool EventManager::eraseEvent(idNum eventId)
325 auto event = findEventINT(eventId);
326 if(event != m_EventsListBySample.end())
328 m_EventsListBySample.erase(event);
329 m_MapIdToSample.erase(eventId);
339 bool status(eventIds.size());
340 for(
const auto&
id: eventIds)
351 bool status(eventIds->size());
352 for(
auto e: *eventIds){
362 std::vector<idNum> idList;
363 for(
auto& e: m_EventsListBySample)
365 if(e.second.getGroupId() == groupId)
367 idList.emplace_back(e.second.getId());
377 m_EventsListBySample.emplace(std::make_pair(e.
getSample(),e));
385 return (
int)(m_GroupsList.size());
392 auto groupFound = m_GroupsList.find(groupId);
393 if(groupFound != m_GroupsList.end())
406 size_t numGroups(m_GroupsList.size());
407 auto pGroupsList(allocateOutputContainer<EventGroup>(numGroups));
408 for(
const auto& g: m_GroupsList)
410 pGroupsList->emplace_back(
EventGroup(g.second));
417 std::unique_ptr<std::vector<EventGroup> >
420 auto pGroupList(allocateOutputContainer<EventGroup>(groupIds.size()));
421 for(
const auto&
id: groupIds)
424 if (group.id != invalidID)
426 pGroupList->push_back(group);
437 m_GroupsList.emplace(newGroup.
getId(), newGroup);
446 m_GroupsList.emplace(newGroup.
getId(), newGroup);
458 auto groupToDeleteIter = m_GroupsList.find(groupId);
459 if(groupToDeleteIter != m_GroupsList.end())
461 m_GroupsList.erase(groupToDeleteIter);
463 if(!m_bDefaultGroupNotCreated && (groupId == m_DefaultGroupId))
465 m_bDefaultGroupNotCreated =
true;
466 m_DefaultGroupId = invalidID;
477 bool out(groupIds.size());
478 for(
auto g: groupIds)
489 auto group = m_GroupsList.find(groupId);
490 if(group != m_GroupsList.end())
492 group->second.setName(newName);
500 auto group = m_GroupsList.find(groupId);
501 if( group != m_GroupsList.end())
503 group->second.setColor(color);
514 for(
const auto& ev: *eventsAll)
516 for(
auto g: groupIds)
534 for(
const auto& e: *eventsToDuplicate)
547 if(m_MapIdToSample.count(eventId))
549 sample = m_MapIdToSample.at(eventId);
550 auto eventsRange = m_EventsListBySample.equal_range(sample);
551 std::multimap<int, EVENTSINTERNAL::EventINT>::iterator e = eventsRange.first;
552 for(; e != eventsRange.second; ++e)
554 if( e->second.getId() == eventId)
570 for( idNum
id: eventIds)
588 m_pSharedMemManager->init(mode);
595 m_pSharedMemManager->stop();
602 return m_pSharedMemManager->isInit();
605 void EventManager::createDefaultGroupIfNeeded()
607 if(m_bDefaultGroupNotCreated)
610 m_bDefaultGroupNotCreated =
false;
611 m_DefaultGroupId = defaultGroup.id;