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 }
svgfig.canvas
def canvas(*sub, **attr)
Definition: svgfig.py:482
Handle.h
mps_fire.i
i
Definition: mps_fire.py:355
edmtest
Definition: AlignPCLThresholdsReader.cc:12
gather_cfg.cout
cout
Definition: gather_cfg.py:144
tfwliteselectortest::ThingsTSelector::postProcessing
void postProcessing(TList &) override
Definition: ThingsTSelector.cc:74
edm::Handle
Definition: AssociativeIterator.h:50
CMS_SA_ALLOW
#define CMS_SA_ALLOW
Definition: thread_safety_macros.h:5
tfwliteselectortest::ThingsTSelector::preProcessing
void preProcessing(const TList *, TList &) override
Definition: ThingsTSelector.cc:17
dqmdumpme.things
things
Definition: dqmdumpme.py:19
edm::propagate_const::get
element_type const * get() const
Definition: propagate_const.h:64
compare.hist
hist
Definition: compare.py:376
tfwliteselectortest::ThingsTSelector::terminate
void terminate(TList &) override
Definition: ThingsTSelector.cc:76
tfwliteselectortest::ThingsTSelector::h_refA
edm::propagate_const< TH1F * > h_refA
Definition: ThingsTSelector.h:28
cppFunctionSkipper.exception
exception
Definition: cppFunctionSkipper.py:10
ThingsTSelector.h
Event.h
tfwliteselectortest::ThingsTSelector::process
void process(const edm::Event &) override
Definition: ThingsTSelector.cc:35
thread_safety_macros.h
iEvent
int iEvent
Definition: GenABIO.cc:224
tfwliteselectortest::ThingsTSelector::begin
void begin(TList *&) override
Definition: ThingsTSelector.cc:15
tfwliteselectortest
Definition: ThingsTSelector.h:15
tfwliteselectortest::ThingsTSelector::h_a
edm::propagate_const< TH1F * > h_a
histograms
Definition: ThingsTSelector.h:27
kRefA
static const char * kRefA
Definition: ThingsTSelector.cc:14
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
cms::Exception
Definition: Exception.h:70
edm::Event
Definition: Event.h:73
kA
static const char * kA
Definition: ThingsTSelector.cc:13