31 int main(
int argc,
char* argv[]) {
34 using namespace KM3NETDAQ;
43 int statPrintInterval_s;
46 JROOTClassSelector selector;
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";
59 zap[
'L'] =
make_field(ligier,
"Ligier server (output)") =
"";
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;
67 zap[
'M'] =
make_field(M,
"multiplicity range for SN coincidences") = JRange<int>(6,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.");
89 using namespace JSUPERNOVA;
98 load(detectorFile, detector);
100 catch(
const JException& error) {
104 const JModuleRouter moduleRouter(detector);
106 const int DETID = detector.getID();
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;
144 JControlHostObjectIterator<data_type> in(controlhost, timeout_us,
true);
145 JControlHostObjectIterator<summary_type> sm(controlhost, 1000.0,
true);
148 JControlHost* out = NULL;
151 out =
new JControlHost(ligier);
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(); }
195 while ( sm.hasNext() ) {
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;
302 out->PutFullString(outputTag, message.str());
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);
339 catch(
const JSocketException& error) {
340 ERROR(error.what() << endl);
Utility class to parse command line options.
SN trigger summary information.
Data structure for UTC time.
Data structure for detector geometry and calibration.
int getFrameIndex() const
Get frame index.
string toSummaryFile()
put statistics into printable form outputs trigger level - rate - error
void setDAQLongprint(const bool option)
Set DAQ print option.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
string toString()
put statistics into printable form outputs trigger level - rate - error
SN trigger statistics, the information is stored in the form of a count as a function of the trigger ...
double getFrameTime()
Get frame time duration.
Auxiliary class to apply the supernova trigger to SN data.
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
Timeslice data structure for SN data.
General purpose messaging.
Auxiliary class to build the supernova trigger dataset.
Utility class to parse command line options.
ROOT TTree parameter settings.
void setLiveTime(const double lt)
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
#define DEBUG(A)
Message macros.
int main(int argc, char *argv[])