当前位置: 首页>>代码示例>>C++>>正文


C++ TDirectory::mkdir方法代码示例

本文整理汇总了C++中TDirectory::mkdir方法的典型用法代码示例。如果您正苦于以下问题:C++ TDirectory::mkdir方法的具体用法?C++ TDirectory::mkdir怎么用?C++ TDirectory::mkdir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TDirectory的用法示例。


在下文中一共展示了TDirectory::mkdir方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

LjmetEventContent::~LjmetEventContent(){

  // save tree
  mpTree->Write();

  // save histograms
  std::map<std::string,std::map<std::string,LjmetEventContent::HistMetadata> >::iterator iMod;
  std::map<std::string,LjmetEventContent::HistMetadata>::iterator iHist;
  TDirectory * rootDir = mpTree->GetDirectory();
  for (iMod=mDoubleHist.begin();iMod!=mDoubleHist.end();++iMod){
    TDirectory * _dir = 0;
    _dir = rootDir->mkdir( iMod->first.c_str() );
    if (!_dir) rootDir->GetDirectory( iMod->first.c_str() );
    for (iHist=iMod->second.begin();iHist!=iMod->second.end();++iHist){
      std::cout << mLegend
		<< "Saving " << iMod->first << "/"
		<< iHist->second.GetName() << std::endl;
      _dir->cd();
      iHist->second.GetHist( )->SetDirectory(_dir);
      iHist->second.GetHist( )->Print();
      iHist->second.GetHist( )->Write();
    }
  }

}
开发者ID:kukarzev,项目名称:snowmass,代码行数:25,代码来源:LjmetEventContent.cpp

示例2: CopyDir

void CopyDir(TDirectory *source) {
   //copy all objects and subdirs of directory source as a subdir of the current directory   
   source->ls();
   TDirectory *savdir = gDirectory;
   TDirectory *adir = savdir->mkdir(source->GetName());
   adir->cd();
   //loop on all entries of this directory
   TKey *key;
   TIter nextkey(source->GetListOfKeys());
   while ((key = (TKey*)nextkey())) {
      const char *classname = key->GetClassName();
      TClass *cl = gROOT->GetClass(classname);
      if (!cl) continue;
      if (cl->InheritsFrom(TDirectory::Class())) {
         source->cd(key->GetName());
         TDirectory *subdir = gDirectory;
         adir->cd();
         CopyDir(subdir);
         adir->cd();
      } else if (cl->InheritsFrom(TTree::Class())) {
         TTree *T = (TTree*)source->Get(key->GetName());
         adir->cd();
         TTree *newT = T->CloneTree(-1,"fast");
         newT->Write();
      } else {
         source->cd();
         TObject *obj = key->ReadObj();
         adir->cd();
         obj->Write();
         delete obj;
     }
  }
  adir->SaveSelf(kTRUE);
  savdir->cd();
}
开发者ID:fcostanz,项目名称:StopAnalysis,代码行数:35,代码来源:mergeFiles.C

示例3: writeCollection

/**
 * @brief Write all TObjects from a given TCollection into a certain directory structure in the file
 *
 * @param col pointer to a TCollection-based container
 * @param dirname name of a directory inside the output file to which the objects should be written
 * @param subdirname optional name of a subdirectory inside dirname to which the objects should be written
 *
 * This method whites all TObject-based objects contained in the TCollection-based container (see ROOT documentation)
 * into a directory whose name is given by dirname inside the output file. If dirname does not exist
 * in the output file, it will be created. Otherwise, contents of the col collection will be appended to an existing
 * directory.
 *
 * If the optional subdirectory name is specified (subdirname parameter, defaults to empty string) then the
 * contents of the collection will be written to "dirname/subdirname". If the "subdirname" directory does not
 * exist inside the "dirname" directory, it will be created.
 *
 */
void JPetWriter::writeCollection(const TCollection* col, const char* dirname, const char* subdirname)
{

  TDirectory* current =  fFile->GetDirectory(dirname);

  if (!current) {
    current = fFile->mkdir(dirname);
  }

  assert(current);

  // use a subdirectory if requested by user
  if (!std::string(subdirname).empty()) {

    if (current->GetDirectory(subdirname)) {
      current = current->GetDirectory(subdirname);
    } else {
      current = current->mkdir(subdirname);
    }
  }

  assert(current);

  current->cd();

  TIterator* it = col->MakeIterator();

  TObject* obj;
  while ((obj = it->Next())) {
    obj->Write();
  }

  fFile->cd();
}
开发者ID:flukson,项目名称:j-pet-framework,代码行数:51,代码来源:JPetWriter.cpp

