/[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 1.7 by kusanagi, Tue Sep 21 20:24:33 2004 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  extern "C" {  extern "C" {
18  //#include "DirectoryStructure.h"  //#include "DirectoryStructure.h"
# Line 19  extern "C" { Line 21  extern "C" {
21    
22    
23  using namespace pamela;  using namespace pamela;
24    using namespace log4cxx;
25    using namespace std;
26  using namespace pamela::techmodel;  using namespace pamela::techmodel;
27    
28  static log4cpp::Category& cat = log4cpp::Category::getInstance("pamela.techmodel.TechmodelReader");  static LoggerPtr logger = Logger::getLogger(_T("pamela.techmodel.TechmodelReader"));
29    
30  int main(int argc, char* argv[]) {  int main(int argc, char* argv[]) {
31        
32        stringstream oss;
33        int maxPackets = 0;
34        char nomeFileLog[L_tmpnam];
35        tmpnam(nomeFileLog);
36        DIR *dirp;
37        string pathDir((char*)getenv("YODA_DATA"));
38        string pathLog = nomeFileLog;
39    
40        //---------------- Log4cxx configuration-----------------------------------------------
41        //Define the configuration file to be used on log4cxx
42        PropertyConfigurator::configure(pathDir + "/log4cxx.conf");
43        //BasicConfigurator::configure();
44        //Retrieve the rootLogger and append to it a default FileAppender.
45        //Note that the priority level of the rootLogger (defined in log4cxx.conf) is unmodified
46        //LoggerPtr rootLogger = Logger::getRootLogger();
47    
48        //FileAppender *fileAppender = new FileAppender();
49        //fileAppender->setFile(pathLog);
50        //fileAppender->setAppend(false);
51        //fileAppender->setBufferedIO(true); //the default size is 8k
52        //fileAppender->setBufferSize(1000000);
53        //fileAppender->activateOptions();
54        //fileAppender->setLayout(new PatternLayout());
55    
56        //FileAppender *fileAppender = new FileAppender(new PatternLayout(), pathLog, false, true, 10000);
57        //rootLogger->addAppender(fileAppender);
58        //rootLogger->removeAppender('A1');
59        //---------------- Log4cxx configuration-----------------------------------------------
60        
61    // Check file name    // Check file name
62    if (argc != 2){    
63      cat.info("You have forgotten the file name");    if (argc < 2){
64        //logger->info(_T("You have forgotten the file name."));
65        cout << "You have forgotten the file name. \n";
66        cout << "Try '--help' for more information. \n";
67      exit(1);      exit(1);
68    }      }  
   
   std::ifstream from (argv[1]);  
   if (!from) cat.info("The file does not exist");  
69        
70      if (!strcmp(argv[1], "--help")){
71            cout << "Usage: yoda FILE [OPTION] \n";
72            cout << "\t --help              print this help and exit \n";
73            cout << "\t -p                  maximum number of packets to process [default all] \n";
74            exit(1);
75      }
76    
77      ifstream from (argv[1]);
78      if (!from) {
79        //logger->info(_T("The file does not exist."));
80        cout << "The file does not exist. \n";
81        exit(1);
82      }  
83    
84    /*try {    for (int i = 2; i < argc; i++){
85      log4cpp::PropertyConfigurator::configure("/home/kusanagi/yoda/techmodel/YodaLog.conf");      if (!strcmp(argv[i], "-p")){
86    } catch (log4cpp::ConfigureFailure& f) {          if (++i >= argc){
87      std::cerr << "Logging Configure Problem " << f.what() << std::endl;              cerr << "-p needs arguments. \n";
88    }*/              cout << "Try '--help' for more information. \n";
89                exit(1);
90            }
91            if (isdigit(*argv[i])) {
92                maxPackets = atoi(argv[i]);
93            } else {
94                //logger->info(_T("The file does not exist."));
95                cerr << "-p needs a integer value. \n";
96                cout << "Try '--help' for more information. \n";
97                exit(1);
98            }
99        }
100    
101        if (!maxPackets){
102            cout << "Try '--help' for more information. \n";
103            exit(1);
104        }
105      }
106      
107      
108  //--------------------------------------------------  //--------------------------------------------------
109  //This is the configuration for the Yoda Logger  //This is the configuration for the Yoda Logger
110  //The parameters in the RollingFileAppender means  //The parameters in the RollingFileAppender means
# Line 49  int main(int argc, char* argv[]) { Line 112  int main(int argc, char* argv[]) {
112  // YodaLog.txt  ------------>the LogFile name  // YodaLog.txt  ------------>the LogFile name
113  // 1000              ------------>The max size (in Kb) of the LogFile  // 1000              ------------>The max size (in Kb) of the LogFile
114  // 5                     ------------>How many times the file will be backup  // 5                     ------------>How many times the file will be backup
115     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);  
116      time_t rawtime;      time_t rawtime;
117      struct tm * timeinfo;      struct tm * timeinfo;
   
118      time ( &rawtime );      time ( &rawtime );
119      timeinfo = localtime ( &rawtime );      timeinfo = localtime ( &rawtime );
120  //--------------------------------------------------        
121      cat << log4cpp::Priority::INFO      oss.flush();
122      << "<-------------------------------START UNPACKING------------------------------->\n"      oss << "<-------------------------------START UNPACKING------------------------------->\n"
123      << " Starting the program at: " << asctime (timeinfo) << " Opening file: " << argv[1]          << " Starting the program at: " << asctime (timeinfo) << " Opening file: " << argv[1];
124      << "\n \n" << log4cpp::CategoryStream::ENDLINE;      logger->info(oss.str().c_str());
125      
126      
127    gROOT->SetBatch(kTRUE);    gROOT->SetBatch(kTRUE);
128      EventReader *reader = new EventReader(maxPackets);
   EventReader Reader;  
129    
130    int num = 0;    int num = 0;
131    TechmodelPamelaRun Run(argv[1]);    TechmodelPamelaRun Run(argv[1]);
132    Reader.Init(&Run);    reader->Init(&Run);
133      cat << log4cpp::Priority::INFO  
134      << "Init successul ok" << asctime (timeinfo) << log4cpp::CategoryStream::ENDLINE;     oss.flush();
135    Reader.RunEvent(num); //TBD --- eliminate the runNumber     oss << "Init successul ok" << asctime (timeinfo);
136    Reader.Finish();     logger->debug(oss.str().c_str());
137    
138      reader->RunEvent(num); //TBD --- eliminate the runNumber
139      reader->Finish();
140    Run.WriteFiles();    Run.WriteFiles();
141      cat << log4cpp::Priority::INFO  
142          << "<-------------------------------END UNPACKING------------------------------->"    logger->info("<-------------------------------END UNPACKING------------------------------->\n");
143          << "\n " << log4cpp::CategoryStream::ENDLINE;  
     log4cpp::Category::shutdown();  
144    std::string command;    std::string command;
145    command = "mv " + pathLog + "  " + pathDir + "/" + Run.GetRun() + "/.";    command = "mv " + pathLog + "  " + pathDir + "/" + Run.GetRun() + "/YodaLog.txt";
146    cat.info(command);    //Momentarly suspended the save  
147    system(command.c_str());    //system(command.c_str());
148  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.23