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

Annotation of /yoda/techmodel/techmodelreader.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6.1 - (hide annotations) (download)
Wed Mar 8 13:51:45 2006 UTC (18 years, 9 months ago) by kusanagi
Branch: MAIN
Changes since 6.0: +46 -25 lines
Update: add the -o option to allow the bypass of the YODA_DATA environment variable

1 kusanagi 1.1
2 kusanagi 1.7 #include <log4cxx/logger.h>
3     #include <log4cxx/propertyconfigurator.h>
4 kusanagi 1.1 #include "EventReader.h"
5     #include <time.h>
6 kusanagi 2.2
7 kusanagi 1.1 extern "C" {
8 kusanagi 5.1 #include <dirent.h>
9 kusanagi 1.1 }
10    
11    
12 kusanagi 2.1
13 kusanagi 1.1 using namespace pamela;
14 kusanagi 1.7 using namespace log4cxx;
15     using namespace std;
16 kusanagi 1.1 using namespace pamela::techmodel;
17    
18 kusanagi 1.7 static LoggerPtr logger = Logger::getLogger(_T("pamela.techmodel.TechmodelReader"));
19 kusanagi 1.1
20     int main(int argc, char* argv[]) {
21 kusanagi 1.7
22     stringstream oss;
23     int maxPackets = 0;
24 kusanagi 5.1 bool multiFile = 0;
25     short compression = 3;
26 kusanagi 1.7 char nomeFileLog[L_tmpnam];
27     tmpnam(nomeFileLog);
28     DIR *dirp;
29 kusanagi 6.1 char *outDir = "";
30    
31 kusanagi 1.7 //---------------- 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 kusanagi 6.1
50 kusanagi 1.1 // Check file name
51 kusanagi 1.7
52     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);
57     }
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 kusanagi 6.1 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 kusanagi 1.7 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 kusanagi 1.1 exit(1);
74     }
75    
76 kusanagi 1.7 for (int i = 2; i < argc; i++){
77     if (!strcmp(argv[i], "-p")){
78     if (++i >= argc){
79     cerr << "-p needs arguments. \n";
80     cout << "Try '--help' for more information. \n";
81     exit(1);
82     }
83 kusanagi 5.1 if (isdigit(*argv[i]) && (atoi(argv[i]) > 0)) {
84 kusanagi 1.7 maxPackets = atoi(argv[i]);
85     } else {
86     //logger->info(_T("The file does not exist."));
87     cerr << "-p needs a integer value. \n";
88     cout << "Try '--help' for more information. \n";
89     exit(1);
90     }
91 kusanagi 5.1 continue;
92 kusanagi 1.7 }
93    
94 kusanagi 6.1 if (!strcmp(argv[i], "-multi")) multiFile = 1;
95 kusanagi 5.1
96     if (!strcmp(argv[i], "-c")){
97     if (++i >= argc){
98     cerr << "-c needs arguments. \n";
99     cout << "Try '--help' for more information. \n";
100     exit(1);
101     }
102     if ((isdigit(*argv[i])) && ( (atoi(argv[i]) >= 0) && (atoi(argv[i]) <= 9))) {
103     compression = atoi(argv[i]);
104     } else {
105     //logger->info(_T("The file does not exist."));
106     cerr << "-c needs a integer value beetween 0 and 9. \n";
107     cout << "Try '--help' for more information. \n";
108     exit(1);
109     }
110     continue;
111 kusanagi 1.7 }
112 kusanagi 6.1
113     if (!strcmp(argv[i], "-o")){
114     if (++i >= argc){
115     cerr << "-o needs arguments. \n";
116     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 kusanagi 1.7 }
133 kusanagi 1.6
134 kusanagi 6.1 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 kusanagi 1.1 time_t rawtime;
154     struct tm * timeinfo;
155     time ( &rawtime );
156     timeinfo = localtime ( &rawtime );
157 kusanagi 1.7
158 kusanagi 2.1 oss.str("");
159 kusanagi 1.7 oss << "<-------------------------------START UNPACKING------------------------------->\n"
160     << " Starting the program at: " << asctime (timeinfo) << " Opening file: " << argv[1];
161     logger->info(oss.str().c_str());
162    
163    
164 kusanagi 1.1 gROOT->SetBatch(kTRUE);
165 kusanagi 1.7 EventReader *reader = new EventReader(maxPackets);
166 kusanagi 1.1
167     int num = 0;
168 kusanagi 5.1 TechmodelPamelaRun Run(argv[1], outDir, multiFile, compression);
169 kusanagi 1.7 reader->Init(&Run);
170    
171 kusanagi 2.1 oss.str("");
172 kusanagi 1.7 oss << "Init successul ok" << asctime (timeinfo);
173     logger->debug(oss.str().c_str());
174    
175     reader->RunEvent(num); //TBD --- eliminate the runNumber
176     reader->Finish();
177 kusanagi 1.1 Run.WriteFiles();
178 kusanagi 1.7
179     logger->info("<-------------------------------END UNPACKING------------------------------->\n");
180    
181     //Momentarly suspended the save
182     //system(command.c_str());
183 kusanagi 1.1 }

  ViewVC Help
Powered by ViewVC 1.1.23