8 # Check arguments and print help function if needed
10 print "Usage: $0 PANDADEF SOURCE SOURCE ... OUTPUTHEAD\n\n";
11 print "PANDADEF Must be a PandaTree def file\n";
12 print "SOURCE Source file(s) that you would like to analyze\n";
13 print "OUTPUTHEAD Place where you would like to put the output header\n";
14 return "\nYou did something wrong with arguments\n";
16 # Check presence of arguments
17 my $out_file = pop @ARGV or die print_use;
22 # Check that each source file exists
23 foreach my $fname (@ARGV) {
25 print "File $fname does not exist!\n\n";
30 # Check first line of header
32 open (my $handle, '<', $out_file);
33 chomp (my $first = <$handle>);
35 if ($first ne '#ifndef CROMBIE_FEEDPANDA_H') {
36 print "First line of $out_file looks suspicious! I don't want to overwrite:\n";
42 # Location of Panda definitions
43 my $def_file = shift @ARGV;
45 my @branches = ('triggers');
51 open(my $handle, '<', shift);
53 if (/#include .([\w\/]+\.h)/) {
54 if (-f "${include_dir}/$1") {
55 if (1 < ($read_files{$1} += 1)) {
58 push @output, open_src("${include_dir}/$1");
75 push @source, open_src($_);
78 # Filter to get the members called
79 chomp(@source = grep { /\.|(->)|(::)/ } @source);
82 # Don't match with function members of event
83 while (/\be(vent)?(\.|->)(\w+)(?!\w*\()/g) {
87 while (/\&panda::Event::(\w+)/g) {
94 return sort(grep {! $seen{$_}++ } @_);
97 # Get unique branches from first pass
98 @branches = uniq_sort @branches;
100 # Now check def file for references to load
101 open (my $handle, '<', $def_file);
102 chomp (my @pandadef = grep { /->/ } <$handle>);
106 while (@last_branches != @branches) {
107 @last_branches = uniq_sort @branches;
109 foreach my $branch (@branches) {
110 foreach my $line (@pandadef) {
111 if ($line =~ /$branch\.(\w+)->(\w+)/) {
112 push @{$poss_refs{$1}}, $2;
116 foreach my $key (keys %poss_refs) {
117 @{$poss_refs{$key}} = uniq_sort @{$poss_refs{$key}};
118 my @new_branches = grep { /(\.|->)$key/ } @source;
120 push @branches, @{$poss_refs{$key}};
123 @branches = uniq_sort @branches;
126 # Now we have our branches. Time to write a header file!
127 open (my $out, '>', $out_file);
130 #ifndef CROMBIE_FEEDPANDA_H
131 #define CROMBIE_FEEDPANDA_H 1
135 #include "PandaTree/Objects/interface/Event.h"
138 void feedpanda(panda::Event& event, TTree* input) {
139 event.setStatus(*input, {"!*"});
140 event.setAddress(*input,
143 print $out ' {"' . join("\",\n \"", @branches) . '"';