Project

General

Profile

TestSRProducer_module.cc

test producer source - Andrei Gaponenko, 11/12/2013 07:18 PM

 
1
// Test memory grows of a job processing large number of subRuns
2
//
3
// Andrei Gaponenko, 2013
4

    
5
#include <iostream>
6
#include <string>
7
#include <vector>
8
#include <memory>
9
#include <cmath>
10
#include <cstdlib>
11
#include <algorithm>
12

    
13
// art includes.
14
#include "fhiclcpp/ParameterSet.h"
15
#include "art/Framework/Core/EDProducer.h"
16
#include "art/Framework/Principal/Event.h"
17
#include "art/Framework/Principal/SubRun.h"
18
#include "art/Framework/Core/ModuleMacros.h"
19
#include "MCDataProducts/inc/PhysicalVolumeInfoMultiCollection.hh"
20
#include "DataProducts/inc/FilterEfficiency.hh"
21

    
22
namespace mu2e {
23

    
24
  //================================================================
25
  class TestSRProducer : public art::EDProducer {
26
    art::InputTag volumesInput_;
27
    std::size_t maxStringLength_;
28
    std::size_t maxEntries_;
29
  public:
30
    explicit TestSRProducer(const fhicl::ParameterSet& pset);
31
    virtual void produce(art::Event& event) override;
32
    virtual void beginSubRun(art::SubRun& sr) override;
33
    virtual void endSubRun(art::SubRun& sr) override;
34
    virtual void endJob() override;
35
  };
36

    
37
  //================================================================
38
  TestSRProducer::TestSRProducer(const fhicl::ParameterSet& pset)
39
    : volumesInput_(pset.get<std::string>("volumesInput"))
40
    , maxStringLength_()
41
    , maxEntries_()
42
  {
43
    //produces<FilterEfficiency,art::InSubRun>(); // a small object
44
    produces<PhysicalVolumeInfoMultiCollection,art::InSubRun>(); // a large object
45
  }
46

    
47
  //================================================================
48
  void TestSRProducer::beginSubRun(art::SubRun& sr) {
49
    art::Handle<PhysicalVolumeInfoMultiCollection> ih;
50
    sr.getByLabel(volumesInput_, ih);
51

    
52
    std::size_t numEntries = 0;
53
    for(const auto& sc : *ih) {
54
      numEntries += sc.second.size();
55
      for(const auto e: sc.second) {
56
        maxStringLength_ = std::max(maxStringLength_, e.second.name().size() + e.second.materialName().size());
57
      }
58
    }
59
    maxEntries_ = std::max(maxEntries_, numEntries);
60
  }
61

    
62
  //================================================================
63
  void TestSRProducer::produce(art::Event& event) {}
64

    
65
  //================================================================
66
  void TestSRProducer::endSubRun(art::SubRun& sr) {
67
    //sr.put(std::move(std::unique_ptr<FilterEfficiency>(new FilterEfficiency())));
68

    
69
    art::Handle<PhysicalVolumeInfoMultiCollection> ih;
70
    sr.getByLabel(volumesInput_, ih);
71
    sr.put(std::move(std::unique_ptr<PhysicalVolumeInfoMultiCollection>(new PhysicalVolumeInfoMultiCollection(*ih))));
72
  }
73

    
74
  //================================================================
75
  void TestSRProducer::endJob() {
76
    std::cout<<"TestSRProducer: sizeof(PhysicalVolumeInfo) = "<<sizeof(PhysicalVolumeInfo)
77
             <<", max sum(strlenght) = "<<maxStringLength_
78
             <<", maxEntries = "<<maxEntries_
79
             <<std::endl;
80
  }
81

    
82
  //================================================================
83
} // namespace mu2e
84

    
85
DEFINE_ART_MODULE(mu2e::TestSRProducer);