| The Gaudi Framework v32r1 (f65d50dc)

extractEvt.cpp
Go to the documentation of this file.
1 #include "merge/extractEvt.C"
2 #include <cstdlib>
3 #include <stdexcept>
4
5 static int usage() {
6 ::printf( "Gaudi event extraction facility for ROOT tree based files.\n"
7 " Usage: \n"
8 "extract_event -o <output-file> -i <input-file> ...]\n\n"
9 "input- and output files may specify any legal (ROOT) file name.\n"
10 " -output Specify output file name.\n"
11 " -input Specify input file name.\n"
12 " -event Specify the event entry number.\n" );
13 return 1;
14 }
15
16 int main( int argc, char** argv ) {
17 string input;
18 string output;
19 int evt_num = -1;
20 for ( int i = 1; i < argc; ++i ) {
21 if ( *argv[i] == '-' ) {
22 switch ( ::toupper( *( argv[i] + 1 ) ) ) {
23 case 'E':
24 if ( 1 != ::sscanf( argv[i + 1], "%d", &evt_num ) ) {
25 ::printf( "\nERROR: No valid event identifier given.\n\n" );
26 return usage();
27 }
28 ++i;
29 break;
30 case 'O':
31 if ( i + 1 < argc ) output = argv[i + 1];
32 ++i;
33 break;
34 case 'I':
35 if ( i + 1 < argc ) input = argv[i + 1];
36 ++i;
37 break;
38 default:
39 return usage();
40 }
41 }
42 }
43 if ( input.empty() ) {
44 ::printf( "\nERROR: No input file(s) supplied\n\n" );
45 return usage();
46 } else if ( output.empty() ) {
47 ::printf( "\nERROR: No output file supplied.\n\n" );
48 return usage();
49 } else if ( evt_num < 0 ) {
50 ::printf( "\nERROR: No valid event identifier given.\n\n" );
51 return usage();
52 }
53 gROOT->SetBatch( kTRUE );
54 try {
55 if ( extract_event( input.c_str(), output.c_str(), evt_num ) != EXTRACT_SUCCESS ) {
56 ::printf( "\nERROR: Event extraction from file %s failed.\n", input.c_str() );
57 return 1;
58 }
59 return 0;
60 } catch ( const std::exception& e ) {
61 ::printf( "\nERROR: Event extraction from file %s failed [%s]\n", input.c_str(), e.what() );
62 } catch ( ... ) { ::printf( "\nERROR: Event extraction from file %s failed [unknown reason]\n", input.c_str() ); }
63 return 1;
64 }
std::string::empty
T empty(T... args)
std::sscanf
T sscanf(T... args)
extractEvt.C
gaudirun.output
output
Definition: gaudirun.py:484
gaudirun.argv
list argv
Definition: gaudirun.py:298
usage
void usage(std::string argv0)
Definition: listcomponents.cpp:41
std::exception::what
T what(T... args)
std::exception
STL class.
plotBacklogPyRoot.argc
argc
Definition: plotBacklogPyRoot.py:142
extract_event
int extract_event(const char *input, const char *output, long num_evt)
Definition: extractEvt.C:374
main
int main(int argc, char **argv)
Definition: extractEvt.cpp:16
std::string::c_str
T c_str(T... args)
toupper
void toupper(std::string &s)
Definition: StatusCodeSvc.cpp:7