]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliAODTagCreator.cxx
coverity warnings 15388 10083 10082 fixed
[u/mrichter/AliRoot.git] / STEER / AliAODTagCreator.cxx
index 322055196007913bfb183e63ec6eaae46d71024a..b2b31f1ab05032ec7b167ad8e9016633f28b4eca 100644 (file)
@@ -27,6 +27,7 @@
 #include <TSystem.h>
 #include <TChain.h>
 #include <TLorentzVector.h>
+#include <TRefArray.h>
 
 //ROOT-AliEn
 #include <TGrid.h>
@@ -35,6 +36,7 @@
 //AliRoot
 #include "AliRunTag.h"
 #include "AliEventTag.h"
+#include "AliFileTag.h"
 #include "AliPID.h"
 #include "AliAODEvent.h"
 #include "AliAODVertex.h"
@@ -74,7 +76,7 @@ Bool_t AliAODTagCreator::ReadGridCollection(TGridResult *fresult) {
   TString alienUrl;
   const char* guid;
   const char* md5;
-  const char* turl;
+  //  const char* turl;
   Long64_t size = -1;
 
   fChain = new TChain("aodTree");
@@ -84,7 +86,7 @@ Bool_t AliAODTagCreator::ReadGridCollection(TGridResult *fresult) {
     guid = fresult->GetKey(i,"guid");
     if(fresult->GetKey(i,"size")) size = atol (fresult->GetKey(i,"size"));
     md5 = fresult->GetKey(i,"md5");
-    turl = fresult->GetKey(i,"turl");
+    //    turl = fresult->GetKey(i,"turl");
     if(md5 && !strlen(guid)) md5 = 0;
     if(guid && !strlen(guid)) guid = 0;
     
@@ -92,7 +94,7 @@ Bool_t AliAODTagCreator::ReadGridCollection(TGridResult *fresult) {
   }//grid result loop
   
   AliInfo(Form("AOD chain created......."));   
-  AliInfo(Form("Chain entries: %d",fChain->GetEntries()));     
+  AliInfo(Form("Chain entries: %lld",fChain->GetEntries()));   
 
   CreateTag(fChain, "grid");
   
@@ -100,34 +102,35 @@ Bool_t AliAODTagCreator::ReadGridCollection(TGridResult *fresult) {
 }
 
 //______________________________________________________________________________
-Bool_t AliAODTagCreator::ReadLocalCollection(const char *localpath) {
+Bool_t AliAODTagCreator::ReadLocalCollection(const char *localpath, const char* pattern) {
   // Checks the different subdirs of the given local path and in the
-  // case where it finds an AliAODs.root file it creates the tags
+  // case where it finds an AliAOD.root file it creates the tags
   
   void *dira =  gSystem->OpenDirectory(localpath);
-  Char_t fPath[256];
-  const char * dirname = 0x0;
+  Char_t fPath[512];
+  const char * dirname  = 0x0;
   const char * filename = 0x0;
-  const char * pattern = "AliAODs.root"; 
 
   fChain = new TChain("aodTree");
 
   while((dirname = gSystem->GetDirEntry(dira))) {
-    sprintf(fPath,"%s/%s",localpath,dirname);
+    snprintf(fPath,512,"%s/%s",localpath,dirname);
     void *dirb =  gSystem->OpenDirectory(fPath);
     while((filename = gSystem->GetDirEntry(dirb))) {
-      if(strstr(filename,pattern)) {
-       TString aodFileName;
-       aodFileName = fPath;
-       aodFileName += "/";
-       aodFileName += pattern;
-       fChain->Add(aodFileName);
-      }//pattern check
-    }//child directory's entry loop
-  }//parent directory's entry loop
-
+       TString bstr = dirname;
+       if(bstr.Contains("..")) continue;
+       if(strstr(filename,pattern)) {
+           TString aodFileName;
+           aodFileName = fPath;
+           aodFileName += "/";
+           aodFileName += pattern;
+           fChain->Add(aodFileName);
+       } //pattern check
+    } //child directory's entry loop
+  } //parent directory's entry loop
+  
   AliInfo(Form("AOD chain created......."));   
-  AliInfo(Form("Chain entries: %d",fChain->GetEntries()));     
+  AliInfo(Form("Chain entries: %lld",fChain->GetEntries()));   
 
   CreateTag(fChain, "local");
 
@@ -155,7 +158,7 @@ Bool_t AliAODTagCreator::ReadCAFCollection(const char *filename) {
   }
 
   AliInfo(Form("AOD chain created......."));   
-  AliInfo(Form("Chain entries: %d",fChain->GetEntries()));     
+  AliInfo(Form("Chain entries: %lld",fChain->GetEntries()));   
 
   CreateTag(fChain, "proof");
 
@@ -185,16 +188,15 @@ void AliAODTagCreator::CreateAODTags(Int_t fFirstEvent, Int_t fLastEvent, TList
     if(fLastEvent == -1) lastEvent = (Int_t)fChain->GetEntries();
     else lastEvent = fLastEvent;
 
-
     char fileName[256];
-    sprintf(fileName, "Run%d.Event%d_%d.AOD.tag.root", 
+    snprintf(fileName, 256, "Run%d.Event%d_%d.AOD.tag.root", 
            fAODEvent->GetRunNumber(), fFirstEvent, lastEvent );
     AliInfo(Form("writing tags to file %s", fileName));
     AliDebug(1, Form("writing tags to file %s", fileName));
  
     TFile* ftag = TFile::Open(fileName, "recreate");
 
-    AliRunTag *fRunTag = new AliRunTag();
+    fRunTag = new AliRunTag();
     fTreeT = new TTree("T","A Tree with event tags");
     TBranch * btag = fTreeT->Branch("AliTAG", &fRunTag);
     btag->SetCompressionLevel(9);
@@ -216,8 +218,7 @@ void AliAODTagCreator::CreateTag(TChain* chain, const char *type) {
     // Private method that creates tag files
     //
 
-
-    //reading the esd tag file                                                  
+    //reading the esd tag file 
     fTreeTEsd = new TChain("T");
     const char * tagPattern = "ESD.tag";
     // Open the working directory
@@ -227,9 +228,8 @@ void AliAODTagCreator::CreateTag(TChain* chain, const char *type) {
     while((name = gSystem->GetDirEntry(dirp))) {
        if (strstr(name,tagPattern)) fTreeTEsd->Add(name);
     }//directory loop
-    AliInfo(Form("Chained tag files: %d", fTreeTEsd->GetEntries()));
-  
-    
+    AliInfo(Form("Chained tag files: %lld",fTreeTEsd->GetEntries()));
+      
     fChain = chain;
     
     TString fSession = type;
@@ -284,7 +284,7 @@ void AliAODTagCreator::CreateTag(TChain* chain, const char *type) {
     ftag->Close();
 }
 
-void AliAODTagCreator::CreateTags(const char* type)
+void AliAODTagCreator::CreateTags(const char* /*type*/)
 {
     // Event loop for tag creation
     TString fturl;
@@ -297,15 +297,17 @@ void AliAODTagCreator::CreateTags(const char* type)
     Int_t nEvents = fChain->GetEntries();
     Int_t ntags    = 0;
     Int_t tagentry = 0;
-    const TClonesArray *evTagList = 0;
+    //    const TClonesArray *evTagList = 0;
+    TString foldguid = "";
 
     for (Int_t iEventNumber = 0; iEventNumber < nEvents; iEventNumber++) {
        // Copy old tag information
        if (iEventNumber >= ntags) {
            fTreeTEsd->GetEntry(tagentry++);
            fRunTag->CopyStandardContent(fRunTagEsd);
-           evTagList = fRunTagEsd->GetEventTags();
-           ntags += evTagList->GetEntries();
+//         evTagList = fRunTagEsd->GetEventTags();
+//         ntags += evTagList->GetEntries();
+           ntags = fRunTagEsd->GetNEvents();
        }
 
        // Create a new Tag
@@ -315,29 +317,33 @@ void AliAODTagCreator::CreateTags(const char* type)
        if (iEventNumber == 0) oldRun = fAODEvent->GetRunNumber();
        // Reference to the input file
        TFile *file = fChain->GetFile();
-       const TUrl *url = file->GetEndpointUrl();
+       //      const TUrl *url = file->GetEndpointUrl();
        fguid = file->GetUUID().AsString();
 
-       if (type == "grid") {
-           TString fturltemp = "alien://"; fturltemp += url->GetFile();
-           fturl = fturltemp(0,fturltemp.Index(".root",5,0,TString::kExact)+5);
-       } else {
-           fturl = url->GetFile();
-       }
+//     if (!strcmp(type,"grid")) {
+//         TString fturltemp = "alien://"; fturltemp += url->GetFile();
+//         fturl = fturltemp(0,fturltemp.Index(".root",5,0,TString::kExact)+5);
+//     } else {
+//         fturl = url->GetFile();
+//     }
+       fturl = file->GetName();
        
        fAODEvent->GetStdContent();
        
        // Fill the event tag from the aod informatiom
        FillEventTag(fAODEvent, evTag);
        // Set the event and input file references
-       evTag->SetEventId(iEventNumber+1);
-       evTag->SetGUID(fguid);
-       if(type == "grid") {
-           evTag->SetMD5(0);
-           evTag->SetTURL(fturl);
-           evTag->SetSize(0);
-           }
-       else evTag->SetPath(fturl);
+       //evTag->SetEventId(iEventNumber+1);
+       
+       // **** FIXME ****
+//     evTag->SetGUID(fguid);
+//     if(!strcmp(type,"grid")) {
+//         evTag->SetMD5("");
+//         evTag->SetTURL(fturl);
+//         evTag->SetSize(0);
+//         }
+//     else evTag->SetPath(fturl);
+       //  **** FIXME ****
 
        // Check if a new run has to be created
        // File has changed
@@ -345,13 +351,58 @@ void AliAODTagCreator::CreateTags(const char* type)
            ftempGuid = fguid;
            fTreeT->Fill();
            fRunTag->Clear("");
+
+           AliFileTag *nftag = new AliFileTag();
+           
+           // if(fSession == "grid") {
+             nftag->SetMD5("");
+             nftag->SetTURL(fturl);
+             nftag->SetSize(0);
+           // }
+           // else {
+           //   nftag->SetPath(fturl);
+           //   nftag->SetSize(0);
+           //   nftag->SetMD5("");
+           //   nftag->SetTURL(fturl);
+           // }
+      
+           if (fRunTag->GetFileId(fguid) > -1)
+             AliFatal("Adding a file which is already in the RunTag.");
+           
+           fRunTag->AddFileTag(nftag);
+           
        }
+
        // Run# has changed
        if (oldRun != (fAODEvent->GetRunNumber()))
        {
            oldRun = fAODEvent->GetRunNumber();
+
            fTreeT->Fill();
            fRunTag->Clear("");
+           ftempGuid = fguid;
+           fTreeT->Fill();
+           fRunTag->Clear("");
+
+           AliFileTag *nftag = new AliFileTag();
+           
+           // if(fSession == "grid") {
+             nftag->SetMD5("");
+             nftag->SetTURL(fturl);
+             nftag->SetSize(0);
+           // }
+           // else {
+           //   nftag->SetPath(fturl);
+           //   nftag->SetSize(0);
+           //   nftag->SetMD5("");
+           //   nftag->SetTURL(fturl);
+           // }
+      
+           if (fRunTag->GetFileId(fguid) > -1)
+             AliFatal("Adding a file which is already in the RunTag.");
+           
+           fRunTag->AddFileTag(nftag);
+           
        }
        
        // Add the event tag
@@ -386,13 +437,25 @@ void AliAODTagCreator::FillEventTag(AliAODEvent* aod, AliEventTag* evTag)
     Int_t   nPos = 0, nNeg = 0, nNeutr =0;
     Int_t   nKinks = 0, nV0s = 0, nCascades = 0;
     Int_t   nK0s = 0, nNeutrons = 0, nPi0s = 0, nGamas = 0;
-    Int_t   nProtons = 0,  nKaons = 0, nPions = 0, nMuons = 0, nElectrons = 0;
+    Int_t   nProtons = 0,  nKaons = 0, nPions = 0, nMuons = 0, nElectrons = 0, nFWMuons = 0;
     Int_t   nCh1GeV = 0, nCh3GeV = 0, nCh10GeV = 0;
     Int_t   nMu1GeV = 0, nMu3GeV = 0, nMu10GeV = 0;
     Int_t   nEl1GeV = 0, nEl3GeV = 0, nEl10GeV = 0;
-    Float_t maxPt =  .0, meanPt = .0, totalP =  .0;
+    Float_t maxPt =  .0, etamaxPt = -999., phimaxPt = -999., meanPt = .0, totalP =  .0;
 
-    Int_t nTracks = fAODEvent->GetNTracks();
+    TRefArray tmp;
+
+
+    // Primary Vertex
+    AliAODVertex *pVertex = fAODEvent->GetPrimaryVertex();
+    if (pVertex) {
+       evTag->SetVertexX(pVertex->GetX());
+       evTag->SetVertexY(pVertex->GetY());
+       evTag->SetVertexZ(pVertex->GetZ());
+       Double_t covmatrix[6];
+       pVertex->GetCovarianceMatrix(covmatrix);
+       evTag->SetVertexZError(sqrt(covmatrix[5]));
+    }
     // loop over vertices 
     Int_t nVtxs = fAODEvent->GetNumberOfVertices();
     for (Int_t nVtx = 0; nVtx < nVtxs; nVtx++) {
@@ -401,11 +464,17 @@ void AliAODTagCreator::FillEventTag(AliAODEvent* aod, AliEventTag* evTag)
        if(vertex->GetType() == 2) nV0s      += 1;
        if(vertex->GetType() == 3) nCascades += 1;
     }
+    Int_t nTracks = fAODEvent->GetNTracks();
     for (Int_t nTr = 0; nTr < nTracks; nTr++) {
        AliAODTrack *track = fAODEvent->GetTrack(nTr);
        
        Double_t fPt = track->Pt();
-       if(fPt > maxPt) maxPt = fPt;
+       if(fPt > maxPt) {
+           maxPt = fPt;
+           etamaxPt = track->Eta();
+           phimaxPt = track->Phi();
+       }
+       
        if(track->Charge() > 0) {
            nPos++;
            if(fPt > fLowPtCut)      nCh1GeV++;
@@ -448,10 +517,12 @@ void AliAODTagCreator::FillEventTag(AliAODEvent* aod, AliEventTag* evTag)
            if(fPt > fHighPtCut) nEl3GeV++;
            if(fPt > fVeryHighPtCut) nEl10GeV++;
        }
-           
        totalP += track->P();
        meanPt += fPt;
        ntrack++;
+       // forward muons (in the dimuon spectrometer)
+       if(track->IsMuonTrack()) nFWMuons++;   
+                                 
     }//track loop
     //
     // Fill the event tags  
@@ -472,6 +543,7 @@ void AliAODTagCreator::FillEventTag(AliAODEvent* aod, AliEventTag* evTag)
     evTag->SetNumOfKaons(nKaons);
     evTag->SetNumOfPions(nPions);
     evTag->SetNumOfMuons(nMuons);
+    evTag->SetNumOfFWMuons(nFWMuons);
     evTag->SetNumOfElectrons(nElectrons);
     evTag->SetNumOfPhotons(nGamas);
     evTag->SetNumOfPi0s(nPi0s);
@@ -487,8 +559,15 @@ void AliAODTagCreator::FillEventTag(AliAODEvent* aod, AliEventTag* evTag)
     evTag->SetNumOfElectronsAbove1GeV(nEl1GeV);
     evTag->SetNumOfElectronsAbove3GeV(nEl3GeV);
     evTag->SetNumOfElectronsAbove10GeV(nEl10GeV);
+
+    tmp.Clear();
+    evTag->SetNumOfPHOSClusters(fAODEvent->GetPHOSClusters(&tmp));
+    tmp.Clear();
+    evTag->SetNumOfEMCALClusters(fAODEvent->GetEMCALClusters(&tmp));
        
     evTag->SetTotalMomentum(totalP);
     evTag->SetMeanPt(meanPt);
     evTag->SetMaxPt(maxPt);
+    evTag->SetEtaMaxPt(etamaxPt);
+    evTag->SetPhiMaxPt(phimaxPt);
 }