]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliAODTagCreator.cxx
more secure string operations
[u/mrichter/AliRoot.git] / STEER / AliAODTagCreator.cxx
index 30b007f4f053e3d9a3c518e7b3490365da561798..74d7d727ec10dbd06244e55b4b4b27de2fb1758a 100644 (file)
@@ -36,6 +36,7 @@
 //AliRoot
 #include "AliRunTag.h"
 #include "AliEventTag.h"
+#include "AliFileTag.h"
 #include "AliPID.h"
 #include "AliAODEvent.h"
 #include "AliAODVertex.h"
@@ -93,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");
   
@@ -101,20 +102,19 @@ 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))) {
        TString bstr = dirname;
@@ -130,7 +130,7 @@ Bool_t AliAODTagCreator::ReadLocalCollection(const char *localpath) {
   } //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");
 
@@ -158,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");
 
@@ -189,7 +189,7 @@ void AliAODTagCreator::CreateAODTags(Int_t fFirstEvent, Int_t fLastEvent, TList
     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));
@@ -228,7 +228,7 @@ 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;
     
@@ -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,15 +317,16 @@ 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 (!strcmp(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();
        
@@ -331,13 +334,16 @@ void AliAODTagCreator::CreateTags(const char* type)
        FillEventTag(fAODEvent, evTag);
        // Set the event and input file references
        //evTag->SetEventId(iEventNumber+1);
-       evTag->SetGUID(fguid);
-       if(!strcmp(type,"grid")) {
-           evTag->SetMD5("");
-           evTag->SetTURL(fturl);
-           evTag->SetSize(0);
-           }
-       else evTag->SetPath(fturl);
+       
+       // **** 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