source: branches/MarsMoreSimulationTruth/mfileio/MRead.cc@ 19128

Last change on this file since 19128 was 9037, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 3.9 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
56// --------------------------------------------------------------------------
57//
58// Return the name of the file we are actually reading from.
59//
60TString MRead::GetFileName() const
61{
62 TString name(GetFullFileName());
63 if (name.IsNull())
64 return "<n/a>";
65 return gSystem->BaseName(name);
66}
67
68Int_t MRead::AddFiles(MDirIter &files)
69{
70 files.Reset();
71
72 Int_t rc = 0;
73
74 TString str;
75 while (!(str=files.Next()).IsNull())
76 {
77 const Int_t num = AddFile(str);
78 if (num<0)
79 *fLog << warn << "Warning: AddFile(\"" << str << "\") returned " << num << "... skipped." << endl;
80 else
81 rc += num;
82 }
83
84 return rc;
85}
86
87// --------------------------------------------------------------------------
88//
89// Read the setup from a TEnv:
90// File0, File1, File2, ..., File10, ..., File100, ...
91//
92// Searching stops if the first key isn't found in the TEnv
93//
94// Enclosing quotation marks (") are removed
95//
96// Number of entries at the moment not supported
97//
98Int_t MRead::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
99{
100 //
101 // Search (beginning with 0) all keys
102 //
103 int i=0;
104 while (1)
105 {
106 TString idx = "File";
107 idx += i;
108
109 // Output if print set to kTRUE
110 if (!IsEnvDefined(env, prefix, idx, print))
111 break;
112
113 // Try to get the file name
114 TString name = GetEnvValue(env, prefix, idx, "");
115 if (name.IsNull())
116 {
117 *fLog << warn << prefix+"."+idx << " empty." << endl;
118 continue;
119 }
120
121 if (name.BeginsWith("\"") && name.EndsWith("\""))
122 {
123 name.Remove(name.Last('\"'), 1);
124 name.Remove(name.First('\"'), 1);
125 }
126
127 *fLog << inf << "Add File: " << name << endl;
128
129 AddFile(name);
130 i++;
131 }
132
133 return i!=0;
134}
135
136// --------------------------------------------------------------------------
137//
138// Check if the file exists and has read permission. Derived classes
139// should also check whether its file type is correct.
140//
141// Returning 0 means: file doesn't exist.
142// A returned number corresponds to different file types (1 if only
143// one exists)
144//
145Byte_t MRead::IsFileValid(const char *name)
146{
147 return !gSystem->AccessPathName(name, kFileExists) ? 1 : 0;
148}
Note: See TracBrowser for help on using the repository browser.