LCOV - code coverage report
Current view: top level - STEER/ESD - AliESDInputHandlerRP.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 187 0.5 %
Date: 2016-06-14 17:26:59 Functions: 1 16 6.2 %

          Line data    Source code
       1             : /**************************************************************************
       2             :  * Copyright(c) 1998-2007, 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             : //-------------------------------------------------------------------------
      19             : //     Event handler for ESD input reading the RecPoint Trees in parallel
      20             : //     Author: Andreas Morsch, CERN
      21             : //-------------------------------------------------------------------------
      22             : 
      23             : #include <TTree.h>
      24             : #include <TList.h>
      25             : #include <TFile.h>
      26             : #include <TArchiveFile.h>
      27             : #include <TSystemDirectory.h>
      28             : #include <TString.h>
      29             : #include <TObjString.h>
      30             : #include <TObjArray.h>
      31             : #include <TProcessID.h>
      32             : #include <TSystem.h>
      33             : #include <TGrid.h>
      34             : 
      35             : #include "AliESDInputHandlerRP.h"
      36             : #include "AliESDEvent.h"
      37             : #include "AliESD.h"
      38             : #include "AliLog.h"
      39             : #include "AliDAQ.h"
      40             : 
      41         172 : ClassImp(AliESDInputHandlerRP)
      42             : 
      43             : //______________________________________________________________________________
      44             : AliESDInputHandlerRP::AliESDInputHandlerRP() :
      45           0 :     AliESDInputHandler(),
      46           0 :     fRTrees(   new TObjArray()),
      47           0 :     fRDirs (   new TObjArray()),
      48           0 :     fRFiles(   new TList()),
      49           0 :     fDetectors(new TList()),
      50           0 :     fDirR(0),
      51           0 :     fEventNumber(-1),
      52           0 :     fFileNumber(0),
      53           0 :     fEventsPerFile(0),
      54           0 :     fExtension(""),
      55           0 :     fPathName(new TString("./")),
      56           0 :     fIsArchive(kFALSE),
      57           0 :     fReadDirectory(kFALSE)
      58           0 : {
      59             :   // Default constructor
      60           0 : }
      61             : 
      62             : 
      63             : //______________________________________________________________________________
      64             : AliESDInputHandlerRP::AliESDInputHandlerRP(const char* name, const char* title):
      65           0 :     AliESDInputHandler(name, title),
      66           0 :     fRTrees(   new TObjArray()),
      67           0 :     fRDirs (   new TObjArray()),
      68           0 :     fRFiles(   new TList()),
      69           0 :     fDetectors(new TList()),
      70           0 :     fDirR(0),
      71           0 :     fEventNumber(-1),
      72           0 :     fFileNumber(0),
      73           0 :     fEventsPerFile(0),
      74           0 :     fExtension(""),
      75           0 :     fPathName(new TString("./")),
      76           0 :     fIsArchive(kFALSE),
      77           0 :     fReadDirectory(kFALSE)
      78           0 : {
      79             :     // Constructor
      80           0 : }
      81             : 
      82             : //______________________________________________________________________________
      83             : AliESDInputHandlerRP::~AliESDInputHandlerRP() 
      84           0 : {
      85             :   // Destructor
      86           0 : }
      87             : 
      88             : Bool_t AliESDInputHandlerRP::Init(Option_t* opt)
      89             : {
      90             :     //
      91             :     // Initialize input
      92             :     //
      93           0 :     if (!(strcmp(opt, "proof")) || !(strcmp(opt, "local"))) return kTRUE;
      94             :     //
      95           0 :     TIter next(fDetectors);
      96             :     TNamed* det;
      97             :     TFile* file = 0;
      98           0 :     while ((det = (TNamed*) next()))
      99             :     {
     100           0 :       TString rppath;
     101           0 :       if (det->TestBit(kReadFromArchiveBIT)) {
     102           0 :         if (fPathName->EndsWith("root_archive.zip"))
     103           0 :           rppath.Form("%s#%s.RecPoints.root", fPathName->Data(), det->GetName());
     104             :         else
     105           0 :           rppath.Form("%sroot_archive.zip#%s.RecPoints.root", fPathName->Data(), det->GetName());
     106             :       }
     107             :       else
     108           0 :         rppath.Form("%s%s.RecPoints.root", fPathName->Data(), det->GetName());
     109           0 :       file = TFile::Open(rppath.Data());
     110           0 :       if (!file) {
     111           0 :         AliErrorF("AliESDInputHandlerRP: Failed to open %s",rppath.Data());
     112           0 :         return kFALSE;
     113             :       }
     114           0 :       fRFiles->Add(file);
     115           0 :     }
     116             : 
     117           0 :     if (file) {
     118           0 :         fEventsPerFile = file->GetNkeys() - file->GetNProcessIDs();
     119             :     } else {
     120           0 :         AliErrorF("AliESDInputHandlerRP: No file with RecPoints found in %s !", fPathName->Data());
     121           0 :         return kFALSE;
     122             :     }
     123             :     
     124             : 
     125             :     // Reset the event number
     126           0 :     fEventNumber      = -1;
     127           0 :     fFileNumber       =  0;
     128             :     // Get number of events from esd tree 
     129           0 :     printf("AliESDInputHandlerRP::Init() %d %d\n",__LINE__, fNEvents);
     130             :     //
     131           0 :     AliESDInputHandler::Init(opt);
     132             :     //
     133           0 :     return kTRUE;
     134           0 : }
     135             : 
     136             : Bool_t AliESDInputHandlerRP::BeginEvent(Long64_t entry)
     137             : {
     138             :     // Begin the next event
     139             :     //
     140           0 :     if (entry == -1) {
     141           0 :         fEventNumber++;
     142           0 :         entry = fEventNumber;
     143           0 :     } else {
     144           0 :         fEventNumber = entry;
     145             :     }
     146             :     
     147           0 :     if (entry >= fNEvents) {
     148           0 :         AliWarning(Form("AliESDInputHandlerRP: Event number out of range %5lld %5d\n", entry, fNEvents));
     149           0 :         return kFALSE;
     150             :     }
     151             :     
     152           0 :     LoadEvent(entry);
     153             : 
     154             :     // Delegate to base class
     155           0 :     return AliESDInputHandler::BeginEvent(entry);
     156             : 
     157           0 : }
     158             : 
     159             : Bool_t AliESDInputHandlerRP::LoadEvent(Int_t iev)
     160             : {
     161             :     // Load the event number iev
     162             :     //
     163             :     // Calculate the file number
     164           0 :   if (fEventsPerFile<=0) return kFALSE;
     165           0 :     Int_t inew  = iev / fEventsPerFile;
     166           0 :     if (inew != fFileNumber) {
     167           0 :         fFileNumber = inew;
     168           0 :         if (!OpenFile(fFileNumber)){
     169           0 :             return kFALSE;
     170             :         }
     171             :     }
     172             :     // Folder name
     173           0 :     char folder[20];
     174           0 :     snprintf(folder, 20, "Event%d", iev);
     175             :     // Tree R
     176             :     // AliInfo("List of files");
     177             :     // fRFiles->ls();
     178           0 :     TIter next(fRFiles);
     179             :     TFile* file;
     180             :     Int_t idx  = 0;
     181             :     
     182           0 :     while ((file = (TFile*) next()))
     183             :     {
     184           0 :         file->GetObject(folder, fDirR);
     185             :         
     186           0 :         if (!fDirR) {
     187           0 :             AliWarning(Form("AliESDInputHandlerRP: Event #%5d not found\n", iev));
     188           0 :             return kFALSE;
     189             :         }
     190           0 :         TTree* tree = 0;
     191           0 :         fDirR->GetObject("TreeR", tree);
     192           0 :         fRDirs ->AddAt(fDirR, idx  );
     193           0 :         fRTrees->AddAt(tree,  idx++);
     194           0 :     }
     195           0 :     return kTRUE;
     196           0 : }
     197             : 
     198             : Bool_t AliESDInputHandlerRP::OpenFile(Int_t i)
     199             : {
     200             :     // Open file i
     201             :     Bool_t ok = kTRUE;
     202           0 :     if (i > 0) {
     203           0 :         fExtension = Form("%d", i);
     204           0 :     } else {
     205           0 :         fExtension = "";
     206             :     }
     207             :     
     208           0 :     fRFiles->Delete();
     209           0 :     TIter next(fDetectors);
     210             :     TNamed* det;
     211             :     TFile* file;
     212           0 :     while ((det = (TNamed*) next()))
     213             :     {
     214           0 :       TString rppath;
     215           0 :       if (det->TestBit(kReadFromArchiveBIT)) {
     216           0 :         if (fPathName->EndsWith("root_archive.zip"))
     217           0 :           rppath.Form("%s#%s.RecPoints.root", fPathName->Data(), det->GetName());
     218             :         else
     219           0 :           rppath.Form("%sroot_archive.zip#%s.RecPoints.root", fPathName->Data(), det->GetName());
     220             :       }
     221             :       else
     222           0 :         rppath.Form("%s%s.RecPoints.root", fPathName->Data(), det->GetName());
     223           0 :       file = TFile::Open(rppath.Data());
     224           0 :       if (!file) AliFatalF("AliESDInputHandlerRP: Failed to open %s !",rppath.Data());
     225           0 :       fRFiles->Add(file);
     226           0 :     }
     227             :     return ok;
     228           0 : }
     229             : 
     230             : Bool_t AliESDInputHandlerRP::Notify(const char *path)
     231             : {
     232             :   // Notify about directory change
     233             :   // The directory is taken from the 'path' argument
     234             :   // 
     235             : 
     236             :     // Get path to directory
     237           0 :     TString fileName(path);
     238             : 
     239             : 
     240             : 
     241           0 :     if (fileName.IsNull()) return kFALSE;
     242           0 :     AliInfo(Form("Directory change %s \n", path));
     243             : 
     244           0 :     TString esdname = gSystem->BaseName(fileName);
     245           0 :     Int_t index = esdname.Index("#")+1;
     246           0 :     if (index) esdname.Remove(0,index);
     247             : 
     248           0 :     if(fileName.Contains("#")){
     249             :     // If this is an archive it will contain a # 
     250           0 :       fIsArchive = kTRUE;
     251             :       /// AliInfoF("%s is an archive", fileName.Data());
     252           0 :     }
     253           0 :     else  if(fileName.Contains(esdname)){
     254           0 :       fileName.ReplaceAll(esdname, "");
     255             :     }
     256             : 
     257             :     //
     258             :     // At this point we have a path to the directory or to the archive anchor
     259           0 :     *fPathName = fileName;
     260             :     // AliInfoF("Path name is now %s", fPathName->Data());
     261             :     //
     262             :     // Now filter the files containing RecPoints *.RecPoints.*
     263             : 
     264             :     TSeqCollection* membersArch=0;
     265             : 
     266             :     
     267           0 :     if (fIsArchive) {
     268             :         // Archive
     269           0 :       TFile* file = TFile::Open(fPathName->Data());
     270           0 :       TArchiveFile* arch = file->GetArchive();
     271           0 :       membersArch = arch->GetMembers();
     272           0 :       fPathName->ReplaceAll("#", "");
     273           0 :       fPathName->ReplaceAll(esdname, "");
     274           0 :     }
     275             :     else {
     276             :         // Directory or alien archive
     277           0 :       if (fileName.BeginsWith("alien:")) {
     278           0 :         AliInfoF("prefix is, alien: trying to open %s/root_archive.zip", fPathName->Data());
     279           0 :         TFile* file = TFile::Open(Form("%s/root_archive.zip", fPathName->Data()));
     280           0 :         TArchiveFile* arch = file->GetArchive();
     281           0 :         membersArch = arch->GetMembers();
     282           0 :       } 
     283             :     }
     284             :     // if (membersArch) {
     285             :     //   AliInfo("List of archive members");
     286             :     //   membersArch->Print();
     287             :     // }
     288             :     TFile* entry;
     289             :     Int_t ien = 0;
     290           0 :     fDetectors->Delete(); 
     291             :     
     292           0 :     if (membersArch) {
     293           0 :       TIter next(membersArch);
     294           0 :       while ( (entry = (TFile*) next()) ) {
     295           0 :         TString name(entry->GetName());
     296           0 :         TObjArray* tokens = name.Tokenize(".");
     297             :         Int_t ntok = 0;
     298           0 :         if (tokens) {
     299           0 :           ntok = tokens->GetEntries();
     300             :         } else {
     301           0 :           continue;
     302             :         }
     303           0 :         if (ntok <= 1) continue;
     304           0 :         TString str = ((TObjString*) tokens->At(1))->GetString();
     305           0 :         if (!(strcmp(str.Data(), "RecPoints"))){
     306           0 :           TString det = ((TObjString*) tokens->At(0))->GetString();
     307           0 :           printf("Found file with RecPoints for %s \n", det.Data());
     308           0 :           TNamed* ent = new TNamed(det.Data(), det.Data());
     309           0 :           fRTrees->AddAt(0, ien);
     310           0 :           ent->SetUniqueID(ien++);
     311           0 :           ent->SetBit(kReadFromArchiveBIT);
     312           0 :           fDetectors->Add(ent);
     313           0 :         }
     314           0 :         if(tokens) delete tokens;
     315           0 :       } // loop over files
     316           0 :     }
     317             :     //
     318           0 :     if (!fDetectors->GetEntries() || fReadDirectory) { // read from directory, overlaps will be sorted out later
     319           0 :       if (fPathName->BeginsWith("alien:") && !gGrid) TGrid::Connect("alien://");
     320           0 :       for (int id=0;id<AliDAQ::kNDetectors;id++) {
     321           0 :         const char* dname = AliDAQ::OfflineModuleName(id);
     322           0 :         if (!dname || fDetectors->FindObject(dname)) continue; // skip already accounted one
     323           0 :         if (gSystem->AccessPathName(Form("%s%s.RecPoints.root",fPathName->Data(),dname))) continue; // no recpoints
     324           0 :         TNamed* ent = new TNamed(dname, dname);
     325           0 :         fRTrees->AddAt(0, ien);
     326           0 :         ent->SetUniqueID(ien++);
     327           0 :         fDetectors->Add(ent);
     328           0 :       }
     329           0 :     }  
     330             :     //
     331             :     // Now we have the path and the list of detectors
     332             :     
     333           0 :     printf("AliESDInputHandlerRP::Notify() Path: %s\n", fPathName->Data());
     334             :     //
     335           0 :     ResetIO();
     336           0 :     InitIO("");
     337             :     // Some clean-up
     338           0 :     if (membersArch) membersArch->Delete();
     339             : 
     340           0 :     AliESDInputHandler::Notify(path);
     341             :     
     342             :     return kTRUE;
     343           0 : }
     344             : 
     345             : Bool_t AliESDInputHandlerRP::FinishEvent()
     346             : {
     347             :     // Clean-up after each event
     348           0 :     fRDirs->Delete();
     349           0 :     AliESDInputHandler::FinishEvent();
     350           0 :     return kTRUE;
     351             : }
     352             : 
     353             : void AliESDInputHandlerRP::ResetIO()
     354             : {
     355             : // Delete trees and files
     356           0 :     fRFiles->Clear("nodelete");
     357           0 :     fExtension="";
     358           0 : }
     359             : 
     360             : TTree* AliESDInputHandlerRP::GetTreeR(const char* det)
     361             : {
     362             : // Return pointer to RecPoint tree for detector det
     363           0 :     TNamed* entry = (TNamed*) (fDetectors->FindObject(det));
     364           0 :     if (!entry) {
     365           0 :         AliWarning(Form("AliESDInputHandlerRP: No RecPoints for detector %s available \n", det));
     366           0 :         return 0;
     367             :     } else {
     368           0 :         Int_t ien = entry->GetUniqueID();
     369           0 :         return ((TTree*) (fRTrees->At(ien)));
     370             :     }
     371           0 : }

Generated by: LCOV version 1.11