source: trunk/MagicSoft/Mars/mfileio/MRead.cc@ 2560

Last change on this file since 2560 was 2298, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 3.6 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Thomas Bretz, 12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2003
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26// //
27// MRead //
28// //
29// Base class for all reading tasks //
30// //
31// You can set a selector. Depending on the impelementation in the derived //
32// class it can be used to skip events, if the filter return kFALSE. //
33// Make sure that the selector (filter) doesn't need information which //
34// doesn't exist before reading an event! //
35// //
36/////////////////////////////////////////////////////////////////////////////
37#include "MRead.h"
38
39#include "MLog.h"
40#include "MLogManip.h"
41
42#include "MDirIter.h"
43
44ClassImp(MRead);
45
46using namespace std;
47
48Bool_t MRead::Rewind()
49{
50 *fLog << err << "ERROR - Rewind() not implemented for " << GetDescriptor() << endl;
51 return kFALSE;
52}
53
54Int_t MRead::AddFiles(MDirIter &files)
55{
56 files.Reset();
57
58 Int_t rc = 0;
59
60 TString str;
61 while (!(str=files.Next()).IsNull())
62 {
63 const Int_t num = AddFile(str);
64 if (num<0)
65 *fLog << warn << "Warning: AddFile(\"" << str << "\") returned " << num << "... skipped." << endl;
66 else
67 rc += num;
68 }
69
70 return rc;
71}
72
73// --------------------------------------------------------------------------
74//
75// Read the setup from a TEnv:
76// File0, File1, File2, ..., File10, ..., File100, ...
77//
78// Searching stops if the first key isn't found in the TEnv
79//
80// Enclosing quotation marks (") are removed
81//
82// Number of entries at the moment not supported
83//
84Bool_t MRead::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
85{
86 //
87 // Search (beginning with 0) all keys
88 //
89 int i=0;
90 while (1)
91 {
92 TString idx = "File";
93 idx += i;
94
95 // Output if print set to kTRUE
96 if (!IsEnvDefined(env, prefix, idx, print))
97 break;
98
99 // Try to get the file name
100 TString name = GetEnvValue(env, prefix, idx, "");
101 if (name.IsNull())
102 {
103 *fLog << warn << prefix+"."+idx << " empty." << endl;
104 continue;
105 }
106
107 if (name.BeginsWith("\"") && name.EndsWith("\""))
108 {
109 name.Remove(name.Last('\"'), 1);
110 name.Remove(name.First('\"'), 1);
111 }
112
113 *fLog << inf << "Add File: " << name << endl;
114
115 AddFile(name);
116 i++;
117 }
118
119 return i!=0;
120}
Note: See TracBrowser for help on using the repository browser.