示例4: store

void store(){
	 if (!TClass::GetDict("NBD")) {
                gROOT->ProcessLine(".L /afs/cern.ch/user/q/qixu/CMSSW_6_2_5/src/Centrality/NBD_Glauber_fit/NBD/NBDclass.C+");
        }
	TH1::AddDirectory(kFALSE); 
	int Gth=atoi(getenv("GTH"));
	int sth=atoi(getenv("STH"));
	NBD *l;
	struct para1 var;
        if(sth==0){TString dirname = "std"; var = var1; if(Gth<nGlau) l = new NBD(datafile,stdGlaulist[Gth],histoname);else l = new NBD(datafile,stdGlaulist[0],histoname);}
        else if(sth==1){TString dirname ="Gri055"; var = var2; if(Gth<nGlau) l = new NBD(datafile,Gri055Glaulist[Gth],histoname);else l = new NBD(datafile,Gri055Glaulist[0],histoname);}
        else {TString dirname ="Gri101"; var = var3; if(Gth<nGlau) l = new NBD(datafile,Gri101Glaulist[Gth],histoname);else l = new NBD(datafile,Gri101Glaulist[0],histoname);}
	l->initmu(var.mumin,var.mumax,var.mustep);
     	l->initk(var.kmin,var.kmax,var.kstep);
	if(Gth<nGlau)
        	l->initx(var.xmin,var.xmax);
	else if(Gth-nGlau==0)
		l->initx(var.xmin-binshift,var.xmax);
	else
		l->initx(var.xmin+binshift,var.xmax);
//	l->fit();

 	if(sth==0) l->assign(bestlist1[Gth].mubest,bestlist1[Gth].kbest);
	else if(sth==1) l->assign(bestlist2[Gth].mubest,bestlist2[Gth].kbest);
	else l->assign(bestlist3[Gth].mubest,bestlist3[Gth].kbest);

        l->initN(bin,N,method);
        l->calcvar();
	TFile *outfile = new TFile(outG,"Update");
	if(Gth==0 && sth==0){
	l->dataname.Write("dataname",TObject::kOverwrite);
	l->histoname.Write("histoname",TObject::kOverwrite);
	}
	TDirectory *dir = outfile->GetDirectory(dirname);
	if (!dir) {outfile->mkdir(dirname);	TDirectory *dir = outfile->GetDirectory(dirname);}
	dir->cd();
	TString name;
	if(Gth==0)
		name = "G0";
	else if(Gth<nGlau)
		name = Form("Glau_%d",Gth);
	else
		name = Form("bin_%d",Gth-nGlau+1);
	TDirectory *subdir = dir->GetDirectory(name);
	if(!subdir) {dir->mkdir(name);	TDirectory *subdir = dir->GetDirectory(name);}
	subdir->cd();
	l->method.Write("method",TObject::kOverwrite);
	l->Glaubername.Write("Glaubername",TObject::kOverwrite);
	l->xmin.Write("xmin",TObject::kOverwrite);l->xmax.Write("xmax",TObject::kOverwrite);
	l->mubest.Write("mubest",TObject::kOverwrite);l->kbest.Write("kbest",TObject::kOverwrite);
	l->chis.Write("chis",TObject::kOverwrite);l->Ndf.Write("Ndf",TObject::kOverwrite);
	l->NcollAver.Write("NcollAver",TObject::kOverwrite);l->NpartAver.Write("NpartAver",TObject::kOverwrite);l->BAver.Write("BAver",TObject::kOverwrite);
	l->centbin.Write("centbin",TObject::kOverwrite);	l->kpoint.Write("kpoint",TObject::kOverwrite);
	l->centbin_.Write("centbin_",TObject::kOverwrite);	l->kpoint_.Write("kpoint_",TObject::kOverwrite);
	l->Npartdis->Write();
        l->Grgrid->Write("Grgrid",TObject::kOverwrite);
        outfile->Close();

}
开发者ID:XuQiao,项目名称:HI,代码行数:59,代码来源:store.C

示例5:

