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


C++ TObject::Write方法代码示例

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


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

示例1: parseStructure

void parseStructure(TDirectory* td1, TDirectory* td2) {
  string dir_name = td1->GetTitle();
  string dir_path = td1->GetPath();
  //  cout << "ParseStructure: dir_name=" << dir_name << ", dir_path=" << dir_path << endl;
  dir_path = dir_path.substr(dir_path.find("DQMData")+8);
  setPath(dir_path, td2);
  TIter next(td1->GetListOfKeys());
  TKey *key;
  while  ( (key = dynamic_cast<TKey*>(next())) ) 
    {
      string clName(key->GetClassName());
      if (clName == "TDirectoryFile") {
        string name(key->GetName());
        if (name.find("forward_") == string::npos  && 
            name.find("backward_") == string::npos &&
            name.find("ring_") == string::npos) {
	  td1->cd(name.c_str());
	  TDirectory *curr_dir = gDirectory; // dynamic_cast<TDirectory*>(obj);
	  parseStructure(curr_dir, td2);
        } else return;
      } else if (clName == "TObjString") {
	//	cout << clName << "  " << key->GetName() << endl;
        TObject* obj = key->ReadObj();
        obj->Write();
      } else {
	key->ReadObj();
      }
    }
}
开发者ID:Andrej-CMS,项目名称:cmssw,代码行数:29,代码来源:sistrip_reduce_file.C

示例2: Terminate

void rdphi::Terminate()
{
//cout << "total event: " << NevtAll << "rejected: " << rejected_events << endl; 

  TFile *f = new TFile("output.root","RECREATE");

  //Write output Histograms
  TList *tl = GetOutputList();
  int l = tl->GetEntries();
  for ( int i = 0 ; i < l ; i++ )
  {
    TObject *o = tl->At(i);

    if ( o->InheritsFrom("TH1") )
    {
      cout << "TresChorros: Saving Histogram: "
          << "  Class: " << o->ClassName()  
          << "  Name: "<< o->GetName() 
          << "  Title: " << o->GetTitle()
          << " " 
          << endl << flush;
      o->Write();
    }
    }
  f->Flush();
  f->Close();  

}
开发者ID:affablelochan,项目名称:DataAnalysis,代码行数:28,代码来源:rdphi_v1.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: 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

示例5: CopyElement

void CopyElement(char *fTempStr) {
	printf("Copy: %s\n", fTempStr);
	RootFileP->cd();
	TObject *o = gROOT->FindObject(fTempStr);
	if (o) {
		RootFile2->cd();
		o->Write();
	} else {
		printf("Object %s not found.\n", fTempStr);
	}
}
开发者ID:peterotte,项目名称:DataAnalyses,代码行数:11,代码来源:CombineButPMScaled.C

示例6: CopyElement

void CopyElement(char *fTempStr) {
	printf("Copy: %s.\n", fTempStr);
	RootFileHHistograms->cd();
	TObject *o = gROOT->FindObject(fTempStr);
	if (o) {
		RootFileHHistograms_Rescaled->cd();
		o->Write();
	} else {
		printf("Object %s not found.\n", fTempStr);
	}
}
开发者ID:peterotte,项目名称:DataAnalyses,代码行数:11,代码来源:RescaleH.C

示例7: addDir

// helper function to add and weight all plots in the subsamples
void addDir(const std::string& path, const std::vector< std::pair< TFile*, double > >& files, TFile *target, int verbose) 
{
  // loop all objects in the file
  std::vector< std::pair< TFile*, double > >::const_iterator first=files.begin();
  first->first->cd(path.c_str());
  TIter nextkey(gDirectory->GetListOfKeys());
  TKey *key=0;
  while ( (key = (TKey*)nextkey())) {
    // read object from first source file
    first->first->cd(path.c_str());
    TObject *obj = key->ReadObj();
    if ( obj->IsA()->InheritsFrom( "TH1" ) ) {
      // if descendant of TH1 -> mergeit
      TH1 *h1 = (TH1*)obj;
      h1->Sumw2();
      h1->Scale(first->second);
      // loop over all source files and add the content of the
      // corresponding histogram to the one pointed to by "h1"
      for(std::vector< std::pair< TFile*, double > >::const_iterator file=first+1; file!=files.end(); ++file) {
	// make sure we are at the correct directory level by cd'ing to path
	file->first->cd(path.c_str());
	TH1 *h2 = (TH1*)gDirectory->Get( h1->GetName() );
	if ( h2 ) {
	  h2->Sumw2();
	  h1->Add(h2,file->second);
	  delete h2; // don't know if this is necessary, i.e. if
	  // h2 is created by the call to gDirectory above.
	}
      }
    }
    else if (obj->IsA()->InheritsFrom( "TDirectory"  ) ) {
      // for a subdirectory
      if(verbose>1) std::cout << "Found subdirectory " << obj->GetName() << std::endl;
      // create a new subdir of same name and title in the target file
      target->cd();
      TDirectory *newdir = target->mkdir( obj->GetName(), obj->GetTitle() );
      // newdir is now the starting point of another round of merging
      // newdir still knows its depth within the target file via
      // GetPath(), so we can still figure out where we are in the recursion
      addDir(newdir->GetName(),files,target, verbose);
    }
    if ( obj ) {
      target->cd(path.c_str());
      obj->Write( key->GetName() );
    }
    delete obj;
  }
  target->Write();
  delete key;
}
开发者ID:kovalch,项目名称:TopAnalysis,代码行数:51,代码来源:combineMCsamples.C

