#include <TChain.h>
#include <TFile.h>
#include <TEventList.h>
+#include <TEntryList.h>
+#include <TTreeFormula.h>
//ROOT-AliEn
#include <TGridResult.h>
#include "AliEventTag.h"
#include "AliTagAnalysis.h"
#include "AliEventTagCuts.h"
+#include "AliRunTagCuts.h"
#include "AliXMLCollection.h"
class TTree;
ClassImp(AliTagAnalysis)
-TChain *AliTagAnalysis::fgChain = 0;
-
//___________________________________________________________________________
AliTagAnalysis::AliTagAnalysis():
TObject(),
- ftagresult(0)
+ ftagresult(0x0),
+ fTagDirName(),
+ fChain(0x0)
{
//Default constructor for a AliTagAnalysis
}
//Default destructor for a AliTagAnalysis
}
+//___________________________________________________________________________
+Bool_t AliTagAnalysis::AddTagsFile(const char *alienUrl) {
+
+ // Add a single tags file to the chain
+
+ Bool_t rv = kTRUE ;
+
+ if (! fChain) fChain = new TChain("T");
+
+ TFile *f = TFile::Open(alienUrl,"READ");
+ fChain->Add(alienUrl);
+ AliInfo(Form("Chained tag files: %d ",fChain->GetEntries()));
+ delete f;
+
+ if (fChain->GetEntries() == 0 )
+ rv = kFALSE ;
+
+ return rv ;
+}
+
//___________________________________________________________________________
void AliTagAnalysis::ChainLocalTags(const char *dirname) {
//Searches the entries of the provided direcory
fTagDirName = dirname;
TString fTagFilename;
- TChain *fgChain = new TChain("T");
- fChain = fgChain;
+ if (! fChain) fChain = new TChain("T");
- const char * tagPattern = "tag";
+ const char * tagPattern = "tag.root";
// Open the working directory
void * dirp = gSystem->OpenDirectory(fTagDirName);
const char * name = 0x0;
fTagFilename += "/";
fTagFilename += name;
- TFile * fTag = TFile::Open(fTagFilename);
- if((!fTag) || (!fTag->IsOpen())) {
- AliError(Form("Tag file not opened!!!"));
- continue;
- }
fChain->Add(fTagFilename);
- fTag->Close();
- delete fTag;
}//pattern check
}//directory loop
AliInfo(Form("Chained tag files: %d ",fChain->GetEntries()));
ftagresult = res;
Int_t nEntries = ftagresult->GetEntries();
- TChain *fgChain = new TChain("T");
- fChain = fgChain;
+ if (! fChain) fChain = new TChain("T");
TString gridname = "alien://";
TString alienUrl;
for(Int_t i = 0; i < nEntries; i++) {
alienUrl = ftagresult->GetKey(i,"turl");
- TFile *f = TFile::Open(alienUrl,"READ");
fChain->Add(alienUrl);
- delete f;
}//grid result loop
}
//___________________________________________________________________________
-TChain *AliTagAnalysis::QueryTags(AliEventTagCuts *EvTagCuts) {
+TChain *AliTagAnalysis::QueryTags(AliRunTagCuts *RunTagCuts, AliEventTagCuts *EvTagCuts) {
//Queries the tag chain using the defined
//event tag cuts from the AliEventTagCuts object
//and returns a TChain along with the associated TEventList
Int_t iAccepted = 0;
for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) {
fChain->GetEntry(iTagFiles);
- Int_t iEvents = tag->GetNEvents();
- const TClonesArray *tagList = tag->GetEventTags();
- for(Int_t i = 0; i < iEvents; i++) {
- evTag = (AliEventTag *) tagList->At(i);
- guid = evTag->GetGUID();
- turl = evTag->GetTURL();
- path = evTag->GetPath();
- if(EvTagCuts->IsAccepted(evTag)) fEventList->Enter(iAccepted+i);
- }//event loop
- iAccepted += iEvents;
+ if(RunTagCuts->IsAccepted(tag)) {
+ Int_t iEvents = tag->GetNEvents();
+ const TClonesArray *tagList = tag->GetEventTags();
+ for(Int_t i = 0; i < iEvents; i++) {
+ evTag = (AliEventTag *) tagList->At(i);
+ guid = evTag->GetGUID();
+ turl = evTag->GetTURL();
+ path = evTag->GetPath();
+ if(EvTagCuts->IsAccepted(evTag)) fEventList->Enter(iAccepted+i);
+ }//event loop
+ iAccepted += iEvents;
- if(path != "") fESDchain->AddFile(path);
- else if(turl != "") fESDchain->AddFile(turl);
+ if(path != "") fESDchain->AddFile(path);
+ else if(turl != "") fESDchain->AddFile(turl);
+ }//run tags cut
}//tag file loop
AliInfo(Form("Accepted events: %d",fEventList->GetN()));
fESDchain->SetEventList(fEventList);
}
//___________________________________________________________________________
-Bool_t AliTagAnalysis::CreateXMLCollection(const char* name, AliEventTagCuts *EvTagCuts) {
+TChain *AliTagAnalysis::QueryTags(const char *fRunCut, const char *fEventCut) {
+ //Queries the tag chain using the defined
+ //event tag cuts from the AliEventTagCuts object
+ //and returns a TChain along with the associated TEventList
+ AliInfo(Form("Querying the tags........"));
+
+ //ESD file chain
+ TChain *fESDchain = new TChain("esdTree");
+ //Event list
+ TEventList *fEventList = new TEventList();
+
+ //Defining tag objects
+ AliRunTag *tag = new AliRunTag;
+ AliEventTag *evTag = new AliEventTag;
+ fChain->SetBranchAddress("AliTAG",&tag);
+
+ TString guid = 0;
+ TString turl = 0;
+ TString path = 0;
+
+ TTreeFormula *fRunFormula = new TTreeFormula("fRun",fRunCut,fChain);
+ TTreeFormula *fEventFormula = new TTreeFormula("fEvent",fEventCut,fChain);
+
+ Int_t current = -1;
+ Int_t iAccepted = 0;
+ for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) {
+ fChain->GetEntry(iTagFiles);
+ if (current != fChain->GetTreeNumber()) {
+ fRunFormula->UpdateFormulaLeaves();
+ fEventFormula->UpdateFormulaLeaves();
+ current = fChain->GetTreeNumber();
+ }
+ if(fRunFormula->EvalInstance(iTagFiles) == 1) {
+ Int_t iEvents = fEventFormula->GetNdata();
+ const TClonesArray *tagList = tag->GetEventTags();
+ for(Int_t i = 0; i < iEvents; i++) {
+ evTag = (AliEventTag *) tagList->At(i);
+ guid = evTag->GetGUID();
+ turl = evTag->GetTURL();
+ path = evTag->GetPath();
+ if(fEventFormula->EvalInstance(i) == 1) fEventList->Enter(iAccepted+i);
+ }//event loop
+ iAccepted += iEvents;
+
+ if(path != "") fESDchain->AddFile(path);
+ else if(turl != "") fESDchain->AddFile(turl);
+ }//run tag cut
+ }//tag file loop
+ AliInfo(Form("Accepted events: %d",fEventList->GetN()));
+ fESDchain->SetEventList(fEventList);
+
+ return fESDchain;
+}
+
+//___________________________________________________________________________
+Bool_t AliTagAnalysis::CreateXMLCollection(const char* name, AliRunTagCuts *RunTagCuts, AliEventTagCuts *EvTagCuts) {
//Queries the tag chain using the defined
//event tag cuts from the AliEventTagCuts object
//and returns a XML collection
collection->WriteHeader();
//Event list
- TEventList *fEventList = new TEventList();
+ //TEntryList *fEventList = new TEntryList();
+ TString guid = 0x0;
+ TString turl = 0x0;
+ TString lfn = 0x0;
+
+ //Defining tag objects
+ AliRunTag *tag = new AliRunTag;
+ AliEventTag *evTag = new AliEventTag;
+ fChain->SetBranchAddress("AliTAG",&tag);
+
+ for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) {
+ //Event list
+ TEntryList *fList = new TEntryList();
+ fChain->GetEntry(iTagFiles);
+ if(RunTagCuts->IsAccepted(tag)) {
+ Int_t iEvents = tag->GetNEvents();
+ const TClonesArray *tagList = tag->GetEventTags();
+ for(Int_t i = 0; i < iEvents; i++) {
+ evTag = (AliEventTag *) tagList->At(i);
+ guid = evTag->GetGUID();
+ turl = evTag->GetTURL();
+ lfn = turl(8,turl.Length());
+ if(EvTagCuts->IsAccepted(evTag)) fList->Enter(i);
+ }//event loop
+ collection->WriteBody(iTagFiles+1,guid,lfn,turl,fList);
+ }//run tag cuts
+ }//tag file loop
+ collection->Export();
+
+ return kTRUE;
+}
+
+//___________________________________________________________________________
+Bool_t AliTagAnalysis::CreateXMLCollection(const char* name, const char *fRunCut, const char *fEventCut) {
+ //Queries the tag chain using the defined
+ //event tag cuts from the AliEventTagCuts object
+ //and returns a XML collection
+ AliInfo(Form("Creating the collection........"));
+
+ AliXMLCollection *collection = new AliXMLCollection();
+ collection->SetCollectionName(name);
+ collection->WriteHeader();
+
TString guid = 0x0;
+ TString turl = 0x0;
+ TString lfn = 0x0;
//Defining tag objects
AliRunTag *tag = new AliRunTag;
AliEventTag *evTag = new AliEventTag;
fChain->SetBranchAddress("AliTAG",&tag);
+ TTreeFormula *fRunFormula = new TTreeFormula("fRun",fRunCut,fChain);
+ TTreeFormula *fEventFormula = new TTreeFormula("fEvent",fEventCut,fChain);
+
+ Int_t current = -1;
for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) {
+ //Event list
+ TEntryList *fList = new TEntryList();
fChain->GetEntry(iTagFiles);
- Int_t iEvents = tag->GetNEvents();
- const TClonesArray *tagList = tag->GetEventTags();
- for(Int_t i = 0; i < iEvents; i++) {
- evTag = (AliEventTag *) tagList->At(i);
- guid = evTag->GetGUID();
- if(EvTagCuts->IsAccepted(evTag)) fEventList->Enter(i);
- }//event loop
- collection->WriteBody(iTagFiles+1,guid,fEventList);
- fEventList->Clear();
+ if (current != fChain->GetTreeNumber()) {
+ fRunFormula->UpdateFormulaLeaves();
+ fEventFormula->UpdateFormulaLeaves();
+ current = fChain->GetTreeNumber();
+ }
+ if(fRunFormula->EvalInstance(iTagFiles) == 1) {
+ Int_t iEvents = fEventFormula->GetNdata();
+ const TClonesArray *tagList = tag->GetEventTags();
+ for(Int_t i = 0; i < iEvents; i++) {
+ evTag = (AliEventTag *) tagList->At(i);
+ guid = evTag->GetGUID();
+ turl = evTag->GetTURL();
+ lfn = turl(8,turl.Length());
+ if(fEventFormula->EvalInstance(i) == 1) fList->Enter(i);
+ }//event loop
+ collection->WriteBody(iTagFiles+1,guid,lfn,turl,fList);
+ }//run tag cuts
}//tag file loop
collection->Export();
return kTRUE;
}
+//___________________________________________________________________________
+TChain *AliTagAnalysis::GetInputChain(const char* system, const char*global, const char *wn) {
+ //returns the chain+event list - used in batch sessions
+ TString fsystem = system;
+ Int_t iAccepted = 0;
+ //ESD file chain
+ TChain *fESDchain = new TChain("esdTree");
+ //Event list
+ TEventList *fEventList = new TEventList();
+ AliXMLCollection *collection1 = AliXMLCollection::Open(global);
+ AliXMLCollection *collection2 = AliXMLCollection::Open(wn);
+ collection1->OverlapCollection(collection2);
+ collection1->Reset();
+ while (collection1->Next()) {
+ AliInfo(Form("Adding: %s",collection1->GetTURL("")));
+ fESDchain->Add(collection1->GetTURL(""));
+ TEntryList *list = (TEntryList *)collection1->GetEventList("");
+ for(Int_t i = 0; i < list->GetN(); i++) fEventList->Enter(iAccepted+list->GetEntry(i));
+
+ if(fsystem == "pp") iAccepted += 100;
+ else if(fsystem == "PbPb") iAccepted += 1;
+ }
+
+ fESDchain->SetEventList(fEventList);
+
+ AliInfo(Form("Number of selected events: %d",fEventList->GetN()));
+
+ return fESDchain;
+}