]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Tree chaching implemented and update of merging of trees
authormivanov <mivanov@f7af4fe6-9843-0410-8265-dc069ae4e863>
Sat, 9 Feb 2013 12:39:03 +0000 (12:39 +0000)
committermivanov <mivanov@f7af4fe6-9843-0410-8265-dc069ae4e863>
Sat, 9 Feb 2013 12:39:03 +0000 (12:39 +0000)
TPC/AliXRDPROOFtoolkit.cxx
TPC/AliXRDPROOFtoolkit.h

index 2bf6fb7fbd1c59ee84dbc27aba6ae268761365b1..f6b8f56850847cb529866e2ded274a36f2d4a4ad 100644 (file)
@@ -47,6 +47,7 @@
 #include <exception>
 #include <fstream>
 #include <TRandom.h>
+#include <TTimeStamp.h>
 #include <AliXRDPROOFtoolkit.h>
 
 
@@ -619,6 +620,7 @@ void AliXRDPROOFtoolkit::JoinTreesIndex(const char * outputFile, const char * ou
   // 3. Make join tree
   //
   Int_t jrun=0;
+  fout->cd();
   joinTree->Branch(indexName, &jrun,Form("%s/I",indexName));
   Int_t *status=new Int_t[nTrees];
   char *brName = new char[10000];
@@ -686,9 +688,132 @@ void AliXRDPROOFtoolkit::JoinTreesIndex(const char * outputFile, const char * ou
       joinTree->Fill();
       printf("\n");
     }}
-  joinTree->Write("joinTree");
+  fout->cd();
+  joinTree->Write(outputTree);
   fout->Close();
 
 }
 
 
+
+void AliXRDPROOFtoolkit::CacheFileList(const char * fileIn, const char* cachePrefix){
+  //
+  // cache the list of file locally, cache valeus are stored in the location
+  // specified by optional argumen prefix 
+  // 2 new files are created 
+  //       <fileIn>.cache    - file with the location of cahe files
+  //       <fileIn>.cacheLog - log file +list of files which can not be cached 
+  //      
+  /*
+    fileIn = "TPCCPass1.list";
+    cachePrefix = "";
+  */
+  ifstream fin;
+  fin.open(fileIn);  
+  ofstream fout;
+  fout.open(Form("%s.cache",fileIn));  
+  ofstream foutLog;
+  foutLog.open(Form("%s.cacheLog",fileIn));  
+  // Read the input list of files and add them to the chain
+  TString currentFile;
+  TString cacheFile;
+  Int_t counter=0;
+  {while(fin.good()) {
+      TTimeStamp s;
+      TString fname;
+      fin >> currentFile;
+      fname=currentFile;
+      fname.ReplaceAll("-","_");
+      fname.ReplaceAll("/","_");
+      fname.ReplaceAll(":","_");
+      cacheFile=cachePrefix;
+      cacheFile+=fname;
+      printf("%s\t%s\n",currentFile.Data(),cacheFile.Data());
+      if (TFile::Cp(currentFile.Data(),cacheFile.Data())){
+       fout<<cacheFile.Data()<<"\n";
+       foutLog<<s.AsString();
+       foutLog<<cacheFile.Data()<<"n";
+      }else{
+       foutLog<<"Copy failed"<<currentFile.Data()<<cacheFile.Data()<<"\n";
+      }
+    }}
+  fout.close();
+  foutLog.close();
+}
+
+
+
+void   AliXRDPROOFtoolkit::MakeTreeFromList(const char *fout, const char * treeOut, const char * treeIn, const char * flist, Bool_t debug){
+  //
+  // join trees from the list  and make a common tree - stored in the file 
+  // 
+  /*
+    Example:
+    const char * fout="TPCCpass1.root";
+    const char *treeOut="tpcQA"
+    const char *treeIn="tpcQA"
+    const char * flist="TPCCPass1.list"    
+  */
+  if (debug>0){
+    printf("MakeTreeFromList\n");
+    printf("fout=%s\n",fout);
+    printf("treeOut=%s\n",treeOut);
+    printf("treeIn=%s\n",treeIn);
+    printf("fileList=%s\n",flist);
+  } 
+  ifstream fin;
+  fin.open(flist);  
+  ofstream foutLog;
+  foutLog.open(Form("%s.chainLog",flist));  
+  // Read the input list of files and add them to the chain
+  TString currentFile;
+  Int_t counter=0;
+  Int_t nbranches=0;
+  {while(fin.good()) {
+      fin >> currentFile;
+      TFile * f = TFile::Open(currentFile.Data());
+      foutLog<<"Opening file"<<currentFile.Data();
+      if (!f) {
+       foutLog<<"Error opening file\t"<<currentFile<<"\n";
+       cout<<"Error opening file\t"<<currentFile<<"\n";
+       continue;
+      }
+      TTree * tree = (TTree*)f->Get(treeIn);
+      if (!tree) {
+       foutLog<<"Error opening tree\t"<<currentFile<<treeIn<<"\n";
+       cout<<"Error opening tree\t"<<currentFile<<treeIn<<"\n";
+       f->ls();        
+       continue;
+      }
+      if (tree->GetListOfBranches()==0){
+       foutLog<<"Error opening tree\t"<<currentFile<<treeIn<<"\n";
+       cout<<"Error opening tree\t"<<currentFile<<treeIn<<"\n";
+       continue;
+      }
+      Int_t nbranchesCurrent = tree->GetListOfBranches()->GetEntries();
+      if ( nbranches ==0 ) nbranches=nbranchesCurrent;
+      if ( nbranches!=nbranchesCurrent){
+       foutLog<<"Error  tree layout\t"<<currentFile<<treeIn<<nbranches<<nbranchesCurrent<<"\n";
+       cout<<"Error tree layout\t"   <<currentFile<<treeIn<<nbranches<<nbranchesCurrent<<"\n";
+      }     
+      counter++;
+    }
+  }
+  foutLog<<"Number of files"<<counter<<"\n";
+  cout<<   "Number of files"<<counter<<"\n";
+  //
+
+  TChain * chain = AliXRDPROOFtoolkit::MakeChain(flist,treeIn,0,1000000000,0);
+  Bool_t status=kTRUE;
+  if (!chain) status=kFALSE;
+  if (chain->GetEntries()==0) status=kFALSE;
+  if (!status){
+    printf("Incorrect list (%s) or trees (%s)", flist,treeIn);
+    return;
+  }
+  TFile *fileOut= TFile::Open(fout, "recreate");
+  TTree * tree = chain->CopyTree("1");
+  fileOut->cd();
+  tree->Write(treeOut);
+  fileOut->Close(); 
+}
index ecd6d8a75646137986398aac70e02fed40972914..8cd4082176b10d2d417fb7304fe0d8452485293e 100644 (file)
@@ -30,6 +30,8 @@ class AliXRDPROOFtoolkit : public TObject
   Bool_t  XRDCopyDir(const char * idir, const char * files, const char *odir, Bool_t zip); 
   static Int_t  CheckTreeInFile(const char*fileName,const char*treeName, Int_t debugLevel=0, const char *branchName=0);
   static void JoinTreesIndex(const char * outputFile, const char * outputTree, const char *indexName, const char *inputTrees, Int_t debugLevel);
+  static void   MakeTreeFromList(const char *fout, const char * treeOut, const char * treeIn, const char * flist, Bool_t debug);
+  static void CacheFileList(const char * fileIn, const char* cachePrefix); 
  private:
   Int_t         fVerbose;          // verbso mode  - print command 
   TString       fUserName;         // user name