45int main(
int argc, 
char* argv[]) {
 
   54  string outputFileName;
 
   59  string domDetectorFile;
 
   62  int numberOfTimeouts = 1e3; 
 
   63  int queueLength = 100; 
 
   67  int preTriggerThreshold = 4; 
 
   69  double TVeto_ns = 1000; 
 
   73  string summaryFile = 
""; 
 
   74  int statPrintInterval_s = 30; 
 
   79    string properties_description = 
"\n";
 
   84    properties_description.append(
"\ttimeout_us: timeout for input [us]\n");
 
   86    properties_description.append(
"\tnumberOfTimeouts: number of timeouts before stop\n");
 
   88    properties_description.append(
"\tqueueLength: number of timeslices of trigger queue\n");
 
   90    properties_description.append(
"\twindowLength: number of timeslices of trigger sliding window\n");
 
   93    properties_description.append(
"\tTMax_ns: coincidence time window [ns]\n");
 
   95    properties_description.append(
"\tpreTriggerThreshold: muon veto multiplicity threshold\n");
 
   97    properties_description.append(
"\ttotSelector_ns: hit selector\n");
 
   99    properties_description.append(
"\tTVeto_ns: muon veto time interval [ns]\n");
 
  101    properties_description.append(
"\tM: multiplicity range for SN coincidence level\n");
 
  103    properties_description.append(
"\tM_BDT: multiplicity range for SN coincidence level (with BDT)\n");
 
  106    properties_description.append(
"\tsummaryFile: summary output file\n");
 
  108    properties_description.append(
"\tstatPrintInterval_s: statistics & file print interval [s]");
 
  110    JParser<> zap(
"Supernova realtime processor");
 
  112    zap[
'H'] = 
make_field(inputLigier, 
"Input Ligier server") = 
"";
 
  114    zap[
'L'] = 
make_field(outputLigier, 
"Output Ligier server") = 
"";
 
  115    zap[
'T'] = 
make_field(outputTag, 
"Output tag for the json messages") = 
JTag();
 
  116    zap[
'o'] = 
make_field(outputFileName, 
"Output json file name (no output to Ligier)") = 
"";
 
  117    zap[
'n'] = 
make_field(nEntries, 
"Number of entries to write") = -1;
 
  127  catch(
const exception &error) {
 
  128    FATAL(error.what() << endl);
 
  131  if (queueLength <= windowLength) {
 
  132    FATAL(
"Length of the trigger window must be smaller than the queue.");
 
  155    load(domDetectorFile, domDetector);
 
  167  const int detectorSize = 
detector.size();
 
  177  typedef priority_queue<trigger_type, vector<trigger_type>, greater<trigger_type> > queue_type;
 
  179  typedef deque<trigger_type> window_type;
 
  188  window_type trgWindow;
 
  195  long int counter_live_ts = 0;
 
  196  long int counter_lost_ts = 0;
 
  202  int nWrittenEntries = 0;
 
  203  if (outputFileName != 
""){
 
  223    if (inputFileName != 
"") {
 
  229    else if (inputLigier != 
"") {
 
  234      const double asyncTimeout_us = 1000.0;
 
  239    else { 
FATAL(
"Need either a root file or a ligier as input!" << endl); }
 
  242    if (outputLigier != 
"") {
 
  247    if (outputFileName != 
"") {
 
  254    int timesliceSize = 0;
 
  256    for (
int i = 0; i != numberOfTimeouts; ) {
 
  262        DEBUG(timeslice->getDAQHeader() << endl);
 
  264        timesliceSize = timeslice->size();
 
  270        const int r = timeslice->getRunNumber();
 
  276            NOTICE(
"RUN CHANGE" << endl);
 
  278            while (trgQueue.size() > 0) { trgQueue.pop(); }
 
  306          for (JDAQSummaryslice::const_iterator summary_frame = summary->begin();
 
  307               summary_frame != summary->end();
 
  310            int DOMID = summary_frame->getModuleID();
 
  313              rates[frame_index][DOMID] += summary_frame->getRate(ipmt, 1.0/1000);
 
  316            pmts[frame_index] += summary_frame->countActiveChannels();
 
  325          DEBUG(
"EVT " << event->getDAQHeader() << endl);
 
  327          int frame_index = 
event->getFrameIndex();
 
  329          veto[frame_index].push_back(
JVeto(*event, hitRouter));
 
  337        JDataSN preTrigger(TMax_ns, preTriggerThreshold);
 
  339        preTrigger(timeslice, moduleRouter, totSelector_ns, domDetector);
 
  351        if ( trgQueue.size() >= (
unsigned) queueLength ) {
 
  353          while ( trgWindow.size() <= (
unsigned) windowLength ) {
 
  355            trigger_type pending = trgQueue.top();
 
  357            if ( trgWindow.size() == 0 || pending > trgWindow.back() ) {
 
  359              trgWindow.push_back( pending );
 
  374          NOTICE(
"Filling trigger queue: " << trgQueue.size() << 
"/" << queueLength << 
'\r');
 
  378      else if ( inputFileName != 
"" ) {
 
  381        if ( trgQueue.size() > 0 ) {
 
  382          while ( trgQueue.size() > 0 ) {
 
  383            trgWindow.push_back(trgQueue.top());
 
  387        else if ( trgWindow.size() < (
unsigned) windowLength ) {
 
  388          i = numberOfTimeouts;
 
  392        NOTICE(
"timeout " << setw(3) << i << endl);
 
  397      if (trgWindow.size() >= (
unsigned) windowLength) {
 
  404        int trg_cc_counts   = 0;
 
  405        int trg_cc_modules  = 0;
 
  408        int trg_ev_counts   = 0;
 
  409        int trg_ev_modules  = 0;
 
  413        for (
int its = 0; its < windowLength; its++) {
 
  415          const int frame_index = trgWindow[its].frameIndex;
 
  418          if (veto.count(frame_index)) {
 
  419            vetoSet = veto.at(frame_index);
 
  425          set<int> cc_vec = trgWindow[its].getModules(F_M1);
 
  426          set<int> ev_vec = trgWindow[its].getModules(F_MV);
 
  428          cc_modules.insert(cc_vec.begin(), cc_vec.end());
 
  429          ev_modules.insert(ev_vec.begin(), ev_vec.end());
 
  431          trg_cc_counts += count_if(trgWindow[its].begin(), trgWindow[its].end(), F_M1);
 
  432          trg_ev_counts += count_if(trgWindow[its].begin(), trgWindow[its].end(), F_MV);
 
  435          for (
auto &trg: trgWindow[its]){
 
  436            auto sn_candidate = trg.getPeak();
 
  437            if (F_MV_BDT(sn_candidate)){
 
  438              multiplicities.push_back(sn_candidate.multiplicity);
 
  439              observables.push_back(sn_candidate.total_ToT);
 
  440              observables.push_back(sn_candidate.deltaT);
 
  441              observables.push_back(sn_candidate.mean_dir_norm);
 
  442              observables.push_back(sn_candidate.mean_dir_ctheta);
 
  447        trg_cc_modules = cc_modules.size();
 
  448        trg_ev_modules = ev_modules.size();
 
  452        int currentFrame             = trgWindow[0].frameIndex;
 
  455        trgWindow.pop_front();
 
  459        ++stats[trg_cc_counts];
 
  463        int    activeModules =  -1;
 
  464        double detectorRate  = 0.0;
 
  466        if (!rates.empty()          &&
 
  467              rates.count(currentFrame)) {
 
  472               p != rates.at(currentFrame).end(); p++ ) {
 
  474            detectorRate  += p->second;
 
  476            activeModules += (p->second > 0);
 
  481          activeModules = timesliceSize;
 
  503        string msg = jd.dump();
 
  507        if (outputFileName != 
""){
 
  508          if (nWrittenEntries < nEntries || nEntries == -1) {
 
  529        if ( (counter_live_ts % ((
int)(statPrintInterval_s / frameTime_s)) == 0 ) ) {
 
  531          double livetime = counter_live_ts * frameTime_s;
 
  537          NOTICE(
"=> discarded out-of-order timeslices = " << counter_lost_ts << endl);
 
  539          if (summaryFile != 
"") {
 
  540            ofstream of(summaryFile.c_str());
 
  551    ERROR(error.what() << endl);
 
  554  if (outputFileName != 
"") { 
outputFile.close(); }