#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
AliInfo(Form("Querying the tags........"));
//ESD file chain
AliEventTag *evTag = new AliEventTag;
fChain->SetBranchAddress("AliTAG",&tag);
- Long64_t size = -1;
- const char* md5 = 0;
- const char* guid = 0;
- const char* turl = 0;
- const char* path = 0;
+ TString guid = 0;
+ TString turl = 0;
+ TString path = 0;
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);
- size = evTag->GetSize();
- md5 = evTag->GetMD5();
- guid = evTag->GetGUID();
- turl = evTag->GetTURL();
- path = evTag->GetPath();
- if(EvTagCuts->IsAccepted(evTag)) fEventList->Enter(iAccepted+i);
- }//event loop
- iAccepted += iEvents;
-
- if(path != NULL) fESDchain->Add(path);
- else if(turl != NULL) fESDchain->Add(turl);
+ 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);
+ }//run tags cut
}//tag file loop
AliInfo(Form("Accepted events: %d",fEventList->GetN()));
fESDchain->SetEventList(fEventList);
return fESDchain;
}
+//___________________________________________________________________________
+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
+ AliInfo(Form("Creating the collection........"));
+
+ AliXMLCollection *collection = new AliXMLCollection();
+ collection->SetCollectionName(name);
+ collection->WriteHeader();
+
+ //Event list
+ //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);
+ 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 *wn) {
+ //returns the chain+event list - used in batch sessions
+ // this function will be removed once the new root
+ // improvements are committed
+ TString fsystem = system;
+ Int_t iAccepted = 0;
+ //ESD file chain
+ TChain *fESDchain = new TChain("esdTree");
+ //Event list
+ TEventList *fEventList = new TEventList();
+ AliXMLCollection *collection = AliXMLCollection::Open(wn);
+
+ collection->Reset();
+ while (collection->Next()) {
+ AliInfo(Form("Adding: %s",collection->GetTURL("")));
+ fESDchain->Add(collection->GetTURL(""));
+ TEntryList *list = (TEntryList *)collection->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;
+}
+
+//___________________________________________________________________________
+TChain *AliTagAnalysis::GetChainFromCollection(const char* collectionname, const char* treename) {
+ //returns the TChain+TEntryList object- used in batch sessions
+ TString fAliceFile = treename;
+ Int_t iAccepted = 0;
+ TChain *fAnalysisChain = new TChain();
+ if(fAliceFile == "esdTree") {
+ //ESD file chain
+ fAnalysisChain->SetName("esdTree");
+ } else if(fAliceFile == "aodTree") {
+ //AOD file chain
+ fAnalysisChain->SetName("aodTree");
+ AliFatal("AOD case not yet implemented!!!");
+ }
+ else AliFatal("Inconsistent tree name - use esdTree or aodTree!");
+ //Event list
+ TEntryList *fGlobalList = new TEntryList();
+ AliXMLCollection *collection = AliXMLCollection::Open(collectionname);
+ collection->Reset();
+ while (collection->Next()) {
+ AliInfo(Form("Adding: %s",collection->GetTURL("")));
+ fAnalysisChain->Add(collection->GetTURL(""));
+ TEntryList *list = (TEntryList *)collection->GetEventList("");
+ list->SetTreeName(fAliceFile.Data());
+ list->SetFileName(collection->GetTURL(""));
+ fGlobalList->Add(list);
+ iAccepted += list->GetN();
+ }
+
+ fAnalysisChain->SetEntryList(fGlobalList,"ne");
+
+ AliInfo(Form("Number of selected events: %d",iAccepted));
+
+ return fAnalysisChain;
+}