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 
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  : fDiblocksToUse(0),
64  fFoundDCMs(0),
65  fExpectedDCMs(0)
66 // Initialize member data here.
67 {
68  std::cout << "--- HardwareStatusCheck instantiate" << std::endl;
69  // Call appropriate Produces<>() functions here.
70  this->reconfigure(pset);
71 }
72 //------------------------------------------------------------------------
74 {
75  std::cout << "--- HardwareStatusCheck reconfigure" << std::endl;
76  fRawDigitModule = pset.get<std::string>("RawDigitModule", "daq");
77  fDiblocksToUse = pset.get<std::vector<unsigned int> >("DiblocksToUse");
78 
79  fTotalDCMsExpected = fExpectedNDCMsPerDiblock*fDiblocksToUse.size();
80  for (const auto db: fDiblocksToUse){
81  for(uint32_t i_dcm =0;i_dcm<fExpectedNDCMsPerDiblock;++i_dcm){
82  fExpectedDCMs.push_back(globalDCMNumber(db, i_dcm));
83  }
84  }
85 
86  std::cout << " RawDigitModule: " << fRawDigitModule << std::endl;
87  std::cout << " Total DCMs expected: " << fTotalDCMsExpected << std::endl;
88  std::cout << " Diblocks to use: ";
89  for (const auto db: fDiblocksToUse) std::cout << " " << db;
91  //std::cout << " abs DCM numbers expected: " << std::endl;
92  //for (const auto i: fExpectedDCMs) std::cout << " " << i << std::endl;
93 }
94 //------------------------------------------------------------------------
96 {
97  // Clean up dynamic memory and other resources here.
98  fFoundDCMs.clear();
99  fDiblocksToUse.clear();
100 }
101 //------------------------------------------------------------------------
103 {
104  std::cout << "--- HardwareStatusCheck beginSubRun" << std::endl;
106  novadaq::cnv::DetId detectorid = geom->DetId();
107  int fRun = sr.run();
108  std::cout << " detector ID: " << detectorid
109  << ", run: " << fRun
110  << std::endl;
111  nova::dbi::RunHistory rh(sr.run(), detectorid);
112  rh.LoadDAQRunHistory();
113  std::cout << " loaded run history" << std::endl;
114  unsigned int nDB = rh.NDiBlocks();
115  std::cout << " N Di-blocks: " << nDB << std::endl;
116  int nDCMs = rh.NLiveDCMs();
117  std::cout << " N DCMs: " << nDCMs << std::endl;
118  int my_nDCMs = 0;
119  int my_active_nDCMs = 0;
120  for (unsigned int i=0; i<nDB; ++i) {
121  const nova::dbi::RunHistory::DiBlock db = rh.GetDiBlock(i);
122  std::vector<nova::dbi::RunHistory::DCM> DCMs = db.dcm;
123  std::cout << " Diblock[" << i
124  << "] has: " << DCMs.size()
125  << " DCMs" << std::endl;
126  my_nDCMs+=DCMs.size();
127  for (unsigned int j=0; j<DCMs.size(); ++j) {
128  if(DCMs[j].isActive){
129  my_active_nDCMs++;
130  std::vector<nova::dbi::RunHistory::FEB> FEBs = DCMs[j].feb;
131  std::cout << " DCM[" << j
132  << "] has: " << FEBs.size()
133  << " FEBs" << std::endl;
134  //for (unsigned int k=0; k<FEBs.size(); ++k) {
135  //std::cout << " FEB[ " << k
136  //<< "], hwid: " << FEBs[k].hwid
137  //<< ", hasAPD: " << FEBs[k].hasAPD
138  //<< ", isEnabled: " << FEBs[k].isEnabled
139  //<< ", isCooled: " << FEBs[k].isCooled
140  //<< ", tempEnabled: " << FEBs[k].tempEnabled
141  //<< ", temperature: " << FEBs[k].temperature
142  //<< ", gain: " << FEBs[k].gain
143  //<< std::endl;
144  //} // end of loop on FEBs
145  } // end of loop on active DCMs
146  } // end of loop on DCMs
147  } // end of loop on diblocks
148  std::cout << " My N DCMs: " << my_nDCMs << std::endl;
149  std::cout << " My N active DCMs: " << my_active_nDCMs << std::endl;
150 
151  //assert(false);
152  return true;
153 }
154 //------------------------------------------------------------------------
156 {
157  // Implementation of required member function here.
158  //std::cout << "--- HardwareStatusCheck filter. Event: "
159  // << evt.id().event()
160  // << std::endl;
161 
162  // Load services
164 
165  // Load hit list (RawDigits)
167  evt.getByLabel(fRawDigitModule, rawdigitcol);
168  //std::cout << " got " << rawdigitcol->size() << " RawDigits" << std::endl;
169 
170  fFoundDCMs.clear();
171  uint32_t daq_channel = 0;
172  uint32_t dcm = 0;
173  uint32_t diblock = 0;
174  uint32_t abs_dcm = 0; // there are 12 DCMs per diblock
175  // Loop over raw digits
176  for (size_t i_digit = 0; i_digit < rawdigitcol->size(); ++i_digit){
177  daq_channel = rawdigitcol->at(i_digit).DaqChannel();
178 
179  diblock = cmap->Map()->getDiBlock(daq_channel);
180  // are we using this diblock?
181  if(std::find(fDiblocksToUse.begin(), fDiblocksToUse.end(), diblock)==fDiblocksToUse.end()){
182  continue;
183  }
184 
185  dcm = cmap->Map()->getDCM(daq_channel);
186  abs_dcm = globalDCMNumber(diblock, dcm);
187  // has this dcm been found before?
188  if(std::find(fFoundDCMs.begin(), fFoundDCMs.end(), abs_dcm)==fFoundDCMs.end()){
189  fFoundDCMs.push_back(abs_dcm);
190  }
191  } // end of loop over raw digits
192  //std::cout << " found " << fFoundDCMs.size() << " DCMs" << std::endl;
193 
194  // fill monitoring histograms
195  hNRawDigits->Fill(rawdigitcol->size());
196  hNDCMs->Fill(fFoundDCMs.size());
197  // all present DCMs
198  for (auto const n_dcm: fFoundDCMs){
199  hPresentDCMs->Fill(n_dcm);
200  }
201  // only fill missing DCMs if there are any missing
202  if (fFoundDCMs.size()!=fTotalDCMsExpected){
203  for (auto const n_dcm: fExpectedDCMs){
204  if(std::find(fFoundDCMs.begin(), fFoundDCMs.end(), n_dcm)==fFoundDCMs.end()){
205  hMissingDCMs->Fill(n_dcm);
206  }
207  }
208  }
209 
210  return (fFoundDCMs.size()==fTotalDCMsExpected);
211 }
212 //------------------------------------------------------------------------
214 {
216 }
217 //------------------------------------------------------------------------
219 {
220  // Implementation of optional member function here.
221  std::cout << "--- HardwareStatusCheck beginJob" << std::endl;
222 
224  hNRawDigits = f->make<TH1F>("hNRawDigits", ";NRawDigits;Events", 100,-0.5,10000.5);
225  hNDCMs = f->make<TH1F>("hNDCMs", ";NDCMs;Events", 169,-0.5,168.5);
226  hPresentDCMs= f->make<TH1F>("hPresentDCMs", ";DCM number + 12#timesdiblock number;Events", 168,-0.5,167.5);
227  hMissingDCMs= f->make<TH1F>("hMissingDCMs", ";DCM number + 12#timesdiblock number;Events", 168,-0.5,167.5);
228 }
229 //------------------------------------------------------------------------
231 {
232  // Implementation of optional member function here.
233  std::cout << "--- HardwareStatusCheck endJob" << std::endl;
234 }
235 //------------------------------------------------------------------------
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)
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
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
T * make(ARGS...args) const
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
bool filter(art::Event &evt) override
void geom(int which=0)
Definition: geom.C:163
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)
RunNumber_t run() const
Definition: SubRun.h:49
enum BeamMode string