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

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

  ViewVC Help
Powered by ViewVC 1.1.23