HardwareStatusCheck_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: HardwareStatusCheck
3 // Module Type: filter
4 // File: HardwareStatusCheck_module.cc
5 //
6 // Generated at Thu Nov 7 05:46:29 2013 by Matthew Tamsett using artmod
7 // from cetpkgsupport v1_04_01.
8 ////////////////////////////////////////////////////////////////////////
9 
16 #include "art_root_io/TFileService.h"
18 #include "fhiclcpp/ParameterSet.h"
19 
20 // NOvA includes
21 #include "RunHistory/RunHistory.h"
22 #include "Geometry/Geometry.h"
24 #include "RawData/RawDigit.h"
26 
27 // ROOT includes
28 #include "TH1F.h"
29 #include "TH2F.h"
30 
31 #include <memory>
32 //------------------------------------------------------------------------
33 namespace DataCheck {
34  class HardwareStatusCheck;
35 }
36 //------------------------------------------------------------------------
38  public:
39  explicit HardwareStatusCheck(fhicl::ParameterSet const & p);
40  virtual ~HardwareStatusCheck();
41  bool filter(art::Event & evt) override;
42  void reconfigure(const fhicl::ParameterSet& pset);
43  void beginJob() override;
44  bool beginSubRun(art::SubRun & sr) override;
45  void endJob() override;
46  uint32_t globalDCMNumber(uint32_t diblock, uint32_t dcm);
47  private:
48  // Declare member data here.
49  std::string fRawDigitModule; ///< Label of the raw digit module; set to default
50  std::vector<uint32_t> fDiblocksToUse; ///< The diblocks we will check. Don't worry about those with bare FEBs
51  unsigned int fTotalDCMsExpected = 0;
52  const unsigned int fExpectedNDCMsPerDiblock = 12; ///< The number of DCMs we expect per diblock in each event
53  std::vector<uint32_t> fFoundDCMs;
54  std::vector<uint32_t> fExpectedDCMs;
55  // histograms
56  TH1F* hNRawDigits;
57  TH1F* hNDCMs;
58  TH1F* hPresentDCMs;
59  TH1F* hMissingDCMs;
60 };
61 //------------------------------------------------------------------------
63  : EDFilter(pset),
64  fDiblocksToUse(0),
65  fFoundDCMs(0),
66  fExpectedDCMs(0)
67 // Initialize member data here.
68 {
69  std::cout << "--- HardwareStatusCheck instantiate" << std::endl;
70  // Call appropriate Produces<>() functions here.
71  this->reconfigure(pset);
72 }
73 //------------------------------------------------------------------------
75 {
76  std::cout << "--- HardwareStatusCheck reconfigure" << std::endl;
77  fRawDigitModule = pset.get<std::string>("RawDigitModule", "daq");
78  fDiblocksToUse = pset.get<std::vector<unsigned int> >("DiblocksToUse");
79 
80  fTotalDCMsExpected = fExpectedNDCMsPerDiblock*fDiblocksToUse.size();
81  for (const auto db: fDiblocksToUse){
82  for(uint32_t i_dcm =0;i_dcm<fExpectedNDCMsPerDiblock;++i_dcm){
83  fExpectedDCMs.push_back(globalDCMNumber(db, i_dcm));
84  }
85  }
86 
87  std::cout << " RawDigitModule: " << fRawDigitModule << std::endl;
88  std::cout << " Total DCMs expected: " << fTotalDCMsExpected << std::endl;
89  std::cout << " Diblocks to use: ";
90  for (const auto db: fDiblocksToUse) std::cout << " " << db;
92  //std::cout << " abs DCM numbers expected: " << std::endl;
93  //for (const auto i: fExpectedDCMs) std::cout << " " << i << std::endl;
94 }
95 //------------------------------------------------------------------------
97 {
98  // Clean up dynamic memory and other resources here.
99  fFoundDCMs.clear();
100  fDiblocksToUse.clear();
101 }
102 //------------------------------------------------------------------------
104 {
105  std::cout << "--- HardwareStatusCheck beginSubRun" << std::endl;
107  novadaq::cnv::DetId detectorid = geom->DetId();
108  int fRun = sr.run();
109  std::cout << " detector ID: " << detectorid
110  << ", run: " << fRun
111  << std::endl;
112  nova::dbi::RunHistory rh(sr.run(), detectorid);
113  rh.LoadDAQRunHistory();
114  std::cout << " loaded run history" << std::endl;
115  unsigned int nDB = rh.NDiBlocks();
116  std::cout << " N Di-blocks: " << nDB << std::endl;
117  int nDCMs = rh.NLiveDCMs();
118  std::cout << " N DCMs: " << nDCMs << std::endl;
119  int my_nDCMs = 0;
120  int my_active_nDCMs = 0;
121  for (unsigned int i=0; i<nDB; ++i) {
122  const nova::dbi::RunHistory::DiBlock db = rh.GetDiBlock(i);
123  std::vector<nova::dbi::RunHistory::DCM> DCMs = db.dcm;
124  std::cout << " Diblock[" << i
125  << "] has: " << DCMs.size()
126  << " DCMs" << std::endl;
127  my_nDCMs+=DCMs.size();
128  for (unsigned int j=0; j<DCMs.size(); ++j) {
129  if(DCMs[j].isActive){
130  my_active_nDCMs++;
131  std::vector<nova::dbi::RunHistory::FEB> FEBs = DCMs[j].feb;
132  std::cout << " DCM[" << j
133  << "] has: " << FEBs.size()
134  << " FEBs" << std::endl;
135  //for (unsigned int k=0; k<FEBs.size(); ++k) {
136  //std::cout << " FEB[ " << k
137  //<< "], hwid: " << FEBs[k].hwid
138  //<< ", hasAPD: " << FEBs[k].hasAPD
139  //<< ", isEnabled: " << FEBs[k].isEnabled
140  //<< ", isCooled: " << FEBs[k].isCooled
141  //<< ", tempEnabled: " << FEBs[k].tempEnabled
142  //<< ", temperature: " << FEBs[k].temperature
143  //<< ", gain: " << FEBs[k].gain
144  //<< std::endl;
145  //} // end of loop on FEBs
146  } // end of loop on active DCMs
147  } // end of loop on DCMs
148  } // end of loop on diblocks
149  std::cout << " My N DCMs: " << my_nDCMs << std::endl;
150  std::cout << " My N active DCMs: " << my_active_nDCMs << std::endl;
151 
152  //assert(false);
153  return true;
154 }
155 //------------------------------------------------------------------------
157 {
158  // Implementation of required member function here.
159  //std::cout << "--- HardwareStatusCheck filter. Event: "
160  // << evt.id().event()
161  // << std::endl;
162 
163  // Load services
165 
166  // Load hit list (RawDigits)
168  evt.getByLabel(fRawDigitModule, rawdigitcol);
169  //std::cout << " got " << rawdigitcol->size() << " RawDigits" << std::endl;
170 
171  fFoundDCMs.clear();
172  uint32_t daq_channel = 0;
173  uint32_t dcm = 0;
174  uint32_t diblock = 0;
175  uint32_t abs_dcm = 0; // there are 12 DCMs per diblock
176  // Loop over raw digits
177  for (size_t i_digit = 0; i_digit < rawdigitcol->size(); ++i_digit){
178  daq_channel = rawdigitcol->at(i_digit).DaqChannel();
179 
180  diblock = cmap->Map()->getDiBlock(daq_channel);
181  // are we using this diblock?
182  if(std::find(fDiblocksToUse.begin(), fDiblocksToUse.end(), diblock)==fDiblocksToUse.end()){
183  continue;
184  }
185 
186  dcm = cmap->Map()->getDCM(daq_channel);
187  abs_dcm = globalDCMNumber(diblock, dcm);
188  // has this dcm been found before?
189  if(std::find(fFoundDCMs.begin(), fFoundDCMs.end(), abs_dcm)==fFoundDCMs.end()){
190  fFoundDCMs.push_back(abs_dcm);
191  }
192  } // end of loop over raw digits
193  //std::cout << " found " << fFoundDCMs.size() << " DCMs" << std::endl;
194 
195  // fill monitoring histograms
196  hNRawDigits->Fill(rawdigitcol->size());
197  hNDCMs->Fill(fFoundDCMs.size());
198  // all present DCMs
199  for (auto const n_dcm: fFoundDCMs){
200  hPresentDCMs->Fill(n_dcm);
201  }
202  // only fill missing DCMs if there are any missing
203  if (fFoundDCMs.size()!=fTotalDCMsExpected){
204  for (auto const n_dcm: fExpectedDCMs){
205  if(std::find(fFoundDCMs.begin(), fFoundDCMs.end(), n_dcm)==fFoundDCMs.end()){
206  hMissingDCMs->Fill(n_dcm);
207  }
208  }
209  }
210 
211  return (fFoundDCMs.size()==fTotalDCMsExpected);
212 }
213 //------------------------------------------------------------------------
215 {
217 }
218 //------------------------------------------------------------------------
220 {
221  // Implementation of optional member function here.
222  std::cout << "--- HardwareStatusCheck beginJob" << std::endl;
223 
225  hNRawDigits = f->make<TH1F>("hNRawDigits", ";NRawDigits;Events", 100,-0.5,10000.5);
226  hNDCMs = f->make<TH1F>("hNDCMs", ";NDCMs;Events", 169,-0.5,168.5);
227  hPresentDCMs= f->make<TH1F>("hPresentDCMs", ";DCM number + 12#timesdiblock number;Events", 168,-0.5,167.5);
228  hMissingDCMs= f->make<TH1F>("hMissingDCMs", ";DCM number + 12#timesdiblock number;Events", 168,-0.5,167.5);
229 }
230 //------------------------------------------------------------------------
232 {
233  // Implementation of optional member function here.
234  std::cout << "--- HardwareStatusCheck endJob" << std::endl;
235 }
236 //------------------------------------------------------------------------
diblock
print "ROW IS " print row
Definition: geo2elec.py:31
TH2 * rh
Definition: drawXsec.C:5
std::string fRawDigitModule
Label of the raw digit module; set to default.
const char * p
Definition: xmltok.h:285
void reconfigure(const fhicl::ParameterSet &pset)
const daqchannelmap::DAQChannelMap * Map() const
Definition: CMap.h:57
DEFINE_ART_MODULE(TestTMapFile)
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:446
T get(std::string const &key) const
Definition: ParameterSet.h:231
novadaq::cnv::DetId DetId() const
Prefer ds::DetectorService::DetId() instead.
Definition: GeometryBase.h:243
int evt
caf::StandardRecord * sr
const double j
Definition: BetheBloch.cxx:29
RunNumber_t run() const
std::vector< uint32_t > fDiblocksToUse
The diblocks we will check. Don&#39;t worry about those with bare FEBs.
OStream cout
Definition: OStream.cxx:6
const unsigned int fExpectedNDCMsPerDiblock
The number of DCMs we expect per diblock in each event.
std::vector< DCM > dcm
Definition: RunHistory.h:311
bool filter(art::Event &evt) override
void geom(int which=0)
Definition: geom.C:163
EDFilter(fhicl::ParameterSet const &pset)
Definition: EDFilter.h:22
HardwareStatusCheck(fhicl::ParameterSet const &p)
dcm_id_t getDCM(dchan daqchan) const
Decode the dcm ID from a dchan.
bool beginSubRun(art::SubRun &sr) override
diblock_t getDiBlock(dchan daqchan) const
Decode the diblock ID from a dchan.
Encapsulate the geometry of one entire detector (near, far, ndos)
uint32_t globalDCMNumber(uint32_t diblock, uint32_t dcm)
enum BeamMode string