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

Annotation of /yoda/techmodel/techmodelreader.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6.6 - (hide annotations) (download)
Mon Oct 16 10:59:14 2006 UTC (18 years, 2 months ago) by mocchiut
Branch: MAIN
CVS Tags: YODA6_3/12
Changes since 6.5: +7 -3 lines
Added branch SoftInfo to store YODA software version in the data

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

  ViewVC Help
Powered by ViewVC 1.1.23