@@ -172,18 +172,33 @@ class O2PrimaryServerDevice final : public fair::mq::Device
172172 TStopwatch timer;
173173 timer.Start ();
174174 try {
175- mStack ->Reset ();
176- // see if we the vertex comes from the collision context
177- if (mCollissionContext ) {
178- const auto & vertices = mCollissionContext ->getInteractionVertices ();
179- if (vertices.size () > 0 ) {
180- auto collisionindex = mEventID_to_CollID .at (mEventCounter );
181- auto & vertex = vertices.at (collisionindex);
182- LOG (info) << " Setting vertex " << vertex << " for event " << mEventCounter << " for prefix " << mSimConfig .getOutPrefix ();
183- mPrimGen ->setExternalVertexForNextEvent (vertex.X (), vertex.Y (), vertex.Z ());
175+ bool valid = false ;
176+ int retry_counter = 0 ;
177+ const int MAX_RETRY = 100 ;
178+ do {
179+ mStack ->Reset ();
180+ // see if we the vertex comes from the collision context
181+ if (mCollissionContext ) {
182+ const auto & vertices = mCollissionContext ->getInteractionVertices ();
183+ if (vertices.size () > 0 ) {
184+ auto collisionindex = mEventID_to_CollID .at (mEventCounter );
185+ auto & vertex = vertices.at (collisionindex);
186+ LOG (info) << " Setting vertex " << vertex << " for event " << mEventCounter << " for prefix " << mSimConfig .getOutPrefix ();
187+ mPrimGen ->setExternalVertexForNextEvent (vertex.X (), vertex.Y (), vertex.Z ());
188+ }
184189 }
185- }
186- mPrimGen ->GenerateEvent (mStack );
190+ mPrimGen ->GenerateEvent (mStack );
191+ if (mStack ->getPrimaries ().size () > 0 ) {
192+ valid = true ;
193+ } else {
194+ retry_counter++;
195+ if (retry_counter > MAX_RETRY) {
196+ LOG (warn) << " Not able to generate a non-empty event in " << MAX_RETRY << " trials" ;
197+ // empty event is sent out
198+ valid = true ;
199+ }
200+ }
201+ } while (!valid);
187202 } catch (std::exception const & e) {
188203 LOG (error) << " Exception occurred during event gen " << e.what ();
189204 }
0 commit comments