CMS 3D CMS Logo

ThingsTSelector2.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 //Names used in common between the worker and the Selector
13 static const char* kA = "a";
14 static const char* kRefA = "refA";
15 
16 ThingsWorker::ThingsWorker(const TList*, TList& out) {
17  std::cout << "begin" << std::endl;
18  h_a = new TH1F(kA, "a", 100, 0, 20);
19  out.Add(h_a);
20 
21  h_refA = new TH1F(kRefA, "refA", 100, 0, 20);
22  out.Add(h_refA);
23 }
24 
26  std::cout << "processing event " << std::endl;
27  // chain->GetEntry( entry );
28  using namespace edmtest;
30  try {
31  iEvent.getByLabel("OtherThing", "testUserTag", hOThings);
32 
33  std::cout << ">> other things found:" << hOThings->size() << std::endl;
34  for (size_t i = 0; i < hOThings->size(); ++i) {
35  const OtherThing& thing = (*hOThings)[i];
36  h_refA->Fill(thing.ref->a);
37  std::cout << ">> ref->a: " << thing.ref->a << std::endl;
38  }
39 
41  iEvent.getByLabel("Thing", hThings);
42  const ThingCollection& things = *hThings;
43  std::cout << ">> things found:" << things.size() << std::endl;
44  for (size_t i = 0; i < things.size(); ++i) {
45  const Thing& thing = things[i];
46  h_a->Fill(thing.a);
47  std::cout << ">> a: " << thing.a << std::endl;
48  }
49  } catch (cms::Exception& x) {
50  std::cout << std::endl << "Failed with cms::Exception: " << std::endl;
51  std::cout << x.what() << std::endl;
52  abort();
53  } catch (std::exception& x) {
54  std::cout << std::endl << "Failed with std::exception" << std::endl;
55  std::cout << x.what() << std::endl;
56  abort();
57  } catch (...) {
58  std::cout << std::endl << "Failed with unknown exception" << std::endl;
59  abort();
60  }
61 }
62 
64 
65 void ThingsTSelector2::begin(TList*&) {}
66 
68  std::cout << "terminate" << std::endl;
69  TCanvas* canvas = new TCanvas();
70  {
71  TObject* hist = out.FindObject(kA);
72  if (nullptr != hist) {
73  hist->Draw();
74  canvas->SaveAs("a.jpg");
75  } else {
76  std::cout << "no '" << kA << "' histogram" << std::endl;
77  }
78  }
79  std::cout << "refA" << std::endl;
80  {
81  TObject* hist = out.FindObject(kRefA);
82  if (nullptr != hist) {
83  hist->Draw();
84  canvas->SaveAs("refA.jpg");
85  } else {
86  std::cout << "no '" << kRefA << "' histogram" << std::endl;
87  }
88  }
89  delete canvas;
90 }
char const * what() const override
Definition: Exception.cc:103
int iEvent
Definition: GenABIO.cc:224
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:480
static const char * kA
static const char * kRefA
edm::propagate_const< TH1F * > h_refA
def canvas(sub, attr)
Definition: svgfig.py:482
ThingsWorker(const TList *, TList &)
void process(const edm::Event &iEvent)
edm::propagate_const< TH1F * > h_a