ATLAS Offline Software
Loading...
Searching...
No Matches
makeSmallRefFile.cxx File Reference

modified from copyFiles.C in ROOT tutuorial More...

#include <string>
#include <iostream>
#include "TROOT.h"
#include "TKey.h"
#include "TFile.h"
#include "TSystem.h"
#include "TTree.h"
Include dependency graph for makeSmallRefFile.cxx:

Go to the source code of this file.

Functions

void CopyDir (TDirectory *source, bool mkdirFlag)
void CopyFile (const char *fname)
void makeSmallRefFile (const std::string &in, const std::string &out)
int usage (int status=0)
int main (int argc, char **argv)

Detailed Description

modified from copyFiles.C in ROOT tutuorial

Author
J.Kirk
Date
Fri 11 Jan 2019 07:41:26 CET

Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration

Definition in file makeSmallRefFile.cxx.

Function Documentation

◆ CopyDir()

void CopyDir ( TDirectory * source,
bool mkdirFlag )

Definition at line 30 of file makeSmallRefFile.cxx.

30 {
31 //copy all objects and subdirs of directory source as a subdir of the current directory
32 printf("CopyDir called with sourcem mkdirFlag: %s , %d\n",source->GetName(), mkdirFlag);
33 source->ls();
34 TDirectory *savdir = gDirectory;
35 TDirectory *adir;
36 if (mkdirFlag) {
37 adir = savdir->mkdir(source->GetName());
38 } else {
39 adir = savdir;
40 }
41 adir->cd();
42 //loop on all entries of this directory
43 TKey *key;
44 TIter nextkey(source->GetListOfKeys());
45 while ((key = (TKey*)nextkey())) {
46 const char *classname = key->GetClassName();
47 TClass *cl = gROOT->GetClass(classname);
48 if (!cl) continue;
49 if (cl->InheritsFrom(TDirectory::Class())) {
50 const char *dirname = key->GetName();
51 printf("Directory: %s\n",dirname);
52 if ( (std::string(dirname).find("EF") !=std::string::npos)) printf ("Found EF");
53 if ( (std::string(dirname).find("L2") !=std::string::npos)) printf ("Found L2");
54 if ( (std::string(dirname).find("HLT") !=std::string::npos)) printf ("Found HLT");
55 if ( (std::string(dirname).find("Fast") !=std::string::npos)) printf ("Found Fast");
56 if ( (std::string(dirname).find("vs") !=std::string::npos)) printf ("Found vs");
57
58 if ( (std::string(dirname).find("EF") !=std::string::npos) || (std::string(dirname).find("L2")!=std::string::npos) || (std::string(dirname).find("HLT")!=std::string::npos) || (std::string(dirname).find("Fast")!=std::string::npos) || (std::string(dirname).find("vs")!=std::string::npos) ) {
59 // if ( std::string(dirname).find("slices") !=std::string::npos || std::string(dirname).find("roi")!=std::string::npos ) {
60 printf("Directory OK will be copied: %s\n",dirname);
61 source->cd(key->GetName());
62 TDirectory *subdir = gDirectory;
63 adir->cd();
64 CopyDir(subdir, true);
65 adir->cd();
66 } else {
67 printf("Directory will NOT be copied: %s\n",dirname);
68 }
69
70
71 } else if (cl->InheritsFrom(TTree::Class())) {
72 TTree *T = (TTree*)source->Get(key->GetName());
73 adir->cd();
74 TTree *newT = T->CloneTree(-1,"fast");
75 newT->Write();
76 } else {
77 source->cd();
78 TObject *obj = key->ReadObj();
79 adir->cd();
80 if ( std::string(key->GetClassName()).find("TH1")!=std::string::npos ) obj->Write();
81 delete obj;
82 }
83
84 }
85 adir->SaveSelf(kTRUE);
86 savdir->cd();
87}
std::string find(const std::string &s)
return a remapped string
Definition hcg.cxx:138
void CopyDir(TDirectory *source, bool mkdirFlag)
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
std::string dirname(std::string name)
Definition utils.cxx:200

◆ CopyFile()

void CopyFile ( const char * fname)

Definition at line 90 of file makeSmallRefFile.cxx.

90 {
91 //Copy all objects and subdirs of file fname as a subdir of the current directory
92 TDirectory *target = gDirectory;
93 TFile *f = TFile::Open(fname);
94 if (!f || f->IsZombie()) {
95 printf("Cannot copy file: %s\n",fname);
96 target->cd();
97 return;
98 }
99 target->cd();
100 CopyDir(f,false);
101 delete f;
102 target->cd();
103}

◆ main()

int main ( int argc,
char ** argv )

Definition at line 122 of file makeSmallRefFile.cxx.

122 {
123
124 if ( argc<3 ) return usage(-1);
125
126 std::string infile = argv[1];
127 std::string outfile = argv[2];
128
129 makeSmallRefFile( infile, outfile );
130
131 return 0;
132}
StatusCode usage()
void makeSmallRefFile(const std::string &in, const std::string &out)
str infile
Definition run.py:13

◆ makeSmallRefFile()

void makeSmallRefFile ( const std::string & in,
const std::string & out )

Definition at line 106 of file makeSmallRefFile.cxx.

106 {
107 //main function copying 4 files as subdirectories of a new file
108 TFile *f = new TFile( out.c_str(), "recreate" );
109 // CopyFile("data-tau-merge.root");
110 CopyFile( in.c_str() );
111 f->ls();
112 delete f;
113}
void CopyFile(const char *fname)

◆ usage()

int usage ( int status = 0)

Definition at line 116 of file makeSmallRefFile.cxx.

116 {
117 std::cout << "Usage: makeSmallRefFile <intputfile> <outputfile>" << std::endl;
118 return status;
119}
status
Definition merge.py:16