/[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 4.0.8.3 by kusanagi, Tue Apr 4 13:31:55 2006 UTC revision 6.7 by mocchiut, Mon Oct 16 16:02:21 2006 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 "Exception.h"  #include "../event/yodaversion.h"
   
7  extern "C" {  extern "C" {
8  //#include "DirectoryStructure.h"      #include <dirent.h>
 #include <dirent.h>  
9  }  }
10    
   
   
11  using namespace pamela;  using namespace pamela;
12  using namespace log4cxx;  using namespace log4cxx;
13  using namespace std;  using namespace std;
# Line 34  int main(int argc, char* argv[]) { Line 19  int main(int argc, char* argv[]) {
19            
20      stringstream oss;      stringstream oss;
21      int maxPackets = 0;      int maxPackets = 0;
22        bool multiFile = 0;
23        short compression = 3;
24      char nomeFileLog[L_tmpnam];      char nomeFileLog[L_tmpnam];
25      tmpnam(nomeFileLog);      mkstemp(nomeFileLog);
26      DIR *dirp;      DIR *dirp;
27        char *outDir = "";
28      // check if yoda_DATA exist!!!!      
     char *outDir;  
     try {  
     outDir = getenv("YODA_DATA");  
     if (getenv("YODA_DATA") == NULL) throw NotFoundEnvironmentVarException("The variable YODA_DATA has not been found.");  
     } catch (NotFoundEnvironmentVarException exc) {  
      cout << "The variable YODA_DATA has not been found. \n";  
      cout << "Please check your environment variables \n";  
      oss.str("");  
      oss << exc.print();  
      logger->fatal(oss.str().c_str());  
      exit(1);  
     }  
   
     string pathDir(outDir);  
   
     string pathLog = nomeFileLog;  
29      //---------------- Log4cxx configuration-----------------------------------------------      //---------------- Log4cxx configuration-----------------------------------------------
     //Define the configuration file to be used on log4cxx  
     PropertyConfigurator::configure(pathDir + "/log4cxx.conf");  
30      //BasicConfigurator::configure();      //BasicConfigurator::configure();
31      //Retrieve the rootLogger and append to it a default FileAppender.      //Retrieve the rootLogger and append to it a default FileAppender.
32      //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 75  int main(int argc, char* argv[]) { Line 44  int main(int argc, char* argv[]) {
44      //rootLogger->addAppender(fileAppender);      //rootLogger->addAppender(fileAppender);
45      //rootLogger->removeAppender('A1');      //rootLogger->removeAppender('A1');
46      //---------------- Log4cxx configuration-----------------------------------------------      //---------------- Log4cxx configuration-----------------------------------------------
47        
48    // Check file name    // Check file name
49        
50    if (argc < 2){    if (argc < 2){
# Line 87  int main(int argc, char* argv[]) { Line 56  int main(int argc, char* argv[]) {
56        
57    if (!strcmp(argv[1], "-help")){    if (!strcmp(argv[1], "-help")){
58          cout << "Usage: yoda FILE [OPTION] \n";          cout << "Usage: yoda FILE [OPTION] \n";
59          cout << "\t -help              print this help and exit \n";          cout << "\t -help               print this help and exit \n";
60            cout << "\t -version            print version number \n";
61          cout << "\t -p                  maximum number of packets to process [default all] \n";          cout << "\t -p                  maximum number of packets to process [default all] \n";
62            cout << "\t -multi              generate multiple root files \n";
63            cout << "\t -c                  set the compression level for the generated root file(s). Values: [0,9] [default = 3]\n";
64            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";
65          exit(1);          exit(1);
66    }    }
67    
68    if (!strcmp(argv[1], "-version")){    if (!strcmp(argv[1], "-version")){
69          cout << GetVersionInfo() << "\n";      printf(" Version %i \n",GetYODAver());
70        //        cout << "$Name:  $ $Revision: 6.5 $" << "\n";
71          exit(1);          exit(1);
72    }    }
73      
74    ifstream from (argv[1]);    ifstream from (argv[1]);
75    if (!from) {    if (!from) {
76      //logger->info(_T("The file does not exist."));      //logger->info(_T("The file does not exist."));
# Line 111  int main(int argc, char* argv[]) { Line 85  int main(int argc, char* argv[]) {
85              cout << "Try '-help' for more information. \n";              cout << "Try '-help' for more information. \n";
86              exit(1);              exit(1);
87          }          }
88          if (isdigit(*argv[i])) {          if (isdigit(*argv[i]) && (atoi(argv[i]) > 0)) {
89              maxPackets = atoi(argv[i]);              maxPackets = atoi(argv[i]);
90          } else {          } else {
91              //logger->info(_T("The file does not exist."));              //logger->info(_T("The file does not exist."));
# Line 119  int main(int argc, char* argv[]) { Line 93  int main(int argc, char* argv[]) {
93              cout << "Try '-help' for more information. \n";              cout << "Try '-help' for more information. \n";
94              exit(1);              exit(1);
95          }          }
96            continue;
97      }      }
98    
99      if (!maxPackets){      if (!strcmp(argv[i], "-multi")) multiFile = 1;
         cout << "Try '-help' for more information. \n";  
         exit(1);  
     }  
100    
101        if (!strcmp(argv[i], "-c")){
102            if (++i >= argc){
103                cerr << "-c needs arguments. \n";
104                cout << "Try '-help' for more information. \n";
105                exit(1);
106            }
107            if ((isdigit(*argv[i])) && ( (atoi(argv[i]) >= 0) && (atoi(argv[i]) <= 9))) {
108                compression = atoi(argv[i]);
109            } else {
110                //logger->info(_T("The file does not exist."));
111                cerr << "-c needs a integer value beetween 0 and 9. \n";
112                cout << "Try '-help' for more information. \n";
113                exit(1);
114            }
115            continue;
116        }
117        
118        if (!strcmp(argv[i], "-o")){
119            if (++i >= argc){
120                cerr << "-o needs arguments. \n";
121                cout << "Try '-help' for more information. \n";
122                exit(1);
123            }
124            DIR* tempdir;
125            if ((tempdir = opendir(argv[i])) != 0) {
126                outDir = argv[i];
127                closedir(tempdir);
128            } else {
129                //logger->info(_T("The file does not exist."));
130                cerr << "-o needs an existing/accessable directory. \n";
131                cout << "Try '-help' for more information. \n";
132                exit(1);
133            }
134            continue;
135        }
136        
137      }
138    
139      if (outDir == ""){
140            try {
141                    outDir = getenv("YODA_DATA");
142                    if (getenv("YODA_DATA") == NULL) throw NotFoundEnvironmentVarException("The variable YODA_DATA has not been found.");
143            } catch (NotFoundEnvironmentVarException exc) {
144                    cout << "The variable YODA_DATA has not been found. \n";
145                    cout << "Please check your environment variables \n";
146                    oss.str("");
147                    oss << exc.print();
148                    logger->fatal(oss.str().c_str());
149                    exit(1);
150            }
151    }    }
152        
153          string pathDir(outDir);
154  //--------------------------------------------------      string pathLog = nomeFileLog;
155  //This is the configuration for the Yoda Logger      //Define the configuration file to be used on log4cxx
156  //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  
157    
158      time_t rawtime;      time_t rawtime;
159      struct tm * timeinfo;      struct tm * timeinfo;
# Line 153  int main(int argc, char* argv[]) { Line 170  int main(int argc, char* argv[]) {
170    EventReader *reader = new EventReader(maxPackets);    EventReader *reader = new EventReader(maxPackets);
171    
172    int num = 0;    int num = 0;
173    TechmodelPamelaRun Run(argv[1]);    TechmodelPamelaRun Run(argv[1], outDir, multiFile, compression);
174    reader->Init(&Run);    reader->Init(&Run);
175    
176     oss.str("");     oss.str("");
# Line 165  int main(int argc, char* argv[]) { Line 182  int main(int argc, char* argv[]) {
182    Run.WriteFiles();    Run.WriteFiles();
183    
184    logger->info("<-------------------------------END UNPACKING------------------------------->\n");    logger->info("<-------------------------------END UNPACKING------------------------------->\n");
185      printf("Finished, exiting...\n");
186    
187    //Momentarly suspended the save      //Momentarly suspended the save  
188    //system(command.c_str());    //system(command.c_str());
189  }  }
190    
 /**  
  * Get a string with the version info of the algorithm.  
  */  
 const char* GetVersionInfo(void) const {  
   return "$Revision$";  
 }  

Legend:
Removed from v.4.0.8.3  
changed lines
  Added in v.6.7

  ViewVC Help
Powered by ViewVC 1.1.23