LCOV - code coverage report
Current view: top level - ANALYSIS/ANALYSISalice - AliAnalysisTaskTagCreator.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 53 85 62.4 %
Date: 2016-06-14 17:26:59 Functions: 10 13 76.9 %

          Line data    Source code
       1             : /**************************************************************************
       2             :  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
       3             :  *                                                                        *
       4             :  * Author: The ALICE Off-line Project.                                    *
       5             :  * Contributors are mentioned in the code where appropriate.              *
       6             :  *                                                                        *
       7             :  * Permission to use, copy, modify and distribute this software and its   *
       8             :  * documentation strictly for non-commercial purposes is hereby granted   *
       9             :  * without fee, provided that the above copyright notice appears in all   *
      10             :  * copies and that both the copyright notice and this permission notice   *
      11             :  * appear in the supporting documentation. The authors make no claims     *
      12             :  * about the suitability of this software for any purpose. It is          *
      13             :  * provided "as is" without express or implied warranty.                  *
      14             :  **************************************************************************/
      15             : 
      16             : /* $Id$ */
      17             : 
      18             : #include <Riostream.h>
      19             : 
      20             : #include <TChain.h>
      21             : #include <TTree.h>
      22             : #include <TString.h>
      23             : #include <TFile.h>
      24             : #include <TSystem.h>
      25             : 
      26             : #include "AliAnalysisTaskTagCreator.h"
      27             : #include "AliAnalysisManager.h"
      28             : #include "AliESDEvent.h"
      29             : #include "AliAODEvent.h"
      30             : #include "AliESDInputHandler.h"
      31             : #include "AliAODHandler.h"
      32             : #include "AliRunTag.h"
      33             : #include "AliEventTag.h"
      34             : #include "AliAODTagCreator.h"
      35             : #include "AliLog.h"
      36             : 
      37             : 
      38             : using std::cout;
      39             : using std::endl;
      40             : using std::ofstream;
      41         170 : ClassImp(AliAnalysisTaskTagCreator)
      42             : 
      43             : ////////////////////////////////////////////////////////////////////////
      44             : 
      45             : AliAnalysisTaskTagCreator::AliAnalysisTaskTagCreator():
      46           0 :     AliAnalysisTaskSE(),
      47           0 :     fCreateTags(kFALSE),
      48           0 :     fFirstFile(kTRUE),
      49           0 :     fRunTag(0), 
      50           0 :     fTreeT(0),
      51           0 :     fTagCreator(0),
      52           0 :     fAODFileName(""),
      53           0 :     fGUID(0)
      54           0 : {
      55             :   // Default constructor
      56           0 : }
      57             : 
      58             : AliAnalysisTaskTagCreator::AliAnalysisTaskTagCreator(const char* name):
      59           2 :     AliAnalysisTaskSE(name),
      60           2 :     fCreateTags(kFALSE),
      61           2 :     fFirstFile(kTRUE),
      62           2 :     fRunTag(0), 
      63           2 :     fTreeT(0),
      64           2 :     fTagCreator(0),
      65           2 :     fAODFileName(""),
      66           2 :     fGUID(0)
      67          10 : {
      68             :   // Constructor
      69           4 :     DefineOutput(1, TTree::Class());    
      70           4 : }
      71             : 
      72             : void AliAnalysisTaskTagCreator::UserCreateOutputObjects()
      73             : {
      74             : // Create the output container
      75           4 :     OpenFile(1);
      76           4 :     fTreeT  = new TTree("T", "AOD Tags");
      77           4 :     fRunTag = new AliRunTag();
      78           2 :     TBranch * btag = fTreeT->Branch("AliTAG", "AliRunTag", &fRunTag);
      79           2 :     btag->SetCompressionLevel(9);
      80           4 :     fTagCreator = new AliAODTagCreator();
      81           2 :     PostData(1, fTreeT);
      82           2 : }
      83             : 
      84             : void AliAnalysisTaskTagCreator::Init()
      85             : {
      86             : 
      87           4 : }
      88             : 
      89             : void AliAnalysisTaskTagCreator::ConnectInputData(Option_t * /*option*/)
      90             : {
      91             :     // Initialization
      92           4 :     const char* turl = gSystem->Getenv("ALIEN_JDL_OUTPUTDIR");
      93           2 :     TString sturl = turl;
      94             :     
      95           4 :     if (sturl.Length() != 0) {
      96           0 :       fAODFileName = "alien://";
      97           0 :       fAODFileName += turl;
      98           0 :       fAODFileName += "/AliAOD.root";
      99             :     }  
     100           2 : }
     101             : 
     102             : void AliAnalysisTaskTagCreator::UserExec(Option_t */*option*/)
     103             : {
     104             : 
     105             :     // Create Tags for the current event
     106          16 :     AliEventTag* evtTag = new AliEventTag();
     107           8 :     fTagCreator->FillEventTag(AODEvent(), evtTag);
     108             :     // Reference to the input file
     109          16 :     TString fturl, fturltemp, guid;
     110             :     
     111          16 :     TString opt(fInputHandler->GetAnalysisType());
     112           8 :     opt.ToLower();
     113             :     
     114          16 :     TFile *file = OutputTree()->GetCurrentFile();
     115           8 :     const TUrl *url = file->GetEndpointUrl();
     116          24 :     guid = file->GetUUID().AsString();
     117          16 :     if (fAODFileName.Length() != 0) {
     118           0 :         fturl = fAODFileName;
     119           0 :         guid  = fGUID;
     120             :     } else {
     121          16 :         fturl = url->GetFile();
     122             :     }
     123             : 
     124          24 :     if (fRunTag->GetFileId(guid) == -1) {
     125           4 :       AliFileTag *eftag = new AliFileTag();
     126             : 
     127           6 :       eftag->SetGUID(guid);
     128           4 :       if(fAODFileName.Length() != 0) {
     129           0 :         eftag->SetMD5("");
     130           0 :         eftag->SetTURL(fturl);
     131           0 :         eftag->SetSize(0);
     132           0 :       }
     133           6 :       else eftag->SetPath(fturl);
     134             : 
     135           2 :       fRunTag->AddFileTag(eftag);
     136           2 :     }
     137             :     //
     138             :     // Add the event tag
     139           8 :     fRunTag->AddEventTag(*evtTag);
     140           8 :     PostData(1, fTreeT);
     141           8 : }
     142             : 
     143             : 
     144             : void AliAnalysisTaskTagCreator::FinishTaskOutput()
     145             : {
     146             : // Terminate analysis
     147             : //
     148           6 :     if (fInputHandler->GetRunTag()) fRunTag->CopyStandardContent(fInputHandler->GetRunTag());      
     149           2 :     fTreeT->Fill();
     150           2 : }
     151             : 
     152             : Bool_t AliAnalysisTaskTagCreator::Notify()
     153             : {
     154             :     // Notify file change
     155           2 :     fInputHandler = (AliInputEventHandler*) 
     156           4 :       ((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
     157           2 :     return kTRUE;
     158             : }
     159             : 
     160             : 
     161             : void AliAnalysisTaskTagCreator::GetGUID(TString &guid) {
     162             :     // Get the guid of the AliAOD.root file
     163           0 :     ofstream myfile ("guid.txt");
     164           0 :     if (myfile.is_open()) {
     165           0 :         TFile *f = TFile::Open("AliAOD.root","read");
     166           0 :         if(f->IsOpen()) {
     167           0 :             guid = f->GetUUID().AsString();
     168           0 :             myfile << "AliAOD.root \t"<<f->GetUUID().AsString();
     169           0 :             cout<<guid.Data()<<endl;
     170           0 :             myfile.close();
     171             :         }
     172           0 :         else cout<<"Input file not found"<<endl;
     173           0 :         f->Close();
     174           0 :     }
     175           0 :     else cout<<"Output file can't be created..."<<endl;
     176           0 : }
     177             : 
     178             : 
     179             : 
     180             : void AliAnalysisTaskTagCreator::Terminate(Option_t */*option*/)
     181             : {
     182             : // Terminate analysis
     183             : //
     184           4 :     if (fDebug > 1) printf("AnalysisTagCreator: Terminate() \n");
     185           2 : }
     186             : 
     187             : 

Generated by: LCOV version 1.11