CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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";
15 {
16 }
17 
18 void ThingsTSelector::preProcessing(const TList*, TList& out ) {
19  if(nullptr != h_a) {
20  out.Remove(h_a);
21  delete h_a.get();
22  h_a = nullptr;
23  }
24  h_a = new TH1F( kA , "a" , 100, 0, 20 );
25  out.Add(h_a);
26 
27  if(nullptr != h_refA) {
28  out.Remove(h_refA);
29  delete h_refA.get();
30  h_refA = nullptr;
31  }
32  h_refA = new TH1F( kRefA , "refA" , 100, 0, 20 );
33  out.Add(h_refA);
34 }
35 
37  std::cout << "processing event " << std::endl;
38  // chain->GetEntry( entry );
39  using namespace edmtest;
41 
42  try {
43  iEvent.getByLabel("OtherThing", "testUserTag", hOThings);
44  std::cout << ">> other things found:" << hOThings->size() << std::endl;
45 
46  for ( size_t i = 0; i < hOThings->size(); ++i ) {
47  const OtherThing & thing = (*hOThings)[ i ];
48  h_refA ->Fill( thing.ref->a );
49  std::cout << ">> ref->a: " << thing.ref->a << std::endl;
50  }
51 
53  iEvent.getByLabel("Thing",hThings);
54  const ThingCollection& things = *hThings;
55  std::cout << ">> things found:" << things.size() << std::endl;
56  for ( size_t i = 0; i < things.size(); ++i ) {
57  const Thing & thing = things[ i ];
58  h_a ->Fill( thing.a );
59  std::cout << ">> a: " << thing.a << std::endl;
60  }
61  } catch (cms::Exception& x) {
62  std::cout << std::endl << "Failed with cms::Exception: " << std::endl;
63  std::cout << x.what() << std::endl;
64  abort();
65  } catch (std::exception& x) {
66  std::cout << std::endl << "Failed with std::exception" << std::endl;
67  std::cout << x.what() << std::endl;
68  abort();
69  } catch (...) {
70  std::cout << std::endl << "Failed with unknown exception" << std::endl;
71  abort();
72  }
73 
74 }
75 
77 {
78 }
79 
81  std::cout << "terminate" << std::endl;
82  TCanvas * canvas = new TCanvas( );
83  {
84  TObject* hist = out.FindObject(kA);
85  if(nullptr != hist) {
86  hist->Draw();
87  canvas->SaveAs( "a.jpg" );
88  } else {
89  std::cout <<"no '"<<kA<<"' histogram"<< std::endl;
90  }
91  }
92  {
93  TObject* hist = out.FindObject(kRefA);
94  if(nullptr != hist) {
95  hist->Draw();
96  canvas->SaveAs( "refA.jpg" );
97  } else {
98  std::cout <<"no '"<<kRefA<<"' histogram"<< std::endl;
99  }
100  }
101  delete canvas;
102 }
virtual char const * what() const
Definition: Exception.cc:141
int i
Definition: DBlmapReader.cc:9
static const char * kA
static const char * kRefA
void process(const edm::Event &)
void preProcessing(const TList *, TList &)
def canvas
Definition: svgfig.py:481
T x() const
Cartesian x coordinate.
int iEvent
Definition: GenABIO.cc:230
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:418
element_type const * get() const
tuple cout
Definition: gather_cfg.py:145