ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/FGolf/Tools/makeChain.cc
Revision: 1.1
Committed: Fri Jan 6 21:24:12 2012 UTC (13 years, 4 months ago) by fgolf
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Error occurred while calculating annotation data.
Log Message:
expand wildcards to add files to a TChain

File Contents

# Content
1 #include "makeChain.h"
2
3 #include <stdio.h>
4 #include <string>
5
6 TChain *makeChain (const char *glob, const char *treename, TChain *chain_in, bool verbose)
7 {
8 std::string cmd = "ls ";
9 cmd += glob;
10 FILE *f = popen(cmd.c_str(), "r");
11 if (!f) {
12 perror("Opening pipe");
13 return 0;
14 }
15 TChain *c = chain_in == 0 ? new TChain(treename) : chain_in;
16 int s;
17 do {
18 char fname[1024];
19 s = fscanf(f, " %1024s\n", fname);
20 if (s != 1) {
21 if (s != EOF)
22 perror("scanning file list");
23 } else {
24 if (verbose)
25 printf("Adding %s\n", fname);
26 c->Add(fname);
27 }
28 } while (s == 1);
29 if (pclose(f) == -1)
30 perror("Closing pipe");
31 return c;
32 }
33
34 TChain *makeChain_command (const char *cmd, const char *treename, bool verbose)
35 {
36 FILE *f = popen(cmd, "r");
37 if (!f) {
38 perror("Opening pipe");
39 return 0;
40 }
41 TChain *c = new TChain(treename);
42 int s;
43 do {
44 char fname[1024];
45 s = fscanf(f, " %1024s\n", fname);
46 if (s != 1) {
47 if (s != EOF)
48 perror("scanning file list");
49 } else {
50 if (verbose)
51 printf("Adding %s\n", fname);
52 c->Add(fname);
53 }
54 } while (s == 1);
55 if (pclose(f) == -1)
56 perror("Closing pipe");
57 return c;
58 }
59