From fcc6b05f0b3d830641f564caf324b6c6256dc07e Mon Sep 17 00:00:00 2001 From: panos Date: Mon, 22 Oct 2007 16:22:59 +0000 Subject: [PATCH] First opening the file and then creating the tree --- STEER/AliAODTagCreator.cxx | 204 +++++++++++-------------------------- STEER/AliESDTagCreator.cxx | 106 ++++++++++--------- 2 files changed, 120 insertions(+), 190 deletions(-) diff --git a/STEER/AliAODTagCreator.cxx b/STEER/AliAODTagCreator.cxx index 093ca2c9829..6b3dd8dbf76 100644 --- a/STEER/AliAODTagCreator.cxx +++ b/STEER/AliAODTagCreator.cxx @@ -98,37 +98,6 @@ Bool_t AliAODTagCreator::ReadGridCollection(TGridResult *fresult) { return kTRUE; } -//______________________________________________________________________________ -/*Bool_t AliAODTagCreator::ReadGridCollection(TGridResult *fresult) { - // Reads the entry of the TGridResult and creates the tags - Int_t nEntries = fresult->GetEntries(); - - TString alienUrl; - const char *guid; - const char *md5; - const char *turl; - Long64_t size = -1; - - Int_t counter = 0; - for(Int_t i = 0; i < nEntries; i++) { - alienUrl = fresult->GetKey(i,"turl"); - 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"); - if(md5 && !strlen(guid)) md5 = 0; - if(guid && !strlen(guid)) guid = 0; - - TFile *f = TFile::Open(alienUrl,"READ"); - CreateTag(f,guid,md5,turl,size,counter); - f->Close(); - delete f; - counter += 1; - }//grid result loop - - return kTRUE; - }*/ - //______________________________________________________________________________ Bool_t AliAODTagCreator::ReadLocalCollection(const char *localpath) { // Checks the different subdirs of the given local path and in the @@ -170,41 +139,6 @@ Bool_t AliAODTagCreator::ReadLocalCollection(const char *localpath) { return kTRUE; } -//______________________________________________________________________________ -/*Bool_t AliAODTagCreator::ReadLocalCollection(const char *localpath) { - // Checks the different subdirs of the given local path and in the - // case where it finds an AliAODs.root file it creates the tags - - void *dira = gSystem->OpenDirectory(localpath); - Char_t fPath[256]; - const char * dirname = 0x0; - const char * filename = 0x0; - const char * pattern = "AliAOD.root"; - - Int_t counter = 0; - while((dirname = gSystem->GetDirEntry(dira))) { - sprintf(fPath,"%s/%s",localpath,dirname); - void *dirb = gSystem->OpenDirectory(fPath); - while((filename = gSystem->GetDirEntry(dirb))) { - if(strstr(filename,pattern)) { - TString fAODFileName; - fAODFileName = fPath; - fAODFileName += "/"; - fAODFileName += pattern; - TFile *f = TFile::Open(fAODFileName,"READ"); - CreateTag(f,fAODFileName,counter); - f->Close(); - delete f; - - counter += 1; - }//pattern check - }//child directory's entry loop - }//parent directory's entry loop - - return kTRUE; - }*/ - - //______________________________________________________________________________ Bool_t AliAODTagCreator::ReadCAFCollection(const char *filename) { // Temporary solution for CAF: Takes as an input the ascii file that @@ -238,32 +172,6 @@ Bool_t AliAODTagCreator::ReadCAFCollection(const char *filename) { return kTRUE; } -//______________________________________________________________________________ -/*Bool_t AliAODTagCreator::ReadCAFCollection(const char *filename) { - // Temporary solution for CAF: Takes as an input the ascii file that - // lists the AODs stored in the SE of the CAF and creates the tags. - - // Open the input stream - ifstream in; - in.open(filename); - - Int_t counter = 0; - TString esdfile; - // Read the input list of files and add them to the chain - while(in.good()) { - in >> esdfile; - if (!esdfile.Contains("root")) continue; // protection - TFile *f = TFile::Open(esdfile,"READ"); - CreateTag(f,esdfile,counter); - f->Close(); - delete f; - - counter += 1; - } - - return kTRUE; - }*/ - //__________________________________________________________________________ void AliAODTagCreator::CreateAODTags(Int_t fFirstEvent, Int_t fLastEvent, TList *grpList) { //creates tag files for AODs @@ -327,6 +235,17 @@ void AliAODTagCreator::CreateAODTags(Int_t fFirstEvent, Int_t fLastEvent, TList if(fLastEvent == -1) lastEvent = (Int_t)aodTree->GetEntries(); else lastEvent = fLastEvent; + if(fLastEvent == -1) lastEvent = (Int_t)aodTree->GetEntries(); + else lastEvent = fLastEvent; + + char fileName[256]; + sprintf(fileName, "Run%d.Event%d_%d.AOD.tag.root", + tag->GetRunId(),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"); + // loop over events Int_t nEvents = aodTree->GetEntries(); for (Int_t iEventNumber = 0; iEventNumber < nEvents; iEventNumber++) { @@ -450,16 +369,7 @@ void AliAODTagCreator::CreateAODTags(Int_t fFirstEvent, Int_t fLastEvent, TList evTag->SetMaxPt(maxPt); tag->AddEventTag(*evTag); }//event loop - if(fLastEvent == -1) lastEvent = (Int_t)aodTree->GetEntries(); - else lastEvent = fLastEvent; - char fileName[256]; - sprintf(fileName, "Run%d.Event%d_%d.AOD.tag.root", - tag->GetRunId(),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"); ftag->cd(); ttag.Fill(); tag->Clear(); @@ -473,7 +383,6 @@ void AliAODTagCreator::CreateAODTags(Int_t fFirstEvent, Int_t fLastEvent, TList void AliAODTagCreator::CreateTag(TChain* fChain, const char *type) { //private method that creates tag files TString fSession = type; - //Int_t iCounter = 0; TString fguid, fmd5, fturl; TString fTempGuid = 0; @@ -494,14 +403,8 @@ void AliAODTagCreator::CreateTag(TChain* fChain, const char *type) { Int_t nMu1GeV, nMu3GeV, nMu10GeV; Int_t nEl1GeV, nEl3GeV, nEl10GeV; Float_t maxPt = .0, meanPt = .0, totalP = .0; - - AliRunTag *tag = new AliRunTag(); - TTree ttag("T","A Tree with event tags"); - TBranch * btag = ttag.Branch("AliTAG", &tag); - btag->SetCompressionLevel(9); - //reading the esd tag file - + //reading the esd tag file TChain *oldTagTree = new TChain("T"); const char * tagPattern = "ESD.tag"; // Open the working directory @@ -513,16 +416,6 @@ void AliAODTagCreator::CreateTag(TChain* fChain, const char *type) { }//directory loop AliInfo(Form("Chained tag files: %d",oldTagTree->GetEntries())); - //reading the esd tag file - AliRunTag *oldtag = new AliRunTag(); - TString tagFilename; - oldTagTree->SetBranchAddress("AliTAG",&oldtag); - oldTagTree->GetEntry(0); - tag->CopyStandardContent(oldtag); - const TClonesArray *evTagList = oldtag->GetEventTags(); - - AliInfo(Form("Creating the AOD tags.......")); - /*if (!file || !file->IsOpen()) { AliError(Form("opening failed")); delete file; @@ -531,9 +424,51 @@ void AliAODTagCreator::CreateTag(TChain* fChain, const char *type) { TTree *aodTree = (TTree*)file->Get("aodTree");*/ AliAODEvent *aod = new AliAODEvent(); aod->ReadFromTree(fChain); + fChain->GetEntry(0); + TFile *f = fChain->GetFile(); + fTempGuid = f->GetUUID().AsString(); Int_t firstEvent = 0, lastEvent = 0; //lastEvent = (Int_t)aodTree->GetEntries(); + TString localFileName = "Run"; localFileName += aod->GetRunNumber(); + localFileName += ".Event"; localFileName += firstEvent; localFileName += "_"; localFileName += fChain->GetEntries(); //localFileName += "."; localFileName += Counter; + localFileName += ".AOD.tag.root"; + + TString fileName; + + if(fStorage == 0) { + fileName = localFileName.Data(); + AliInfo(Form("Writing tags to local file: %s",fileName.Data())); + } + else if(fStorage == 1) { + TString alienLocation = "/alien"; + alienLocation += gGrid->Pwd(); + alienLocation += fgridpath.Data(); + alienLocation += "/"; + alienLocation += localFileName; + alienLocation += "?se="; + alienLocation += fSE.Data(); + fileName = alienLocation.Data(); + AliInfo(Form("Writing tags to grid file: %s",fileName.Data())); + } + + TFile* ftag = TFile::Open(fileName, "recreate"); + + AliRunTag *tag = new AliRunTag(); + TTree ttag("T","A Tree with event tags"); + TBranch * btag = ttag.Branch("AliTAG", &tag); + btag->SetCompressionLevel(9); + + //reading the esd tag file + AliRunTag *oldtag = new AliRunTag(); + TString tagFilename; + oldTagTree->SetBranchAddress("AliTAG",&oldtag); + oldTagTree->GetEntry(0); + tag->CopyStandardContent(oldtag); + const TClonesArray *evTagList = oldtag->GetEventTags(); + + AliInfo(Form("Creating the AOD tags.......")); + // loop over events Int_t nEvents = fChain->GetEntries(); for (Int_t iEventNumber = 0; iEventNumber < nEvents; iEventNumber++) { @@ -668,40 +603,21 @@ void AliAODTagCreator::CreateTag(TChain* fChain, const char *type) { evTag->SetTotalMomentum(totalP); evTag->SetMeanPt(meanPt); evTag->SetMaxPt(maxPt); - tag->AddEventTag(*evTag); if(fguid != fTempGuid) { fTempGuid = fguid; ttag.Fill(); tag->Clear(""); } + tag->AddEventTag(*evTag); + if(iEventNumber+1 == fChain->GetEntries()) { + //AliInfo(Form("File: %s",fturl.Data())); + ttag.Fill(); + tag->Clear(""); + } }//event loop lastEvent = fChain->GetEntries(); - TString localFileName = "Run"; localFileName += tag->GetRunId(); - localFileName += ".Event"; localFileName += firstEvent; localFileName += "_"; - localFileName += lastEvent; //localFileName += "."; localFileName += Counter; - localFileName += ".AOD.tag.root"; - - TString fileName; - - if(fStorage == 0) { - fileName = localFileName.Data(); - AliInfo(Form("Writing AOD tags to local file: %s",fileName.Data())); - } - else if(fStorage == 1) { - TString alienLocation = "/alien"; - alienLocation += gGrid->Pwd(); - alienLocation += fgridpath.Data(); - alienLocation += "/"; - alienLocation += localFileName; - alienLocation += "?se="; - alienLocation += fSE.Data(); - fileName = alienLocation.Data(); - AliInfo(Form("Writing AOD tags to grid file: %s",fileName.Data())); - } - - TFile* ftag = TFile::Open(fileName, "recreate"); ftag->cd(); //ttag.Fill(); tag->Clear(); diff --git a/STEER/AliESDTagCreator.cxx b/STEER/AliESDTagCreator.cxx index 9ce7d664907..41ba94f4de7 100644 --- a/STEER/AliESDTagCreator.cxx +++ b/STEER/AliESDTagCreator.cxx @@ -185,7 +185,6 @@ Bool_t AliESDTagCreator::ReadCAFCollection(const char *filename) { void AliESDTagCreator::CreateTag(TChain* fChain, const char *type) { //private method that creates tag files TString fSession = type; - //Int_t iCounter = 0; TString fguid, fmd5, fturl; TString fTempGuid = 0; @@ -224,11 +223,6 @@ void AliESDTagCreator::CreateTag(TChain* fChain, const char *type) { Int_t iRunNumber = 0; TString fVertexName; - AliRunTag *tag = new AliRunTag(); - AliEventTag *evTag = new AliEventTag(); - TTree ttag("T","A Tree with event tags"); - TBranch * btag = ttag.Branch("AliTAG", &tag); - btag->SetCompressionLevel(9); //gSystem->GetMemInfo(meminfo); //AliInfo(Form("After the tag initialization - Memory used: %d MB",meminfo->fMemUsed)); //Int_t tempmem = meminfo->fMemUsed; @@ -238,12 +232,47 @@ void AliESDTagCreator::CreateTag(TChain* fChain, const char *type) { Int_t firstEvent = 0,lastEvent = 0; AliESDEvent *esd = new AliESDEvent(); esd->ReadFromTree(fChain); + AliESD *esdold = 0x0; //gSystem->GetMemInfo(meminfo); //AliInfo(Form("After the esd initialization - Memory used: %d MB - Increase: %d MB",meminfo->fMemUsed,meminfo->fMemUsed - tempmem)); //tempmem = meminfo->fMemUsed; Int_t iInitRunNumber = -1; + fChain->GetEntry(0); + TFile *f = fChain->GetFile(); + fTempGuid = f->GetUUID().AsString(); + + TString localFileName = "Run"; localFileName += esd->GetRunNumber(); + localFileName += ".Event"; localFileName += firstEvent; localFileName += "_"; localFileName += fChain->GetEntries(); //localFileName += "."; localFileName += Counter; + localFileName += ".ESD.tag.root"; + + TString fileName; + + if(fStorage == 0) { + fileName = localFileName.Data(); + AliInfo(Form("Writing tags to local file: %s",fileName.Data())); + } + else if(fStorage == 1) { + TString alienLocation = "/alien"; + alienLocation += gGrid->Pwd(); + alienLocation += fgridpath.Data(); + alienLocation += "/"; + alienLocation += localFileName; + alienLocation += "?se="; + alienLocation += fSE.Data(); + fileName = alienLocation.Data(); + AliInfo(Form("Writing tags to grid file: %s",fileName.Data())); + } + + TFile* ftag = TFile::Open(fileName, "recreate"); + + AliRunTag *tag = new AliRunTag(); + AliEventTag *evTag = new AliEventTag(); + TTree ttag("T","A Tree with event tags"); + TBranch * btag = ttag.Branch("AliTAG", &tag); + btag->SetCompressionLevel(9); + for(Int_t iEventNumber = 0; iEventNumber < fChain->GetEntries(); iEventNumber++) { ntrack = 0; nPos = 0; nNeg = 0; nNeutr =0; nK0s = 0; nNeutrons = 0; nPi0s = 0; @@ -255,7 +284,10 @@ void AliESDTagCreator::CreateTag(TChain* fChain, const char *type) { maxPt = .0; meanPt = .0; totalP = .0; fVertexflag = 1; - fChain->GetEntry(iEventNumber); + fChain->GetEntry(iEventNumber); + esdold = esd->GetAliESDOld(); + if(esdold) esd->CopyFromOldESD(); + TFile *f = fChain->GetFile(); const TUrl *url = f->GetEndpointUrl(); fguid = f->GetUUID().AsString(); @@ -381,9 +413,9 @@ void AliESDTagCreator::CreateTag(TChain* fChain, const char *type) { // Fill the event tags if(ntrack != 0) meanPt = meanPt/ntrack; - AliInfo(Form("=====================================")); - AliInfo(Form("URL: %s - GUID: %s",fturl.Data(),fguid.Data())); - AliInfo(Form("=====================================")); + //AliInfo(Form("=====================================")); + //AliInfo(Form("URL: %s - GUID: %s",fturl.Data(),fguid.Data())); + //AliInfo(Form("=====================================")); evTag->SetEventId(iEventNumber+1); evTag->SetGUID(fguid); @@ -453,13 +485,18 @@ void AliESDTagCreator::CreateTag(TChain* fChain, const char *type) { tag->SetRunId(iInitRunNumber); if(fIsSim) tag->SetDataType(0); else tag->SetDataType(1); - tag->AddEventTag(*evTag); if(fguid != fTempGuid) { fTempGuid = fguid; ttag.Fill(); tag->Clear(""); } + tag->AddEventTag(*evTag); + if(iEventNumber+1 == fChain->GetEntries()) { + //AliInfo(Form("File: %s",fturl.Data())); + ttag.Fill(); + tag->Clear(""); + } }//event loop lastEvent = fChain->GetEntries(); @@ -473,31 +510,7 @@ void AliESDTagCreator::CreateTag(TChain* fChain, const char *type) { //AliInfo(Form("After the t->Delete - Memory used: %d MB - Increase: %d MB",meminfo->fMemUsed,meminfo->fMemUsed - tempmem)); //tempmem = meminfo->fMemUsed; - TString localFileName = "Run"; localFileName += tag->GetRunId(); - localFileName += ".Event"; localFileName += firstEvent; localFileName += "_"; localFileName += lastEvent; //localFileName += "."; localFileName += Counter; - localFileName += ".ESD.tag.root"; - - TString fileName; - - if(fStorage == 0) { - fileName = localFileName.Data(); - AliInfo(Form("Writing tags to local file: %s",fileName.Data())); - } - else if(fStorage == 1) { - TString alienLocation = "/alien"; - alienLocation += gGrid->Pwd(); - alienLocation += fgridpath.Data(); - alienLocation += "/"; - alienLocation += localFileName; - alienLocation += "?se="; - alienLocation += fSE.Data(); - fileName = alienLocation.Data(); - AliInfo(Form("Writing tags to grid file: %s",fileName.Data())); - } - - TFile* ftag = TFile::Open(fileName, "recreate"); ftag->cd(); - //ttag.Fill(); tag->Clear(); ttag.Write(); ftag->Close(); @@ -506,10 +519,9 @@ void AliESDTagCreator::CreateTag(TChain* fChain, const char *type) { //AliInfo(Form("After the file closing - Memory used: %d MB - Increase: %d MB",meminfo->fMemUsed,meminfo->fMemUsed - tempmem)); //tempmem = meminfo->fMemUsed; - delete ftag; delete esd; - delete tag; + //gSystem->GetMemInfo(meminfo); //AliInfo(Form("After the delete objects - Memory used: %d MB - Increase: %d MB",meminfo->fMemUsed,meminfo->fMemUsed - tempmem)); } @@ -1206,6 +1218,17 @@ void AliESDTagCreator::CreateESDTags(Int_t fFirstEvent, Int_t fLastEvent, TList Int_t iInitRunNumber = esd->GetRunNumber(); Int_t iNumberOfEvents = (Int_t)b->GetEntries(); + if(fLastEvent == -1) lastEvent = (Int_t)b->GetEntries(); + else lastEvent = fLastEvent; + + char fileName[256]; + sprintf(fileName, "Run%d.Event%d_%d.ESD.tag.root", + tag->GetRunId(),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"); + if(fLastEvent != -1) iNumberOfEvents = fLastEvent + 1; for (Int_t iEventNumber = fFirstEvent; iEventNumber < iNumberOfEvents; iEventNumber++) { ntrack = 0; @@ -1414,16 +1437,7 @@ void AliESDTagCreator::CreateESDTags(Int_t fFirstEvent, Int_t fLastEvent, TList tag->SetRunId(iInitRunNumber); tag->AddEventTag(*evTag); } - if(fLastEvent == -1) lastEvent = (Int_t)b->GetEntries(); - else lastEvent = fLastEvent; - char fileName[256]; - sprintf(fileName, "Run%d.Event%d_%d.ESD.tag.root", - tag->GetRunId(),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"); ftag->cd(); ttag.Fill(); tag->Clear(); -- 2.43.0