独立读取多堆文件
Reading multipile files independently
我有一个相当大的数据分析软件根(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() );
要在单个根宏中执行此操作,您可以尝试类似于下面的代码片段。 在这里,我将文件添加到 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;
}
(改编自这篇根话帖子:http://root.cern.ch/phpBB3/viewtopic.php?f=3&t=13666)
话虽如此,我认为@m0skit0每次都启动一个较小的脚本的建议比执行您上面建议的操作更好。根是挑剔的,工作越小越好。
相关文章:
- 正在将csv文件读取为双精度矢量
- 将从格式化文本文件读取的文本数据存储到链表
- C++ 读取文件读取文件不正确
- 使用对象文件读取三角形数据网格
- 如何减慢从 BVH 文件读取的 opengl 动画?
- 从文件读取,并写入函数C++中的数组
- 从对象C++中的文件读取内容时出现分段错误
- 从文件读取并通过矢量输出到控制台
- 尝试将字符串从文件读取到无符号字符向量中
- 如何将文本文件读取到二维数组中并以 c++ 打印
- 简化文件读取的函数
- 如何将逗号分隔的文件读取为 2D int 数组?
- 在 c++ 中将数据从文件读取到队列中
- 'std::wstring_convert'尽可能多地转换(从 UTF8 文件读取块)
- C++,从文件读取到结构,然后读取到向量(结构被推入向量太多次,而不仅仅是一次)
- 文件读取C++包括空格键
- 从文件读取时未将值推回矢量
- 从文件 C++ 读取时的无限循环
- 从同一文件读取和写入?
- 从.txt文件读取到C++中的双精度向量