FACT++  1.0
bool writeEvt ( const shared_ptr< EVT_CTRL2 > &  evt)

Definition at line 822 of file EventBuilder.cc.

References RUN_CTRL2::closeTime, factPrintf(), RUN_CTRL2::fileStat, MessageImp::kError, kFileClosed, kFileNotYetOpen, kFileOpen, MessageImp::kInfo, kRequestConnectionChange, kRequestEventCheckFailed, kRequestManual, kRequestMaxEvtsReached, kRequestMaxTimeReached, kRequestNone, kRequestTimeout, RUN_CTRL2::maxEvt, RUN_CTRL2::openTime, Queue< T, List >::post(), run, runClose(), runOpen(), runWrite(), secondaryQueue, and str.

823 {
824  //const shared_ptr<RUN_CTRL2> &run = evt->runCtrl;
825  RUN_CTRL2 &run = *evt->runCtrl;
826 
827  // Is this a valid event or just an empty event to trigger run close?
828  // If this is not an empty event open the new run-file
829  // Empty events are there to trigger run-closing conditions
830  if (evt->valid())
831  {
832  // File not yet open
833  if (run.fileStat==kFileNotYetOpen)
834  {
835  // runOpen will close a previous run, if still open
836  if (!runOpen(*evt))
837  {
838  factPrintf(MessageImp::kError, "Could not open new file for run %d (evt=%d, runOpen failed)", evt->runNum, evt->evNum);
839  run.fileStat = kFileClosed;
840  return true;
841  }
842 
843  factPrintf(MessageImp::kInfo, "Opened new file for run %d (evt=%d)", evt->runNum, evt->evNum);
844  run.fileStat = kFileOpen;
845  }
846 
847  // Here we have a valid calibration and can go on with that.
848  // It is important that _all_ events are sent for calibration (except broken ones)
849  processingQueue1.post(evt);
850  }
851 
852  // File already closed
853  if (run.fileStat==kFileClosed)
854  return true;
855 
856  // If we will have a software trigger which prevents single events from writing,
857  // the logic of writing the stop time and the trigger counters need to be adapted.
858  // Currently it is just the values of the last valid event.
859  bool rc1 = true;
860  if (evt->valid())
861  {
862  rc1 = runWrite(*evt);
863  if (!rc1)
864  factPrintf(MessageImp::kError, "Writing event %d for run %d failed (runWrite)", evt->evNum, evt->runNum);
865  }
866 
867  // File not open... no need to close or to check for close
868  // ... this is the case if CloseRunFile was called before any file was opened.
869  if (run.fileStat!=kFileOpen)
870  return true;
871 
872  // File is not yet to be closed.
873  if (rc1 && evt->closeRequest==kRequestNone)
874  return true;
875 
876  runClose(*evt);
877  run.fileStat = kFileClosed;
878 
879  vector<string> reason;
880  if (evt->closeRequest&kRequestManual)
881  reason.emplace_back("close requested");
882  if (evt->closeRequest&kRequestTimeout)
883  reason.emplace_back("receive timeout");
884  if (evt->closeRequest&kRequestConnectionChange)
885  reason.emplace_back("connection changed");
886  if (evt->closeRequest&kRequestEventCheckFailed)
887  reason.emplace_back("event check failed");
888  if (evt->closeRequest&kRequestMaxTimeReached)
889  reason.push_back(to_string(run.closeTime-run.openTime)+"s reached");
890  if (evt->closeRequest&kRequestMaxEvtsReached)
891  reason.push_back(to_string(run.maxEvt)+" evts reached");
892  if (!rc1)
893  reason.emplace_back("runWrite failed");
894 
895  const string str = boost::algorithm::join(reason, ", ");
896  factPrintf(MessageImp::kInfo, "File closed because %s", str.c_str());
897 
898  return true;
899 }
bool runWrite(const EVT_CTRL2 &evt)
void factPrintf(int severity, const char *fmt,...)
Queue< shared_ptr< EVT_CTRL2 > > processingQueue1(bind(&proc1, placeholders::_1))
char str[80]
Definition: test_client.c:7
An info telling something which can be interesting to know.
Definition: MessageImp.h:17
bool runOpen(const EVT_CTRL2 &evt)
uint32_t maxEvt
Definition: EventBuilder.h:67
void runClose(const EVT_CTRL2 &run)
static int run
Definition: dim_fork.cxx:9
FileStatus_t fileStat
Definition: EventBuilder.h:74
Error, something unexpected happened, but can still be handled by the program.
Definition: MessageImp.h:19
time_t openTime
Definition: EventBuilder.h:61
time_t closeTime
Definition: EventBuilder.h:63

+ Here is the call graph for this function: