]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ANALYSIS/AliTagAnalysis.cxx
fatal error in case OCDB entry with alignment objects is not found for one or more...
[u/mrichter/AliRoot.git] / ANALYSIS / AliTagAnalysis.cxx
index 5826fe98510eed04604d2ad3be68ee26610d591b..199544aeadbb19cc8b4cedfeef058a1d7fcbbf36 100644 (file)
@@ -20,6 +20,7 @@
 //-----------------------------------------------------------------
 
 //ROOT
+#include <Riostream.h>
 #include <TSystem.h>
 #include <TChain.h>
 #include <TFile.h>
@@ -50,19 +51,33 @@ AliTagAnalysis::AliTagAnalysis():
   TObject(),
   ftagresult(0x0),
   fTagDirName(),
-  fChain(0x0)
-{
+  fChain(0x0),
+  fAnalysisType(),
+  fGlobalList(0) {
   //Default constructor for a AliTagAnalysis
 }
 
+//___________________________________________________________________________
+AliTagAnalysis::AliTagAnalysis(const char* type): 
+  TObject(),
+  ftagresult(0x0),
+  fTagDirName(),
+  fChain(0x0),
+  fAnalysisType(type),
+  fGlobalList(0) {
+  //constructor for a AliTagAnalysis
+}
+
 //___________________________________________________________________________
 AliTagAnalysis::~AliTagAnalysis() {
-//Default destructor for a AliTagAnalysis
+  //Default destructor for a AliTagAnalysis
+  if(ftagresult) delete ftagresult;
+  if(fChain) delete fChain;
+  if(fGlobalList) delete fGlobalList;
 }
 
 //___________________________________________________________________________
 Bool_t  AliTagAnalysis::AddTagsFile(const char *alienUrl) {
-
   // Add a single tags file to the chain
 
   Bool_t rv = kTRUE ;
@@ -88,8 +103,11 @@ void AliTagAnalysis::ChainLocalTags(const char *dirname) {
   TString fTagFilename;
   
   if (! fChain)  fChain = new TChain("T");
-  
-  const char * tagPattern = "tag.root";
+  const char * tagPattern = 0x0;
+  if(fAnalysisType == "ESD") tagPattern = "ESD.tag.root";
+  else if(fAnalysisType == "AOD") tagPattern = "AOD.tag.root";
+  else AliFatal("Only ESD and AOD type is implemented!!!");
+
   // Open the working directory
   void * dirp = gSystem->OpenDirectory(fTagDirName);
   const char * name = 0x0;
@@ -108,7 +126,7 @@ void AliTagAnalysis::ChainLocalTags(const char *dirname) {
 
 
 //___________________________________________________________________________
-void AliTagAnalysis::ChainGridTags(TGridResult *res) {
+TChain * AliTagAnalysis::ChainGridTags(TGridResult *res) {
   //Loops overs the entries of the TGridResult
   //Chains the tags that are stored in the GRID
   ftagresult = res;
@@ -122,32 +140,39 @@ void AliTagAnalysis::ChainGridTags(TGridResult *res) {
   for(Int_t i = 0; i < nEntries; i++) {
     alienUrl = ftagresult->GetKey(i,"turl");
     fChain->Add(alienUrl);
-  }//grid result loop  
+  }//grid result loop
+  return fChain;
 }
 
 
 //___________________________________________________________________________
-TChain *AliTagAnalysis::QueryTags(AliRunTagCuts *runTagCuts, AliLHCTagCuts *lhcTagCuts, AliDetectorTagCuts *detTagCuts, AliEventTagCuts *evTagCuts) {
+TChain *AliTagAnalysis::QueryTags(AliRunTagCuts *runTagCuts, 
+                                 AliLHCTagCuts *lhcTagCuts, 
+                                 AliDetectorTagCuts *detTagCuts, 
+                                 AliEventTagCuts *evTagCuts) {
   //Queries the tag chain using the defined 
   //event tag cuts from the AliEventTagCuts object
   //and returns a TChain along with the associated TEventList
   AliInfo(Form("Querying the tags........"));
 
-  TString fAliceFile = "esdTree";
+  TString fAliceFile;
+  if(fAnalysisType == "ESD") fAliceFile = "esdTree";
+  else if(fAnalysisType == "AOD") fAliceFile = "aodTree";
+  else AliFatal("Only ESD and AOD type is implemented!!!");
 
   //ESD file chain
   TChain *fESDchain = new TChain(fAliceFile.Data());
   //global entry list
-  TEntryList *fGlobalList = new TEntryList();
+  fGlobalList = new TEntryList();
   
   //Defining tag objects
-  AliRunTag *tag = new AliRunTag;
-  AliEventTag *evTag = new AliEventTag;
+  AliRunTag   *tag     = new AliRunTag;
+  AliEventTag *evTag   = new AliEventTag;
   fChain->SetBranchAddress("AliTAG",&tag);
 
-  TString guid = 0;
-  TString turl = 0;
-  TString path = 0;
+  TString guid;
+  TString turl;
+  TString path;
 
   Int_t iAccepted = 0;
   for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) {
@@ -164,10 +189,10 @@ TChain *AliTagAnalysis::QueryTags(AliRunTagCuts *runTagCuts, AliLHCTagCuts *lhcT
            turl = evTag->GetTURL(); 
            path = evTag->GetPath();
            fLocalList->SetTreeName(fAliceFile.Data());
-           fLocalList->SetFileName(turl.Data());
+           if(turl!="") fLocalList->SetFileName(turl.Data());
+           else fLocalList->SetFileName(path.Data());
            if(evTagCuts->IsAccepted(evTag)) fLocalList->Enter(i);
          }//event loop
-         
          if(path != "") fESDchain->AddFile(path);
          else if(turl != "") fESDchain->AddFile(turl);
          fGlobalList->Add(fLocalList);
@@ -175,6 +200,7 @@ TChain *AliTagAnalysis::QueryTags(AliRunTagCuts *runTagCuts, AliLHCTagCuts *lhcT
        }//detector tag cuts
       }//lhc tag cuts
     }//run tags cut
+    tag->Clear();
   }//tag file loop
   AliInfo(Form("Accepted events: %d",iAccepted));
   fESDchain->SetEntryList(fGlobalList,"ne");
@@ -183,27 +209,33 @@ TChain *AliTagAnalysis::QueryTags(AliRunTagCuts *runTagCuts, AliLHCTagCuts *lhcT
 }
 
 //___________________________________________________________________________
-TChain *AliTagAnalysis::QueryTags(const char *fRunCut, const char *fLHCCut, const char *fDetectorCut, const char *fEventCut) {          
+TChain *AliTagAnalysis::QueryTags(const char *fRunCut, 
+                                 const char *fLHCCut, 
+                                 const char *fDetectorCut, 
+                                 const char *fEventCut) {       
   //Queries the tag chain using the defined     
   //event tag cuts from the AliEventTagCuts object      
   //and returns a TChain along with the associated TEventList   
   AliInfo(Form("Querying the tags........"));   
   
-  TString fAliceFile = "esdTree";
+  TString fAliceFile;
+  if(fAnalysisType == "ESD") fAliceFile = "esdTree";
+  else if(fAnalysisType == "AOD") fAliceFile = "aodTree";
+  else AliFatal("Only ESD and AOD type is implemented!!!");
 
   //ESD file chain
   TChain *fESDchain = new TChain(fAliceFile.Data());
   //global entry list
-  TEntryList *fGlobalList = new TEntryList();
+  fGlobalList = new TEntryList();
   
   //Defining tag objects        
   AliRunTag *tag = new AliRunTag;       
   AliEventTag *evTag = new AliEventTag;         
   fChain->SetBranchAddress("AliTAG",&tag);      
   
-  TString guid = 0;     
-  TString turl = 0;     
-  TString path = 0;     
+  TString guid;         
+  TString turl;         
+  TString path;         
   
   TTreeFormula *fRunFormula = new TTreeFormula("fRun",fRunCut,fChain);          
   TTreeFormula *fLHCFormula = new TTreeFormula("fLHC",fLHCCut,fChain);          
@@ -212,7 +244,7 @@ TChain *AliTagAnalysis::QueryTags(const char *fRunCut, const char *fLHCCut, cons
   
   Int_t current = -1;   
   Int_t iAccepted = 0;          
-  for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) {     
+  for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) {
     fChain->GetEntry(iTagFiles);        
     if (current != fChain->GetTreeNumber()) {   
       fRunFormula->UpdateFormulaLeaves();       
@@ -253,7 +285,11 @@ TChain *AliTagAnalysis::QueryTags(const char *fRunCut, const char *fLHCCut, cons
 }
 
 //___________________________________________________________________________
-Bool_t AliTagAnalysis::CreateXMLCollection(const char* name, AliRunTagCuts *runTagCuts, AliLHCTagCuts *lhcTagCuts, AliDetectorTagCuts *detTagCuts, AliEventTagCuts *evTagCuts) {
+Bool_t AliTagAnalysis::CreateXMLCollection(const char* name, 
+                                          AliRunTagCuts *runTagCuts, 
+                                          AliLHCTagCuts *lhcTagCuts, 
+                                          AliDetectorTagCuts *detTagCuts, 
+                                          AliEventTagCuts *evTagCuts) {
   //Queries the tag chain using the defined 
   //event tag cuts from the AliEventTagCuts object
   //and returns a XML collection
@@ -263,9 +299,9 @@ Bool_t AliTagAnalysis::CreateXMLCollection(const char* name, AliRunTagCuts *runT
   collection->SetCollectionName(name);
   collection->WriteHeader();
 
-  TString guid = 0x0;
-  TString turl = 0x0;
-  TString lfn = 0x0;
+  TString guid;
+  TString turl;
+  TString lfn;
   
   //Defining tag objects
   AliRunTag *tag = new AliRunTag;
@@ -292,6 +328,7 @@ Bool_t AliTagAnalysis::CreateXMLCollection(const char* name, AliRunTagCuts *runT
        }//detector tag cuts
       }//lhc tag cuts 
     }//run tag cuts
+    tag->Clear();
   }//tag file loop
   collection->Export();
 
@@ -299,7 +336,11 @@ Bool_t AliTagAnalysis::CreateXMLCollection(const char* name, AliRunTagCuts *runT
 }
 
 //___________________________________________________________________________
-Bool_t AliTagAnalysis::CreateXMLCollection(const char* name, const char *fRunCut, const char *fLHCCut, const char *fDetectorCut, const char *fEventCut) {
+Bool_t AliTagAnalysis::CreateXMLCollection(const char* name, 
+                                          const char *fRunCut, 
+                                          const char *fLHCCut, 
+                                          const char *fDetectorCut, 
+                                          const char *fEventCut) {
   //Queries the tag chain using the defined 
   //event tag cuts from the AliEventTagCuts object
   //and returns a XML collection
@@ -309,9 +350,9 @@ Bool_t AliTagAnalysis::CreateXMLCollection(const char* name, const char *fRunCut
   collection->SetCollectionName(name);
   collection->WriteHeader();
 
-  TString guid = 0x0;
-  TString turl = 0x0;
-  TString lfn = 0x0;
+  TString guid;
+  TString turl;
+  TString lfn;
   
   //Defining tag objects
   AliRunTag *tag = new AliRunTag;
@@ -357,6 +398,134 @@ Bool_t AliTagAnalysis::CreateXMLCollection(const char* name, const char *fRunCut
   return kTRUE;
 }
 
+//___________________________________________________________________________
+Bool_t AliTagAnalysis::CreateAsciiCollection(const char* name, 
+                                            AliRunTagCuts *runTagCuts, 
+                                            AliLHCTagCuts *lhcTagCuts, 
+                                            AliDetectorTagCuts *detTagCuts, 
+                                            AliEventTagCuts *evTagCuts) {
+  //Queries the tag chain using the defined 
+  //event tag cuts from the AliEventTagCuts object
+  //and returns a XML collection
+  AliInfo(Form("Creating the collection........"));
+
+  ofstream fout;
+  fout.open(name);
+
+  TString guid;
+  TString turl;
+  TString lfn;
+
+  TString line0;
+
+  //Defining tag objects
+  AliRunTag *tag = new AliRunTag;
+  AliEventTag *evTag = new AliEventTag;
+  fChain->SetBranchAddress("AliTAG",&tag);
+
+  for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) {
+    //Event list
+    TEntryList *fList = new TEntryList();
+    fChain->GetEntry(iTagFiles);
+    if(runTagCuts->IsAccepted(tag)) {
+      if(lhcTagCuts->IsAccepted(tag->GetLHCTag())) {
+       if(detTagCuts->IsAccepted(tag->GetDetectorTags())) {
+         Int_t iEvents = tag->GetNEvents();
+         const TClonesArray *tagList = tag->GetEventTags();
+         for(Int_t i = 0; i < iEvents; i++) {
+           evTag = (AliEventTag *) tagList->At(i);
+           guid = evTag->GetGUID(); 
+           turl = evTag->GetTURL(); 
+           lfn = turl(8,turl.Length());
+           if(evTagCuts->IsAccepted(evTag)) fList->Enter(i);
+         }//event loop
+         line0 = guid; line0 += " "; line0 += turl; line0 += " ";
+         for(Int_t i = 0; i < fList->GetN(); i++) {
+           line0 += fList->GetEntry(i); 
+           line0 += " ";
+         }  
+         fout<<line0<<"\n";
+       }//detector tag cuts
+      }//lhc tag cuts 
+    }//run tag cuts
+    tag->Clear();
+  }//tag file loop
+
+  fout.close();
+
+  return kTRUE;
+}
+
+//___________________________________________________________________________
+Bool_t AliTagAnalysis::CreateAsciiCollection(const char* name, 
+                                            const char *fRunCut, 
+                                            const char *fLHCCut, 
+                                            const char *fDetectorCut, 
+                                            const char *fEventCut) {
+  //Queries the tag chain using the defined 
+  //event tag cuts from the AliEventTagCuts object
+  //and returns a XML collection
+  AliInfo(Form("Creating the collection........"));
+
+  ofstream fout;
+  fout.open(name);
+
+  TString guid;
+  TString turl;
+  TString lfn;
+
+  TString line0;
+  
+  //Defining tag objects
+  AliRunTag *tag = new AliRunTag;
+  AliEventTag *evTag = new AliEventTag;
+  fChain->SetBranchAddress("AliTAG",&tag);
+
+  TTreeFormula *fRunFormula = new TTreeFormula("fRun",fRunCut,fChain);
+  TTreeFormula *fLHCFormula = new TTreeFormula("fLHC",fLHCCut,fChain);          
+  TTreeFormula *fDetectorFormula = new TTreeFormula("fDetector",fDetectorCut,fChain);
+  TTreeFormula *fEventFormula = new TTreeFormula("fEvent",fEventCut,fChain);
+
+  Int_t current = -1;
+  for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) {
+    //Event list
+    TEntryList *fList = new TEntryList();
+    fChain->GetEntry(iTagFiles);
+    if (current != fChain->GetTreeNumber()) {
+      fRunFormula->UpdateFormulaLeaves();
+      fLHCFormula->UpdateFormulaLeaves();
+      fDetectorFormula->UpdateFormulaLeaves();
+      fEventFormula->UpdateFormulaLeaves();
+      current = fChain->GetTreeNumber();
+    }
+    if(fRunFormula->EvalInstance(iTagFiles) == 1) {
+      if(fLHCFormula->EvalInstance(iTagFiles) == 1) {   
+       if(fDetectorFormula->EvalInstance(iTagFiles) == 1) {     
+         Int_t iEvents = fEventFormula->GetNdata();
+         const TClonesArray *tagList = tag->GetEventTags();
+         for(Int_t i = 0; i < iEvents; i++) {
+           evTag = (AliEventTag *) tagList->At(i);
+           guid = evTag->GetGUID(); 
+           turl = evTag->GetTURL(); 
+           lfn = turl(8,turl.Length());
+           if(fEventFormula->EvalInstance(i) == 1) fList->Enter(i);
+         }//event loop
+         line0 = guid; line0 += " "; line0 += turl; line0 += " ";
+         for(Int_t i = 0; i < fList->GetN(); i++) {
+           line0 += fList->GetEntry(i); 
+           line0 += " ";
+         }  
+         fout<<line0<<"\n";
+       }//detector tag cuts
+      }//lhc tag cuts 
+    }//run tag cuts
+  }//tag file loop
+
+  fout.close();
+
+  return kTRUE;
+}
+
 //___________________________________________________________________________
 TChain *AliTagAnalysis::GetInputChain(const char* system, const char *wn) {
   //returns the chain+event list - used in batch sessions
@@ -364,8 +533,12 @@ TChain *AliTagAnalysis::GetInputChain(const char* system, const char *wn) {
   // improvements are committed
   TString fsystem = system;
   Int_t iAccepted = 0;
-  //ESD file chain
-  TChain *fESDchain = new TChain("esdTree");
+
+  TChain *fAnalysisChain = 0;
+  if(fAnalysisType == "ESD") fAnalysisChain = new TChain("esdTree");
+  else if(fAnalysisType == "AOD") fAnalysisChain = new TChain("aodTree");
+  else AliFatal("Only ESD and AOD type is implemented!!!");
+  
   //Event list
   TEventList *fEventList = new TEventList();
   AliXMLCollection *collection = AliXMLCollection::Open(wn);
@@ -373,7 +546,7 @@ TChain *AliTagAnalysis::GetInputChain(const char* system, const char *wn) {
   collection->Reset();
   while (collection->Next()) {
     AliInfo(Form("Adding: %s",collection->GetTURL("")));
-    fESDchain->Add(collection->GetTURL(""));
+    fAnalysisChain->Add(collection->GetTURL(""));
     TEntryList *list = (TEntryList *)collection->GetEventList("");
     for(Int_t i = 0; i < list->GetN(); i++) fEventList->Enter(iAccepted+list->GetEntry(i));
 
@@ -381,30 +554,26 @@ TChain *AliTagAnalysis::GetInputChain(const char* system, const char *wn) {
     else if(fsystem == "PbPb") iAccepted += 1;
   }
 
-  fESDchain->SetEventList(fEventList);
+  fAnalysisChain->SetEventList(fEventList);
   
   AliInfo(Form("Number of selected events: %d",fEventList->GetN()));
 
-  return fESDchain;
+  return fAnalysisChain;
 }
 
 //___________________________________________________________________________
-TChain *AliTagAnalysis::GetChainFromCollection(const char* collectionname, const char* treename) {
+TChain *AliTagAnalysis::GetChainFromCollection(const char* collectionname, 
+                                              const char* treename) {
   //returns the TChain+TEntryList object- used in batch sessions
   TString fAliceFile = treename;
   Int_t iAccepted = 0;
-  TChain *fAnalysisChain = new TChain();
-  if(fAliceFile == "esdTree") {
-    //ESD file chain
-    fAnalysisChain->SetName("esdTree");
-  } else if(fAliceFile == "aodTree") {
-    //AOD file chain
-    fAnalysisChain->SetName("aodTree");
-    AliFatal("AOD case not yet implemented!!!");
-  }
+  TChain *fAnalysisChain = 0;
+  if(fAliceFile == "esdTree") fAnalysisChain = new TChain("esdTree");
+  else if(fAliceFile == "aodTree") fAnalysisChain = new TChain("aodTree");
   else AliFatal("Inconsistent tree name - use esdTree or aodTree!");
+
   //Event list
-  TEntryList *fGlobalList = new TEntryList();
+  fGlobalList = new TEntryList();
   AliXMLCollection *collection = AliXMLCollection::Open(collectionname);
 
   collection->Reset();