void	drift_efficiency()
{
	TDirectory	*rootdir = gDirectory;
	TFile	f(gSystem->Getenv("EPECUR_ROOTFILE2"), "READ");
	TTree	*events = (TTree*)f.Get("events");
	rootdir->cd();

	c2.Divide(2, 2);
	c3.Divide(2, 2);

	rootdir->mkdir("lx")->cd();
	make_drift_efficiency_hist('l', 'X', events);
	rootdir->mkdir("ly")->cd();
	make_drift_efficiency_hist('l', 'Y', events);
	rootdir->mkdir("rx")->cd();
	make_drift_efficiency_hist('r', 'X', events);
	rootdir->mkdir("ry")->cd();
	make_drift_efficiency_hist('r', 'Y', events);

	c1.Show();
	c2.Show();
	c3.Show();
}
开发者ID:veprbl,项目名称:libepecur,代码行数:23,代码来源:drift_efficiency.C

示例6: copy

void copy(const std::string& src_file, const std::string& src_obj, const std::string& des_file, const std::string& des_path, const std::string& des_obj) {

  gStyle->SetPalette(1,0);

  TFile *old_file = new TFile(src_file.c_str());
  if (!old_file) {
    std::cerr << "Can not open file: " << src_file << std::endl;
    return;
  }

  TObject* old_obj = old_file->Get(src_obj.c_str());
  if (!old_obj) {
    std::cerr << "Can not open object: " << src_obj << " in file " << src_file << std::endl;
    return;
  }

  TFile *new_file = new TFile(des_file.c_str(), "RECREATE");
  TDirectory *cdto = 0;

  std::vector<std::string> tokens;
  splitString(des_path, "/", tokens);
  for (unsigned int i = 0; i < tokens.size(); i++) {
    if (cdto == 0) {
      cdto = new_file->mkdir(tokens.at(i).c_str());
    } else {
      cdto = cdto->mkdir(tokens.at(i).c_str());
    }
    cdto->cd();
  }

  TObject *new_obj = dynamic_cast<TObject*> (old_obj->Clone(des_obj.c_str()));

  if (new_obj->IsA()->InheritsFrom("TH2")) {
    TH2* h2 = (TH2*) new_obj;
    if (h2) {
      if(h2->GetXaxis()->GetXmin() <= 1 && h2->GetXaxis()->GetXmax() >= 36 &&
         h2->GetYaxis()->GetXmin() <= 1 && h2->GetYaxis()->GetXmax() >= 18) {

        //fillCellsWithRowNeighbourAverage(h2);
        fillCellsWithRowAverage(h2);
        h2->Draw("colz");

      }
    }
  }

  new_file->Write();

}
开发者ID:Andrej-CMS,项目名称:cmssw,代码行数:49,代码来源:reference.C

示例7: importdir

void importdir(const char *dirname) {
	//Example of script showing how to create a ROOT file with subdirectories.
	//The script scans a given directory tree and recreates the
	//same structure in the ROOT file.
	//All source files of type .h,cxx,c,dat,py are imported as TMacro objects
	//see also other tutorial readCode.C
	//Author: Rene Brun
	                   
	char *slash = (char*)strrchr(dirname,'/');
	char *locdir;
	if (slash) locdir = slash+1;
	else       locdir = (char*)dirname;
	printf("processing dir %s\n",dirname);
	TDirectory *savdir = gDirectory;
	TDirectory *adir = savdir->mkdir(locdir);
	adir->cd();
	void *dirp = gSystem->OpenDirectory(dirname);
	if (!dirp) return;
	char *direntry;
	Long_t id, size,flags,modtime;
	//loop on all entries of this directory
	while ((direntry=(char*)gSystem->GetDirEntry(dirp))) {
		TString afile = Form("%s/%s",dirname,direntry);
		gSystem->GetPathInfo(afile,&id,&size,&flags,&modtime);
		if (direntry[0] == '.')             continue; //forget the "." and ".." special cases
		if (!strcmp(direntry,"CVS"))        continue; //forget some special directories
		if (!strcmp(direntry,"htmldoc"))    continue;
		if (strstr(dirname,"root/include")) continue;
		if (strstr(direntry,"G__"))         continue;
		if (strstr(direntry,".c")    ||
				strstr(direntry,".h")    ||
				strstr(direntry,".dat")  ||
				strstr(direntry,".py")   ||
				strstr(direntry,".C")) {
			TMacro *m = new TMacro(afile);
			m->Write(direntry);
			delete m;
		} else {
			if (flags != 3)                     continue; //must be a directory
			//we have found a valid sub-directory. Process it
			importdir(afile);
		}
	}
	gSystem->FreeDirectory(dirp);
	savdir->cd();
}
开发者ID:hkaushalya,项目名称:CDFPhoJets,代码行数:46,代码来源:RecreteRootFile.C

