CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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"
10 
11 using namespace tfwliteselectortest;
12 
13 //Names used in common between the worker and the Selector
14 static const char* kA = "a";
15 static const char* kRefA = "refA";
16 
17 ThingsWorker::ThingsWorker(const TList*, TList& out) {
18  std::cout << "begin" << std::endl;
19  h_a = new TH1F(kA, "a", 100, 0, 20);
20  out.Add(h_a);
21 
22  h_refA = new TH1F(kRefA, "refA", 100, 0, 20);
23  out.Add(h_refA);
24 }
25 
27  std::cout << "processing event " << std::endl;
28  // chain->GetEntry( entry );
29  using namespace edmtest;
31  // In case of an exception prints the message and aborts the process
32  CMS_SA_ALLOW try {
33  iEvent.getByLabel("OtherThing", "testUserTag", hOThings);
34 
35  std::cout << ">> other things found:" << hOThings->size() << std::endl;
36  for (size_t i = 0; i < hOThings->size(); ++i) {
37  const OtherThing& thing = (*hOThings)[i];
38  h_refA->Fill(thing.ref->a);
39  std::cout << ">> ref->a: " << thing.ref->a << std::endl;
40  }
41 
43  iEvent.getByLabel("Thing", hThings);
44  const ThingCollection& things = *hThings;
45  std::cout << ">> things found:" << things.size() << std::endl;
46  for (size_t i = 0; i < things.size(); ++i) {
47  const Thing& thing = things[i];
48  h_a->Fill(thing.a);
49  std::cout << ">> a: " << thing.a << std::endl;
50  }
51  } catch (cms::Exception& x) {
52  std::cout << std::endl << "Failed with cms::Exception: " << std::endl;
53  std::cout << x.what() << std::endl;
54  abort();
55  } catch (std::exception& x) {
56  std::cout << std::endl << "Failed with std::exception" << std::endl;
57  std::cout << x.what() << std::endl;
58  abort();
59  } catch (...) {
60  std::cout << std::endl << "Failed with unknown exception" << std::endl;
61  abort();
62  }
63 }
64 
66 
67 void ThingsTSelector2::begin(TList*&) {}
68 
70  std::cout << "terminate" << std::endl;
71  TCanvas* canvas = new TCanvas();
72  {
73  TObject* hist = out.FindObject(kA);
74  if (nullptr != hist) {
75  hist->Draw();
76  canvas->SaveAs("a.jpg");
77  } else {
78  std::cout << "no '" << kA << "' histogram" << std::endl;
79  }
80  }
81  std::cout << "refA" << std::endl;
82  {
83  TObject* hist = out.FindObject(kRefA);
84  if (nullptr != hist) {
85  hist->Draw();
86  canvas->SaveAs("refA.jpg");
87  } else {
88  std::cout << "no '" << kRefA << "' histogram" << std::endl;
89  }
90  }
91  delete canvas;
92 }
#define CMS_SA_ALLOW
tuple things
Definition: dqmdumpme.py:19
def canvas
Definition: svgfig.py:482
int iEvent
Definition: GenABIO.cc:224
char const * what() const noexceptoverride
Definition: Exception.cc:103
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:500
__shared__ Hist hist
static const char * kA
static const char * kRefA
edm::propagate_const< TH1F * > h_refA
ThingsWorker(const TList *, TList &)
void process(const edm::Event &iEvent)
tuple cout
Definition: gather_cfg.py:144
edm::propagate_const< TH1F * > h_a