/[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.2 by kusanagi, Mon Jul 26 23:09:45 2004 UTC revision 4.0 by kusanagi, Sun Mar 6 04:33:02 2005 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        bool ANALIZE = false;
59        //---------------- Log4cxx configuration-----------------------------------------------
60        //Define the configuration file to be used on log4cxx
61        PropertyConfigurator::configure(pathDir + "/log4cxx.conf");
62        //BasicConfigurator::configure();
63        //Retrieve the rootLogger and append to it a default FileAppender.
64        //Note that the priority level of the rootLogger (defined in log4cxx.conf) is unmodified
65        //LoggerPtr rootLogger = Logger::getRootLogger();
66    
67        //FileAppender *fileAppender = new FileAppender();
68        //fileAppender->setFile(pathLog);
69        //fileAppender->setAppend(false);
70        //fileAppender->setBufferedIO(true); //the default size is 8k
71        //fileAppender->setBufferSize(1000000);
72        //fileAppender->activateOptions();
73        //fileAppender->setLayout(new PatternLayout());
74    
75        //FileAppender *fileAppender = new FileAppender(new PatternLayout(), pathLog, false, true, 10000);
76        //rootLogger->addAppender(fileAppender);
77        //rootLogger->removeAppender('A1');
78        //---------------- Log4cxx configuration-----------------------------------------------
79        
80    // Check file name    // Check file name
81    if (argc != 2){    
82      cat.info("You have forgotten the file name");    if (argc < 2){
83        //logger->info(_T("You have forgotten the file name."));
84        cout << "You have forgotten the file name. \n";
85        cout << "Try '--help' for more information. \n";
86      exit(1);      exit(1);
87    }      }  
   
   std::ifstream from (argv[1]);  
   if (!from) cat.info("The file does not exist");  
88        
89      if (!strcmp(argv[1], "--help")){
90            cout << "Usage: yoda FILE [OPTION] \n";
91            cout << "\t --help              print this help and exit \n";
92            cout << "\t -p                  maximum number of packets to process [default all] \n";
93            cout << "\t -analize            generate pre-defined analisys files (gif/text) inside the unpacking directory\n";
94            exit(1);
95      }
96    
97      ifstream from (argv[1]);
98      if (!from) {
99        //logger->info(_T("The file does not exist."));
100        cout << "The file does not exist. \n";
101        exit(1);
102      }  
103    
104    /*try {    for (int i = 2; i < argc; i++){
105      log4cpp::PropertyConfigurator::configure("/home/kusanagi/yoda/techmodel/YodaLog.conf");      if (!strcmp(argv[i], "-p")){
106    } catch (log4cpp::ConfigureFailure& f) {          if (++i >= argc){
107      std::cerr << "Logging Configure Problem " << f.what() << std::endl;              cerr << "-p needs arguments. \n";
108    }*/              cout << "Try '--help' for more information. \n";
109                exit(1);
110            }
111            if (isdigit(*argv[i])) {
112                maxPackets = atoi(argv[i]);
113            } else {
114                //logger->info(_T("The file does not exist."));
115                cerr << "-p needs a integer value. \n";
116                cout << "Try '--help' for more information. \n";
117                exit(1);
118            }
119        }
120    
121        if (!maxPackets){
122            cout << "Try '--help' for more information. \n";
123            exit(1);
124        }
125    
126        if (!strcmp(argv[i], "-analize")) ANALIZE = true;
127        
128      }
129      
130      
131  //--------------------------------------------------  //--------------------------------------------------
132  //This is the configuration for the Yoda Logger  //This is the configuration for the Yoda Logger
133  //The parameters in the RollingFileAppender means  //The parameters in the RollingFileAppender means
# Line 49  int main(int argc, char* argv[]) { Line 135  int main(int argc, char* argv[]) {
135  // YodaLog.txt  ------------>the LogFile name  // YodaLog.txt  ------------>the LogFile name
136  // 1000              ------------>The max size (in Kb) of the LogFile  // 1000              ------------>The max size (in Kb) of the LogFile
137  // 5                     ------------>How many times the file will be backup  // 5                     ------------>How many times the file will be backup
138     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"));  
         
    std::string pathLog = pathDir + "/" + nomeFileLog;  
    appender = new log4cpp::FileAppender("default", pathLog.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);  
139      time_t rawtime;      time_t rawtime;
140      struct tm * timeinfo;      struct tm * timeinfo;
   
141      time ( &rawtime );      time ( &rawtime );
142      timeinfo = localtime ( &rawtime );      timeinfo = localtime ( &rawtime );
143  //--------------------------------------------------        
144      cat << log4cpp::Priority::INFO      oss.str("");
145      << "<-------------------------------START UNPACKING------------------------------->\n"      oss << "<-------------------------------START UNPACKING------------------------------->\n"
146      << " Starting the program at: " << asctime (timeinfo) << " Opening file: " << argv[1]          << " Starting the program at: " << asctime (timeinfo) << " Opening file: " << argv[1];
147      << "\n \n" << log4cpp::CategoryStream::ENDLINE;      logger->info(oss.str().c_str());
148      
149      
150    gROOT->SetBatch(kTRUE);    gROOT->SetBatch(kTRUE);
151      EventReader *reader = new EventReader(maxPackets);
   EventReader Reader;  
152    
153    int num = 0;    int num = 0;
154    TechmodelPamelaRun Run(argv[1]);    TechmodelPamelaRun Run(argv[1]);
155    Reader.Init(&Run);    reader->Init(&Run);
156      cat << log4cpp::Priority::INFO  
157      << "Init successul ok" << asctime (timeinfo) << log4cpp::CategoryStream::ENDLINE;     oss.str("");
158    Reader.RunEvent(num); //TBD --- eliminate the runNumber     oss << "Init successul ok" << asctime (timeinfo);
159    Reader.Finish();     logger->debug(oss.str().c_str());
160    
161      reader->RunEvent(num); //TBD --- eliminate the runNumber
162      reader->Finish();
163    Run.WriteFiles();    Run.WriteFiles();
164      cat << log4cpp::Priority::INFO  
165          << "<-------------------------------END UNPACKING------------------------------->"    logger->info("<-------------------------------END UNPACKING------------------------------->\n");
166          << "\n " << log4cpp::CategoryStream::ENDLINE;  
167      log4cpp::Category::shutdown();    //Momentarly suspended the save  
168    std::string command;    //system(command.c_str());
   command = "mv " + pathLog + "  " + pathDir + "/" + Run.GetRun() + "/.";  
   cat.info(command);  
   system(command.c_str());  
169  }  }

Legend:
Removed from v.1.2  
changed lines
  Added in v.4.0

  ViewVC Help
Powered by ViewVC 1.1.23