52 using namespace EVENTSLIB;
58 constexpr
static int invalidID(0);
59 static std::string defaultGroupName(
"Default");
64 : m_iEventIdCounter(invalidID)
65 , m_iGroupIdCounter(invalidID)
66 , m_bDefaultGroupNotCreated(true)
67 , m_DefaultGroupId(invalidID)
70 m_pSharedMemManager = std::make_unique<EVENTSINTERNAL::EventSharedMemManager>(
this);
78 auto eventInt = findEventINT(eventId);
79 if(eventInt != m_EventsListBySample.end())
81 return Event(eventInt->second);
88 std::multimap<int, EVENTSINTERNAL::EventINT>::const_iterator EventManager::findEventINT(idNum eventId)
const
90 int sample = m_MapIdToSample.at(eventId);
91 auto eventsRange = m_EventsListBySample.equal_range(sample);
92 for(
auto e = eventsRange.first; e != eventsRange.second; ++e)
94 if( e->second.getId() == eventId)
99 return m_EventsListBySample.end();
104 std::unique_ptr<std::vector<Event> >
107 auto pEventsList(allocateOutputContainer<Event>(eventIds.size()));
108 for (
const auto&
id: eventIds)
111 if(event.id != invalidID)
113 pEventsList->push_back(event);
123 auto pEventsList(allocateOutputContainer<Event>(
getNumEvents()));
124 for(
auto& e: m_EventsListBySample)
126 pEventsList->emplace_back(
Event(e.second));
135 size_t numEventsInSample = m_EventsListBySample.count(sample);
136 auto pEventsList(allocateOutputContainer<Event>(numEventsInSample));
138 auto eventsRange = m_EventsListBySample.equal_range(sample);
139 for(
auto e = eventsRange.first; e != eventsRange.second; e++)
141 pEventsList->emplace_back(
Event(e->second));
148 std::unique_ptr<std::vector<Event> >
151 int memoryHint = ((sampleEnd-sampleStart)/1000)+2;
152 auto pEventsList(allocateOutputContainer<Event>(memoryHint));
154 auto eventStart = m_EventsListBySample.lower_bound(sampleStart);
155 auto eventEnd = m_EventsListBySample.upper_bound(sampleEnd);
157 for(
auto e = eventStart; e != eventEnd; e++)
159 pEventsList->emplace_back(
Event(e->second));
166 std::unique_ptr<std::vector<Event> >
169 int memoryHint = ((sampleEnd-sampleStart)/1000)+2;
170 auto pEventsList(allocateOutputContainer<Event>(memoryHint));
172 auto eventStart = m_EventsListBySample.lower_bound(sampleStart);
173 auto eventEnd = m_EventsListBySample.upper_bound(sampleEnd);
175 for(
auto e = eventStart; e != eventEnd; e++)
177 if(e->second.getGroupId() == groupId)
179 pEventsList->emplace_back(
Event(e->second));
187 std::unique_ptr<std::vector<Event> >
190 int memoryHint = (sampleEnd-sampleStart)/200;
191 auto pEventsList(allocateOutputContainer<Event>(memoryHint));
193 auto eventStart = m_EventsListBySample.lower_bound(sampleStart);
194 auto eventEnd = m_EventsListBySample.upper_bound(sampleEnd);
196 for(
auto e = eventStart; e != eventEnd; e++)
198 for(
auto& groupId: groupIdsList)
200 if(e->second.getGroupId() == groupId)
202 pEventsList->emplace_back(
Event(e->second));
211 std::unique_ptr<std::vector<Event> >
214 auto pEventsList(allocateOutputContainer<Event>());
216 for(
const auto& e: m_EventsListBySample)
218 if(e.second.getGroupId() == groupId)
220 pEventsList->emplace_back(
Event(e.second));
230 auto pEventsList(allocateOutputContainer<Event>());
232 for(
const auto& e: m_EventsListBySample)
234 for (
const auto groupId : groupIdsList)
236 if(e.second.getGroupId() == groupId)
238 pEventsList->emplace_back(
Event(e.second));
249 idNum EventManager::generateNewEventId()
251 return ++m_iEventIdCounter;
256 idNum EventManager::generateNewGroupId()
258 return ++m_iGroupIdCounter;
265 return m_EventsListBySample.size();
273 insertEvent(newEvent);
276 if(m_pSharedMemManager->isInit())
278 qDebug() <<
"Sending event to SM: Sample: " << sample;
279 m_pSharedMemManager->addEvent(newEvent.
getSample());
282 return Event(newEvent);
289 createDefaultGroupIfNeeded();
290 return addEvent(sample, m_DefaultGroupId);
298 auto event = findEventINT(eventId);
299 if(event != m_EventsListBySample.end())
304 insertEvent(newEvent);
314 bool eventFound(
false);
315 eventFound = eraseEvent(eventId);
319 if(eventFound && m_pSharedMemManager->isInit())
321 m_pSharedMemManager->deleteEvent(m_MapIdToSample.at(eventId));
329 bool EventManager::eraseEvent(idNum eventId)
331 auto event = findEventINT(eventId);
332 if(event != m_EventsListBySample.end())
334 m_EventsListBySample.erase(event);
335 m_MapIdToSample.erase(eventId);
345 bool status(eventIds.size());
346 for(
const auto&
id: eventIds)
357 bool status(eventIds->size());
358 for(
auto& e: *eventIds){
368 std::vector<idNum> idList;
369 for(
auto& e: m_EventsListBySample)
371 if(e.second.getGroupId() == groupId)
373 idList.emplace_back(e.second.getId());
383 m_EventsListBySample.emplace(std::make_pair(e.
getSample(),e));
391 return (
int)(m_GroupsList.size());
398 auto groupFound = m_GroupsList.find(groupId);
399 if(groupFound != m_GroupsList.end())
412 size_t numGroups(m_GroupsList.size());
413 auto pGroupsList(allocateOutputContainer<EventGroup>(numGroups));
414 for(
const auto& g: m_GroupsList)
416 pGroupsList->emplace_back(
EventGroup(g.second));
423 std::unique_ptr<std::vector<EventGroup> >
426 auto pGroupList(allocateOutputContainer<EventGroup>(groupIds.size()));
427 for(
const auto&
id: groupIds)
430 if (group.id != invalidID)
432 pGroupList->push_back(group);
443 m_GroupsList.emplace(newGroup.
getId(), newGroup);
452 m_GroupsList.emplace(newGroup.
getId(), newGroup);
464 auto groupToDeleteIter = m_GroupsList.find(groupId);
465 if(groupToDeleteIter != m_GroupsList.end())
467 m_GroupsList.erase(groupToDeleteIter);
469 if(!m_bDefaultGroupNotCreated && (groupId == m_DefaultGroupId))
471 m_bDefaultGroupNotCreated =
true;
472 m_DefaultGroupId = invalidID;
483 bool out(groupIds.size());
484 for(
auto g: groupIds)
495 auto group = m_GroupsList.find(groupId);
496 if(group != m_GroupsList.end())
498 group->second.setName(newName);
506 auto group = m_GroupsList.find(groupId);
507 if( group != m_GroupsList.end())
509 group->second.setColor(color);
520 for(
const auto& ev: *eventsAll)
522 for(
auto g: groupIds)
540 for(
const auto& e: *eventsToDuplicate)
553 if(m_MapIdToSample.count(eventId))
555 sample = m_MapIdToSample.at(eventId);
556 auto eventsRange = m_EventsListBySample.equal_range(sample);
557 std::multimap<int, EVENTSINTERNAL::EventINT>::iterator e = eventsRange.first;
558 for(; e != eventsRange.second; ++e)
560 if( e->second.getId() == eventId)
576 for( idNum
id: eventIds)
597 m_pSharedMemManager->init(mode);
606 m_pSharedMemManager->stop();
615 return m_pSharedMemManager->isInit();
620 void EventManager::createDefaultGroupIfNeeded()
622 if(m_bDefaultGroupNotCreated)
625 m_bDefaultGroupNotCreated =
false;
626 m_DefaultGroupId = defaultGroup.id;