1

我有一个用于数据分析软件 Root (CERN) 的相当大的代码,并且我有一系列数据,我想查看这些数据是否存在不良运行。我将它们全部放在一个目录中,但是想编写一段代码以一次从该文件夹中取出一个文件,运行代码,输出结果图,然后取出下一个文件..等等。我正在使用宏来像现在一样运行此代码。我希望只是为那个宏添加一些东西。我对编程有点陌生。

gSystem->Load("AlgoCompSelector_C.so");
// make the chains
std::string filekey;
TChain tree1 = new TChain("tree");
filekey = std::string("data/run715604.EEmcTree_Part1.root");
tree1->Add( filekey.data() );
4

1 回答 1

1

要在单个根宏中执行此操作,您可以尝试以下代码片段。在这里,我将文件添加到 TChain,但您当然可以TChain::Add用您想要的任何内容替换。

int addfiles(TChain *ch, const char *dirname=".", const char *ext=".root")
{
   int added = 0;
   TSystemDirectory dir(dirname, dirname);
   TList *files = dir.GetListOfFiles();
   if (files) {
      TSystemFile *file;
      TString fname;
      TIter next(files);
      while ((file=(TSystemFile*)next())) {
         fname = file->GetName();
         if (!file->IsDirectory() && fname.EndsWith(ext)) {
         ch->Add(fname); // or call your function on this one file
         ++added;
         }
     }
   }
   return added;
}

(改编自这篇root-talk帖子:http ://root.cern.ch/phpBB3/viewtopic.php?f=3&t=13666 )

话虽如此,我认为@m0skit0 每次启动一个较小的脚本的建议比执行您上面建议的操作更好。Root 是挑剔的,拥有较小的工作更好。

于 2012-07-17T19:30:10.500 回答