TEST(podio, AutoDelete) { auto store = podio::EventStore(); auto hit1 = EventInfo(); auto hit2 = EventInfo(); auto hit3 = EventInfo(); auto& coll = store.create<EventInfoCollection>("info"); coll.push_back(hit1); hit3 = hit2; }
void GameResultProcessor::processExp(GameContext &context, GameResult &data) const { auto &uRes = context.uRes; auto &uHis = context.gHis; // if zero bet then exp will not change if (data.bFreeGame) { return; } auto &levelConfig = SlotsConfig::getInstance().levelConfig; // exp = bet; auto expGot = data.bet; uRes.incrExp(expGot); int64_t expNeed = 0; while(true) { expNeed = levelConfig.expNeedForNextLevel(uRes.level); if (expNeed < 0 || expNeed > uRes.exp ) { return; } uRes.levelUp(); // get level reward. auto reward = levelConfig.fortuneRewardForLevel(uRes.level); uRes.incrFortune(reward); uHis.newFortune(uRes.fortune); context.events.push_back(EventInfo(ECT_LEVEL, uRes.level)); } }
void ItemView::contentsMouseReleaseEvent(QMouseEvent *e) { if (!e) return; e->accept(); p_itemDocument->m_cmManager->mouseReleaseEvent(EventInfo(this, e)); }
void DInputEventQueue::pushEvent( const DJoyStickEvent& e, uint64 time ) { if (mEventInforQueue.size() < maxEventCount) { mEventInforQueue.push(EventInfo(IDT_JoyStick, time)); mJoyStickEventQueue.push(e); mEventCount++; } }
void DInputEventQueue::pushEvent( const DMouseEvent& e, uint64 time ) { if (mEventInforQueue.size() < maxEventCount) { mEventInforQueue.push(EventInfo(IDT_Mouse, time)); mMouseEventQueue.push(e); mEventCount++; } }
void DInputEventQueue::pushEvent( const DKeyEvent& e, uint64 time ) { if (mEventInforQueue.size() < maxEventCount) { mEventInforQueue.push(EventInfo(IDT_Keyboard, time)); mKeyEventQueue.push(e); mEventCount++; } }
void Emit(const EventType& event_type) const { if(!function_objects.count(event_type)) { return; } for(const auto& it : function_objects.at(event_type)) { it.second(EventInfo()); } }
void ItemView::contentsMouseDoubleClickEvent(QMouseEvent *e) { if (!e) return; e->accept(); //HACK: Pass this of as a single press event if widget underneath QCanvasItem * atTop = p_itemDocument->itemAtTop(e->pos() / zoomLevel()); if (dynamic_cast<Widget*>(atTop)) contentsMousePressEvent(e); else p_itemDocument->m_cmManager->mouseDoubleClickEvent(EventInfo(this, e)); }
void GameResultProcessor::processLines(GameContext &context, GameResult &data) const { auto &tHis = context.tHis; auto pre = tHis.maxLinkCount.val; for (auto &line: data.lines){ if (line.count == 5) { tHis.maxLinkCount += 1; } } if (pre != tHis.maxLinkCount.val) { context.events.push_back( EventInfo(ECT_SIX_LINK, pre, tHis.maxLinkCount.val)); } }
EventId Scheduler::schedulePeriodicEvent(const time::Duration& after, const time::Duration& period, const Event& event) { EventQueue::iterator i = m_events.insert(EventInfo(after, period, event)); i->m_eventId = make_shared<EventIdImpl>(boost::cref(i)); if (m_scheduledEvent == m_events.end() || *i < *m_scheduledEvent) { m_deadlineTimer.expires_from_now(after); m_deadlineTimer.async_wait(bind(&Scheduler::onEvent, this, _1)); m_scheduledEvent = i; } return i->m_eventId; }
bool GameResultProcessor::process(GameContext &context) const { auto &gInfo = context.gameInfo; processHall(context, gInfo); processGameDetail(context, gInfo); processLines(context, gInfo); // is free to play if (!gInfo.bFreeGame) { context.events.push_back(EventInfo(ECT_BET_SUM, gInfo.bet)); } else { // reduce freeGameTimes --gInfo.freeGameTimes; } // update user fortune processMoney(context, gInfo); // update user exp&level processExp(context, gInfo); // save this result to history context.preGameInfo = gInfo; return true; }
void GameResultProcessor::processMoney(GameContext &context, GameResult &data) const { auto &uHis = context.gHis; uHis.incrBet(data.bet); int64_t actualEarned = data.earned.sum() - (data.bFreeGame ? 0: data.bet); if (actualEarned == 0) { return; } UserResource &uRes = context.uRes; uRes.incrFortune(actualEarned); // update max fortune uHis.newFortune(uRes.fortune); // update max earned uHis.newEarned(data.earned.normal); // update earned (include this week and total) auto pre = uHis.totalEarned; uHis.incrEarned(data.earned.sum()); if (pre != uHis.totalEarned) { // if total earned changed, create event. context.events.push_back(EventInfo(ECT_FORTUNE_SUM, pre, uHis.totalEarned)); } }
EventId Scheduler::scheduleEvent(const time::nanoseconds& after, const Event& event) { EventQueue::iterator i = m_events.insert(EventInfo(after, event)); // On OSX 10.9, boost, and C++03 the following doesn't work without ndn:: // because the argument-dependent lookup prefers STL to boost i->m_eventId = ndn::make_shared<EventIdImpl>(i); if (!m_isEventExecuting) { if (m_scheduledEvent == m_events.end() || *i < *m_scheduledEvent) { m_deadlineTimer.expires_from_now(after); m_deadlineTimer.async_wait(bind(&Scheduler::onEvent, this, _1)); m_scheduledEvent = i; } } return i->m_eventId; }
int main(){ std::cout<<"start processing"<<std::endl; auto store = podio::EventStore(); auto writer = podio::ASCIIWriter("example.txt", &store); auto& info = store.create<EventInfoCollection>("info"); auto& mcps = store.create<ExampleMCCollection>("mcparticles"); auto& hits = store.create<ExampleHitCollection>("hits"); auto& clusters = store.create<ExampleClusterCollection>("clusters"); auto& refs = store.create<ExampleReferencingTypeCollection>("refs"); auto& refs2 = store.create<ExampleReferencingTypeCollection>("refs2"); auto& comps = store.create<ExampleWithComponentCollection>("Component"); auto& oneRels = store.create<ExampleWithOneRelationCollection>("OneRelation"); auto& vecs = store.create<ExampleWithVectorMemberCollection>("WithVectorMember"); auto& namesps = store.create<ex::ExampleWithNamespaceCollection>("WithNamespaceMember"); auto& namesprels = store.create<ex::ExampleWithARelationCollection>("WithNamespaceRelation"); auto& strings = store.create<ExampleWithStringCollection>("strings"); writer.registerForWrite<EventInfoCollection>("info"); writer.registerForWrite<ExampleMCCollection>("mcparticles"); writer.registerForWrite<ExampleHitCollection>("hits"); writer.registerForWrite<ExampleClusterCollection>("clusters"); writer.registerForWrite<ExampleReferencingTypeCollection>("refs"); writer.registerForWrite<ExampleReferencingTypeCollection>("refs2"); writer.registerForWrite<ExampleWithComponentCollection>("Component"); writer.registerForWrite<ExampleWithOneRelationCollection>("OneRelation"); writer.registerForWrite<ExampleWithVectorMemberCollection>("WithVectorMember"); writer.registerForWrite<ex::ExampleWithNamespaceCollection>("WithNamespaceMember"); writer.registerForWrite<ex::ExampleWithARelationCollection>("WithNamespaceRelation"); writer.registerForWrite<ExampleWithStringCollection>("strings"); unsigned nevents=1;//2000; for(unsigned i=0; i<nevents; ++i) { if(i % 1000 == 0) { std::cout << "processing event " << i << std::endl; } auto item1 = EventInfo(); item1.Number(i); info.push_back(item1); auto hit1 = ExampleHit(0.,0.,0.,23.+i); auto hit2 = ExampleHit(1.,0.,0.,12.+i); hits.push_back(hit1); hits.push_back(hit2); // ---- add some MC particles ---- auto mcp0 = ExampleMC(); auto mcp1 = ExampleMC(); auto mcp2 = ExampleMC(); auto mcp3 = ExampleMC(); auto mcp4 = ExampleMC(); auto mcp5 = ExampleMC(); auto mcp6 = ExampleMC(); auto mcp7 = ExampleMC(); auto mcp8 = ExampleMC(); auto mcp9 = ExampleMC(); mcps.push_back( mcp0 ) ; mcps.push_back( mcp1 ) ; mcps.push_back( mcp2 ) ; mcps.push_back( mcp3 ) ; mcps.push_back( mcp4 ) ; mcps.push_back( mcp5 ) ; mcps.push_back( mcp6 ) ; mcps.push_back( mcp7 ) ; mcps.push_back( mcp8 ) ; mcps.push_back( mcp9 ) ; // --- add some daughter relations auto p = ExampleMC(); auto d = ExampleMC(); p = mcps[0] ; p.adddaughters( mcps[2] ) ; p.adddaughters( mcps[3] ) ; p.adddaughters( mcps[4] ) ; p.adddaughters( mcps[5] ) ; p = mcps[1] ; p.adddaughters( mcps[2] ) ; p.adddaughters( mcps[3] ) ; p.adddaughters( mcps[4] ) ; p.adddaughters( mcps[5] ) ; p = mcps[2] ; p.adddaughters( mcps[6] ) ; p.adddaughters( mcps[7] ) ; p.adddaughters( mcps[8] ) ; p.adddaughters( mcps[9] ) ; p = mcps[3] ; p.adddaughters( mcps[6] ) ; p.adddaughters( mcps[7] ) ; p.adddaughters( mcps[8] ) ; p.adddaughters( mcps[9] ) ; //--- now fix the parent relations for( unsigned j=0,N=mcps.size();j<N;++j){ p = mcps[j] ; for(auto it = p.daughters_begin(), end = p.daughters_end() ; it!=end ; ++it ){ int dIndex = it->getObjectID().index ; d = mcps[ dIndex ] ; d.addparents( p ) ; } } //-------- print relations for debugging: for( auto p : mcps ){ std::cout << " particle " << p.getObjectID().index << " has daughters: " ; for(auto it = p.daughters_begin(), end = p.daughters_end() ; it!=end ; ++it ){ std::cout << " " << it->getObjectID().index ; } std::cout << " and parents: " ; for(auto it = p.parents_begin(), end = p.parents_end() ; it!=end ; ++it ){ std::cout << " " << it->getObjectID().index ; } std::cout << std::endl ; } //------------------------------- auto cluster = ExampleCluster(); auto clu0 = ExampleCluster(); auto clu1 = ExampleCluster(); clu0.addHits(hit1); clu0.energy(hit1.energy()); clu1.addHits(hit2); clu1.energy(hit2.energy()); cluster.addHits(hit1); cluster.addHits(hit2); cluster.energy(hit1.energy()+hit2.energy()); cluster.addClusters( clu0 ) ; cluster.addClusters( clu1 ) ; clusters.push_back(clu0); clusters.push_back(clu1); clusters.push_back(cluster); auto ref = ExampleReferencingType(); refs.push_back(ref); auto ref2 = ExampleReferencingType(); refs2.push_back(ref2); ref.addClusters(cluster); ref.addRefs(ref2); auto comp = ExampleWithComponent(); comp.component().data.x = 0; comp.component().data.y = 1; comp.component().data.z = i; comps.push_back(comp); auto cyclic = ExampleReferencingType(); cyclic.addRefs(cyclic); refs.push_back(cyclic); auto oneRel = ExampleWithOneRelation(); oneRel.cluster(cluster); oneRels.push_back(oneRel); // write non-filled relation auto oneRelEmpty = ExampleWithOneRelation(); oneRels.push_back(oneRelEmpty); auto vec = ExampleWithVectorMember(); vec.addcount(23); vec.addcount(24); vecs.push_back(vec); auto namesp = ex::ExampleWithNamespace(); namesp.data().x = 1; namesp.data().y = i; namesps.push_back(namesp); auto rel = ex::ExampleWithARelation(); rel.ref(namesp); namesprels.push_back(rel); auto string = ExampleWithString("SomeString"); strings.push_back(string); writer.writeEvent(); store.clearCollections(); } writer.finish(); }
void write(std::string outfilename) { std::cout<<"start processing"<<std::endl; auto store = podio::EventStore(); auto writer = podio::ROOTWriter(outfilename, &store); auto& info = store.create<EventInfoCollection>("info"); auto& mcps = store.create<ExampleMCCollection>("mcparticles"); auto& hits = store.create<ExampleHitCollection>("hits"); auto& clusters = store.create<ExampleClusterCollection>("clusters"); auto& refs = store.create<ExampleReferencingTypeCollection>("refs"); auto& refs2 = store.create<ExampleReferencingTypeCollection>("refs2"); auto& comps = store.create<ExampleWithComponentCollection>("Component"); auto& oneRels = store.create<ExampleWithOneRelationCollection>("OneRelation"); auto& vecs = store.create<ExampleWithVectorMemberCollection>("WithVectorMember"); auto& namesps = store.create<ex::ExampleWithNamespaceCollection>("WithNamespaceMember"); auto& namesprels = store.create<ex::ExampleWithARelationCollection>("WithNamespaceRelation"); auto& cpytest = store.create<ex::ExampleWithARelationCollection>("WithNamespaceRelationCopy"); auto& strings = store.create<ExampleWithStringCollection>("strings"); auto& arrays = store.create<ExampleWithArrayCollection>("arrays"); writer.registerForWrite("info"); writer.registerForWrite("mcparticles"); writer.registerForWrite("hits"); writer.registerForWrite("clusters"); writer.registerForWrite("refs"); writer.registerForWrite("refs2"); writer.registerForWrite("Component"); writer.registerForWrite("OneRelation"); writer.registerForWrite("WithVectorMember"); writer.registerForWrite("WithNamespaceMember"); writer.registerForWrite("WithNamespaceRelation"); writer.registerForWrite("WithNamespaceRelationCopy"); writer.registerForWrite("strings"); writer.registerForWrite("arrays"); unsigned nevents = 2000; for(unsigned i=0; i<nevents; ++i) { if(i % 1000 == 0) { std::cout << "processing event " << i << std::endl; } auto item1 = EventInfo(); item1.Number(i); info.push_back(item1); auto hit1 = ExampleHit(0.,0.,0.,23.+i); auto hit2 = ExampleHit(1.,0.,0.,12.+i); hits.push_back(hit1); hits.push_back(hit2); // ---- add some MC particles ---- auto mcp0 = ExampleMC(); auto mcp1 = ExampleMC(); auto mcp2 = ExampleMC(); auto mcp3 = ExampleMC(); auto mcp4 = ExampleMC(); auto mcp5 = ExampleMC(); auto mcp6 = ExampleMC(); auto mcp7 = ExampleMC(); auto mcp8 = ExampleMC(); auto mcp9 = ExampleMC(); mcps.push_back( mcp0 ) ; mcps.push_back( mcp1 ) ; mcps.push_back( mcp2 ) ; mcps.push_back( mcp3 ) ; mcps.push_back( mcp4 ) ; mcps.push_back( mcp5 ) ; mcps.push_back( mcp6 ) ; mcps.push_back( mcp7 ) ; mcps.push_back( mcp8 ) ; mcps.push_back( mcp9 ) ; // --- add some daughter relations auto p = ExampleMC(); auto d = ExampleMC(); p = mcps[0] ; p.adddaughters( mcps[2] ) ; p.adddaughters( mcps[3] ) ; p.adddaughters( mcps[4] ) ; p.adddaughters( mcps[5] ) ; p = mcps[1] ; p.adddaughters( mcps[2] ) ; p.adddaughters( mcps[3] ) ; p.adddaughters( mcps[4] ) ; p.adddaughters( mcps[5] ) ; p = mcps[2] ; p.adddaughters( mcps[6] ) ; p.adddaughters( mcps[7] ) ; p.adddaughters( mcps[8] ) ; p.adddaughters( mcps[9] ) ; p = mcps[3] ; p.adddaughters( mcps[6] ) ; p.adddaughters( mcps[7] ) ; p.adddaughters( mcps[8] ) ; p.adddaughters( mcps[9] ) ; //--- now fix the parent relations for( unsigned j=0,N=mcps.size();j<N;++j){ p = mcps[j] ; for(auto it = p.daughters_begin(), end = p.daughters_end() ; it!=end ; ++it ){ int dIndex = it->getObjectID().index ; d = mcps[ dIndex ] ; d.addparents( p ) ; } } //-------- print relations for debugging: for( auto p : mcps ){ std::cout << " particle " << p.getObjectID().index << " has daughters: " ; for(auto it = p.daughters_begin(), end = p.daughters_end() ; it!=end ; ++it ){ std::cout << " " << it->getObjectID().index ; } std::cout << " and parents: " ; for(auto it = p.parents_begin(), end = p.parents_end() ; it!=end ; ++it ){ std::cout << " " << it->getObjectID().index ; } std::cout << std::endl ; } //------------------------------- auto cluster = ExampleCluster(); auto clu0 = ExampleCluster(); auto clu1 = ExampleCluster(); clu0.addHits(hit1); clu0.energy(hit1.energy()); clu1.addHits(hit2); clu1.energy(hit2.energy()); cluster.addHits(hit1); cluster.addHits(hit2); cluster.energy(hit1.energy()+hit2.energy()); cluster.addClusters( clu0 ) ; cluster.addClusters( clu1 ) ; clusters.push_back(clu0); clusters.push_back(clu1); clusters.push_back(cluster); auto ref = ExampleReferencingType(); refs.push_back(ref); auto ref2 = ExampleReferencingType(); refs2.push_back(ref2); ref.addClusters(cluster); ref.addRefs(ref2); auto comp = ExampleWithComponent(); comp.component().data.x = 0; comp.component().data.y = 1; comp.component().data.z = i; comps.push_back(comp); auto cyclic = ExampleReferencingType(); cyclic.addRefs(cyclic); refs.push_back(cyclic); auto oneRel = ExampleWithOneRelation(); oneRel.cluster(cluster); oneRels.push_back(oneRel); // write non-filled relation auto oneRelEmpty = ExampleWithOneRelation(); oneRels.push_back(oneRelEmpty); auto vec = ExampleWithVectorMember(); vec.addcount(i); vec.addcount(i+10); vecs.push_back(vec); auto vec1 = ExampleWithVectorMember(); vec1.addcount(i+1); vec1.addcount(i+11); vecs.push_back(vec1); for (int j = 0; j < 5; j++) { auto rel = ex::ExampleWithARelation(); rel.number(0.5*j); auto exWithNamesp = ex::ExampleWithNamespace(); exWithNamesp.data().x = i; exWithNamesp.data().y = 1000*i; namesps.push_back(exWithNamesp); if (j != 3) { // also check for empty relations rel.ref(exWithNamesp); for (int k = 0; k < 5; k++) { auto namesp = ex::ExampleWithNamespace(); namesp.x(3*k); namesp.data().y = k; namesps.push_back(namesp); rel.addrefs(namesp); } } namesprels.push_back(rel); } for (int j = 0; j < namesprels.size(); ++j) { cpytest.push_back(namesprels.at(j).clone()); } auto string = ExampleWithString("SomeString"); strings.push_back(string); std::array<int, 4> arrayTest = {0, 0, 2, 3}; std::array<int, 4> arrayTest2 = {4, 4, 2 * static_cast<int>(i)}; NotSoSimpleStruct a; a.data.p = arrayTest2; ex2::NamespaceStruct nstruct; nstruct.x = static_cast<int>(i); std::array<ex2::NamespaceStruct, 4> structArrayTest = {nstruct, nstruct, nstruct, nstruct}; auto array = ExampleWithArray(a, arrayTest, arrayTest, arrayTest, arrayTest, structArrayTest); array.myArray(1, i); array.arrayStruct(a); arrays.push_back(array); writer.writeEvent(); store.clearCollections(); } writer.finish(); }
EventInfo EventSupplement::operator[](uint i){ return EventInfo(*this, i); }