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