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

Contents of /yoda/techmodel/techmodelreader.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2.2 - (show annotations) (download)
Tue Feb 15 17:55:25 2005 UTC (20 years ago) by kusanagi
Branch: MAIN
Changes since 2.1: +16 -1 lines
Fix: if the program started without the environment variable YODA_DATA set the
program crashed. A specific Exception has been added

1
2 #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
9 #include "TROOT.h"
10
11 #include "TechmodelPamelaRun.h"
12 #include "EventReader.h"
13
14 #include <cstdlib>
15 #include <iostream>
16 #include <time.h>
17 #include "Exception.h"
18
19 extern "C" {
20 //#include "DirectoryStructure.h"
21 #include <dirent.h>
22 }
23
24
25
26 using namespace pamela;
27 using namespace log4cxx;
28 using namespace std;
29 using namespace pamela::techmodel;
30
31 static LoggerPtr logger = Logger::getLogger(_T("pamela.techmodel.TechmodelReader"));
32
33 int main(int argc, char* argv[]) {
34
35 stringstream oss;
36 int maxPackets = 0;
37 char nomeFileLog[L_tmpnam];
38 tmpnam(nomeFileLog);
39 DIR *dirp;
40
41 // check if yoda_DATA exist!!!!
42 char *outDir;
43 try {
44 outDir = getenv("YODA_DATA");
45 if (getenv("YODA_DATA") == NULL) throw NotFoundEnvironmentVarException("The variable YODA_DATA has not been found. Please check your environment variables.");
46 } catch (NotFoundEnvironmentVarException exc) {
47 oss.str("");
48 oss << exc.print();
49 logger->fatal(oss.str().c_str());
50 }
51
52 string pathDir(outDir);
53
54 string pathLog = nomeFileLog;
55 bool ANALIZE = false;
56 //---------------- Log4cxx configuration-----------------------------------------------
57 //Define the configuration file to be used on log4cxx
58 PropertyConfigurator::configure(pathDir + "/log4cxx.conf");
59 //BasicConfigurator::configure();
60 //Retrieve the rootLogger and append to it a default FileAppender.
61 //Note that the priority level of the rootLogger (defined in log4cxx.conf) is unmodified
62 //LoggerPtr rootLogger = Logger::getRootLogger();
63
64 //FileAppender *fileAppender = new FileAppender();
65 //fileAppender->setFile(pathLog);
66 //fileAppender->setAppend(false);
67 //fileAppender->setBufferedIO(true); //the default size is 8k
68 //fileAppender->setBufferSize(1000000);
69 //fileAppender->activateOptions();
70 //fileAppender->setLayout(new PatternLayout());
71
72 //FileAppender *fileAppender = new FileAppender(new PatternLayout(), pathLog, false, true, 10000);
73 //rootLogger->addAppender(fileAppender);
74 //rootLogger->removeAppender('A1');
75 //---------------- Log4cxx configuration-----------------------------------------------
76
77 // Check file name
78
79 if (argc < 2){
80 //logger->info(_T("You have forgotten the file name."));
81 cout << "You have forgotten the file name. \n";
82 cout << "Try '--help' for more information. \n";
83 exit(1);
84 }
85
86 if (!strcmp(argv[1], "--help")){
87 cout << "Usage: yoda FILE [OPTION] \n";
88 cout << "\t --help print this help and exit \n";
89 cout << "\t -p maximum number of packets to process [default all] \n";
90 cout << "\t -analize generate pre-defined analisys files (gif/text) inside the unpacking directory\n";
91 exit(1);
92 }
93
94 ifstream from (argv[1]);
95 if (!from) {
96 //logger->info(_T("The file does not exist."));
97 cout << "The file does not exist. \n";
98 exit(1);
99 }
100
101 for (int i = 2; i < argc; i++){
102 if (!strcmp(argv[i], "-p")){
103 if (++i >= argc){
104 cerr << "-p needs arguments. \n";
105 cout << "Try '--help' for more information. \n";
106 exit(1);
107 }
108 if (isdigit(*argv[i])) {
109 maxPackets = atoi(argv[i]);
110 } else {
111 //logger->info(_T("The file does not exist."));
112 cerr << "-p needs a integer value. \n";
113 cout << "Try '--help' for more information. \n";
114 exit(1);
115 }
116 }
117
118 if (!maxPackets){
119 cout << "Try '--help' for more information. \n";
120 exit(1);
121 }
122
123 if (!strcmp(argv[i], "-analize")) ANALIZE = true;
124
125 }
126
127
128 //--------------------------------------------------
129 //This is the configuration for the Yoda Logger
130 //The parameters in the RollingFileAppender means
131 // default ------------>the selected category
132 // YodaLog.txt ------------>the LogFile name
133 // 1000 ------------>The max size (in Kb) of the LogFile
134 // 5 ------------>How many times the file will be backup
135
136 time_t rawtime;
137 struct tm * timeinfo;
138 time ( &rawtime );
139 timeinfo = localtime ( &rawtime );
140
141 oss.str("");
142 oss << "<-------------------------------START UNPACKING------------------------------->\n"
143 << " Starting the program at: " << asctime (timeinfo) << " Opening file: " << argv[1];
144 logger->info(oss.str().c_str());
145
146
147 gROOT->SetBatch(kTRUE);
148 EventReader *reader = new EventReader(maxPackets);
149
150 int num = 0;
151 TechmodelPamelaRun Run(argv[1]);
152 reader->Init(&Run);
153
154 oss.str("");
155 oss << "Init successul ok" << asctime (timeinfo);
156 logger->debug(oss.str().c_str());
157
158 reader->RunEvent(num); //TBD --- eliminate the runNumber
159 reader->Finish();
160 Run.WriteFiles();
161
162 logger->info("<-------------------------------END UNPACKING------------------------------->\n");
163
164 //Momentarly suspended the save
165 //system(command.c_str());
166 }

  ViewVC Help
Powered by ViewVC 1.1.23