/[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 1.1.1.1 by kusanagi, Tue Jul 6 12:20:23 2004 UTC revision 4.0.8.3 by kusanagi, Tue Apr 4 13:31:55 2006 UTC
# Line 1  Line 1 
1    
2  #include "log4cpp/Category.hh"  #include <log4cxx/logger.h>
3  #include "log4cpp/PropertyConfigurator.hh"  #include <log4cxx/basicconfigurator.h>
4  #include "log4cpp/RollingFileAppender.hh"  #include <log4cxx/fileappender.h>
5  #include "log4cpp/PatternLayout.hh"  #include <log4cxx/patternlayout.h>
6    #include <log4cxx/propertyconfigurator.h>
7    #include <log4cxx/helpers/exception.h>
8    
9  #include "TROOT.h"  #include "TROOT.h"
10    
11  #include "TechmodelPamelaRun.h"  #include "TechmodelPamelaRun.h"
12  #include "EventReader.h"  #include "EventReader.h"
13  #include <fstream>  
14  #include <cstdlib>  #include <cstdlib>
15  #include <stream.h>  #include <iostream>
16  #include <time.h>  #include <time.h>
17    #include "Exception.h"
18    
19  extern "C" {  extern "C" {
20  //#include "DirectoryStructure.h"  //#include "DirectoryStructure.h"
21  #include <dirent.h>  #include <dirent.h>
22  }  }
23    
24    
25    
26  using namespace pamela;  using namespace pamela;
27    using namespace log4cxx;
28    using namespace std;
29  using namespace pamela::techmodel;  using namespace pamela::techmodel;
30    
31  static log4cpp::Category& cat = log4cpp::Category::getInstance("pamela.techmodel.TechmodelReader");  static LoggerPtr logger = Logger::getLogger(_T("pamela.techmodel.TechmodelReader"));
32    
33  int main(int argc, char* argv[]) {  int main(int argc, char* argv[]) {
34        
35        stringstream oss;
36        int maxPackets = 0;
37        char nomeFileLog[L_tmpnam];
38        tmpnam(nomeFileLog);
39        DIR *dirp;
40    
41        // check if yoda_DATA exist!!!!
42        char *outDir;
43        try {
44        outDir = getenv("YODA_DATA");
45        if (getenv("YODA_DATA") == NULL) throw NotFoundEnvironmentVarException("The variable YODA_DATA has not been found.");
46        } catch (NotFoundEnvironmentVarException exc) {
47         cout << "The variable YODA_DATA has not been found. \n";
48         cout << "Please check your environment variables \n";
49         oss.str("");
50         oss << exc.print();
51         logger->fatal(oss.str().c_str());
52         exit(1);
53        }
54    
55        string pathDir(outDir);
56    
57        string pathLog = nomeFileLog;
58        //---------------- Log4cxx configuration-----------------------------------------------
59        //Define the configuration file to be used on log4cxx
60        PropertyConfigurator::configure(pathDir + "/log4cxx.conf");
61        //BasicConfigurator::configure();
62        //Retrieve the rootLogger and append to it a default FileAppender.
63        //Note that the priority level of the rootLogger (defined in log4cxx.conf) is unmodified
64        //LoggerPtr rootLogger = Logger::getRootLogger();
65    
66        //FileAppender *fileAppender = new FileAppender();
67        //fileAppender->setFile(pathLog);
68        //fileAppender->setAppend(false);
69        //fileAppender->setBufferedIO(true); //the default size is 8k
70        //fileAppender->setBufferSize(1000000);
71        //fileAppender->activateOptions();
72        //fileAppender->setLayout(new PatternLayout());
73    
74        //FileAppender *fileAppender = new FileAppender(new PatternLayout(), pathLog, false, true, 10000);
75        //rootLogger->addAppender(fileAppender);
76        //rootLogger->removeAppender('A1');
77        //---------------- Log4cxx configuration-----------------------------------------------
78        
79    // Check file name    // Check file name
80    if (argc != 2){    
81      cat.info("You have forgotten the file name");    if (argc < 2){
82        //logger->info(_T("You have forgotten the file name."));
83        cout << "You have forgotten the file name. \n";
84        cout << "Try '-help' for more information. \n";
85      exit(1);      exit(1);
86    }      }  
   
   std::ifstream from (argv[1]);  
   if (!from) cat.info("The file does not exist");  
87        
88      if (!strcmp(argv[1], "-help")){
89            cout << "Usage: yoda FILE [OPTION] \n";
90            cout << "\t -help              print this help and exit \n";
91            cout << "\t -p                  maximum number of packets to process [default all] \n";
92            exit(1);
93      }
94    
95      if (!strcmp(argv[1], "-version")){
96            cout << GetVersionInfo() << "\n";
97            exit(1);
98      }
99      
100      ifstream from (argv[1]);
101      if (!from) {
102        //logger->info(_T("The file does not exist."));
103        cout << "The file does not exist. \n";
104        exit(1);
105      }  
106    
107    /*try {    for (int i = 2; i < argc; i++){
108      log4cpp::PropertyConfigurator::configure("/home/kusanagi/yoda/techmodel/YodaLog.conf");      if (!strcmp(argv[i], "-p")){
109    } catch (log4cpp::ConfigureFailure& f) {          if (++i >= argc){
110      std::cerr << "Logging Configure Problem " << f.what() << std::endl;              cerr << "-p needs arguments. \n";
111    }*/              cout << "Try '-help' for more information. \n";
112                exit(1);
113            }
114            if (isdigit(*argv[i])) {
115                maxPackets = atoi(argv[i]);
116            } else {
117                //logger->info(_T("The file does not exist."));
118                cerr << "-p needs a integer value. \n";
119                cout << "Try '-help' for more information. \n";
120                exit(1);
121            }
122        }
123    
124        if (!maxPackets){
125            cout << "Try '-help' for more information. \n";
126            exit(1);
127        }
128    
129    
130      }
131      
132      
133  //--------------------------------------------------  //--------------------------------------------------
134  //This is the configuration for the Yoda Logger  //This is the configuration for the Yoda Logger
135  //The parameters in the RollingFileAppender means  //The parameters in the RollingFileAppender means
# Line 49  int main(int argc, char* argv[]) { Line 137  int main(int argc, char* argv[]) {
137  // YodaLog.txt  ------------>the LogFile name  // YodaLog.txt  ------------>the LogFile name
138  // 1000              ------------>The max size (in Kb) of the LogFile  // 1000              ------------>The max size (in Kb) of the LogFile
139  // 5                     ------------>How many times the file will be backup  // 5                     ------------>How many times the file will be backup
140     std::string nomeFileLog = "YodaLog.txt";  
    log4cpp::Appender* appender;  
    log4cpp::Category& cat = log4cpp::Category::getRoot();  
    DIR *dirp;  
    //std::string pathDir((char*)getenv("YODA_LOGS"));  
    std::string pathDir((char*)getenv("YODA_DATA"));  
    pathDir = pathDir + "/";  
    pathDir = pathDir + nomeFileLog;  
    appender = new log4cpp::FileAppender("default", pathDir.c_str(), false);  
    log4cpp::PatternLayout * pl = new log4cpp::PatternLayout();  
    pl->setConversionPattern("%d{%Y/%m/%d %H:%M:%S.%l} %p %c - %m");  
    appender->setLayout(pl);  
    cat.setAppender(appender);  
    cat.setPriority(log4cpp::Priority::DEBUG);  
