source: fact/tools/rootmacros/PulseTemplates/configfile.C@ 19876

Last change on this file since 19876 was 13860, checked in by Jens Buss, 13 years ago
Initial commit: class for reading an interpreting a selfdefined rc filse
  • Property svn:executable set to *
File size: 15.4 KB
Line 
1#include "configfile.h"
2using namespace std;
3
4/////////////////////////////// PUBLIC ///////////////////////////////////////
5
6//============================= LIFECYCLE ====================================
7
8configfile::configfile(
9 TString rcFileName,
10 TString processType
11 )
12{
13 mRcFileName = rcFileName;
14 mProcessType = processType;
15
16 cout << "...opening RC File" << endl;
17 DefineTokens();
18
19 // reading rc-File:
20 ifstream rcFile;
21 rcFile.open(mRcFileName, ifstream::in);
22
23 bool rcReadable = true;
24 rcReadable = CheckIfRcReadable( rcFile );
25 if ( !rcReadable )
26 {
27 cerr << "rc File is not readable" << endl;
28 return;
29 }
30 SetParamFromRc( rcFile );
31 rcFile.close();
32 return;
33}
34
35//XX::XX(const XX&)
36//{
37//}// XX
38
39configfile::~configfile()
40{
41}// ~XX
42
43
44//============================= OPERATORS ====================================
45
46//XX&
47//XX::operator=(const XX&);
48//{
49// return *this;
50
51//}// =
52
53//============================= OPERATIONS ===================================
54
55// decode arguments
56void
57configfile::DefineTokens()
58{
59 mDataFileNameRC = "DataFileName";
60 mDrsFileNameRC = "DrsFileName";
61 mInputFileRC = "InputFileName";
62 mInputPathRC = "InputPath";
63 mOutputFileRC = "OutputFileName";
64 mOutputPathRC = "OutPutPath";
65
66 mFirstPixelRC = "firstPixel";
67 mNumPixelRC = "nPixel";
68 mPixelSetSizeRC = "pixelSetSize";
69 mFirstEventRC = "firstEvent";
70 mNumEventsRC = "nEvents";
71 mMaxOrderRC = "maxPulseOrder";
72
73 mGainMeanRC = "gainMean";
74 mBSLMeanRC = "bslMean";
75
76 mAmplWindowWidthRC = "AmplWindowWidth";
77 mAvg1RC = "sildingAvgWin1";
78 mAvg2RC = "sildingAvgWin2";
79 mOverlayWindowLeftRC = "olWindowLeft";
80 mOverlayWindowRightRC = "olWindowRight";
81
82 mHistoOptionsRC = "histoOptions";
83 mRefreshRateRC = "refreshRate";
84 mSpikeDebugRC = "spikeDebug";
85 mVerbLevelRC = "verbosityLevel";
86 mDbgPixelRC = "debugPixel";
87 mSaveRC = "saveResults";
88 mProduceGraphicRC = "produceGraphic";
89 mFitDataRC = "fitdata";
90 mTestModeRC = "testmode";
91 mPrintStatsRC = "stats";
92
93 cout << "...defining tokens" << endl;
94}
95
96bool
97configfile::CheckIfRcReadable( ifstream& rcFile )
98{
99 cout << "...checking if config file readable" << endl;
100 if(!rcFile)
101 {
102 cerr << "***** no config-file in the user defined directory.\n"
103 << "Check the path .\n" << endl;
104 return false;
105 }
106
107 if(!rcFile.good()) {
108 cerr << "***** not able to read config-file." << endl;
109 return false;
110 }
111 return true;
112}
113
114void
115configfile::SetParamFromRc( ifstream& rcFile )
116{
117 cout << "...reading RC File" << endl;
118
119 int index;
120 char input[256];
121 char* word;
122 TString keyword;
123
124 const char* comment = "#";
125 while (rcFile.good())
126 {
127 if(!rcFile.good())
128 {
129 cout << "no more lines to read" << endl;
130 break;
131 }
132
133 rcFile.getline(input,256); // get one line of the file parameter.config
134 word = strtok(input," \t");
135
136 if(word != NULL)
137 {
138 keyword = word;
139
140 }
141 index = 0;
142 while ( word != NULL)
143 {
144 // skip comment lines
145 if ( *word == *comment)
146 {
147 break ;
148 }
149 else
150 {
151 CheckKeywords( keyword, word, index );
152 }
153
154 word = strtok(NULL, " "); // take next token or set word to NULL
155 index++;
156 }
157 }
158
159 PrintSetParameters();
160}
161
162void
163configfile::CheckKeywords(
164 TString keyword,
165 const char* word,
166 int index
167 )
168{
169 const char* yes = "yes";
170 const char* no = "no";
171
172 //------------------------------------------------------------------------
173 // filenames and pathes
174 //------------------------------------------------------------------------
175
176 // get Input Data File Name
177 if( keyword == mDataFileNameRC )
178 {
179 if (mProcessType.Contains("emplate")) return;
180 if(index == 1)
181 {
182 mDataFileName = word;
183 }
184 }
185
186 // get Input DRS-Config File Name
187 else if( keyword == mDrsFileNameRC )
188 {
189 if (mProcessType.Contains("emplate")) return;
190 if(index == 1)
191 {
192 mDrsFileName = word;
193 }
194 }
195
196 // get Input Path
197 else if( keyword == mInputPathRC )
198 {
199 if(index == 1)
200 {
201 mInputPath = word;
202 }
203 }
204
205 // get Input File
206 else if(keyword == mInputFileRC)
207 {
208 if (mProcessType.Contains("verlay")) return;
209 if(index == 1)
210 {
211 mInputFile = word;
212 }
213 }
214
215 // get Output Path
216 else if(keyword == mOutputPathRC)
217 {
218 if(index == 1)
219 {
220 mOutputPath = word;
221
222 }
223
224 }
225
226 // get Output File
227 else if(keyword == mOutputFileRC)
228 {
229 if(index == 1)
230 {
231 mOutputFile = word;
232 }
233 }
234
235 //------------------------------------------------------------------------
236 // Parameters
237 //------------------------------------------------------------------------
238
239 // get number of first event
240 else if(keyword == mFirstEventRC)
241 {
242 if (mProcessType.Contains("emplate")) return;
243 if(index == 1)
244 {
245 mFirstEvent = atoi(word);
246
247 }
248 }
249
250 // get number of events computed
251 else if(keyword == mNumEventsRC)
252 {
253 if (mProcessType.Contains("emplate")) return;
254 if(index == 1)
255 {
256 mNumEvents = atoi(word);
257
258 }
259 }
260
261 // get number of first pixel
262 else if(keyword == mFirstPixelRC)
263 {
264 if(index == 1)
265 {
266 mFirstPixel = atoi(word);
267 }
268 }
269
270 // get maximum number of pixels computed
271 else if(keyword == mNumPixelRC)
272 {
273 if(index == 1)
274 {
275 mNumPixel = atoi(word);
276
277 }
278 }
279
280 // get size of a pixel set
281 else if(keyword == mPixelSetSizeRC)
282 {
283 if(index == 1)
284 {
285 mPixelSetSize = atoi(word);
286
287 }
288 }
289
290 // get condition for maxeOrderRC graphic
291 else if(keyword == mMaxOrderRC)
292 {
293 if(index == 1)
294 {
295 mMaxOrder = atoi(word);
296
297 }
298 }
299
300 // get parameter for mean of gain
301 else if(keyword == mGainMeanRC)
302 {
303 if (mProcessType.Contains("emplate")) return;
304 if(index == 1)
305 {
306 mGainMean = atof(word);
307
308 }
309 }
310
311 // get parameter for mean of baseline
312 else if(keyword == mBSLMeanRC)
313 {
314 if (mProcessType.Contains("emplate")) return;
315 if(index == 1)
316 {
317 mBSLMean = atof(word);
318
319 }
320 }
321
322
323 // get parameter for the windowwith of 1. Slidiging average filter
324 else if(keyword == mAmplWindowWidthRC)
325 {
326 if (mProcessType.Contains("emplate")) return;
327 if(index == 1)
328 {
329 mAmplWindowWidth = atoi(word);
330 }
331 }
332
333 // get parameter for the windowwith of 1. Slidiging average filter
334 else if(keyword == mAvg1RC)
335 {
336 if (mProcessType.Contains("emplate")) return;
337 if(index == 1)
338 {
339 mAvg1 = atoi(word);
340
341 }
342 }
343
344 // get parameter for the windowwith of 2. Slidiging average filter
345 else if(keyword == mAvg2RC)
346 {
347 if (mProcessType.Contains("emplate")) return;
348 if(index == 1)
349 {
350 mAvg2 = atoi(word);
351
352 }
353 }
354
355 // get parameter for left edge of window in wich pulses are overlayed
356 else if(keyword == mOverlayWindowLeftRC)
357 {
358 if (mProcessType.Contains("emplate")) return;
359 if(index == 1)
360 {
361 mOverlayWindowLeft = atoi(word);
362
363 }
364 }
365
366 // get parameter for right edge of window in wich pulses are overlayed
367 else if(keyword == mOverlayWindowRightRC)
368 {
369 if (mProcessType.Contains("emplate")) return;
370 if(index == 1)
371 {
372 mOverlayWindowRight = atoi(word);
373
374 }
375 }
376
377 //------------------------------------------------------------------------
378 // Conditions
379 //------------------------------------------------------------------------
380
381 // get verbositylevel
382 else if(keyword == mVerbLevelRC)
383 {
384 if(index == 1)
385 {
386 mVerbLevel = atoi(word);
387 }
388 }
389
390 // get Refreshrate of histograms
391 else if(keyword == mRefreshRateRC)
392 {
393 if(index == 1)
394 {
395 mRefreshRate = atoi(word);
396 }
397 }
398
399 // get condition for produceing graphic
400 else if(keyword == mProduceGraphicRC)
401 {
402 if(index == 1)
403 {
404 if (*word == *yes)
405 {
406 mProduceGraphic = true;
407
408 }
409 if (*word == *no)
410 {
411 mProduceGraphic = false;
412
413 }
414 }
415 }
416
417 // get condition for saving
418 else if(keyword == mSaveRC)
419 {
420 if(index == 1)
421 {
422 if (*word == *yes)
423 {
424 mSave = true;
425
426 }
427 if (*word == *no)
428 {
429 mSave = false;
430
431 }
432 }
433 }
434
435 // get condition for mFitDataRC graphic
436 else if(keyword == mFitDataRC)
437 {
438 if(index == 1)
439 {
440 if (*word == *yes)
441 {
442 mFitData = true;
443
444 }
445 if (*word == *no)
446 {
447 mFitData = false;
448
449 }
450 }
451 }
452
453 // get condition for mPrintStatsRC graphic
454 else if(keyword == mPrintStatsRC)
455 {
456 if(index == 1)
457 {
458 if (*word == *yes)
459 {
460 mPrintStats = true;
461
462 }
463 if (*word == *no)
464 {
465 mPrintStats = false;
466
467 }
468 }
469 }
470
471 // get condition for showing single pixel graphics
472 else if(keyword == mDbgPixelRC)
473 {
474 if(index == 1)
475 {
476 if (*word == *yes)
477 {
478 mDbgPixel = true;
479
480 }
481 if (*word == *no)
482 {
483 mDbgPixel = false;
484 }
485 }
486 }
487
488 // get condition for showing spike detection histograms
489 else if(keyword == mSpikeDebugRC)
490 {
491 if (mProcessType.Contains("emplate")) return;
492 if(index == 1)
493 {
494 if (*word == *yes)
495 {
496 mSpikeDebug = true;
497
498 }
499 if (*word == *no)
500 {
501 mSpikeDebug = false;
502
503 }
504 }
505 }
506
507 // get condition for showing spike detection histograms
508 else if(keyword == mTestModeRC)
509 {
510 if (mProcessType.Contains("emplate")) return;
511 if(index == 1)
512 {
513 if (*word == *yes)
514 {
515 mTestMode = true;
516
517 }
518 if (*word == *no)
519 {
520 mTestMode = false;
521
522 }
523 }
524 }
525
526 // get condition for showing single pixel graphics
527 else if(keyword == mHistoOptionsRC)
528 {
529 if(index == 1)
530 {
531 mHistoOptions = word;
532 }
533 }
534return ;
535}
536//EOF: CheckKeywords
537
538void
539configfile::PrintSetParameters()
540{
541 //------------------------------------------------------------------------
542 // filenames and pathes
543 //------------------------------------------------------------------------
544 if (mProcessType.Contains("verlay"))
545 {
546 cout << endl
547 << "data file:\t\t\t"
548 << mDataFileName << endl;
549
550 cout << "drs config File:\t\t"
551 << mDrsFileName << endl;
552 }
553 cout << endl
554 << "input Path:\t\t\t"
555 << mInputPath << endl;
556
557 if (mProcessType.Contains("emplate"))
558 {
559 cout << "input data File:\t\t"
560 << mInputFile << endl;
561 }
562 cout << "output folder:\t\t\t"
563 << mOutputPath << endl;
564
565 cout << "output data File:\t\t"
566 << mOutputFile << endl;
567 cout << endl;
568
569 //------------------------------------------------------------------------
570 // Parameters
571 //------------------------------------------------------------------------
572
573 cout << "First Pixel:\t\t\t"
574 << mFirstPixel << endl;
575
576 cout << "# of pixels:\t\t\t";
577 if ( mNumPixel == -1 ) cout << "All" << endl;
578 else cout << mNumPixel << endl;
579
580 cout << "Size of Pixelset:\t\t";
581 if ( mPixelSetSize == -1 ) cout << "Max" << endl;
582 else cout << mPixelSetSize << endl;
583
584 if (mProcessType.Contains("verlay"))
585 {
586 cout << "First Event:\t\t\t"
587 << mFirstEvent << endl;
588
589 cout << "# of Events:\t\t\t";
590 if ( mNumEvents == -1 ) cout << "All" << endl;
591 else cout << mNumEvents << endl;
592 cout << endl;
593 }
594
595 cout << "Maximum Pulseorder:\t\t"
596 << mMaxOrder << endl;
597 if (mProcessType.Contains("verlay"))
598 {
599 cout << "Mean of Gain:\t\t\t"
600 << mGainMean << endl;
601
602 cout << "Mean of Baseline:\t\t"
603 << mBSLMean << endl;
604
605 cout << "Sliding Average 1:\t\t"
606 << mAvg1 << endl;
607
608 cout << "Sliding Average 2:\t\t"
609 << mAvg2 << endl;
610
611 cout << "Overlay Window's Left Edge:\t"
612 << mOverlayWindowLeft << endl;
613
614 cout << "Overlay Window's Right Edge:\t"
615 << mOverlayWindowRight << endl;
616 }
617 //------------------------------------------------------------------------
618 // Conditions
619 //-----------------------------------------------------------------------
620
621 cout << "Verbosity Level:\t\t"
622 << mVerbLevel << endl;
623
624 cout << "Histogram Options:\t\t"
625 << mHistoOptions << endl;
626
627 cout << "Refresh Rate:\t\t\t"
628 << mRefreshRate
629 << endl
630 << endl;
631
632 if (mProduceGraphic) cout << "will produce graphics" << endl;
633 else cout << "will not produce graphics" << endl;
634
635 if (mSave) cout << "will save" << endl;
636 else cout << "will not save" << endl;
637
638 if (mProcessType.Contains("emplate"))
639 {
640 if (mFitData) cout << "will fit" << endl;
641 else cout << "will not fit" << endl;
642 }
643
644 if (mPrintStats) cout << "will print stats" << endl;
645 else cout << "will not print stats" << endl;
646
647 if (mDbgPixel) cout << "will show single pixel histos " << endl;
648 else cout << "will not show single pixel histos " << endl;
649
650 if (mProcessType.Contains("verlay"))
651 {
652 if (mSpikeDebug) cout << "will show pulse smothing histos " << endl;
653 else cout << "will not show pulse smothing histos " << endl;
654
655 if (mTestMode) cout << "will operate in testmode " << endl;
656 else cout << "will not operate in testmode " << endl;
657 }
658}
659
660//============================= ACESS ===================================
661//============================= INQUIRY ===================================
662/////////////////////////////// PROTECTED ///////////////////////////////////
663
664/////////////////////////////// PRIVATE ///////////////////////////////////
Note: See TracBrowser for help on using the repository browser.