/[PAMELA software]/yoda/techmodel/techmodelreader.cpp
ViewVC logotype

Diff of /yoda/techmodel/techmodelreader.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2.1 by kusanagi, Fri Dec 3 22:08:01 2004 UTC revision 6.8 by mocchiut, Fri Oct 19 08:14:52 2007 UTC
# Line 1  Line 1 
1    
2  #include <log4cxx/logger.h>  #include <log4cxx/logger.h>
 #include <log4cxx/basicconfigurator.h>  
 #include <log4cxx/fileappender.h>  
 #include <log4cxx/patternlayout.h>  
3  #include <log4cxx/propertyconfigurator.h>  #include <log4cxx/propertyconfigurator.h>
 #include <log4cxx/helpers/exception.h>  
   
 #include "TROOT.h"  
   
 #include "TechmodelPamelaRun.h"  
4  #include "EventReader.h"  #include "EventReader.h"
   
 #include <cstdlib>  
 #include <iostream>  
5  #include <time.h>  #include <time.h>
6    #include <TROOT.h>
7    #include "../event/yodaversion.h"
8  extern "C" {  extern "C" {
9  //#include "DirectoryStructure.h"      #include <dirent.h>
 #include <dirent.h>  
10  }  }
11    
   
   
12  using namespace pamela;  using namespace pamela;
13  using namespace log4cxx;  using namespace log4cxx;
14  using namespace std;  using namespace std;
# Line 32  int main(int argc, char* argv[]) { Line 20  int main(int argc, char* argv[]) {
20            
21      stringstream oss;      stringstream oss;
22      int maxPackets = 0;      int maxPackets = 0;
23        bool multiFile = 0;
24        short compression = 3;
25      char nomeFileLog[L_tmpnam];      char nomeFileLog[L_tmpnam];
26      tmpnam(nomeFileLog);      mkstemp(nomeFileLog);
27      DIR *dirp;      DIR *dirp;
28      string pathDir((char*)getenv("YODA_DATA"));      char *outDir = "";
29      string pathLog = nomeFileLog;      
     bool ANALIZE = false;  
30      //---------------- Log4cxx configuration-----------------------------------------------      //---------------- Log4cxx configuration-----------------------------------------------
     //Define the configuration file to be used on log4cxx  
     PropertyConfigurator::configure(pathDir + "/log4cxx.conf");  
31      //BasicConfigurator::configure();      //BasicConfigurator::configure();
32      //Retrieve the rootLogger and append to it a default FileAppender.      //Retrieve the rootLogger and append to it a default FileAppender.
33      //Note that the priority level of the rootLogger (defined in log4cxx.conf) is unmodified      //Note that the priority level of the rootLogger (defined in log4cxx.conf) is unmodified
# Line 58  int main(int argc, char* argv[]) { Line 45  int main(int argc, char* argv[]) {
45      //rootLogger->addAppender(fileAppender);      //rootLogger->addAppender(fileAppender);
46      //rootLogger->removeAppender('A1');      //rootLogger->removeAppender('A1');
47      //---------------- Log4cxx configuration-----------------------------------------------      //---------------- Log4cxx configuration-----------------------------------------------
48        
49    // Check file name    // Check file name
50        
51    if (argc < 2){    if (argc < 2){
52      //logger->info(_T("You have forgotten the file name."));      //logger->info(_T("You have forgotten the file name."));
53      cout << "You have forgotten the file name. \n";      cout << "You have forgotten the file name. \n";
54      cout << "Try '--help' for more information. \n";      cout << "Try '-help' for more information. \n";
55      exit(1);      exit(1);
56    }      }  
57        
58    if (!strcmp(argv[1], "--help")){    if (!strcmp(argv[1], "-help")){
59          cout << "Usage: yoda FILE [OPTION] \n";          cout << "Usage: yoda FILE [OPTION] \n";
60          cout << "\t --help              print this help and exit \n";          cout << "\t -help               print this help and exit \n";
61            cout << "\t -version            print version number \n";
62          cout << "\t -p                  maximum number of packets to process [default all] \n";          cout << "\t -p                  maximum number of packets to process [default all] \n";
63          cout << "\t -analize            generate pre-defined analisys files (gif/text) inside the unpacking directory\n";          cout << "\t -multi              generate multiple root files \n";
64            cout << "\t -c                  set the compression level for the generated root file(s). Values: [0,9] [default = 3]\n";
65            cout << "\t -o                  set the output directory for the generated root file(s). [default = $YODA_DATA]. Notice that in the same directory have to be prensent a log4cxx configuration file called \"log4cxx.conf\" \n";
66            exit(1);
67      }
68    
69      if (!strcmp(argv[1], "-version")){
70        printf(" Version %i \n",GetYODAver());
71        //        cout << "$Name:  $ $Revision: 6.7 $" << "\n";
72          exit(1);          exit(1);
73    }    }
74    
# Line 87  int main(int argc, char* argv[]) { Line 83  int main(int argc, char* argv[]) {
83      if (!strcmp(argv[i], "-p")){      if (!strcmp(argv[i], "-p")){
84          if (++i >= argc){          if (++i >= argc){
85              cerr << "-p needs arguments. \n";              cerr << "-p needs arguments. \n";
86              cout << "Try '--help' for more information. \n";              cout << "Try '-help' for more information. \n";
87              exit(1);              exit(1);
88          }          }
89          if (isdigit(*argv[i])) {          if (isdigit(*argv[i]) && (atoi(argv[i]) > 0)) {
90              maxPackets = atoi(argv[i]);              maxPackets = atoi(argv[i]);
91          } else {          } else {
92              //logger->info(_T("The file does not exist."));              //logger->info(_T("The file does not exist."));
93              cerr << "-p needs a integer value. \n";              cerr << "-p needs a integer value. \n";
94              cout << "Try '--help' for more information. \n";              cout << "Try '-help' for more information. \n";
95              exit(1);              exit(1);
96          }          }
97            continue;
98      }      }
99    
100      if (!maxPackets){      if (!strcmp(argv[i], "-multi")) multiFile = 1;
         cout << "Try '--help' for more information. \n";  
         exit(1);  
     }  
