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


C++ TString::CountChar方法代码示例

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


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

示例1: MakeLabel

Label MakeLabel(TString str)
{
    if (str.CountChar(';') != 2)
        std::cout << "ERROR: Must contain 2 ';': " << str << std::endl;
    str.ReplaceAll(";;", "; ;");
    TStringToken token(str, ";");
    TString labeltype;
    Label label;

    if(token.NextToken())  label.xlabel = token;
    if(token.NextToken())  label.unit = token;
    if(token.NextToken())  labeltype = token;
    
    if (label.unit == " ")
        label.unit = "";
    if (labeltype != "F" && labeltype != "I")
        std::cout << "ERROR: Must be either 'F' or 'I': " << labeltype << std::endl;
    else
        label.type = (labeltype == "F") ? 'F' : 'I';
    
    return label;
}
开发者ID:degrutto,项目名称:VHbbUF,代码行数:22,代码来源:TrainRegressionFJ.C

示例2: GeomDraw

//_____________________________________________________________________________________________________________
void GeomDraw(const char *fzFile="complete",Float_t bombFactor=1.4, const char *out = "")
{
   // Read the ZEBRA file with GEANT geometry
   // Convert it to TVolume format 
   // draw it out with OpenGL Viewer
  TString geomAccess = fzFile;
  TString geomKuipCmd;
  if (gSystem->AccessPathName(geomAccess.Data()) ) 
  {
     // Check 
     geomAccess.Strip(TString::kBoth);
     if (!geomAccess.CountChar(' ') && (geomAccess.First('y')==0 || geomAccess.First("complete") == 0 ) ) {
       geomKuipCmd = "detp geometry ";
       geomKuipCmd += geomAccess; geomAccess = "" ;
     } else {
          printf("\n *** Error ***   Wrong input parameter: <%s>\n", fzFile);
          GeomDrawUsage();
          return;              
     }
   }
   
  // Workaroung of STAR bug with ROOT 4.00.04
  //- TString unixLDPath = "$ROOT/$ROOT_LEVEL.qt/.$STAR_HOST_SYS/rootdeb/lib:";
  //-  unixLDPath += gEnv->GetValue("Root.DynamicPath","");
  //- gEnv->SetValue("Root.DynamicPath",unixLDPath.Data());
  //- gSystem->Load("$ROOT/$ROOT_LEVEL.qt/.$STAR_HOST_SYS/rootdeb/lib/libRQTGL.so");
  //- end of workaroung
  
  gSystem->Load("St_base");
  gSystem->Load("StChain");
  gSystem->Load("St_Tables");
  gSystem->Load("St_g2t.so");
  gSystem->Load("StarMagField");
  gSystem->Load("St_geant_Maker");  
  gSystem->Load("StUtilities");
  chain = new StChain(); 
  geant = new St_geant_Maker();
  geant->SetActive(kFALSE);
  if (! geomAccess.IsNull() ) {
     printf("\n ----------------------------------------------------------\n");
     printf(" Draw the GEANT geometry from <%s> file\n", geomAccess.Data());
     printf(" ----------------------------------------------------------\n\n");
     geant->SetInputFile(geomAccess.Data());
  } else {
     printf("\n ----------------------------------------------------------\n");
     printf(" Draw the GEANT generated geometry <%s> \n", geomKuipCmd.Data());
     printf(" ----------------------------------------------------------\n\n");
     gSystem->Load("geometry");
     geant->LoadGeometry(geomKuipCmd.Data());            
  }
  chain->Init();
  TVolume *v = (TVolume *)geant->Work();
  if (v) {
     // Make CAVE invisible
     TVolume *cave = (TVolume *)v->FindByName("CAVE");
     if (cave) cave->SetVisibility(2);
     TVolume *hall = (TVolume *)v->FindByName("HALL");
     GeomDrawUsage();
     if (hall) {
        hall->SetVisibility(2);
        new TBrowser("STAR Geometry", hall);
        if (bombFactor < 1)  bombFactor = 1.;
        gGeometry->SetBomb(bombFactor);        
        hall->Draw("6");        
        gPad->SetFillColor(kBlack);
    }
    gPad->Modified();
    gPad->Update();
    if (out && out[0]) {
       TFile outFile(out,"RECREATE");
       v->Write();
       outFile.Write();
       outFile.Close();      
    }   
  } else {
     fprintf(stderr,"\n\n, ** Error **, No suitable STAR geometry has been found. Abort !!! \n");   
  }
//  delete chain; chain = 0;
}
开发者ID:star-bnl,项目名称:star-macros,代码行数:80,代码来源:GeomDraw.C

