void execCreateAndMerge() { 
//-------------------------------------------------------------------------- 
for ( Int_t ifile = 0 ; ifile < 4 ; ifile++ ) { 
   TFile* outputFile = TFile::Open(Form("a_file_%d.root",ifile),"RECREATE"); 
   TNamed* namedObj = new TNamed(Form("namedObj%d",ifile),Form("namedObj%d",ifile)); 
   namedObj->Write(); 
   outputFile->Close(); 
} 
cout << "4 a files created" << endl; 
//-------------------------------------------------------------------------- 
//-------------------------------------------------------------------------- 
for ( Int_t ifile = 0 ; ifile < 4 ; ifile++ ) { 
   TFile* outputFile = TFile::Open(Form("b_file_%d.root",ifile),"RECREATE"); 
   TNamed* namedObj = new TNamed("namedObj","namedObj"); 
   namedObj->Write(); 
   outputFile->Close(); 
} 
cout << "4 b files created" << endl; 
//-------------------------------------------------------------------------- 
//-------------------------------------------------------------------------- 
TFileMerger* aMerger = new TFileMerger(kFALSE); 
 for ( Int_t ifile = 0 ; ifile < 4 ; ifile++ ) { 
    TFile* inFile = TFile::Open(Form("a_file_%d.root",ifile)); 
    aMerger->AddFile(inFile); 
 } 
 aMerger->OutputFile("a_file.root"); 
 aMerger->Merge(); 
 cout << "4 a files merged" << endl; 
//-------------------------------------------------------------------------- 
//-------------------------------------------------------------------------- 
 TFileMerger* bMerger = new TFileMerger(kFALSE); 
 for ( Int_t ifile = 0 ; ifile < 4 ; ifile++ ) { 
    TFile* inFile = TFile::Open(Form("b_file_%d.root",ifile)); 
    bMerger->AddFile(inFile); 
 } 
 bMerger->OutputFile("b_file.root"); 
 bMerger->Merge(); 
cout << "4 b files merged" << endl; 
//-------------------------------------------------------------------------- 
//-------------------------------------------------------------------------- 
TFile* inAFile = TFile::Open("a_file.root"); 
cout << "******* MERGED A FILE ******** 4 objects with different names" << endl; 
inAFile->ls(); 
cout << "******************************" << endl; 
//-------------------------------------------------------------------------- 
//-------------------------------------------------------------------------- 
TFile* inBFile = TFile::Open("b_file.root"); 
cout << "******* MERGED B FILE ******** 4 objects with the same names" << endl; 
inBFile->ls(); 
cout << "******************************" << endl; 
//-------------------------------------------------------------------------- 
} 
void MergeFlowd() 
{
	TGrid *alien = TGrid::Connect("alien");
	if (alien->IsZombie())
	{
		delete alien;
		cout << "Fatal: Alien is a zombie!" << endl;
		return;
	}

  Int_t runlist[] = {                                                               // Counter
    /*170309, 170308, 170306, 170270, 170269, 170268, 170230, 170228,*/ 170204, 170203, // 10
    170193, 170163, 170159, 170155, 170081, 170027, 169859, 169858, 169855, 169846, // 20
    169838, 169837, 169835, 169417, 169415, 169411, 169238, 169167, 169160, 169156, // 30
    169148, 169145, 169144, 169138, 169094, 169091, 169035, 168992, 168988, 168826, // 40
    168777, 168514, 168512, 168511, 168467, 168464, 168460, 168458, 168362, 168361, // 50
    168342, 168341, 168325, 168322, 168311, 168310, 167988, 167987                  // 58
  };	

  TFileMerger merger;
  TString dataBaseDir = "/alice/cern.ch/user/m/mpuccio/Flowd_PbPb2011/output/000";
  merger.OutputFile("FileMerger.root");
  for (int iRun = 0; iRun < 1; ++iRun)
  {
  	TString runDir = Form("%s%i",dataBaseDir.Data(),runlist[iRun]);
  	TGridResult *res = alien->Command(Form("find %s */mpuccio_Flowd.root",runDir.Data()));
  	TIter iter(res);
  	TMap *map;
  	while ((map = (TMap*)iter())) 
  	{
  		TObjString *obj = dynamic_cast<TObjString*>(map->GetValue("turl"));
  		if (!obj || !obj->String().Length())
  		{
  			delete res;
  			break;
  		}

  		TFile *f = TFile::Open(obj->String().Data());
  		if (!f->IsOpen())
  		{
  			cout << "File " << obj->String().Data() << " has some problems..." << endl;
  			continue;
  		}
  		merger.AddFile(f);
  		merger.PartialMerge();
  		f->Close();
  	}
  }
  merger.Merge();
  merger.Write();
}
Example #3
0
void MergeCollectionFromGrid(const char * incollection = "test.xml", const char * outputfile= "dndeta_merged.root")
{
  // for running with root only
  gSystem->Load("libTree");
  gSystem->Load("libGeom");
  gSystem->Load("libVMC");
  gSystem->Load("libSTEERBase");
  gSystem->Load("libESD");
  gSystem->Load("libAOD");

  // load analysis framework
  gSystem->Load("libANALYSIS");
  gSystem->Load("libANALYSISalice");

  // load dndeta task
  gROOT->LoadMacro("AliAnalysisTaskdNdetaMC.cxx+");


  TFileMerger * fileMerger  = new TFileMerger(0); // dont merge local files

  TGrid::Connect("alien://");
  TGridCollection * coll = TAlienCollection::Open (incollection);
  Int_t  ifile=0;
  while(coll->Next()){
    fileMerger->AddFile(TString("alien://")+coll->GetLFN());
    ifile++;
    //    if(ifile>2) break;
  }
  fileMerger->OutputFile("tmp.root");
  fileMerger->Merge();

  // Reopen the merged file, normalize histos and save them back.
  // SOME DUPLICATED CODE... SOME CLEAN UP WOULD BE GOOD
  AliAnalysisTaskdNdetaMC * localTask  = new AliAnalysisTaskdNdetaMC("merger", "tmp.root");
  localTask->Finalize();
  
  TFile * fout = new TFile (outputfile, "recreate");
  localTask->GetList()->Write();
  fout->Close();
}
Example #4
0
File: BA.C Project: ktf/AliPhysics
Int_t BA(  const TString& pSpectra   = "~/alice/output/Proton-lhc10d-Spectra.root"
         , const TString& dSpectra   = "~/alice/output/Deuteron-lhc10d-Spectra.root"
         , const TString& ptag       = "lhc10d"
         , const TString& dtag       = "lhc10d"
         , const TString& outputfile = "~/alice/output/lhc10d-B2.root"
         , const TString& otag       = "lhc10d"
         , const Bool_t   draw       = 1)
{
//
// coalescence parameter for nucleus and antinucleus
//
	using namespace std;
	
	Int_t A = 2;
	Int_t Z = 1;
	
	if(nucleus == "Deuteron")
	{
		A = 2;
		Z = 1;
	}
	else if(nucleus == "Triton")
	{
		A = 3;
		Z = 1;
	}
	else if(nucleus == "He3")
	{
		A = 3;
		Z = 2;
	}
	else
	{
		cerr << "only valid names: Deuteron, Triton and He3" << endl;
		return 1;
	}
	
	const Int_t kNpart = 2;
	const Int_t kZ[kNpart] = { Z, -Z };
	const TString kB2File[kNpart] = {"BA.root", "AntiBA.root" };
	
	TFileMerger m;
	
	for(Int_t i=0; i<kNpart; ++i)
	{
		AliLnBA b2(pSpectra, ptag, dSpectra, dtag, kB2File[i], otag, A, kZ[i]);
		
		b2.Run();
		
		m.AddFile(kB2File[i].Data(),0);
	}
	
	m.OutputFile(outputfile.Data());
	m.Merge();
	
	gSystem->Exec(Form("rm -f %s %s", kB2File[0].Data(), kB2File[1].Data()));
	
	if(!draw) return 0;
	
	const TString kNucleus[kNpart] = { nucleus, Form("Anti%s",nucleus.Data())};
	
	for(Int_t i=0; i<kNpart; ++i)
	{
		gROOT->ProcessLine(Form(".x DrawBA.C+g(\"%s\",\"%s\",\"%s\")", outputfile.Data(), otag.Data(), kNucleus[i].Data()));
	}
	
	return 0;
}