示例8: WriteMergeObjects

void WriteMergeObjects( TFile *target ) {
  cout << "Writing the merged data." << endl;

  TIterator *nextobj = MergeObjects.MakeIterator();
  TObjString *pathname_obj;
  while( (pathname_obj = (TObjString *)nextobj->Next()) ) {
    TString path,name;
    SplitPathName(pathname_obj->String(),&path,&name);

    TObject *obj = MergeObjects.GetValue(pathname_obj);
    target->cd(path);

    obj->Write( name );

    delete obj;
  }
  MergeObjects.Clear();

  target->Write();

  // Temporarily let multiple root files remain if > 2GB
  // Prevent Target_1.root Target_2.root, ... from happening.
  //  long long max_tree_size = 200000000000LL; // 200 GB
  //  if(TTree::GetMaxTreeSize() < max_tree_size ) {
  //    TTree::SetMaxTreeSize(max_tree_size);
  //  }

  nextobj = MergeChains.MakeIterator();
  TObjString *pathname_obj;
  while( (pathname_obj = (TObjString *)nextobj->Next()) ) {
    TString path,name;
    SplitPathName(pathname_obj->String(),&path,&name);

    TChain *ch = (TChain *)MergeChains.GetValue(pathname_obj);
    target->cd(path);
    ch->Merge(target,0,"KEEP");

    delete ch;

	// in case of multiple objects with same pathname, must remove
	// this one from the list so we don't get the same (deleted)
	// one next time we look up the same name
	MergeChains.Remove(pathname_obj);
  }
  MergeChains.Clear();

  InitializedMergeObjects = false;
}
开发者ID:ekfriis,项目名称:farmout,代码行数:48,代码来源:mergeFiles.C

示例9: mode1

//================================================
void mode1()
{
  TString filename = "Rootfiles/Run14_AuAu200.StudyLumiDep.root";
  TFile *fin = TFile::Open(filename.Data());
  TFile *fout = TFile::Open(Form("%s_filter.root",filename.Data()),"recreate");
  TKey *key;
  TIter nextkey(fin->GetListOfKeys());
  while ((key = (TKey*)nextkey())) 
    {
      TObject *obj = key->ReadObj();   
      if ( obj->IsA()->InheritsFrom( "TH2" ) ) continue;
      obj->Write();
    }
  fout->Close();
  fin->Close();
}
开发者ID:marrbnl,项目名称:STAR,代码行数:17,代码来源:filter.C

示例10: saveHist

void saveHist(const char* filename, const char* pat)
{
  TList* list = gDirectory->GetList() ;
  TIterator* iter = list->MakeIterator();

  TRegexp re(pat,kTRUE) ;

  TFile outf(filename,"RECREATE") ;
  TObject* obj ;
  while((obj=iter->Next())) {    
    if (TString(obj->GetName()).Index(re)>=0) {
      obj->Write() ;
      std::cout << "." ;
    //  cout << setw(9) << counter++ << " : " << obj->GetName() << std::endl ;
    }
  }
  std::cout << std::endl ;
  outf.Close() ;

  delete iter ;
}
开发者ID:SusyRa2b,项目名称:Statistics,代码行数:21,代码来源:histio.c

示例11: createAddress

//-----------------------------------------------------------------------------
/// Convert the transient object to the requested representation.
StatusCode RootHistCnv::RConverter::createRep(DataObject* pObject,
                                              IOpaqueAddress*& pAddr)
//-----------------------------------------------------------------------------
{
  GlobalDirectoryRestore restore;
  pAddr = 0;
  try   {
    TDirectory* pParentDir = changeDirectory(pObject);
    if ( pParentDir )   {
      TObject* pTObj = createPersistent(pObject);
      if ( pTObj )   {
        pTObj->Write();
        delete pTObj;
        return createAddress(pObject, pParentDir, 0, pAddr);
      }
    }
  }
  catch (...)   {
  }
  MsgStream log (msgSvc(), "RConverter");
  log << MSG::ERROR << "Failed to create persistent Object!" << endmsg;
  return StatusCode::FAILURE;
}
开发者ID:atlas-org,项目名称:gaudi,代码行数:25,代码来源:RConverter.cpp

示例12: saveHist

void saveHist(const char* filename, const char* pat)
{

  cout << "\n\n Saving histograms matching " << pat << " in file " << filename << "\n\n" << flush ;

  TList* list = gDirectory->GetList() ;
  TIterator* iter = list->MakeIterator();

  TRegexp re(pat,kTRUE) ;

  TFile outf(filename,"RECREATE") ;
  TObject* obj ;
  while((obj=iter->Next())) {
    if (TString(obj->GetName()).Index(re)>=0) {
      obj->Write() ;
      std::cout << "." ;
    }
  }
  std::cout << std::endl ;
  outf.Close() ;

  delete iter ;
}
开发者ID:SusyRa2b,项目名称:Statistics,代码行数:23,代码来源:qcd_study1.c