示例8: make

void make(TDirectory & out, TObject * o) {
  TDirectory * dir;
  TH1F * th1f;
  TH1D * th1d;
  TH2F * th2f;
  TH2D * th2d;
  out.cd();
  if((dir = dynamic_cast<TDirectory*>(o)) != 0) {
    TDirectory * outDir = out.mkdir(dir->GetName(), dir->GetTitle());
    TIter next(dir->GetListOfKeys());
    TKey *key;
    while( (key = dynamic_cast<TKey*>(next())) ) {
      string className(key->GetClassName());
      string name(key->GetName());
      TObject * obj = dir->Get(name.c_str());
      if(obj == 0) {
	cerr <<"error: key " << name << " not found in directory " << dir->GetName() << endl;
	exit(-1);
      }
      make(*outDir, obj);
    }
  } else if((th1f = dynamic_cast<TH1F*>(o)) != 0) {
    TH1F *h = (TH1F*) th1f->Clone();
    h->Reset();
    h->Sumw2();
    h->SetDirectory(&out);
  } else if((th1d = dynamic_cast<TH1D*>(o)) != 0) {
    TH1D *h = (TH1D*) th1d->Clone();
    h->Reset();
    h->Sumw2();
    h->SetDirectory(&out);
  } else if((th2f = dynamic_cast<TH2F*>(o)) != 0) {
    TH2F *h = (TH2F*) th2f->Clone();
    h->Reset();   
    h->Sumw2();
    h->SetDirectory(&out);
  } else if((th2d = dynamic_cast<TH2D*>(o)) != 0) {
    TH2D *h = (TH2D*) th2d->Clone();
    h->Reset();   
    h->Sumw2();
    h->SetDirectory(&out);
  }
}
开发者ID:Andrej-CMS,项目名称:cmssw,代码行数:43,代码来源:mergeTFileServiceHistograms.cpp

示例9: setPath

void setPath(string& path, TDirectory* topDir) {

  TDirectory* cdir = dynamic_cast<TDirectory*> (topDir->GetDirectory(path.c_str()));
  if (!cdir) {
    vector<string> names;
    string tag = "/";
    split(path, names, tag);
    cdir = topDir;
    for (unsigned int it = 0; it < names.size();  it++) {
      string name = names[it];
      if (name.size() != 0) {
	TDirectory* td  = dynamic_cast<TDirectory*> (cdir->Get(name.c_str()));
        if (!td) td = cdir->mkdir(name.c_str());
	cdir = td;
      }
    }     
  }
  cdir->cd();
  //cdir->pwd();
}
开发者ID:Andrej-CMS,项目名称:cmssw,代码行数:20,代码来源:sistrip_reduce_file.C

示例10: doit

void doit()
{
   TFile* base = new TFile("f.db","recreate");
   TDirectory* a = base->mkdir("a","First Level Dir");
   a->cd();
   TH1D* ha = new TH1D("ha","ha",10,0,1);
   TDirectory* aa = a->mkdir("aa","Second Level Dira");
   aa->cd();
   TH1D* haa = new TH1D("haa","haa",10,0,1);
   
   a->ls();
   
   printf(" a: [email protected] %p  [email protected] %p\n", a,base->FindObjectAny("a"));
   printf("ha: [email protected] %p  [email protected] %p\n",ha,base->FindObjectAny("ha"));
   printf("ha: [email protected] %p  [email protected] %p\n",ha,base->FindObjectAny("a/ha"));
#ifdef ClingWorkAroundMissingImplicitAuto
   TDirectory *k = (TDirectory*)base->FindObjectAny("a");
#else
   k = (TDirectory*)base->FindObjectAny("a");
#endif
   printf("ha: [email protected] %p  [email protected] %p\n",ha,k->FindObjectAny("ha"));
   
   printf("aa: [email protected] %p  [email protected] %p\n",aa,base->FindObjectAny("aa"));
   printf("aa: [email protected] %p  [email protected] %p\n",aa,base->FindObjectAny("a/aa"));
   printf("aa: [email protected] %p  [email protected] %p\n",aa,k->FindObjectAny("aa"));
   
   printf("haa: [email protected] %p  [email protected] %p\n",haa,base->FindObjectAny("haa"));
   printf("haa: [email protected] %p  [email protected] %p\n",haa,base->FindObjectAny("aa/haa"));
   printf("haa: [email protected] %p  [email protected] %p\n",haa,base->FindObjectAny("a/aa/haa"));
   printf("haa: [email protected] %p  [email protected] %p\n",haa,k->FindObjectAny("haa"));
   printf("haa: [email protected] %p  [email protected] %p\n",haa,k->FindObjectAny("aa/haa"));
#ifdef ClingWorkAroundMissingImplicitAuto
   TDirectory *kk = (TDirectory*)k->FindObjectAny("aa");
#else
   kk = (TDirectory*)k->FindObjectAny("aa");
#endif
   printf("haa: [email protected] %p  [email protected] %p\n",haa,kk->FindObjectAny("haa"));
   
   base->Write();
   
}
开发者ID:jlsalmon,项目名称:roottest,代码行数:41,代码来源:testFindObjectAny.C

