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

Legend:
Removed from v.1.6  
changed lines
  Added in v.5.1

  ViewVC Help
Powered by ViewVC 1.1.23