/[PAMELA software]/yoda/techmodel/techmodelreader.cpp
ViewVC logotype

Annotation of /yoda/techmodel/techmodelreader.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (hide annotations) (download)
Tue Sep 21 20:24:33 2004 UTC (20 years, 2 months ago) by kusanagi
Branch: MAIN
Changes since 1.6: +103 -70 lines
Commit toward log4cxx plus new packets types Reader

1 kusanagi 1.1
2 kusanagi 1.7 #include <log4cxx/logger.h>
3     #include <log4cxx/basicconfigurator.h>
4     #include <log4cxx/fileappender.h>
5     #include <log4cxx/patternlayout.h>
6     #include <log4cxx/propertyconfigurator.h>
7     #include <log4cxx/helpers/exception.h>
8 kusanagi 1.1
9     #include "TROOT.h"
10    
11     #include "TechmodelPamelaRun.h"
12     #include "EventReader.h"
13 kusanagi 1.7
14 kusanagi 1.1 #include <cstdlib>
15 kusanagi 1.7 #include <iostream>
16 kusanagi 1.1 #include <time.h>
17     extern "C" {
18     //#include "DirectoryStructure.h"
19     #include <dirent.h>
20     }
21    
22    
23     using namespace pamela;
24 kusanagi 1.7 using namespace log4cxx;
25     using namespace std;
26 kusanagi 1.1 using namespace pamela::techmodel;
27    
28 kusanagi 1.7 static LoggerPtr logger = Logger::getLogger(_T("pamela.techmodel.TechmodelReader"));
29 kusanagi 1.1
30     int main(int argc, char* argv[]) {
31 kusanagi 1.7
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 kusanagi 1.1
40 kusanagi 1.7 //---------------- 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 kusanagi 1.1 // Check file name
62 kusanagi 1.7
63     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);
68     }
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 kusanagi 1.1 exit(1);
82     }
83    
84 kusanagi 1.7 for (int i = 2; i < argc; i++){
85     if (!strcmp(argv[i], "-p")){
86     if (++i >= argc){
87     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 kusanagi 1.1
108     //--------------------------------------------------
109     //This is the configuration for the Yoda Logger
110     //The parameters in the RollingFileAppender means
111     // default ------------>the selected category
112     // YodaLog.txt ------------>the LogFile name
113     // 1000 ------------>The max size (in Kb) of the LogFile
114     // 5 ------------>How many times the file will be backup
115 kusanagi 1.6
116 kusanagi 1.1 time_t rawtime;
117     struct tm * timeinfo;
118     time ( &rawtime );
119     timeinfo = localtime ( &rawtime );
120 kusanagi 1.7
121     oss.flush();
122     oss << "<-------------------------------START UNPACKING------------------------------->\n"
123     << " Starting the program at: " << asctime (timeinfo) << " Opening file: " << argv[1];
124     logger->info(oss.str().c_str());
125    
126    
127 kusanagi 1.1 gROOT->SetBatch(kTRUE);
128 kusanagi 1.7 EventReader *reader = new EventReader(maxPackets);
129 kusanagi 1.1
130     int num = 0;
131     TechmodelPamelaRun Run(argv[1]);
132 kusanagi 1.7 reader->Init(&Run);
133    
134     oss.flush();
135     oss << "Init successul ok" << asctime (timeinfo);
136     logger->debug(oss.str().c_str());
137    
138     reader->RunEvent(num); //TBD --- eliminate the runNumber
139     reader->Finish();
140 kusanagi 1.1 Run.WriteFiles();
141 kusanagi 1.7
142     logger->info("<-------------------------------END UNPACKING------------------------------->\n");
143    
144 kusanagi 1.1 std::string command;
145 kusanagi 1.3 command = "mv " + pathLog + " " + pathDir + "/" + Run.GetRun() + "/YodaLog.txt";
146 kusanagi 1.7 //Momentarly suspended the save
147     //system(command.c_str());
148 kusanagi 1.1 }

  ViewVC Help
Powered by ViewVC 1.1.23