FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairMQExHistoCanvasDrawerExample.cxx
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
9 
10 #include <TCanvas.h>
11 #include <TH1.h>
12 #include <THttpServer.h>
13 #include <TObjArray.h>
14 #include <TString.h> // for TString
15 #include <cassert>
16 
17 class TObject;
18 
20  : fCanvas(nullptr)
21 {}
22 
24 
26 {
27  assert(!fCanvas);
28  fCanvas = std::unique_ptr<TCanvas, std::function<void(TCanvas*)>>(new TCanvas("c1", "", 10, 10, 1000, 1000),
29  [&](TCanvas* p) {
30  server.Unregister(p);
31  delete p;
32  });
33  fCanvas->Divide(2, 2);
34  server.Register("Canvases", fCanvas.get());
35 }
36 
38 {
39  for (int i = 0; i < arrayHisto.GetEntriesFast(); i++) {
40  TObject* obj = arrayHisto.At(i);
41  TH1* histogram = static_cast<TH1*>(obj);
42 
43  if (TString(histogram->GetName()).EqualTo("histo1")) {
44  fCanvas->cd(1);
45  histogram->Draw();
46  fCanvas->cd(0);
47  fCanvas->Modified();
48  fCanvas->Update();
49  } else if (TString(histogram->GetName()).EqualTo("histo2")) {
50  fCanvas->cd(2);
51  histogram->Draw();
52  fCanvas->cd(0);
53  fCanvas->Modified();
54  fCanvas->Update();
55  } else if (TString(histogram->GetName()).EqualTo("histo3")) {
56  fCanvas->cd(3);
57  histogram->Draw("COL");
58  fCanvas->cd(0);
59  fCanvas->Modified();
60  fCanvas->Update();
61  } else if (TString(histogram->GetName()).EqualTo("histo4")) {
62  fCanvas->cd(4);
63  histogram->Draw("COL");
64  fCanvas->cd(0);
65  fCanvas->Modified();
66  fCanvas->Update();
67  }
68  }
69 }