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

Last change on this file since 6463 was 5160, checked in by tbretz, 20 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 <TSystem.h>
40
41#include "MLog.h"
42#include "MLogManip.h"
43
44#include "MDirIter.h"
45
46ClassImp(MRead);
47
48using namespace std;
49
50Bool_t MRead::Rewind()
51{
52 *fLog << err << "ERROR - Rewind() not implemented for " << GetDescriptor() << endl;
53 return kFALSE;
54}
55
56Int_t MRead::AddFiles(MDirIter &files)
57{
58 files.Reset();
59
60 Int_t rc = 0;
61
62 TString str;
63 while (!(str=files.Next()).IsNull())
64 {
65 const Int_t num = AddFile(str);
66 if (num<0)
67 *fLog << warn << "Warning: AddFile(\"" << str << "\") returned " << num << "... skipped." << endl;
68 else
69 rc += num;
70 }
71
72 return rc;
73}
74
75// --------------------------------------------------------------------------
76//
77// Read the setup from a TEnv:
78// File0, File1, File2, ..., File10, ..., File100, ...
79//
80// Searching stops if the first key isn't found in the TEnv
81//
82// Enclosing quotation marks (") are removed
83//
84// Number of entries at the moment not supported
85//
86Int_t MRead::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
87{
88 //
89 // Search (beginning with 0) all keys
90 //
91 int i=0;
92 while (1)
93 {
94 TString idx = "File";
95 idx += i;
96
97 // Output if print set to kTRUE
98 if (!IsEnvDefined(env, prefix, idx, print))
99 break;
100
101 // Try to get the file name
102 TString name = GetEnvValue(env, prefix, idx, "");
103 if (name.IsNull())
104 {
105 *fLog << warn << prefix+"."+idx << " empty." << endl;
106 continue;
107 }
108
109 if (name.BeginsWith("\"") && name.EndsWith("\""))
110 {
111 name.Remove(name.Last('\"'), 1);
112 name.Remove(name.First('\"'), 1);
113 }
114
115 *fLog << inf << "Add File: " << name << endl;
116
117 AddFile(name);
118 i++;
119 }
120
121 return i!=0;
122}
123
124// --------------------------------------------------------------------------
125//
126// Check if the file exists and has read permission. Derived classes
127// should also check whether its file type is correct.
128//
129// Returning 0 means: file doesn't exist.
130// A returned number corresponds to different file types (1 if only
131// one exists)
132//
133Byte_t MRead::IsFileValid(const char *name)
134{
135 return !gSystem->AccessPathName(name, kFileExists) ? 1 : 0;
136}
Note: See TracBrowser for help on using the repository browser.