CMS 3D CMS Logo

ThingsTSelector.cc
Go to the documentation of this file.
2 #include <TCanvas.h>
3 #include <iostream>
4 #include "Rtypes.h"
7 #include "DataFormats/TestObjects/interface/OtherThingCollection.h"
8 #include "DataFormats/TestObjects/interface/ThingCollection.h"
9 
10 using namespace tfwliteselectortest;
11 
12 static const char* kA = "a";
13 static const char* kRefA = "refA";
14 void ThingsTSelector::begin(TList*&) {}
15 
16 void ThingsTSelector::preProcessing(const TList*, TList& out) {
17  if (nullptr != h_a) {
18  out.Remove(h_a);
19  delete h_a.get();
20  h_a = nullptr;
21  }
22  h_a = new TH1F(kA, "a", 100, 0, 20);
23  out.Add(h_a);
24 
25  if (nullptr != h_refA) {
26  out.Remove(h_refA);
27  delete h_refA.get();
28  h_refA = nullptr;
29  }
30  h_refA = new TH1F(kRefA, "refA", 100, 0, 20);
31  out.Add(h_refA);
32 }
33 
35  std::cout << "processing event " << std::endl;
36  // chain->GetEntry( entry );
37  using namespace edmtest;
39 
40  try {
41  iEvent.getByLabel("OtherThing", "testUserTag", hOThings);
42  std::cout << ">> other things found:" << hOThings->size() << std::endl;
43 
44  for (size_t i = 0; i < hOThings->size(); ++i) {
45  const OtherThing& thing = (*hOThings)[i];
46  h_refA->Fill(thing.ref->a);
47  std::cout << ">> ref->a: " << thing.ref->a << std::endl;
48  }
49 
51  iEvent.getByLabel("Thing", hThings);
52  const ThingCollection& things = *hThings;
53  std::cout << ">> things found:" << things.size() << std::endl;
54  for (size_t i = 0; i < things.size(); ++i) {
55  const Thing& thing = things[i];
56  h_a->Fill(thing.a);
57  std::cout << ">> a: " << thing.a << std::endl;
58  }
59  } catch (cms::Exception& x) {
60  std::cout << std::endl << "Failed with cms::Exception: " << std::endl;
61  std::cout << x.what() << std::endl;
62  abort();
63  } catch (std::exception& x) {
64  std::cout << std::endl << "Failed with std::exception" << std::endl;
65  std::cout << x.what() << std::endl;
66  abort();
67  } catch (...) {
68  std::cout << std::endl << "Failed with unknown exception" << std::endl;
69  abort();
70  }
71 }
72 
74 
76  std::cout << "terminate" << std::endl;
77  TCanvas* canvas = new TCanvas();
78  {
79  TObject* hist = out.FindObject(kA);
80  if (nullptr != hist) {
81  hist->Draw();
82  canvas->SaveAs("a.jpg");
83  } else {
84  std::cout << "no '" << kA << "' histogram" << std::endl;
85  }
86  }
87  {
88  TObject* hist = out.FindObject(kRefA);
89  if (nullptr != hist) {
90  hist->Draw();
91  canvas->SaveAs("refA.jpg");
92  } else {
93  std::cout << "no '" << kRefA << "' histogram" << std::endl;
94  }
95  }
96  delete canvas;
97 }
static const char * kA
static const char * kRefA
char const * what() const override
Definition: Exception.cc:103
int iEvent
Definition: GenABIO.cc:224
void postProcessing(TList &) override
edm::propagate_const< TH1F * > h_a
histograms
edm::propagate_const< TH1F * > h_refA
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:480
element_type const * get() const
void process(const edm::Event &) override
def canvas(sub, attr)
Definition: svgfig.py:482
void preProcessing(const TList *, TList &) override