source: trunk/MagicSoft/Mars/mbase/MReadMarsFile.cc@ 1181

Last change on this file since 1181 was 1172, checked in by tbretz, 23 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 4.8 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@uni-sw.gwdg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2001
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26// //
27// MReadMarsFile //
28// //
29// This task works more or less like MReadTree, but in addition PreProcess //
30// reads all the information from the 'RunHeader' tree. //
31// //
32// Warning: Until now this works only for 'one run header per file' //
33// //
34/////////////////////////////////////////////////////////////////////////////
35
36#include "MReadMarsFile.h"
37
38#include "MLog.h"
39#include "MLogManip.h"
40
41#include "MParList.h"
42#include "MTaskList.h"
43
44ClassImp(MReadMarsFile);
45
46// --------------------------------------------------------------------------
47//
48// Default constructor. It creates a MReadTree object to read the
49// RunHeaders and disables Auto Scheme for this tree.
50//
51MReadMarsFile::MReadMarsFile(const char *tname, const char *fname,
52 const char *name, const char *title)
53 : MReadTree(tname, fname)
54{
55 fName = name ? name : "MReadMarsFile";
56 fTitle = title ? title : "Task to loop over all events in a tree of a Mars file.";
57
58 //
59 // open the input stream
60 //
61 fRun = new MReadTree("RunHeaders", fname);
62
63 //
64 // This disables the auto scheme. because reading new runheader is done
65 // at a low frequency we don't loose time if we always read all
66 // runheaders
67 //
68 fRun->DisableAutoScheme();
69}
70
71// --------------------------------------------------------------------------
72//
73// Destructor. Deleted the MReadTree object for the RunHeaders
74//
75MReadMarsFile::~MReadMarsFile()
76{
77 delete fRun;
78}
79
80// --------------------------------------------------------------------------
81//
82// see MReadTree::AddFile, too. The file is also added to the chain for
83// the run headers. If adding file gives a different result for both
84// chains -1 is returned, otherwise the number of files which were added.
85//
86Int_t MReadMarsFile::AddFile(const char *fname)
87{
88 //
89 // FIXME! A check is missing whether the file already exists or not.
90 //
91 //
92 // returns the number of file which were added
93 //
94 Int_t n1 = fRun->AddFile(fname);
95 Int_t n2 = MReadTree::AddFile(fname);
96
97 return n1 != n2 ? -1 : n1;
98}
99
100// --------------------------------------------------------------------------
101//
102// This overload MReadTree::Notify. Before the MReadTree Notify
103// TObjects are called the RunHeaders of the next files are read.
104//
105// WARNING: This doesn't work correctly yet, if the files are not read in
106// increasing order.
107//
108Bool_t MReadMarsFile::Notify()
109{
110 //
111 // Try to read the new run headers. If reading the new run header
112 // was successfull call the ReInits
113 //
114 if (fRun->Process())
115 {
116 TString name(GetFileName());
117 name.Remove(0, name.Last('/')+1);
118
119 *fLog << inf << "MReadMarsFile: Switching to '" << name << "' ";
120 *fLog << "(before event #" << GetEventNum()-1 << ")" << endl;
121
122 fTaskList->ReInit();
123 //MReadTree::Notify();
124 }
125 else
126 *fLog << warn << "Warning: Cannot read new runheaders after reading event #" << GetEventNum() << endl;
127
128 return kTRUE;
129}
130
131// --------------------------------------------------------------------------
132//
133// PreProcessed the MReadTree to read the run headers and its base class.
134// see MReadTree::PreProcess for more information
135//
136Bool_t MReadMarsFile::PreProcess(MParList *pList)
137{
138 fTaskList = (MTaskList*)pList->FindObject("MTaskList");
139
140 if (!fRun->PreProcess(pList))
141 return kFALSE;
142
143 if (!fRun->Process())
144 return kFALSE;
145
146 fRun->SetEventNum(0);
147
148 return MReadTree::PreProcess(pList);
149}
Note: See TracBrowser for help on using the repository browser.