StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
histCopy.C
1 
2 void histCopy(const char *nameIn, const char *nameOut)
3 {
4 // Input file
5  TFile* fileIn = new TFile(nameIn, "READ");
6  if (!fileIn->IsOpen()) {
7  cout << "### Can't find file" << nameIn << endl;
8  return;
9  }
10  TFile* fileOut = new TFile(nameOut, "RECREATE");
11  if (!fileOut->IsOpen()){
12  cout << "### Can't open file" << nameOut << endl;
13  return;
14  }
15 
16  TKey* key;
17  TObject* obj;
18  TIter nextkey(fileIn->GetListOfKeys());
19  int num=0;
20  while (key = (TKey*)nextkey()) {
21  fileIn->cd();
22  char* objName = key->GetName();
23  char* clsName = key->GetClassName();
24  char* ignore ="";
25  if (strcmp("TNtuple",clsName)==0) ignore =" IGNORED";
26  if (strcmp("TTree" ,clsName)==0) ignore =" IGNORED";
27  obj=0;
28  if (*ignore==0) obj = key->ReadObj();
29  num++;
30 
31  cout << num << " obj name= " << clsName << "::" << objName << ignore << endl;
32  if (obj) {
33  fileOut->cd();
34  obj->Write(objName);
35  delete obj;
36  }
37  }
38  fileIn->Close();
39  fileOut->Close();
40 }