141      time_t rawtime;      time_t rawtime;
142      struct tm * timeinfo;      struct tm * timeinfo;
   
143      time ( &rawtime );      time ( &rawtime );
144      timeinfo = localtime ( &rawtime );      timeinfo = localtime ( &rawtime );
145  //--------------------------------------------------        
146      cat << log4cpp::Priority::INFO      oss.str("");
147      << "<-------------------------------START UNPACKING------------------------------->\n"      oss << "<-------------------------------START UNPACKING------------------------------->\n"
148      << " Starting the program at: " << asctime (timeinfo) << " Opening file: " << argv[1]          << " Starting the program at: " << asctime (timeinfo) << " Opening file: " << argv[1];
149      << "\n \n" << log4cpp::CategoryStream::ENDLINE;      logger->info(oss.str().c_str());
150      
151      
152    gROOT->SetBatch(kTRUE);    gROOT->SetBatch(kTRUE);
153      EventReader *reader = new EventReader(maxPackets);
   EventReader Reader;  
154    
155    int num = 0;    int num = 0;
156    TechmodelPamelaRun Run(argv[1]);    TechmodelPamelaRun Run(argv[1]);
157    Reader.Init(&Run);    reader->Init(&Run);
158      cat << log4cpp::Priority::INFO  
159      << "Init successul ok" << asctime (timeinfo) << log4cpp::CategoryStream::ENDLINE;     oss.str("");
160    Reader.RunEvent(num); //TBD --- eliminate the runNumber     oss << "Init successul ok" << asctime (timeinfo);
161    Reader.Finish();     logger->debug(oss.str().c_str());
162    
163      reader->RunEvent(num); //TBD --- eliminate the runNumber
164      reader->Finish();
165    Run.WriteFiles();    Run.WriteFiles();
166      cat << log4cpp::Priority::INFO  
167          << "<-------------------------------END UNPACKING------------------------------->"    logger->info("<-------------------------------END UNPACKING------------------------------->\n");
168          << "\n " << log4cpp::CategoryStream::ENDLINE;  
169      log4cpp::Category::shutdown();    //Momentarly suspended the save  
170    std::string command;    //system(command.c_str());
171    command = "mv " + nomeFileLog + "  " + Run.GetRun() + "/.";  }
172    cat.info(command);  
173    system(command.c_str());  /**
174     * Get a string with the version info of the algorithm.
175     */
176    const char* GetVersionInfo(void) const {
177      return "$Revision$";
178  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.23