tdaq-develop-2025-02-12
testFragments_module.cc
1 // Class: testFragments
3 // Module Type: EDAnalyzer
4 // File: testFragments_module.cc
5 // Description: Prints out mu2eFragments in HWUG Packet format (see mu2e-docdb #4097)
7 
8 #include "art/Framework/Core/EDAnalyzer.h"
9 #include "art/Framework/Core/ModuleMacros.h"
10 #include "art/Framework/Principal/Event.h"
11 #include "art/Framework/Principal/Handle.h"
12 #include "art_root_io/TFileService.h"
13 #include "canvas/Utilities/Exception.h"
14 
15 #include "artdaq-core/Data/Fragment.hh"
16 
17 #include "trace.h"
18 #include "TH1.h"
19 #include <unistd.h>
20 #include <iomanip>
21 #include <iostream>
22 #include <string>
23 
24 namespace mu2e {
25 class testFragments;
26 }
27 
28 class mu2e::testFragments : public art::EDAnalyzer
29 {
30 public:
31  explicit testFragments(fhicl::ParameterSet const& pset);
32  virtual void analyze(art::Event const& evt);
33 
34 private:
35  art::InputTag caloFragmentsTag_;
36  //TTree* testTree;
37  TH1F *testHist;
38 };
39 
40 mu2e::testFragments::testFragments(fhicl::ParameterSet const& pset)
41  : EDAnalyzer{pset}, caloFragmentsTag_{"calo"} {
42  art::ServiceHandle<art::TFileService> tfs;
43  //testTree = tfs->make<TTree>("test", "test");
44  //testTree->Branch("nSize", &_nSize, "nSize/F");
45 testHist = tfs->make<TH1F>("test", "test", 100, 0., 500. );
46 
47 }
48 
49 void mu2e::testFragments::analyze(art::Event const& e)
50 {
51  std::cout<<" [testFragments] analyzer testing simulated events "<<std::endl;
52  std::vector<art::Handle<artdaq::Fragments>> vah = e.getMany<artdaq::Fragments>();
53 
54  std::cout<<"[testFragments] size "<<vah.size()<<std::endl;
55  for (auto const& calFragments : vah) {
56  const art::Provenance* prov = calFragments.provenance();
57 
58  std::string fcn = prov->friendlyClassName();
59  std::string modn = prov->moduleLabel();
60  std::string instn = prov->processName();
61 
62  std::string name = fcn + "_" + prov->moduleLabel() + "_" + instn;
63  std::cout<<"[testFragments] extracting name = "<<fcn<<" "<<modn<<" "<<instn<<std::endl; //artdaq::Fragments daq test001
64 
65  size_t totalSize = 0;
66 
67  for (size_t idx = 0; idx < calFragments->size(); ++idx) {
68  auto size = ((*calFragments)[idx]).size() * sizeof(artdaq::RawDataType);
69  testHist->Fill(size);
70  totalSize += size;
71  std::cout << "[testFragments] \tCAL Fragment " << idx << " has size " << size << std::endl;
72  }
73  //testTree->Fill();
74  std::cout << "[testFragments] \tTotal Size: " << (int)totalSize << " bytes." << std::endl;
75  }
76 
77 }
78 
79 DEFINE_ART_MODULE(mu2e::testFragments)