]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/UNICOR/AliUnicorAnal.cxx
Fix Coverity
[u/mrichter/AliRoot.git] / PWG2 / UNICOR / AliUnicorAnal.cxx
CommitLineData
621688e4 1/*************************************************************************
2* Copyright(c) 1998-2048, ALICE Experiment at CERN, All rights reserved. *
3* *
4* Author: The ALICE Off-line Project. *
5* Contributors are mentioned in the code where appropriate. *
6* *
7* Permission to use, copy, modify and distribute this software and its *
8* documentation strictly for non-commercial purposes is hereby granted *
9* without fee, provided that the above copyright notice appears in all *
10* copies and that both the copyright notice and this permission notice *
11* appear in the supporting documentation. The authors make no claims *
12* about the suitability of this software for any purpose. It is *
13* provided "as is" without express or implied warranty. *
14**************************************************************************/
15
16// Author: Dariusz Miskowiec <mailto:d.miskowiec@gsi.de> 2007
17
18//=============================================================================
19// parent class of all analyzers
20// keeps the obj array of histograms filled by the daughter
21// takes care of storing them on file at the end
22//=============================================================================
23
24#include <TROOT.h>
25#include <TFile.h>
c6fc7f72 26#include <TCollection.h>
27#include <TClass.h>
28#include <TH1.h>
28eee19b 29#include "AliUnicorHN.h"
621688e4 30#include "AliUnicorAnal.h"
31
32ClassImp(AliUnicorAnal)
33
34TDatabasePDG AliUnicorAnal::fgPDG;
35
36//=============================================================================
61e4657c 37AliUnicorAnal::AliUnicorAnal(const char *nam) : TNamed(nam,nam), fHistos() {
c6fc7f72 38
621688e4 39 // constructor
40
41 fHistos.SetOwner(1);
42 TDirectory *dir = gROOT->mkdir(GetName());
43 dir->cd();
621688e4 44 printf("%s object named %s created\n",ClassName(),GetName());
45}
46//=============================================================================
c6fc7f72 47Long64_t AliUnicorAnal::Merge(const TCollection * const list) {
48
49 // sumup fHistos objects
50
51 for (int i=0; i<fHistos.GetEntries(); i++) {
52 if (fHistos.At(i)->IsA()->InheritsFrom("TH1")) {
53 TH1 *hi = (TH1*) fHistos.At(i);
54 TIter next(list);
55 while (AliUnicorAnal *analtoadd = (AliUnicorAnal*) next()) {
56 TH1 *histotoadd = (TH1*) analtoadd->GetHist(i);
57 hi->Add(histotoadd);
58 }
59 }
60 }
61 return 0;
62}
63//=============================================================================
28eee19b 64void AliUnicorAnal::Save(const char *outfil, const char *mode) {
65
621688e4 66 // store histograms on file in a directory named after the object
67 // mode should be "update" (default) or "new"
68
c6fc7f72 69 printf("%s %s: saving histograms on %s (%s)\n",ClassName(),GetName(),outfil,mode);
621688e4 70 TFile * f = TFile::Open(outfil, mode);
71 TDirectory *dest = f->mkdir(GetName());
72 dest->cd();
28eee19b 73 for (int i=0; i<fHistos.GetEntries(); i++) {
74 TObject *obj = fHistos.At(i);
75 if (obj->IsA()->InheritsFrom("AliUnicorHN")) ((AliUnicorHN*) obj)->Save();
76 else obj->Write();
77 }
621688e4 78 gROOT->cd();
79 f->Close();
80}
81//=============================================================================