示例3: fillHistoFromTreeVar

void fillHistoFromTreeVar(std::string& treedrawspec,
			  int  index,
			  wTH1 *&wth1)
{
  // Sample treedrawspec:
  // mytree:"TDCwinstart[%d]:runnum>>winstrt%d(70,202000,209000)","evtnum==1","prof P"
  //
  vector<string> v_tokens;
  string tid;
  TString drawspec;
  Tokenize(treedrawspec,v_tokens,":",true);
  if( (v_tokens.size() < 2) ||
      (!v_tokens[0].size())  ||
      (!v_tokens[2].size())    ) {
    cerr << "malformed root tree draw spec treeid:\"varexp\",\"selection\",option: " << treedrawspec << endl;
    return;
  }

  tid = v_tokens[0];
  for (size_t i=2; i<v_tokens.size(); i++) {
    drawspec += v_tokens[i];
  }
  int fmtcnt = drawspec.CountChar('%');

  if (fmtcnt) { // use index for tree array var
    switch(fmtcnt) {
    case 1: drawspec = Form(drawspec,index); break;
    case 2: drawspec = Form(drawspec,index,index); break;
    case 3: drawspec = Form(drawspec,index,index,index); break;
    case 4: drawspec = Form(drawspec,index,index,index,index); break;
    case 5: drawspec = Form(drawspec,index,index,index,index,index); break;
    case 6: drawspec = Form(drawspec,index,index,index,index,index,index); break;
    default:
      cerr << "More than six fmt specifiers in drawspec found, fix me! " << drawspec <<endl;
      exit(-1);
    }
  }
  if( gl_verbose)
    cout<<"drawspec="<<drawspec<<endl;

  TTree *tree = findTree(tid);
  assert (tree);

  // can't use comma as delimiter since histo with binning spec may be supplied
  TObjArray *tokens = drawspec.Tokenize("\"");
  TString hname;

  TString varexp = ((TObjString *)(*tokens)[0])->GetString();

  if (varexp.Contains(">>")) {
    TObjArray *rematches = TPRegexp(">>(\\w+)").MatchS(varexp); // get histo name
    assert(rematches->GetEntriesFast() ==2);
    hname = ((TObjString *)(*rematches)[1])->GetString();

    if (wth1 && !hname.EqualTo(wth1->histo()->GetName())) {
      cerr << "Error: histo name in treedraw spec "<<hname;
      cerr <<" doesn't match named histo "<<wth1->histo()->GetName()<<endl;
      exit(-1);
    }
  } else { // add histo name
    assert (wth1);
    hname = TString(wth1->histo()->GetName());
    varexp = varexp + ">>+" + hname; // append to pre-existing histo
  }

  if( gl_verbose)
    cout<<"varexp="<<varexp<<", hname="<<hname<<endl;
  switch(tokens->GetEntriesFast()) {
  case 1:
    tree->Draw(varexp,"","goff");
    break;
  case 3:
    {
      TString cut = ((TObjString *)(*tokens)[2])->GetString();
      tree->Draw(varexp,cut,"goff"); 
    }
    break;
  case 4: // assume the cut string is blank
    {
      TString gopt = ((TObjString *)(*tokens)[3])->GetString();
      gopt = gopt + " goff";
      tree->Draw(varexp,"",gopt);
    }
    break;
  case 5:
    {
      TString cut  = ((TObjString *)(*tokens)[2])->GetString();
      TString gopt = ((TObjString *)(*tokens)[4])->GetString();
      gopt = gopt + " goff";
      tree->Draw(varexp,cut,gopt);
    }
    break;
  default:
    cerr << "malformed root tree draw spec treeid:varexp,selection,option";
    for (int i=0; i<tokens->GetEntriesFast(); i++)
      cerr << i<<": "<< ((TObjString *)(*tokens)[i])->GetString() << " ";
    cerr << endl;
    break;
  }
  if (!wth1) {
//.........这里部分代码省略.........
开发者ID:kalanand,项目名称:UserCode,代码行数:101,代码来源:spTree.C

示例4: fillGraphFromTreeVar

void fillGraphFromTreeVar(std::string& treedrawspec,int index,wGraph_t *&pwg)
{
  // Sample treedrawspec:
  // mytree:"TDCwinstart[%d]:runnum","evtnum==1","P"
  //
  vector<string> v_tokens;
  string tid;
  TString drawspec;
  Tokenize(treedrawspec,v_tokens,":",true);
  if( (v_tokens.size() < 2) ||
      (!v_tokens[0].size())  ||
      (!v_tokens[2].size())    ) {
    cerr << "malformed root tree draw spec treeid:\"varexp\",\"selection\",option: " << treedrawspec << endl;
    return;
  }

  tid = v_tokens[0];
  for (size_t i=2; i<v_tokens.size(); i++) {
    drawspec += v_tokens[i];
  }
  int fmtcnt = drawspec.CountChar('%');

  if (fmtcnt) { // use index for tree array var
    switch(fmtcnt) {
    case 1: drawspec = Form(drawspec,index); break;
    case 2: drawspec = Form(drawspec,index,index); break;
    case 3: drawspec = Form(drawspec,index,index,index); break;
    case 4: drawspec = Form(drawspec,index,index,index,index); break;
    case 5: drawspec = Form(drawspec,index,index,index,index,index); break;
    case 6: drawspec = Form(drawspec,index,index,index,index,index,index); break;
    default:
      cerr << "More than six fmt specifiers in drawspec found, fix me! " << drawspec <<endl;
      exit(-1);
    }
  }
  if( gl_verbose)
    cout<<"drawspec="<<drawspec<<endl;

  TTree *tree = findTree(tid);
  assert (tree);

  // can't use comma as delimiter since histo with binning spec may be supplied
  TObjArray *tokens = drawspec.Tokenize("\"");
  TString hname;

  TString varexp = ((TObjString *)(*tokens)[0])->GetString();

  if( gl_verbose)
    cout<<"varexp="<<varexp<<endl;
  switch(tokens->GetEntriesFast()) {
  case 1:
    tree->Draw(varexp,"","goff");
    break;
  case 3:
    {
      TString cut = ((TObjString *)(*tokens)[2])->GetString();
      tree->Draw(varexp,cut,"goff"); 
    }
    break;
  case 4: // assume the cut string is blank
    {
      TString gopt = ((TObjString *)(*tokens)[3])->GetString();
      gopt = gopt + " goff";
      tree->Draw(varexp,"",gopt);
    }
    break;
  case 5:
    {
      TString cut  = ((TObjString *)(*tokens)[2])->GetString();
      TString gopt = ((TObjString *)(*tokens)[4])->GetString();
      gopt = gopt + " goff";
      tree->Draw(varexp,cut,gopt);
    }
    break;
  default:
    cerr << "malformed root tree draw spec treeid:varexp,selection,option";
    for (int i=0; i<tokens->GetEntriesFast(); i++)
      cerr << i<<": "<< ((TObjString *)(*tokens)[i])->GetString() << " ";
    cerr << endl;
    break;
  }

  assert(tree->GetSelectedRows());

  if (!pwg)
    pwg = new wGraph_t();

  assert(pwg);
  pwg->gr = new TGraph(tree->GetSelectedRows(),
		       tree->GetV2(), tree->GetV1());

}                                                // fillGraphFromTreeVar
开发者ID:kalanand,项目名称:UserCode,代码行数:92,代码来源:spTree.C


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