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

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

  ViewVC Help
Powered by ViewVC 1.1.23