All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
WebReaderTest_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: WebReaderTest
3 // Module Type: analyzer
4 // File: WebReaderTest_module.cc
5 //
6 // Generated at Wed Feb 11 07:17:16 2015 by Kazuhiro Terao using artmod
7 // from cetpkgsupport v1_08_02.
8 ////////////////////////////////////////////////////////////////////////
9 
10 #include "art/Framework/Core/EDAnalyzer.h"
11 #include "art/Framework/Core/ModuleMacros.h"
12 #include "art/Framework/Principal/Event.h"
13 #include "art/Framework/Principal/Handle.h"
14 #include "art/Framework/Principal/Run.h"
15 #include "art/Framework/Principal/SubRun.h"
16 #include "art/Framework/Services/Registry/ServiceHandle.h"
17 #include "art_root_io/TFileService.h"
18 #include "art_root_io/TFileDirectory.h"
19 #include "canvas/Utilities/InputTag.h"
20 #include "fhiclcpp/ParameterSet.h"
21 #include "messagefacility/MessageLogger/MessageLogger.h"
22 
23 // CalibrationDBI
24 #include "WebReaderService.h"
25 
26 // ROOT
27 #include "TGraph.h"
28 #include "TAxis.h"
29 #include "TCanvas.h"
30 
31 class WebReaderTest;
32 
33 class WebReaderTest : public art::EDAnalyzer {
34 public:
35  explicit WebReaderTest(fhicl::ParameterSet const & p);
36  // The destructor generated by the compiler is fine for classes
37  // without bare pointers or other resource use.
38 
39  // Plugins should not be copied or assigned.
40  WebReaderTest(WebReaderTest const &) = delete;
41  WebReaderTest(WebReaderTest &&) = delete;
42  WebReaderTest & operator = (WebReaderTest const &) = delete;
44 
45  // Required functions.
46  void analyze(art::Event const & e) override;
47 
48 
49 private:
50 
51  TGraph* gPed;
52 };
53 
54 
55 WebReaderTest::WebReaderTest(fhicl::ParameterSet const & p)
56  : EDAnalyzer(p)
57  , gPed(nullptr)
58 {}
59 
60 
61 void WebReaderTest::analyze(art::Event const & e)
62 {
63  // Do it only once in the lifetime
64  if(!gPed) {
65 
66  // Let's retrieve ch==0 parameter "mean" from "kazu_pedestal"
67  const std::string folder ("kazu_pedestal");
68  const unsigned int ch = 0;
69  const std::string param ("mean");
70  int param_index = -1;
71 
72  // We sample over 100 time stamps, store values (time & mean value) in vector containers
73  const size_t npoints=100;
74  std::vector<double> xarray, yarray;
75  xarray.reserve(npoints);
76  yarray.reserve(npoints);
77  double ymax = std::numeric_limits<double>::min();
78  double ymin = std::numeric_limits<double>::max();
79 
80  // Loop over known time range in which data exists
81  TTimeStamp start (2015,2,6,0,0,1,0,false);
82  TTimeStamp end (2015,2,6,1,0,1,0,false);
83  TTimeStamp now (start);
84 
85  // Now create DBI instance and loop over sampling points
86  art::ServiceHandle<lariov::WebReaderService const> db_handle;
87  auto& db = db_handle->GetWebReader<double>();
88 
89  int period = (int)( (end.GetSec() - start.GetSec()) / (double)(npoints) );
90  for(size_t i=0; i<npoints; ++i) {
91 
92  // Set time for "now"
93  now.SetSec( now.GetSec() + period );
94 
95  // Request Snapshot for "now"
96  auto snapshot = db.Request(folder,now);
97 
98  // Retrieve a specific channel data
99  auto ch_data = snapshot.ChData(ch);
100 
101  // If param_index is unset, figure out (only once) for fast index access
102  if( param_index < 0 ) param_index = snapshot.Name2Index(param);
103 
104  // Retrieve a mean value
105  auto val = ch_data[ param_index ];
106 
107  // Record
108  xarray.push_back( now.GetSec() );
109  yarray.push_back( val );
110 
111  // Record min/max for plotting purpose
112  if( val > ymax ) ymax = val;
113  if( val < ymin ) ymin = val;
114  }
115 
116  // Decorate min/max
117  ymax *= 1.2;
118  ymin *= 1.2;
119  if( !ymax && !ymin ) { ymax=1; ymin=-1; }
120 
121  // Plot in TGraph
122  // Store in a histogram
123  art::ServiceHandle<art::TFileService const> fs;
124  gPed = fs->make<TGraph>(npoints,&xarray[0],&yarray[0]);
125  gPed->SetName("gPed");
126  gPed->SetTitle("Pedestal Mean Value Over Time; ;Pedestal Mean");
127  gPed->GetXaxis()->SetTimeDisplay(1);
128  gPed->GetXaxis()->SetNdivisions(-503);
129  gPed->GetXaxis()->SetTimeFormat("%Y-%m-%d %H:%M");
130  gPed->GetXaxis()->SetTimeOffset(0,"gmt");
131  gPed->GetXaxis()->SetRangeUser(start.GetSec(),end.GetSec());
132  gPed->SetMarkerStyle(22);
133  gPed->SetMarkerSize(1);
134  gPed->SetMaximum(ymax);
135  gPed->SetMinimum(ymin);
136 
137  TCanvas c("c","",600,500);
138  gPed->Draw("APL");
139  c.SaveAs("gPed.gif");
140  }
141 }
142 
143 DEFINE_ART_MODULE(WebReaderTest)
WebReaderTest(fhicl::ParameterSet const &p)
void analyze(art::Event const &e) override
pdgs p
Definition: selectors.fcl:22
auto end(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:585
do i e
height to which particles are projected pnfs larsoft persistent physics cosmics Fermilab CORSIKA standard He_showers_ * db
WebReaderTest & operator=(WebReaderTest const &)=delete