/[PAMELA software]/DarthVader/CalorimeterLevel2/src/CalorimeterLevel2.cpp
ViewVC logotype

Contents of /DarthVader/CalorimeterLevel2/src/CalorimeterLevel2.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations) (download)
Wed Sep 6 11:03:32 2006 UTC (18 years, 2 months ago) by mocchiut
Branch: MAIN
CVS Tags: v5r00, v4r00, v2r01, v9r00, v9r01, v3r04, v3r05, v3r06, v3r00, v3r03, v6r01, v6r00, v2r00BETA
Changes since 1.1: +3 -3 lines
Adapted to the new profiler

1 //
2 // L2CAL.cc -- standalone program to call the l2calcore subroutine.
3 // Written by Emiliano Mocchiutti (2005).
4 //
5 // Version 2.00 (2006/03/23)
6 //
7 // Changelog:
8 //
9 // 1.00 - 2.00 (2006/03/23): Input parameters must be now introduced by an identifier (-id run_id -file filename). Order does not matter.
10 // Added verbose/not verbose option.
11 //
12 // 0.00 - 1.00 : working.
13 //
14 //
15 // C/C++ headers
16 //
17 #include <iostream>
18 #include <sstream>
19 //
20 // ROOT headers
21 //
22 #include <TFile.h>
23 #include <TString.h>
24 #include <TSQLServer.h>
25 //
26 // This package headers
27 //
28 #include <CaloCore.h>
29 #include <CaloVerl2.h>
30 //
31 using namespace std;
32 //
33 // Usage subroutine
34 //
35 void usage(){
36 printf("\nUsage:\n");
37 printf("\n CalorimeterLevel2 [-v] [-h] [--version] -idRun ID_RUN [-processFile filename] [-processFolder folder]\n");
38 printf("\n [-host host] [-user username] [-psw password]\n");
39 printf("\n --version print informations about compilation and exit\n");
40 printf("\n -h | --help print this help and exit \n");
41 printf("\n -v | --verbose be verbose [default: print nothing on STDOUT]\n");
42 printf("\n -idRun ID_RUN: ID number of the run to be processed \n");
43 printf("\n -processFile output filename [default ID_RUN.Level2.root]\n");
44 printf("\n -processFolder folder for output data but the processFile [default \"calorimeterFolder\"]\n");
45 printf("\n -host name for the host [default = mysql://localhost/pamelaprod]\n");
46 printf("\n -user username for the DB [default = anonymous] \n");
47 printf("\n -psw password for the DB [default = \"\"]\n");
48 printf("\n Notice that parameter order does not matter. \n");
49 printf("\nExample: \n\nCalorimeterLevel2 -idRun 1085 -processFile nomefile.root\n\n");
50 };
51 //
52 Bool_t debug = false;
53 //
54 // Here the main
55 //
56 int main(int numinp, char *inps[]){
57 //
58 // Variables booking
59 //
60 int nul = 0;
61 Int_t error = 0;
62 TFile *processFile =0;
63 Bool_t beverbose = false;
64 UInt_t run = 0;
65 TString filename;
66 TString processFolder;
67 TString outDir="./";
68 TSQLServer *dbc = 0;
69 Bool_t givenid = false;
70 processFolder = "calorimeterFolder";
71 //
72 TString host = "mysql://localhost/pamelaprod";
73 TString user = "anonymous";
74 TString psw = "";
75 //
76 // Checking input parameters
77 //
78 if ( numinp > 1 ){
79 for ( int i = 0; i < numinp; i++ ){
80 if ( !strcmp(inps[i],"--version") ){
81 CaloInfo(true);
82 exit(0);
83 };
84 if ( !strcmp(inps[i],"-h") || !strcmp(inps[i],"--help") ){
85 usage();
86 exit(0);
87 };
88 if ( !strcmp(inps[i],"-idRun") ) {
89 if ( numinp-1 < i+1 ) {
90 usage();
91 exit(-3);
92 };
93 givenid = true;
94 run = (UInt_t)atoll(inps[i+1]);
95 };
96 if ( !strcmp(inps[i],"-processFile") ) {
97 if ( numinp-1 < i+1 ){
98 usage();
99 exit(-3);
100 };
101 filename = (TString)inps[i+1];
102 };
103 if ( !strcmp(inps[i],"-processFolder") ) {
104 if ( numinp-1 < i+1 ){
105 usage();
106 exit(-3);
107 };
108 processFolder = (TString)inps[i+1];
109 };
110 if ( !strcmp(inps[i],"-host") ) {
111 if ( numinp-1 < i+1 ){
112 usage();
113 exit(-3);
114 };
115 host = (TString)inps[i+1];
116 };
117 if ( !strcmp(inps[i],"-user") ) {
118 if ( numinp-1 < i+1 ){
119 usage();
120 exit(-3);
121 };
122 user = (TString)inps[i+1];
123 };
124 if ( !strcmp(inps[i],"-psw") ) {
125 if ( numinp-1 < i+1 ){
126 usage();
127 exit(-3);
128 };
129 psw = (TString)inps[i+1];
130 };
131 if ( !strcmp(inps[i],"-v") || !strcmp(inps[i],"--verbose") ) beverbose = true;
132 };
133 } else {
134 //
135 // no input parameters exit with error, we need at least the run id.
136 //
137 printf("\n CALORIMETER - ERROR: you must provide a run number (at least 0)\n\n");
138 exit(-1);
139 };
140 //
141 // If not in verbose mode redirect to /dev/null the stdout and stderr
142 //
143 if ( !beverbose ){
144 nul = open("/dev/null", O_CREAT | O_RDWR,S_IREAD | S_IWRITE);
145 dup2(nul,1);
146 dup2(nul,2);
147 };
148 //
149 // Check that an input run number has been given
150 //
151 if ( !givenid ) {
152 printf("\n CALORIMETER - ERROR: you must provide a run number (at least 0)\n\n");
153 exit(-1);
154 };
155 //
156 char *version = CaloInfo(false);
157 //
158 // Start:
159 //
160 printf("\n Welcome to the Calorimeter LEVEL2 flight software, version %s \n",version);
161 //
162 // Connect to the DB
163 //
164 printf("\nConnecting to database... \n");
165 //
166 dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
167 if( !dbc ) {
168 printf(" CALORIMETER - ERROR: problems connecting to the DB (check username and passwd), exiting...\n\n");
169 exit(-2);
170 };
171 bool connect = dbc->IsConnected();
172 //
173 if( !connect ) {
174 printf(" CALORIMETER - ERROR: problems connecting to the DB (check username and passwd), exiting...\n\n");
175 exit(-2);
176 };
177 printf("...connected! \n\n");
178 //
179 if ( filename.IsNull() ){
180 stringstream strun;
181 strun.str("");
182 strun << run;
183 filename += strun.str();
184 filename += ".Level2.root";
185 };
186 filename = outDir + "/" + filename;
187 processFile = new TFile(filename.Data(),"UPDATE");
188 //
189 // Run the core program, put any output error in the "error" variable
190 //
191 error = CaloCore(run, processFile, dbc, numinp, inps);
192 //
193 // Close the DB connection
194 //
195 printf("\nClose the connection to the database... \n");
196 dbc->Close();
197 printf("...connection terminated!\n\n");
198 //
199 // Close redirection if the case.
200 //
201 if ( !beverbose ) close(nul);
202 //
203 // Return "error"
204 //
205 if ( error > 0 ) printf(" CALORIMETER - WARNING: exiting with signal %i \n\n",error);
206 if ( error < 0 ) printf(" CALORIMETER - ERROR: exiting with signal %i \n\n",error);
207 processFile->Close();
208 exit(error);
209 }

  ViewVC Help
Powered by ViewVC 1.1.23