Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
hd_root.cc
Go to the documentation of this file.
1 // Author: Edward Brash February 15, 2005
2 //
3 //
4 // hd_root.cc
5 //
6 
7 #include <dlfcn.h>
8 
9 #include <TFile.h>
10 
11 #include "MyProcessor.h"
12 #include "DANA/DApplication.h"
13 using namespace std;
14 
15 typedef void SetTFilePtrAddress_t(TFile **);
16 TFile* tfilePtr = NULL;
17 string OUTPUT_FILENAME = "hd_root.root";
20 
21 void ParseCommandLineArguments(int &narg, char *argv[]);
22 void DecideOutputFilename(void);
23 void Usage(void);
24 
25 
26 //-----------
27 // main
28 //-----------
29 int main(int narg, char *argv[])
30 {
31  // Parse the command line
32  ParseCommandLineArguments(narg, argv);
33 
34  // Instantiate our event processor
36 
37  // Instantiate an event loop object
38  DApplication app(narg, argv);
39 
40  // Decide on the output filename
42 
43  // Run though all events, calling our event processor's methods
44  app.monitor_heartbeat = 0;
45  app.Run(myproc);
46 
47  delete myproc;
48 
49  if( app.GetExitCode() ) cerr << "Exit code: " << app.GetExitCode() << endl;
50  return app.GetExitCode();
51 }
52 
53 
54 //-----------
55 // ParseCommandLineArguments
56 //-----------
57 void ParseCommandLineArguments(int &narg, char *argv[])
58 {
59  if(narg==1)Usage();
60 
61  for(int i=1;i<narg;i++){
62  if(argv[i][0] != '-')continue;
63  switch(argv[i][1]){
64  case 'h':
65  Usage();
66  break;
67  case 'D':
68  toprint.push_back(&argv[i][2]);
69  break;
70  case 'A':
71  ACTIVATE_ALL = 1;
72  case 'o':
73  if(i>=narg-1){
74  cerr<<"\"-o\" requires a filename!"<<endl;
75  exit(-1);
76  }
77  COMMAND_LINE_OUTPUT_FILENAME = argv[i+1];
79 
80  // Remove the "-o fname" arguments from file list so
81  // JANA won't think the "fname" is an input file.
82  for(int j=i; j<(narg-2); j++)argv[j] = argv[j+2];
83  narg -= 2;
84  break;
85  }
86  }
87 }
88 
89 //-----------
90 // DecideOutputFilename
91 //-----------
93 {
94  /// Decide on the output filename to use based on the command line
95  /// input and configuration parameter input. The command line takes
96  /// precedence. This also makes sure to copy the filename that is
97  /// being used into the configuration parameter.
98 
99  // Set the default output filename (avoids later warnings from JANA)
100  gPARMS->SetDefaultParameter("OUTPUT_FILENAME", OUTPUT_FILENAME,"Output filename used by hd_root");
101 
102  // If the user specified an output filename on the command line,
103  // use it to overwrite the config. parameter/default one
106 
107  // Set the actual output filename in config. param.
108  gPARMS->SetParameter("OUTPUT_FILENAME", OUTPUT_FILENAME);
109  }
110 
111  jout<<"OUTPUT_FILENAME: "<<OUTPUT_FILENAME<<endl;
112 
113 }
114 
115 //-----------
116 // Usage
117 //-----------
118 void Usage(void)
119 {
120  // Make sure a JApplication object exists so we can call Usage()
121  JApplication *app = japp;
122  if(app == NULL) app = new DApplication(0, NULL);
123 
124  cout<<"Usage:"<<endl;
125  cout<<" hd_root [options] source1 source2 ..."<<endl;
126  cout<<endl;
127  cout<<"Process events from a Hall-D data source (e.g. a file)"<<endl;
128  cout<<"This will create a ROOT file that plugins or debug histos"<<endl;
129  cout<<"can write into."<<endl;
130  cout<<endl;
131  cout<<"Options:"<<endl;
132  cout<<endl;
133  app->Usage();
134  cout<<endl;
135  cout<<" -h Print this message"<<endl;
136  cout<<" -Dname Activate factory for data of type \"name\" (can be used multiple times)"<<endl;
137  cout<<" -A Activate factories (overrides and -DXXX options)"<<endl;
138  cout<<" -o fname Set output filename (default is \"hd_root.root\")"<<endl;
139  cout<<endl;
140 
141  exit(0);
142 }
bool filename_from_command_line
Definition: hd_root.cc:19
string OUTPUT_FILENAME
Definition: hd_root.cc:17
void DecideOutputFilename(void)
Definition: hd_root.cc:92
JApplication * japp
string COMMAND_LINE_OUTPUT_FILENAME
Definition: hd_root.cc:18
TFile * tfilePtr
Definition: hd_root.cc:16
bool ACTIVATE_ALL
void ParseCommandLineArguments(int &narg, char *argv[])
Definition: hd_dump.cc:124
MyProcessor * myproc
Definition: hdview2.cc:17
void SetTFilePtrAddress_t(TFile **)
Definition: hd_root.cc:15
set< string > toprint
void Usage(JApplication &app)
Definition: hd_ana.cc:33
int main(int argc, char *argv[])
Definition: gendoc.cc:6