示例11: Proc_hYW

void ProcYields::Proc_hYW(){
	Info("Proc_hYW()", "");
		
	TDirectory* dirhYW = _fout->mkdir("hYW");
	TH1F* hYW[nVARSET];
	
	TDirectory* dirVarset=NULL;
	for(Int_t iVarset=0;iVarset<nVARSET;iVarset++){
		Info("Proc_hYW()","Varset = Varset%d", iVarset+1);
		dirVarset=dirhYW->mkdir(TString::Format("Varset%d",iVarset+1));
		dirVarset->cd();
		hYW[iVarset] = new TH1F("hYW","hYW", _user.nWbins, _user.Wmin, _user.Wmax);
		hYW[iVarset]->SetXTitle("W[GeV]");
		
		//!Loop over Q2W dirs, get h5Ds and their yields
		TIter nextkey(_fout->GetListOfKeys());
		TKey *key;
		while (key = (TKey*)nextkey()) {
			TString Q2Wdirname = key->GetName();
			if(Q2Wdirname.EqualTo("hYW_Dir") || Q2Wdirname.EqualTo("hYW"))continue;
			Info("Proc_hYW()","Q2Wdir = %s", Q2Wdirname.Data());
			TString wrange = Q2Wdirname.Tokenize("_")->At(1)->GetName();
			TString wlow = wrange.Tokenize(",")->At(0)->GetName();
			wlow.Remove(0,1); //remove "["
			//Float_t w = wlow.Atof();
			Double_t w = wlow.Atof();
									
			sprintf(_hname, "%s/hY5D/Varset%d/hY5D_FULL", Q2Wdirname.Data(),iVarset+1);
			THnSparse* hY5D_FULL = (THnSparse*)_fout->Get(_hname);
			if (hY5D_FULL == NULL) cout <<"could not get h5D" << endl;
			//Float_t yield = getIntegral(hY5D_FULL);
			Double_t yield = getIntegral(hY5D_FULL);
			//hYW[iVarset]->Fill(w, yield);
			hYW[iVarset]->SetBinContent(hYW[iVarset]->FindBin(w+_intrinsic.Wbinw), yield);
			Info("Proc_hYW()","W = %f, bin# = %d, yield = %f\n", w, hYW[iVarset]->FindBin(w+_intrinsic.Wbinw), yield);
		}
	}
	Info("Proc_hYW()", "done\n");
}
开发者ID:arjun-trivedi,项目名称:ana2pi,代码行数:39,代码来源:proc_yields.preMtg091013.C

示例12: copyDir

//Clone the file excluding the histogram (code stolen from Rene Brun)
void copyDir(TDirectory *source,std::string iSkipHist,bool iFirst=true) { 
  //copy all objects and subdirs of directory source as a subdir of the current directory   
  TDirectory *savdir = gDirectory;
  TDirectory *adir   = savdir;
  if(!iFirst) adir   = savdir->mkdir(source->GetName());
  if(!iFirst) adir->cd();
  //loop on all entries of this directory
  TKey *key;
  TIter nextkey(source->GetListOfKeys());
  while ((key = (TKey*)nextkey())) {
    const char *classname = key->GetClassName();
    TClass *cl = gROOT->GetClass(classname);
    if (!cl) continue;
    if (cl->InheritsFrom(TDirectory::Class())) {
      source->cd(key->GetName());
      TDirectory *subdir = gDirectory;
      adir->cd();
      copyDir(subdir,iSkipHist,false);
      adir->cd();
    } else {
      source->cd();
      TObject *obj = key->ReadObj();
      std::string pFullName = std::string(adir->GetName())+"/"+std::string(obj->GetName());
      std::string iSkipHist2 = iSkipHist;
      std::string fine_binning = "_fine_binning";
      iSkipHist2.replace(iSkipHist2.find(fine_binning), fine_binning.length(),"");
      if(pFullName.find(iSkipHist) != std::string::npos || pFullName.find(iSkipHist2) != std::string::npos) {
	continue;
      }
      adir->cd();
      obj->Write();
      delete obj;
    }
  }
  adir->SaveSelf(kTRUE);
  savdir->cd();
}
开发者ID:jjswan33,项目名称:HiggsAnalysis-HiggsToTauTau,代码行数:38,代码来源:addFitNuisanceBiasStudy.C

