source: tags/Mars-V0.7/mbase/MReadMarsFile.cc

Last change on this file was 1211, 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-2002
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 *fLog << inf << "MReadMarsFile: Switching to '" << GetFileName() << "' ";
117 *fLog << "(before event #" << GetEventNum()-1 << ")" << endl;
118
119 fTaskList->ReInit();
120 //MReadTree::Notify();
121 }
122 else
123 *fLog << warn << "Warning: Cannot read new runheaders after reading event #" << GetEventNum() << endl;
124
125 return kTRUE;
126}
127
128// --------------------------------------------------------------------------
129//
130// PreProcessed the MReadTree to read the run headers and its base class.
131// see MReadTree::PreProcess for more information
132//
133Bool_t MReadMarsFile::PreProcess(MParList *pList)
134{
135 fTaskList = (MTaskList*)pList->FindObject("MTaskList");
136
137 if (!fRun->PreProcess(pList))
138 return kFALSE;
139
140 if (!fRun->Process())
141 return kFALSE;
142
143 fRun->SetEventNum(0);
144
145 return MReadTree::PreProcess(pList);
146}
Note: See TracBrowser for help on using the repository browser.