101    
102      if (!strcmp(argv[i], "-analize")) ANALIZE = true;      if (!strcmp(argv[i], "-c")){
103            if (++i >= argc){
104                cerr << "-c needs arguments. \n";
105                cout << "Try '-help' for more information. \n";
106                exit(1);
107            }
108            if ((isdigit(*argv[i])) && ( (atoi(argv[i]) >= 0) && (atoi(argv[i]) <= 9))) {
109                compression = atoi(argv[i]);
110            } else {
111                //logger->info(_T("The file does not exist."));
112                cerr << "-c needs a integer value beetween 0 and 9. \n";
113                cout << "Try '-help' for more information. \n";
114                exit(1);
115            }
116            continue;
117        }
118        
119        if (!strcmp(argv[i], "-o")){
120            if (++i >= argc){
121                cerr << "-o needs arguments. \n";
122                cout << "Try '-help' for more information. \n";
123                exit(1);
124            }
125            DIR* tempdir;
126            if ((tempdir = opendir(argv[i])) != 0) {
127                outDir = argv[i];
128                closedir(tempdir);
129            } else {
130                //logger->info(_T("The file does not exist."));
131                cerr << "-o needs an existing/accessable directory. \n";
132                cout << "Try '-help' for more information. \n";
133                exit(1);
134            }
135            continue;
136        }
137            
138    }    }
139    
140      if (outDir == ""){
141            try {
142                    outDir = getenv("YODA_DATA");
143                    if (getenv("YODA_DATA") == NULL) throw NotFoundEnvironmentVarException("The variable YODA_DATA has not been found.");
144            } catch (NotFoundEnvironmentVarException exc) {
145                    cout << "The variable YODA_DATA has not been found. \n";
146                    cout << "Please check your environment variables \n";
147                    oss.str("");
148                    oss << exc.print();
149                    logger->fatal(oss.str().c_str());
150                    exit(1);
151            }
152      }
153        
154          string pathDir(outDir);
155  //--------------------------------------------------      string pathLog = nomeFileLog;
156  //This is the configuration for the Yoda Logger      //Define the configuration file to be used on log4cxx
157  //The parameters in the RollingFileAppender means      PropertyConfigurator::configure(pathDir + "/log4cxx.conf");
 // default           ------------>the selected category  
 // YodaLog.txt  ------------>the LogFile name  
 // 1000              ------------>The max size (in Kb) of the LogFile  
 // 5                     ------------>How many times the file will be backup  
158    
159      time_t rawtime;      time_t rawtime;
160      struct tm * timeinfo;      struct tm * timeinfo;
# Line 133  int main(int argc, char* argv[]) { Line 171  int main(int argc, char* argv[]) {
171    EventReader *reader = new EventReader(maxPackets);    EventReader *reader = new EventReader(maxPackets);
172    
173    int num = 0;    int num = 0;
174    TechmodelPamelaRun Run(argv[1]);    TechmodelPamelaRun Run(argv[1], outDir, multiFile, compression);
175    reader->Init(&Run);    reader->Init(&Run);
176    
177     oss.str("");     oss.str("");
# Line 145  int main(int argc, char* argv[]) { Line 183  int main(int argc, char* argv[]) {
183    Run.WriteFiles();    Run.WriteFiles();
184    
185    logger->info("<-------------------------------END UNPACKING------------------------------->\n");    logger->info("<-------------------------------END UNPACKING------------------------------->\n");
186      printf("Finished, exiting...\n");
187    
188    //Momentarly suspended the save      //Momentarly suspended the save  
189    //system(command.c_str());    //system(command.c_str());
190  }  }
191    

Legend:
Removed from v.2.1  
changed lines
  Added in v.6.8

  ViewVC Help
Powered by ViewVC 1.1.23