]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWG0/CreateESDChain.C
Multiply with parent transformation matrix thus allowing global positioning.
[u/mrichter/AliRoot.git] / PWG0 / CreateESDChain.C
index a6a2926351146944d8d0e79a19e4915e7a812c6a..157849980327eeb4ed1d15e973c8aa890b1e611e 100644 (file)
@@ -21,7 +21,7 @@
 //
 // Author: Jan.Fiete.Grosse-Oetringhaus@cern.ch
 
-TChain* CreateESDChain(const char* aDataDir = "ESDfiles.txt", Int_t aRuns = 20, Int_t offset = 0, Bool_t addFileName = kFALSE, Bool_t addFriend = kFALSE, Bool_t check = kFALSE)
+TChain* CreateESDChain(const char* aDataDir = "ESDfiles.txt", Int_t aRuns = 20, Int_t offset = 0, Bool_t addFileName = kFALSE, Bool_t addFriend = kFALSE, const char* check = 0)
 {
   // creates chain of files in a given directory or file containing a list.
   // In case of directory the structure is expected as:
@@ -31,6 +31,7 @@ TChain* CreateESDChain(const char* aDataDir = "ESDfiles.txt", Int_t aRuns = 20,
   //
   // if addFileName is true the list only needs to contain the directories that contain the AliESDs.root files
   // if addFriend is true a file AliESDfriends.root is expected in the same directory and added to the chain as friend
+  // if check is != 0 the files that work are written back into the textfile with the name check
 
   if (!aDataDir)
     return 0;
@@ -86,6 +87,10 @@ TChain* CreateESDChain(const char* aDataDir = "ESDfiles.txt", Int_t aRuns = 20,
     ifstream in;
     in.open(aDataDir);
 
+    ofstream outfile;
+    if (check)
+      outfile.open(check);
+
     Int_t count = 0;
 
     // Read the input list of files and add them to the chain
@@ -129,6 +134,7 @@ TChain* CreateESDChain(const char* aDataDir = "ESDfiles.txt", Int_t aRuns = 20,
           file->Close();
         }
         
+        outfile << line.Data() << endl;
         printf("%s\n", line.Data());
       }        
         
@@ -141,6 +147,9 @@ TChain* CreateESDChain(const char* aDataDir = "ESDfiles.txt", Int_t aRuns = 20,
     }
 
     in.close();
+    
+    if (check)
+      outfile.close();
   }
   
   if (chainFriend)
@@ -149,12 +158,10 @@ TChain* CreateESDChain(const char* aDataDir = "ESDfiles.txt", Int_t aRuns = 20,
   return chain;
 }
 
-void LookupWrite(TChain* chain, const char* target)
+void ChainToTextFile(TChain* chain, const char* target)
 {
-  // looks up the chain and writes the remaining files to the text file target
-
-  chain->Lookup();
-
+  // write a text list of the files in the chain
+  
   TObjArray* list = chain->GetListOfFiles();
   TIterator* iter = list->MakeIterator();
   TObject* obj = 0;
@@ -162,10 +169,65 @@ void LookupWrite(TChain* chain, const char* target)
   ofstream outfile;
   outfile.open(target);
 
-  while ((obj = iter->Next()))
-    outfile << obj->GetTitle() << endl;
+  while ((obj = iter->Next())) {
+    TString fileName(obj->GetTitle());
+    
+    fileName.Remove(fileName.Length()-13);
+
+    outfile << fileName.Data() << endl;
+  }
 
   outfile.close();
 
   delete iter;
+} 
+
+void LookupWrite(TChain* chain, const char* target)
+{
+  // looks up the chain and writes the remaining files to the text file target
+
+  chain->Lookup();
+
+  ChainToTextFile(chain, target);
+}
+
+TChain* CreateChain(const char* treeName, const char* aDataDir, Int_t aRuns, Int_t offset = 0)
+{
+  // creates chain of files in a given directory or file containing a list.
+
+  if (!treeName || !aDataDir)
+    return 0;
+
+  TChain* chain = new TChain(treeName);
+  
+  // Open the input stream
+  ifstream in;
+  in.open(aDataDir);
+
+  Int_t count = 0;
+
+  // Read the input list of files and add them to the chain
+  TString line;
+  while(in.good()) 
+  {
+    in >> line;
+      
+    if (line.Length() == 0)
+      continue;      
+    
+    if (offset > 0)
+    {
+      --offset;
+      continue;
+    }
+
+    if (count++ == aRuns)
+      break;
+
+    chain->Add(line);
+  }
+
+  in.close();
+
+  return chain;
 }