]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TPC/AliTPCHits2Digits.C
CMake: same deps for linked libs and rootmaps
[u/mrichter/AliRoot.git] / TPC / AliTPCHits2Digits.C
index e4a424f8863858ed05db2f4fdf39ade63c9ce34e..7957a98baad294056557f3ed6011a12e7d7ed9d5 100644 (file)
@@ -1,55 +1,69 @@
-void TPCHits2Digits()
-{
-  // Dynamically link some shared libs
-  if (gClassTable->GetID("AliRun") < 0) {
-    gROOT->LoadMacro("loadlibs.C");
-    loadlibs();
-  }  
-  gROOT->LoadMacro("SetTPCParam.C");
-  AliTPCParam *par=SetTPCParam();
+#if !defined(__CINT__) || defined(__MAKECINT__)
+  #include <Riostream.h>
 
+  #include "AliRun.h"
+  #include "AliRunLoader.h"
+  #include "AliLoader.h"
+  #include "AliTPC.h"
 
+  #include "TStopwatch.h"
+#endif
+
+extern AliRun *gAlice;
+
+Int_t AliTPCHits2Digits(Int_t nev=5) {
   // Connect the Root Galice file containing Geometry, Kine and Hits
-  const char * inFile = "galice.root";  
-  TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(inFile);
-  if (file) file->Close();
-  file = new TFile(inFile,"UPDATE");
+  if (gAlice) { 
+     delete AliRunLoader::Instance();
+     delete gAlice;//if everything was OK here it is already NULL
+     gAlice = 0x0;
+  }
+
+  AliRunLoader *rl = AliRunLoader::Open("galice.root","Event","update");
+  if (!rl) {
+    cerr<<"Can't load RunLoader from "<<endl;
+    return 1;
+  }
+
   // Get AliRun object from file or create it if not on file
 
-  gAlice = (AliRun*)file->Get("gAlice");
-  if (gAlice) printf("AliRun object found on file\n");
-  if (!gAlice) gAlice = new AliRun("gAlice","Alice test program");
+  rl->LoadgAlice();
+  gAlice = rl->GetAliRun();
+  if (!gAlice) {
+    cerr<<"AliTPCHits2Digits.C : AliRun object not found on file\n";
+    return 2;
+  }
 
-  gAlice->GetEvent(0);
   AliTPC *TPC = (AliTPC*)gAlice->GetDetector("TPC");      
-    
-  cerr<<"Hits2Digits\n";
-  //setup TPCDigitsArray 
-  AliTPCDigitsArray *arr = new AliTPCDigitsArray; 
-  arr->SetClass("AliSimDigits");
-  arr->Setup(par);
-  TPC->SetParam(par);
-  arr->MakeTree();
-
-  TPC->SetDigitsArray(arr);
-  TPC->Hits2DigitsSector(1);             
-  TPC->Hits2DigitsSector(2);             
-  TPC->Hits2DigitsSector(3);             
-  TPC->Hits2DigitsSector(1+18);             
-  TPC->Hits2DigitsSector(2+18);             
-  TPC->Hits2DigitsSector(3+18);             
-
-  TPC->Hits2DigitsSector(36+1);             
-  TPC->Hits2DigitsSector(36+2);             
-  TPC->Hits2DigitsSector(36+3);             
-  TPC->Hits2DigitsSector(36+1+18);             
-  TPC->Hits2DigitsSector(36+2+18);             
-  TPC->Hits2DigitsSector(36+3+18);             
-  //write results
-  char treeName[100];
-  sprintf(treeName,"TreeD_%s",par->GetTitle());
-  TPC->GetDigitsArray()->GetTree()->Write(treeName);
-  par->Write(par->GetTitle());
-  file->Close();
-};
+  AliLoader * tpcl = rl->GetLoader("TPCLoader");
+  if ((TPC == 0x0) || (tpcl == 0x0)) {
+    cerr<<"AliTPCHits2Digits.C : Can not find TPC or TPCLoader\n";
+    delete rl;
+    return 3;
+  }
+  tpcl->LoadHits("READ");
+  tpcl->LoadDigits("recreate");
+
+  TStopwatch timer;
+  timer.Start();
+
+ // uncomment below lines to set sectors active
+ // Int_t sec[10]={0,1,2,3,4,5,6,7,8,9};
+ // TPC->SetActiveSectors(sec,10);
+
+  for (Int_t i=0; i<nev; i++){
+    printf("Processing event %d \n",i);
+    if(rl->GetEvent(i)) break;
+    TPC->SetActiveSectors(); // all sectors set active
+    TPC->Hits2Digits(i);
+  }
+
+  delete rl;
+
+  timer.Stop();
+  timer.Print();
+
+  return 0;
+}