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"
10 
11 using namespace tfwliteselectortest;
12 
13 static const char* kA = "a";
14 static const char* kRefA = "refA";
15 void ThingsTSelector::begin(TList*&) {}
16 
17 void ThingsTSelector::preProcessing(const TList*, TList& out) {
18  if (nullptr != h_a) {
19  out.Remove(h_a);
20  delete h_a.get();
21  h_a = nullptr;
22  }
23  h_a = new TH1F(kA, "a", 100, 0, 20);
24  out.Add(h_a);
25 
26  if (nullptr != h_refA) {
27  out.Remove(h_refA);
28  delete h_refA.get();
29  h_refA = nullptr;
30  }
31  h_refA = new TH1F(kRefA, "refA", 100, 0, 20);
32  out.Add(h_refA);
33 }
34 
36  std::cout << "processing event " << std::endl;
37  // chain->GetEntry( entry );
38  using namespace edmtest;
40  // In case of an exception prints the message and aborts the process
41  CMS_SA_ALLOW try {
42  iEvent.getByLabel("OtherThing", "testUserTag", hOThings);
43  std::cout << ">> other things found:" << hOThings->size() << std::endl;
44 
45  for (size_t i = 0; i < hOThings->size(); ++i) {
46  const OtherThing& thing = (*hOThings)[i];
47  h_refA->Fill(thing.ref->a);
48  std::cout << ">> ref->a: " << thing.ref->a << std::endl;
49  }
50 
52  iEvent.getByLabel("Thing", hThings);
53  const ThingCollection& things = *hThings;
54  std::cout << ">> things found:" << things.size() << std::endl;
55  for (size_t i = 0; i < things.size(); ++i) {
56  const Thing& thing = things[i];
57  h_a->Fill(thing.a);
58  std::cout << ">> a: " << thing.a << std::endl;
59  }
60  } catch (cms::Exception& x) {
61  std::cout << std::endl << "Failed with cms::Exception: " << std::endl;
62  std::cout << x.what() << std::endl;
63  abort();
64  } catch (std::exception& x) {
65  std::cout << std::endl << "Failed with std::exception" << std::endl;
66  std::cout << x.what() << std::endl;
67  abort();
68  } catch (...) {
69  std::cout << std::endl << "Failed with unknown exception" << std::endl;
70  abort();
71  }
72 }
73 
75 
77  std::cout << "terminate" << std::endl;
78  TCanvas* canvas = new TCanvas();
79  {
80  TObject* hist = out.FindObject(kA);
81  if (nullptr != hist) {
82  hist->Draw();
83  canvas->SaveAs("a.jpg");
84  } else {
85  std::cout << "no '" << kA << "' histogram" << std::endl;
86  }
87  }
88  {
89  TObject* hist = out.FindObject(kRefA);
90  if (nullptr != hist) {
91  hist->Draw();
92  canvas->SaveAs("refA.jpg");
93  } else {
94  std::cout << "no '" << kRefA << "' histogram" << std::endl;
95  }
96  }
97  delete canvas;
98 }
#define CMS_SA_ALLOW
static const char * kA
static const char * kRefA
constexpr element_type const * get() const
int iEvent
Definition: GenABIO.cc:224
void postProcessing(TList &) override
edm::propagate_const< TH1F * > h_a
histograms
edm::propagate_const< TH1F * > h_refA
__shared__ Hist hist
void process(const edm::Event &) override
def canvas(sub, attr)
Definition: svgfig.py:482
float x
void preProcessing(const TList *, TList &) override