11// Author: G. Pezzullo
2- // This module produces histograms of data from the TriggerResults
2+ // This module produces an example DQM histogram and sends it to the visualizer
33
44#include " art/Framework/Core/EDAnalyzer.h"
55#include " art/Framework/Core/ModuleMacros.h"
66#include " art/Framework/Principal/Event.h"
77#include " art/Framework/Principal/Handle.h"
8- #include " art/Framework/Services/System/TriggerNamesService.h"
98#include " art_root_io/TFileService.h"
10- #include " canvas/Persistency/Common/TriggerResults.h"
11- #include " fhiclcpp/types/OptionalAtom.h"
129
1310#include < TBufferFile.h>
11+ #include < TH1.h>
1412#include < TH1F.h>
1513
16- #include " otsdaq-mu2e-dqm/ArtModules/SimpleDQMHistoContainer.h"
1714#include " otsdaq-mu2e/ArtModules/HistoSender.hh"
1815#include " otsdaq/Macros/CoutMacros.h"
1916#include " otsdaq/Macros/ProcessorPluginMacros.h"
2017#include " otsdaq/MessageFacility/MessageFacility.h"
2118#include " otsdaq/NetworkUtilities/TCPSendClient.h"
2219
23- #include " Offline/Mu2eUtilities/inc/TriggerResultsNavigator.hh"
20+ #include " trace.h"
21+ #define TRACE_NAME " SimpleDQM"
2422
2523namespace ots
2624{
@@ -38,14 +36,16 @@ class SimpleDQM : public art::EDAnalyzer
3836 Name (" address" ),
3937 Comment (" This paramter sets the IP address where the "
4038 " histogram will be sent" )};
41- fhicl::Atom<std::string> moduleTag{Name (" moduleTag" ), Comment (" Module tag name" )};
42- fhicl::Sequence<std::string> histType{
43- Name (" histType" ),
44- Comment (" This parameter determines which quantity is histogrammed" )};
45- fhicl::Atom<int > freqDQM{
46- Name (" freqDQM" ),
47- Comment (" Frequency for sending histograms to the data-receiver" )};
48- fhicl::Atom<int > diag{Name (" diagLevel" ), Comment (" Diagnostic level" ), 0 };
39+ fhicl::Atom<std::string> outputTag{Name (" outputTag" ),
40+ Comment (" Tag to use in output name" )};
41+ fhicl::Atom<int > freqDQM{
42+ Name (" freqDQM" ),
43+ Comment (" Frequency for sending histograms to the data-receiver" )};
44+ fhicl::Atom<int > diag{Name (" diagLevel" ), Comment (" Diagnostic level" ), 0 };
45+ fhicl::Atom<bool > sendHists{
46+ Name (" sendHists" ),
47+ Comment (" Whether or not to send histograms to the receiver" ),
48+ true };
4949 };
5050
5151 typedef art::EDAnalyzer::Table<Config> Parameters;
@@ -57,21 +57,18 @@ class SimpleDQM : public art::EDAnalyzer
5757 void beginJob () override ;
5858 void endJob () override ;
5959
60- void summary_trigger_fill (SimpleDQMHistoContainer* histos);
61- void PlotRate (art::Event const & e);
62-
6360 private:
6461 Config conf_;
6562 int port_;
6663 std::string address_;
67- std::string moduleTag_;
68- std::vector<std::string> histType_;
64+ std::string outputTag_;
6965 int freqDQM_, diagLevel_, evtCounter_;
66+ bool sendHists_;
7067 art::ServiceHandle<art::TFileService> tfs;
71- SimpleDQMHistoContainer* summary_histos = new SimpleDQMHistoContainer();
7268 HistoSender* histSender_;
73- bool doOnspillHist_, doOffspillHist_;
74- std::string moduleTag;
69+
70+ // Simple event counter
71+ TH1* hist_;
7572};
7673} // namespace ots
7774
@@ -80,82 +77,60 @@ ots::SimpleDQM::SimpleDQM(Parameters const& conf)
8077 , conf_(conf())
8178 , port_(conf().port())
8279 , address_(conf().address())
83- , moduleTag_(conf().moduleTag())
84- , histType_(conf().histType())
80+ , outputTag_(conf().outputTag())
8581 , freqDQM_(conf().freqDQM())
8682 , diagLevel_(conf().diag())
8783 , evtCounter_(0 )
88- , doOnspillHist_(false )
89- , doOffspillHist_(false )
84+ , sendHists_(conf().sendHists())
9085{
91- histSender_ = new HistoSender (address_, port_);
92-
93- if (diagLevel_ > 0 )
94- {
95- __COUT__ << " [SimpleDQM::analyze] DQM for " << histType_[0 ] << std::endl;
96- }
86+ histSender_ = (sendHists_) ? new HistoSender (address_, port_) : nullptr ;
9787
98- for (std::string name : histType_)
99- {
100- if (name == " Onspill" )
101- {
102- doOnspillHist_ = true ;
103- }
104- if (name == " Offspill" )
105- {
106- doOffspillHist_ = true ;
107- }
108- }
88+ __COUT__ << " [SimpleDQM::" << __func__ << " ] Constructor" << std::endl;
10989}
11090
11191void ots::SimpleDQM::beginJob ()
11292{
113- __COUT__ << " [SimpleDQM::beginJob] Beginning job" << std::endl;
114- summary_histos->BookSummaryHistos (tfs, " Trigger counts" , 1 , 0 , 1 );
93+ __COUT__ << " [SimpleDQM::" << __func__ << " ] Beginning job" << std::endl;
94+
95+ // Create the histograms of interest
96+ art::TFileDirectory dir = tfs->mkdir (outputTag_);
97+ hist_ = dir.make <TH1F>(" event_count" , " Event counter;Bin;Events" , 1 , 0 , 1 );
98+ hist_->SetLineWidth (2 );
99+ hist_->SetFillColor (kAzure - 9 );
100+ hist_->SetLineColor (kAzure + 2 );
101+ hist_->SetFillStyle (3001 );
115102}
116103
117104void ots::SimpleDQM::analyze (art::Event const & event)
118105{
106+ // fill the histograms of interest
119107 ++evtCounter_;
108+ hist_->Fill (1 );
109+ TLOG (TLVL_DEBUG + 20 ) << " [SimpleDQM::" << __func__ << " ] Analyzing event "
110+ << evtCounter_ << std::endl;
120111
121- summary_trigger_fill (summary_histos);
122-
123- if (evtCounter_ % freqDQM_ != 0 )
112+ // Only send histograms at a given frequency
113+ if (evtCounter_ % freqDQM_ != 0 || !sendHists_)
124114 return ;
125115
126- // send a packet AND reset the histograms
116+ // Add a clone of the histogram to a map of <path/in/output, <list of histograms>>
127117 std::map<std::string, std::vector<TH1*>> hists_to_send;
118+ TLOG (TLVL_DEBUG + 5 ) << " [SimpleDQM::" << __func__
119+ << " ] collecting summary histogram " << hist_->GetName ()
120+ << std::endl;
121+ // histograms can be replaced with ":replace" or added together with ":add" appended to the directory path
122+ hists_to_send[outputTag_ + " _summary:replace" ].push_back ((TH1*)hist_->Clone ());
128123
129- // send the summary hists
130- for (size_t i = 0 ; i < summary_histos->histograms .size (); i++)
131- {
132- __COUT__ << " [SimpleDQM::analyze] collecting summary histogram "
133- << summary_histos->histograms [i]._Hist << std::endl;
134- hists_to_send[moduleTag_ + " _summary" ].push_back (
135- (TH1*)summary_histos->histograms [i]._Hist ->Clone ());
136- summary_histos->histograms [i]._Hist ->Reset ();
137- }
138-
124+ // send the histograms to the receiver
139125 histSender_->sendHistograms (hists_to_send);
140126}
141127
142- void ots::SimpleDQM::summary_trigger_fill (SimpleDQMHistoContainer* histos )
128+ void ots::SimpleDQM::endJob ( )
143129{
144- // __COUT__ << "filling Summary histograms..."<< std::endl;
145-
146- if (histos->histograms .size () == 0 )
147- {
148- __COUT__ << " No histograms booked. Should they have been created elsewhere?"
149- << std::endl;
150- }
151- else
152- {
153- histos->histograms [1 ]._Hist ->Fill (0 );
154- }
130+ __COUT__ << " [SimpleDQM::" << __func__ << " ] Ending job, saw " << evtCounter_
131+ << " events\n " ;
155132}
156133
157- void ots::SimpleDQM::endJob () {}
158-
159- void ots::SimpleDQM::beginRun (const art::Run& run) {}
134+ void ots::SimpleDQM::beginRun (const art::Run&) {}
160135
161136DEFINE_ART_MODULE (ots::SimpleDQM)
0 commit comments