示例13: 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

示例14: SavePerfInfo

void SavePerfInfo(const Char_t *filename)
{
   // Save PROOF timing information from TPerfStats to file 'filename' 

   if (!gProof) {
      cout << "PROOF must be run to save output performance information" << endl;
      return;
   }
   
   TFile f(filename, "UPDATE");
   if (f.IsZombie()) {
      cout << "Could not open file " << filename << " for writing" << endl;
   } else {
      f.cd();
      
      TIter NextObject(gProof->GetOutputList());
      TObject* obj = 0;
      while (obj = NextObject()) {
         TString objname = obj->GetName();
         if (objname.Contains(TRegexp("^PROOF_"))) {
            // must list the objects since other PROOF_ objects exist
            // besides timing objects
            if (objname == "PROOF_PerfStats" ||
                objname == "PROOF_PacketsHist" ||
                objname == "PROOF_EventsHist" ||
                objname == "PROOF_NodeHist" ||
                objname == "PROOF_LatencyHist" ||
                objname == "PROOF_ProcTimeHist" ||
                objname == "PROOF_CpuTimeHist")
               obj->Write();
         }
      }

      f.Close();
   }

}
开发者ID:My-Source,项目名称:root,代码行数:37,代码来源:SavePerfInfo.C

示例15: DumpGlobalTrigger


//.........这里部分代码省略.........
	// Setup the raw reader and HLTOUT handler.
	AliRawReader* rawReader = AliRawReader::Create(dataSource);
	if (rawReader == NULL)
	{
		cerr << "ERROR: Could not create raw reader for '" << dataSource << "'." << endl;
		if (file != NULL) delete file;
		return;
	}
	if (! rawReader->IsRawReaderValid())
	{
		cerr << "ERROR: Raw reader is not valid for '" << dataSource << "'." << endl;
		delete rawReader;
		if (file != NULL) delete file;
		return;
	}
	AliHLTOUT* hltout = AliHLTOUT::New(rawReader);
	if (hltout == NULL)
	{
		cerr << "ERROR: Could not create an AliHLTOUT object for '" << dataSource << "'." << endl;
		delete rawReader;
		if (file != NULL) delete file;
		return;
	}
	
	// Make sure that the lastEvent is greater than firstEvent.
	if (lastEvent < firstEvent) lastEvent = rawReader->GetNumberOfEvents();
	if (lastEvent < firstEvent) lastEvent = firstEvent;
	
	// Need to call NextEvent once here or we will start at the wrong event.
	if (! rawReader->NextEvent())
	{
		cout << "No events found in '" << dataSource << "'." << endl;
		AliHLTOUT::Delete(hltout);
		delete rawReader;
		if (file != NULL) delete file;
		return;
	}
	
	// Now step through the events.
	for (int i = 0; i < firstEvent; i++) rawReader->NextEvent();
	for (int i = firstEvent; i <= lastEvent; i++)
	{
		int result = hltout->Init();
		if (result != 0)
		{
			cerr << "ERROR: could not initialise HLTOUT." << endl;
			hltout->Reset();
			continue;
		}
		cout << "#################### Event " << i << " in " << dataSource
			<< " has event ID = " << hltout->EventId()
			<< " (0x" << hex << hltout->EventId() << dec << ")"
			<< " ####################" << endl;
		
		for (result = hltout->SelectFirstDataBlock();
		     result >= 0;
		     result = hltout->SelectNextDataBlock()
		    )
		{
			AliHLTComponentDataType dt;
			AliHLTUInt32_t spec = 0;
			hltout->GetDataBlockDescription(dt, spec);
			TObject* obj = hltout->GetDataObject();
			if (obj == NULL) continue;
			if (obj->IsA()->GetBaseClass("AliHLTGlobalTriggerDecision") != NULL)
			{
				if (dt != kAliHLTDataTypeGlobalTrigger)
				{
					cerr << "WARNING: Found an AliHLTGlobalTriggerDecision object in a data block of type '"
						<< AliHLTComponent::DataType2Text(dt).c_str()
						<< "' but expected '"
						<< AliHLTComponent::DataType2Text(kAliHLTDataTypeGlobalTrigger).c_str()
						<< "'." << endl;
				}
				if (file != NULL)
				{
					obj->Write(
						Form("HLTGlobalDecision_event_0x%llX", hltout->EventId()),
						TObject::kOverwrite
					);
				}
				obj->Print();
			}
			hltout->ReleaseDataObject(obj);
		}
		
		result = hltout->Reset();
		if (result != 0)
		{
			cerr << "ERROR: could not reset HLTOUT." << endl;
			hltout->Reset();
			continue;
		}
		rawReader->NextEvent();
	}
	
	AliHLTOUT::Delete(hltout);
	delete rawReader;
	if (file != NULL) delete file;
}
开发者ID:alisw,项目名称:AliRoot,代码行数:101,代码来源:DumpGlobalTrigger.C


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