31 int main(
int argc,
char* argv[]) {
43 int statPrintInterval_s;
50 int preTriggerThreshold;
56 JParser<> zap(
"Example program to test receiving of objects from ControlHost server.");
58 zap[
'H'] =
make_field(controlhost,
"CH server (input)") =
"localhost";
63 zap[
'C'] =
make_field(selector) = getROOTClassSelection<JDAQTimesliceTypes_t>();
64 zap[
'Q'] =
make_field(queueLength,
"number of timeslices of trigger queue") = 100;
65 zap[
'W'] =
make_field(windowLength,
"number of timeslices of trigger sliding window") = 5;
66 zap[
'T'] =
make_field(TMax_ns,
"coincidence time window [ns]") = 10;
68 zap[
'S'] =
make_field(preTriggerThreshold,
"muon veto multiplicity threshold") = 4;
69 zap[
'V'] =
make_field(TVeto_ns,
"muon veto time interval") = 1000;
70 zap[
's'] =
make_field(summaryFile,
"summary output file");
71 zap[
'P'] =
make_field(statPrintInterval_s,
"statistics & file print interval [s]") = 30;
78 catch(
const exception &error) {
79 FATAL(error.what() << endl);
82 if (queueLength < windowLength) {
83 FATAL(
"Length of the trigger window must be smaller than the queue.");
108 const int detectorSize =
detector.size();
116 typedef priority_queue<trigger_type, vector<trigger_type>, greater<trigger_type> > queue_type;
118 typedef deque<trigger_type> window_type;
123 window_type trgWindow;
124 rates_type moduleRates;
128 long int counter_live_ts = 0;
129 long int counter_lost_ts = 0;
155 const string outputTag =
"SNT";
161 for (
int i = 0; i != numberOfTimeouts; ) {
165 data_type* timeslice = in.
next();
167 DEBUG(timeslice->getDAQHeader() << endl);
173 const int r = timeslice->getRunNumber();
181 NOTICE(
"RUN CHANGE" << endl);
183 while (trgQueue.size() > 0) { trgQueue.pop(); }
201 for (JDAQSummaryslice::const_iterator summary_frame = summary->begin(); summary_frame != summary->end(); ++summary_frame) {
203 int DOMID = summary_frame->getModuleID();
206 moduleRates[index][DOMID] += summary_frame->getRate(ipmt, 1.0/1000);
215 JDataSN preTrigger(TMax_ns, preTriggerThreshold);
217 preTrigger(timeslice, moduleRouter);
223 trgQueue.push(trigger);
229 if (trgQueue.size() >= (unsigned) queueLength) {
231 while (trgWindow.size() <= (unsigned) windowLength) {
233 trigger_type pending = trgQueue.top();
235 if ( trgWindow.size() == 0 || pending > trgWindow.back() ) {
237 trgWindow.push_back( pending );
254 for (
int its = 0; its < windowLength; its++) {
256 set<int> current = trgWindow[its].getModules();
258 triggeredModules.insert(current.begin(), current.end());
264 int currentFrame = trgWindow[0].frameIndex;
267 trgWindow.pop_front();
271 int trigger = triggeredModules.size();
275 DEBUG(
"TRIGGER => TS = " << currentFrame <<
"; LEVEL = " << trigger << endl);
278 int activeModules = -1;
280 if (!moduleRates.empty() &&
281 moduleRates.count(currentFrame)) {
286 p != moduleRates.at(currentFrame).end(); p++ ) {
297 JSummarySN summary(DETID, activeModules, RUN, currentFrame, currentTime, trigger);
299 stringstream message;
308 if ( (counter_live_ts % ((
int)(statPrintInterval_s / frameTime_s)) == 0 ) ) {
310 double livetime = counter_live_ts * frameTime_s;
316 NOTICE(
"=> discarded out-of-order timeslices = " << counter_lost_ts << endl);
318 if (summaryFile !=
"") {
319 ofstream of(summaryFile.c_str());
327 NOTICE(
"Filling trigger queue: " << trgQueue.size() <<
"/" << queueLength <<
'\r');
332 NOTICE(
"timeout " << setw(3) << i << endl);