ARTEMIS-CRIB
 
Loading...
Searching...
No Matches
TCmdErase.cc
Go to the documentation of this file.
1/**
2 * @file TCmdErase.cc
3 * @brief
4 * @author
5 * @date 2023-06-13 17:34:11
6 * @note last modified: 2024-08-23 21:38:12
7 * @details
8 */
9
10#include "TCmdErase.h"
11
12#include <TFile.h>
13#include <TH1.h>
14
16
18
20 SetName("erase");
21 SetTitle("Erase the histograms in the current directory");
22}
23
25
26// TCmdErase* TCmdErase::Instance()
27//{
28// static TCmdErase instance;
29// return &instance;
30// }
31
32Long_t TCmdErase::Cmd(vector<TString>) {
33 /* if (args.size() == 1) {
34 // at least one arguments except command itself is required
35 Help();
36 return 1;
37 }*/
38 // TString opt(args.size()>2 ? args[2] : "create");
39 // return Run(args[1],opt);
40 return Run();
41}
42
44 TList *objects = gDirectory->GetList();
45 TDirectory *wkdir = gDirectory;
46 // open file
47 // art::Util::PrepareDirectoryFor(filename);
48 EraseRecursive(objects);
49
50 wkdir->cd();
51 return 1;
52}
53
54void TCmdErase::EraseRecursive(TList *list) {
55 if (!list)
56 return;
57 Int_t nObj = list->GetEntries();
58 for (Int_t i = 0; i != nObj; i++) {
59 TObject *obj = list->At(i);
60 // parent->cd();
61 if (obj->InheritsFrom("TH1")) {
62
63 /* if (obj->InheritsFrom("art::TH1FTreeProj")) {
64 TH1F(*(art::TH1FTreeProj*)obj).Write();
65 } else if (obj->InheritsFrom("art::TH2FTreeProj")) {
66 TH2F(*(art::TH2FTreeProj*)obj).Write();
67 } else if (obj->InheritsFrom("art::TH2FTreeProj")) {
68 TH3F(*(art::TH3FTreeProj*)obj).Write();
69 } else {*/
70 TH1 *hist = (TH1 *)obj;
71 hist->Reset();
72 //}
73 } else if (obj->InheritsFrom("TDirectory")) {
74 TDirectory *dir = (TDirectory *)obj;
75 EraseRecursive(dir->GetList());
76 } else {
77 // obj->Write();
78 }
79 }
80}
ClassImp(TCmdErase)
~TCmdErase() override
Definition TCmdErase.cc:24
Long_t Cmd(vector< TString >) override
Definition TCmdErase.cc:32
void EraseRecursive(TList *list)
Definition TCmdErase.cc:54
return to the guide