]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/EVE/AliHLTEveBase.cxx
Fix for coverity, potential mem leak
[u/mrichter/AliRoot.git] / HLT / EVE / AliHLTEveBase.cxx
1 /**************************************************************************
2  * This file is property of and copyright by the ALICE HLT Project        *
3  * ALICE Experiment at CERN, All rights reserved.                         *
4  *                                                                        *
5  * Primary Authors: Svein Lindal <slindal@fys.uio.no   >                  *
6  *                  for The ALICE HLT Project.                            *
7  *                                                                        *
8  * Permission to use, copy, modify and distribute this software and its   *
9  * documentation strictly for non-commercial purposes is hereby granted   *
10  * without fee, provided that the above copyright notice appears in all   *
11  * copies and that both the copyright notice and this permission notice   *
12  * appear in the supporting documentation. The authors make no claims     *
13  * about the suitability of this software for any purpose. It is          *
14  * provided "as is" without express or implied warranty.                  *
15  **************************************************************************/
16
17 /// @file   AliHLTEveBase.cxx
18 /// @author Svein Lindal <slindal@fys.uio.no>
19 /// @brief  Base class for the HLT eve display detector elements
20
21
22 #include "AliHLTEveBase.h"
23 #include "AliHLTHOMERBlockDesc.h"
24 #include "TCollection.h"
25 #include "TObjArray.h"
26 #include "AliEveHLTEventManager.h"
27 #include "TCanvas.h"
28 #include "TEveWindow.h"
29 #include "TEveManager.h"
30 #include "TEveBrowser.h"
31 #include "TH1F.h"
32 #include "TH2F.h"
33
34 ClassImp(AliHLTEveBase);
35
36 AliHLTEveBase::AliHLTEveBase(const char * name) : 
37   TEveElementList(name),
38   fEventManager(NULL), 
39   fCanvas(NULL),
40   fHistoCount(0),
41   fMaxHistos(0), 
42   fDetector("")
43 {
44   // Constructor.
45 }
46
47 AliHLTEveBase::~AliHLTEveBase()
48 {
49   //Destructor
50
51   if(fCanvas) 
52     delete fCanvas;
53   fCanvas = NULL;
54
55         //  fEventManager->DestroyElements();
56   //fEventManager = NULL;
57
58 }
59
60
61
62 TCanvas * AliHLTEveBase::CreateCanvas(TString  tabTitle, TString  canvasTitle ) {
63    //See header file for documentation
64
65   TEveWindowSlot *slot = TEveWindow::CreateWindowInTab(fEventManager->GetEveManager()->GetBrowser()->GetTabRight());
66   slot->StartEmbedding();
67   TCanvas * canvas = new TCanvas(canvasTitle.Data(),canvasTitle.Data(), 600, 400);
68   slot->StopEmbedding(tabTitle.Data());
69
70   return canvas;
71 }
72
73
74 void AliHLTEveBase::AddHistogramsToCanvas(AliHLTHOMERBlockDesc * block, TCanvas * canvas, Int_t &cdCount ) {
75   //See header file for documentation
76
77
78
79   if ( ! block->GetClassName().CompareTo("TObjArray")) {
80
81     // // TObjArray * blocks = dynamic_cast<TObjArray*>(block->GetTObject());
82     // // TIterator* next = block::MakeIterator();
83
84     TIter next((TObjArray*)(block->GetTObject()));
85     TObject *object;
86     
87     while (( object = (TObject*) next())) {
88       if (cdCount == fMaxHistos) {
89         cout << "Too many histograms from detector, increase division size!!!!!!!!!!!! Detector: " << GetDetector() << endl;
90         break;
91       }
92       TH2F* histo = dynamic_cast<TH2F*>(object);
93       if(histo){
94         canvas->cd(++cdCount);
95         histo->Draw("COLZ");
96       } else {
97         TH1F* hist = dynamic_cast<TH1F*>(object);
98         if (hist) {
99           canvas->cd(++cdCount);
100           hist->Draw();
101         } else {
102           cout <<"AliHLTEveCaloBase::AddHistogramsTocCanvas: Histogram neither TH1F nor TH2F"<<endl;
103         }
104       }
105     }
106   }
107     
108   else if ( ! block->GetClassName().CompareTo("TH1F")) {
109
110     TH1F* histo = reinterpret_cast<TH1F*>(block->GetTObject());
111     ++cdCount;
112     if(cdCount > fMaxHistos){
113     
114       cout << "Too many histograms, divide canvas more or create additional. Or ask svein to fix it! Detector: "<< GetDetector()<<endl;
115       cdCount = 1;
116     }  canvas->cd(cdCount);
117     histo->Draw();
118     
119   } 
120   
121   else if ( ! block->GetClassName().CompareTo("TH2F")) {
122     TH2F *histo = reinterpret_cast<TH2F*>(block->GetTObject());
123     if (histo) {
124       ++cdCount;
125
126       if(cdCount > fMaxHistos){ 
127         cdCount = 1;
128         cout << "Too many histograms, divide canvas more or create additional. Or ask svein to fix it! Detector :" << GetDetector()<<endl;
129       }
130
131       canvas->cd(cdCount);
132       histo->Draw("COLZ");
133     }
134   }
135
136   canvas->cd();
137 }
138
139