示例13: Write

 void Write(TDirectory * dir){
     TDirectory * inDir = dir->mkdir(Name.c_str());
     inDir->cd();
     cosTheta->Write();
     Wmass->Write();
     topMass->Write();
     cosThetaII->Write();
     WmassII->Write();
     topMassII->Write();
     cosTheta2D->Write();
     cosTheta2DII->Write();
     (inDir->mkdir("ttDecayModes"))->cd();
     semiEcosTheta->Write();
     semiTaucosTheta->Write();
     diTaucosTheta->Write();
     diEcosTheta->Write();
     diMucosTheta->Write();
     MuEcosTheta->Write();
     TauEcosTheta->Write();
     MuTaucosTheta->Write();
     fullHadcosTheta->Write();
     inDir->cd();
     dir->cd();
 }
开发者ID:nadjieh,项目名称:work,代码行数:24,代码来源:HistogramCreator.C

示例14: MergeComplexHistogramFile

//________________________________________________________________________________
void MergeComplexHistogramFile( const Char_t *TargetName=0, const Char_t *inputFilesPattern=0) 
{
  if (TargetName && TargetName[0] && inputFilesPattern && inputFilesPattern[0] ) {
    printf(" An experimental version of macro.\n");
    TStopwatch time;
    Int_t fileCounter = 0;
    Int_t dirCounter = 0;
    Int_t treeCounter = 0;
    Int_t histogramCounter = 0;
     // Create the output file
     TFile *outFile = TFile::Open(TargetName,"RECREATE");
     TDirectory *outDir = outFile;
     TDirIter listOfFiles(inputFilesPattern);
     const char *fileName = 0;
     while ( (fileName =  listOfFiles.NextFile() ) ) {
        Int_t currentDirDepth = 0;
        printf(".");
        fileCounter++;
        StFileIter file(fileName);
        TObject *obj = 0;
        while ( (obj = *file) ) {
           Int_t depth = file.GetDepth();
           while (depth < currentDirDepth) {
                outDir = outDir->GetMotherDir();
                currentDirDepth--;
           }
           if ( obj->IsA()->InheritsFrom(TH1::Class()) ) {
              // descendant of TH1 -> merge it
              // printf("Merging histogram: %s\n",obj->GetName() ); 
//              std::cout << "Merging histogram " << obj->GetName() << std::endl;
              TH1 *h1 = (TH1*)obj;
              TH1 *dstHistogram = 0;
              // Check whether we found the new histogram
              if ( (dstHistogram = (TH1 *)outDir->FindObject(h1->GetName()))) {
                 // Accumulate  the  histogram
                  dstHistogram->Add(h1);
                  delete h1;  // Optional, to reduce the memory consumption
                  printf("h");
              } else {
                // First time - move the histogram
                h1->SetDirectory(outDir);
                printf(" The new Histogram found: %s \n", h1->GetName() );
                histogramCounter++;
              }
           } else  if ( obj->IsA()->InheritsFrom(TTree::Class()) ) {
              // descendant of TTree  -> merge it
              // printf("Merging Tree %p:%s\n",obj, obj->GetName() ); 
              TTree *tree = (TTree*)obj;
              TTree *dstTree = 0;
              // Check whether we found the new histogram
              if ( (dstTree = (TTree *)outDir->FindObject(tree->GetName()))) {
                   // printf("Merging %p:%s with the existing Tree %p:%s\n"
                   //       ,tree,tree->GetName(),dstTree, dstTree->GetName() ); 
                  // Merge  the  tree
                  TList *nextTree = new TList(); nextTree->Add(tree); 
                  dstTree->Merge(nextTree);
                  delete tree;  // Optional, to reduce the memory consumption
                  delete nextTree;
                  printf("t");
              } else {
                // First time - move the TTree
                TDirectory *saveDir = 0;
                if (outDir != gDirectory) {
                   saveDir = gDirectory;
                   outDir->cd();
                }
                TList *nextTree = new TList(); nextTree->Add(tree);               
                dstTree = TTree::MergeTrees(nextTree);
                if (saveDir) saveDir->cd();
                // printf(" The new TTree found: %p:%s \n",tree, tree->GetName() );
                // printf(" Create the destination Tree %p:%s\n\n",dstTree, dstTree->GetName() );
                delete tree;  // Optional, to reduce the memory consumption
                delete nextTree;
                treeCounter++;
              }
           } else if ( obj->IsA()->InheritsFrom(TDirectory::Class()) ) {
               printf("The input sub-TDirectory object: %s depth=%d\n",obj->GetName(), depth); 
               TDirectory *d =  (TDirectory *)outDir->FindObject(obj->GetName());
               if (!d) {
                  d = outDir->mkdir(obj->GetName());
                  dirCounter++;
                  printf("The new TDirectory object: %s depth=%d\n",d->GetPathStatic(), depth); 
               }
               if (d) {
                  outDir = d;                  
                  printf("The output sub-TDirectory object: %s depth=%d\n",outDir->GetPathStatic(), depth); 

               }
           } else {
              printf("I have no idea how to merge the %s objects of the %s class. Skipping .... \n",obj->GetName(), obj->ClassName() ); 
           }
           ++file;
        }
              
     }
     printf("\n Finishing  . . . \n");
     outFile->Write();  // this creates a second copy of the TTree ???
     outFile->Close();     
     delete outFile;
//.........这里部分代码省略.........
开发者ID:kalanand,项目名称:UserCode,代码行数:101,代码来源:MergeHistogramFile.C

示例15: getResVsub

void getResVsub(){
	string SumorProd = getenv("SUMORPROD");

//------------------------Deal with the number and get the output stored in txt files and root files
	double Vmax[nbin], eps[nbin];
	string dir = getenv("DIR");
	for(int ibin=0; ibin<nbin ;ibin++){
        	Vmax[ibin]=0.065*(trkbin[ibin]+30);
        	eps[ibin]=0.00025*(trkbin[ibin]+30);
	}
	ofstream  fstrV;
	double theta[ntheta];
	TVectorD Nevent[nbin], totmultall[nbin];
	TVectorD avgmult[nbin], avgpt[nbin], totmult[nbin], totpt[nbin];
	TVectorD Qx1[nbin], Qy1[nbin], Q2[nbin];
	TVectorD Gmod2[nbin][nptV][ntheta];
	TVectorD sigma2[nbin][nptV],deltaV[nbin][nptV];
	TVectorD sigma2_[nbin],chi_[nbin];
	TVectorD deltaVmean[nbin], Vmean[nbin];
	TVectorD Vmeanmean, deltaVmeanmean, sigmaVmeanmean;
	TVectorD r[nbin];
	TVectorD r0[nbin][nptV], r01[nbin][nptV], V[nbin][nptV], chi[nbin][nptV];
	TVectorD GRe[nbin][nptV][ntheta]; TVectorD* GRe_t[nbin][nptV][ntheta];
	TVectorD GIm[nbin][nptV][ntheta]; TVectorD* GIm_t[nbin][nptV][ntheta];
	TVectorD IFILE[nbin];
	TComplex G[nbin][nptV][ntheta][nstepr];
	if(SumorProd=="Sum")	fstrV.open("V_Sum_sub.txt");
	else	fstrV.open("V_Prod_sub.txt");
	if(SumorProd=="Sum")       TString outname = "mergedV_Sum_sub.root";
        else    TString outname="mergedV_Prod_sub.root";
      	TFile *outf = new TFile(outname,"Recreate");
	TFile *f[nFileAll];
	TVectorD Nevent_;	Nevent_.ResizeTo(nbin);  Nevent_.Zero();

	Vmeanmean.ResizeTo(nbin);  Vmeanmean.Zero();
	deltaVmeanmean.ResizeTo(nbin);  deltaVmeanmean.Zero();
	sigmaVmeanmean.ResizeTo(nbin);  sigmaVmeanmean.Zero();
 
	for(int ibin=0; ibin<nbin; ibin++){
		r[ibin].ResizeTo(nstepr);
                for(int ir=0; ir<nstepr; ir++){
        if(isSimple==0)  r[ibin][ir]=j01/(Vmax[ibin]-eps[ibin]*ir);	
	else		 r[ibin][ir]=0.00025*20*(ir+1);
		}
         
	for(int ifile=0; ifile<nFileAll; ifile++){
	if(SumorProd=="Sum") f[ifile] = TFile::Open(Form("/scratch/xuq7/flow/pbsjoboutput/tracknormcpt03to6/%s/AnaV_Sum_%d.root",dir.c_str(),ifile));
        else f[ifile] = TFile::Open(Form("/scratch/xuq7/flow/pbsjoboutput/tracknormcpt03to6/%s/AnaV_Prod_%d.root",dir.c_str(),ifile));
        TVectorD* Nevent_t =  (TVectorD*)f[ifile]->Get(Form("Nevent"));
	Nevent_[ibin]+=(*Nevent_t)[ibin];
	f[ifile]->Close();
	}
      
	IFILE[ibin].ResizeTo(nsamples);
	Nevent[ibin].ResizeTo(nsamples);  Nevent[ibin].Zero();
	totmultall[ibin].ResizeTo(nsamples);      totmultall[ibin].Zero();
        TDirectory *dir0 = outf->mkdir(Form("D_%d",ibin));

	for(int isample=0;isample<nsamples;isample++){
		TVectorD Nevent0;	Nevent0.ResizeTo(nbin);  Nevent0.Zero();
	
	for(int itheta=0;itheta<ntheta;itheta++)
        	theta[itheta]=itheta*TMath::Pi()/ntheta/nn;

		for(int iptbin=0;iptbin<nptV;iptbin++){
			r0[ibin][iptbin].ResizeTo(ntheta);
			r01[ibin][iptbin].ResizeTo(ntheta);
			sigma2[ibin][iptbin].ResizeTo(ntheta);
			V[ibin][iptbin].ResizeTo(ntheta);
			deltaV[ibin][iptbin].ResizeTo(ntheta);
			chi[ibin][iptbin].ResizeTo(ntheta);
                        for(int itheta=0;itheta<ntheta;itheta++){
				Gmod2[ibin][iptbin][itheta].ResizeTo(nstepr);
				GRe[ibin][iptbin][itheta].ResizeTo(nstepr);
				GRe[ibin][iptbin][itheta].Zero();
				GIm[ibin][iptbin][itheta].ResizeTo(nstepr);
				GIm[ibin][iptbin][itheta].Zero();
			}
		}

		avgmult[ibin].ResizeTo(nptV);	deltaVmean[ibin].ResizeTo(nptV);	Vmean[ibin].ResizeTo(nptV);
		deltaVmean[ibin].Zero();	Vmean[ibin].Zero();
		Vmean[ibin].Zero();	deltaVmean[ibin].Zero();
		totpt[ibin].ResizeTo(nptV);	totpt[ibin].Zero();
		totmult[ibin].ResizeTo(nptV);	totmult[ibin].Zero();
		avgpt[ibin].ResizeTo(nptV);
                Qx1[ibin].ResizeTo(nptV);     Qx1[ibin].Zero();
                Qy1[ibin].ResizeTo(nptV);     Qy1[ibin].Zero();
                Q2[ibin].ResizeTo(nptV);     Q2[ibin].Zero();
		sigma2_[ibin].ResizeTo(nptV);sigma2_[ibin].Zero();
		chi_[ibin].ResizeTo(nptV);chi_[ibin].Zero();

	for(int ifile=0; ifile<nFileAll; ifile++){
		if(SumorProd=="Sum") f[ifile] = TFile::Open(Form("/scratch/xuq7/flow/pbsjoboutput/tracknormcpt03to6/%s/AnaV_Sum_%d.root",dir.c_str(),ifile));
		else f[ifile] = TFile::Open(Form("/scratch/xuq7/flow/pbsjoboutput/tracknormcpt03to6/%s/AnaV_Prod_%d.root",dir.c_str(),ifile));
		TVectorD* Nevent_t =  (TVectorD*)f[ifile]->Get(Form("Nevent"));
		TVectorD* totmultall_t =  (TVectorD*)f[ifile]->Get(Form("totmultall"));
		Nevent0[ibin] += (*Nevent_t)[ibin];
		double start=isample*Nevent_[ibin]/nsamples;
		double end=(isample+1)*Nevent_[ibin]/nsamples;
//.........这里部分代码省略.........
开发者ID:XuQiao,项目名称:HI,代码行数:101,代码来源:getResVsub.C


注:本文中的TDirectory::mkdir方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。