Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
hd_dump.cc
Go to the documentation of this file.
1 // Author: David Lawrence June 25, 2004
2 //
3 //
4 // hd_ana.cc
5 //
6 
7 #include <iostream>
8 using namespace std;
9 
10 #include <termios.h>
11 
12 #include "MyProcessor.h"
13 #include "DANA/DApplication.h"
14 
16 void ParseCommandLineArguments(int &narg, char *argv[]);
17 void Usage(void);
18 
19 bool LIST_FACTORIES = false;
20 bool SPARSIFY_SUMMARY = true;
22 
23 //-----------
24 // main
25 //-----------
26 int main(int narg, char *argv[])
27 {
28  // Parse the command line
29  ParseCommandLineArguments(narg, argv);
30 
31  // Instantiate our event processor
33 
34  // Instantiate an event loop object
35  DApplication *app = new DApplication(narg, argv);
36 
37  // Set tag prefix for JANA streams to empty
38  jout.SetTag("");
39 
40  // If LIST_FACTORIES is set, print all factories and exit
41  if(LIST_FACTORIES){
42  PrintFactoryList(app);
43  return 0;
44  }
45 
46  // This monkeyshines is needed to get getchar() to return single
47  // characters without waiting for the user to hit return
48  struct termios t;
49  tcgetattr(fileno(stdin), &t);
50  t.c_lflag &= (~ICANON);
51  //t.c_cc[VMIN] = 1;
52  tcsetattr(fileno(stdin), TCSANOW, &t);
53 
54  // If only DEPICSvalue is specified to print, then automatically
55  // turn on sparsified reading unless user specifically requests
56  // that we don't.
57  if(toprint.size()==1 && ALLOW_SPARSIFIED_EVIO){
58  if( toprint.find("EPICSvalue") != toprint.end() ){
59  cout << endl;
60  cout << "-- Only DEPICSvalue objects requested" << endl;
61  cout << "-- * Enabling EVIO file mapping and sparse readout" << endl;
62  cout << "-- * Automatically invoking -f and -s options" << endl;
63  cout << endl;
64  gPARMS->SetParameter("EVIO:SPARSE_READ", true);
65  gPARMS->SetParameter("EVIO:EVENT_MASK", string("EPICS"));
66  PRINT_SUMMARY_HEADER = false;
68  }
69  }
70 
71  // Run though all events, calling our event processor's methods
72  app->SetShowTicker(0);
73  app->monitor_heartbeat = false;
74  app->Run(&myproc);
75 
76  delete app;
77 
78  return 0;
79 }
80 
81 //-----------
82 // PrintFactoryList
83 //-----------
85 {
86  // When we get here, the Run() method hasn't been
87  // called so the JEventLoop objects haven't
88  // been created yet and cansequently the factory objects
89  // don't yet exist. Since we want the "list factories"
90  // option to work even without an input file, we need
91  // to first make the factories before we can list them.
92  // To do this we only need to instantiate a JEventLoop object
93  // passing it our "app" pointer. The JEventLoop will automatically
94  // register itself with the DApplication and the factories
95  // will be made, even ones from plugins passed on the command
96  // line.
97  app->Init();
98  JEventLoop *loop = new JEventLoop(app);
99 
100  // Print header
101  cout<<endl;
102  cout<<" Factory List"<<endl;
103  cout<<"-------------------------"<<endl;
104 
105  // Get list of factories from the JEventLoop and loop over them
106  // Printing out the data types and tags.
107  vector<JFactory_base*> factories = loop->GetFactories();
108  vector<JFactory_base*>::iterator iter = factories.begin();
109  for(; iter!=factories.end(); iter++){
110  cout<<" "<<(*iter)->GetDataClassName();
111  if(strlen((*iter)->Tag()) !=0){
112  cout<<" : "<<(*iter)->Tag();
113  }
114  cout<<endl;
115  }
116  cout<<endl;
117  cout<<" "<<factories.size()<<" factories registered"<<endl;
118  cout<<endl;
119 }
120 
121 //-----------
122 // ParseCommandLineArguments
123 //-----------
124 void ParseCommandLineArguments(int &narg, char *argv[])
125 {
126  if(narg==1)Usage();
127 
128  for(int i=1;i<narg;i++){
129  if(argv[i][0] != '-')continue;
130  switch(argv[i][1]){
131  case 'h':
132  Usage();
133  break;
134  case 'D':
135  toprint.insert(&argv[i][2]);
136  break;
137  case 'p':
138  PAUSE_BETWEEN_EVENTS = false;
139  break;
140  case 's':
141  SKIP_BORING_EVENTS = true;
142  break;
143  case 'A':
144  PRINT_ALL = true;
145  break;
146  case 'c':
147  PRINT_CORE = true;
148  PRINT_SUMMARY_HEADER = true;
149  break;
150  case 'L':
151  LIST_FACTORIES = true;
152  break;
153  case 'a':
155  break;
156  case 'S':
157  SPARSIFY_SUMMARY = false;
158  break;
159  case 'f':
160  cout << "WARNING: -f option is deprecated as it is now the default" << endl;
161  break;
162  case 'V':
163  PRINT_SUMMARY_ALL = true;
164  PRINT_SUMMARY_HEADER = true;
165  break;
166  case 'b':
167  PRINT_STATUS_BITS = true;
168  break;
169  case 'e':
170  ALLOW_SPARSIFIED_EVIO = false;
171  break;
172  }
173  }
174 
175  if(toprint.empty() && !PRINT_ALL ){
176  PRINT_CORE = true;
177  PRINT_SUMMARY_HEADER = true;
178  }
179 }
180 
181 //-----------
182 // Usage
183 //-----------
184 void Usage(void)
185 {
186  DApplication dapp(0,NULL);
187 
188  cout<<"Usage:"<<endl;
189  cout<<" hd_dump [options] source1 source2 ..."<<endl;
190  cout<<endl;
191  cout<<"Print the contents of a Hall-D data source (e.g. a file)"<<endl;
192  cout<<"to the screen."<<endl;
193  cout<<endl;
194  cout<<"Options:"<<endl;
195  cout<<endl;
196  cout<<" -h Print this message"<<endl;
197  cout<<" -Dname Print the data of type \"name\" (can be used multiple times)"<<endl;
198  cout<<" -A Print ALL data types (overrides and -DXXX options)"<<endl;
199  cout<<" -L List available factories and exit"<<endl;
200  cout<<" -p Don't pause for keystroke between events (def. is to pause)"<<endl;
201  cout<<" -s Skip events which don't have any of the specified data types"<<endl;
202  cout<<" -a List types and number of associated objects"<<endl;
203  cout<<" -S Don't supress printing of factories with no objects in summary"<<endl;
204  cout<<" -c Print summary header lisiting for select factories."<<endl;
205  cout<<" -V Print summary header lisiting for all factories."<<endl;
206  cout<<" (warning: this activates every single factory!)"<<endl;
207  cout<<" -b Print event status bits"<<endl;
208  cout<<" -e Don't allow automatic EVIO sparse readout for EPICS data"<<endl;
209  cout<<endl;
210 
211  dapp.Usage();
212 
213  exit(0);
214 }
215 
216 
DApplication * dapp
bool LIST_ASSOCIATED_OBJECTS
bool SPARSIFY_SUMMARY
Definition: hd_dump.cc:20
bool SKIP_BORING_EVENTS
bool PRINT_SUMMARY_HEADER
bool PAUSE_BETWEEN_EVENTS
void ParseCommandLineArguments(int &narg, char *argv[])
Definition: hd_dump.cc:124
MyProcessor * myproc
Definition: hdview2.cc:17
bool PRINT_SUMMARY_ALL
jerror_t Init(void)
set< string > toprint
bool ALLOW_SPARSIFIED_EVIO
Definition: hd_dump.cc:21
void PrintFactoryList(DApplication *app)
Definition: hd_dump.cc:84
bool PRINT_CORE
bool PRINT_STATUS_BITS
bool LIST_FACTORIES
Definition: hd_dump.cc:19
bool PRINT_ALL
void Usage(JApplication &app)
Definition: hd_ana.cc:33
int main(int argc, char *argv[])
Definition: gendoc.cc:6