| 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 10/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
|
|---|
| 19 | !
|
|---|
| 20 | ! Copyright: MAGIC Software Development, 2000-2003
|
|---|
| 21 | !
|
|---|
| 22 | !
|
|---|
| 23 | \* ======================================================================== */
|
|---|
| 24 |
|
|---|
| 25 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 26 | //
|
|---|
| 27 | // MContinue
|
|---|
| 28 | //
|
|---|
| 29 | // Does nothing than return kCONTINUE in the Process-function
|
|---|
| 30 | // (use with filters). For more details see the description of the
|
|---|
| 31 | // constructors.
|
|---|
| 32 | //
|
|---|
| 33 | // To invert the meaning of the contained filter call SetInverted()
|
|---|
| 34 | //
|
|---|
| 35 | // Input Containers:
|
|---|
| 36 | // -/-
|
|---|
| 37 | //
|
|---|
| 38 | // Output Containers:
|
|---|
| 39 | // -/-
|
|---|
| 40 | //
|
|---|
| 41 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 42 | #include "MContinue.h"
|
|---|
| 43 |
|
|---|
| 44 | #include "MLog.h"
|
|---|
| 45 | #include "MLogManip.h"
|
|---|
| 46 |
|
|---|
| 47 | #include "MF.h"
|
|---|
| 48 | #include "MParList.h"
|
|---|
| 49 | #include "MTaskList.h"
|
|---|
| 50 |
|
|---|
| 51 | ClassImp(MContinue);
|
|---|
| 52 |
|
|---|
| 53 | using namespace std;
|
|---|
| 54 |
|
|---|
| 55 | // --------------------------------------------------------------------------
|
|---|
| 56 | //
|
|---|
| 57 | // Default constructor.
|
|---|
| 58 | //
|
|---|
| 59 | // Use this constructor if a rule (see MF for more details) shell be used.
|
|---|
| 60 | // MContinue will create a MF object and use it as a filter for the
|
|---|
| 61 | // instance. The MF-Task is added to the tasklist in front of the MContinue
|
|---|
| 62 | // instance and also automatically deleted, eg.
|
|---|
| 63 | // MContinue cont("MHillas.fSize<20");
|
|---|
| 64 | // tasklist.AddToList(&cont);
|
|---|
| 65 | // would skip all events which fullfill "MHillas.fSize<20" from this point
|
|---|
| 66 | // in the tasklist.
|
|---|
| 67 | // It is not necessary to put the filter in the tasklist. The PreProcess
|
|---|
| 68 | // will search for the filter and if it isn't found in the tasklist it
|
|---|
| 69 | // is added to the tasklist in front of MContinue.
|
|---|
| 70 | //
|
|---|
| 71 | // Use the default constructor (or an empty rule) if you want to read the
|
|---|
| 72 | // rule from a resource file.
|
|---|
| 73 | //
|
|---|
| 74 | MContinue::MContinue(const TString rule, const char *name, const char *title)
|
|---|
| 75 | : fTaskList(0)
|
|---|
| 76 | {
|
|---|
| 77 | fName = name ? name : "MContinue";
|
|---|
| 78 | fTitle = title ? title : "Task returning kCONTINUE";
|
|---|
| 79 |
|
|---|
| 80 | if (rule.IsNull())
|
|---|
| 81 | return;
|
|---|
| 82 |
|
|---|
| 83 | SetBit(kIsOwner);
|
|---|
| 84 |
|
|---|
| 85 | MTask::SetFilter(new MF(rule, TString("MF(")+fName+")"));
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | // --------------------------------------------------------------------------
|
|---|
| 89 | //
|
|---|
| 90 | // Use this if you have a filter. Would be the same as if you would call:
|
|---|
| 91 | // MContinue cont;
|
|---|
| 92 | // cont.SetFilter(f);
|
|---|
| 93 | // It is not necessary to put the filter in the tasklist. The PreProcess
|
|---|
| 94 | // will search for the filter and if it isn't found in the tasklist it
|
|---|
| 95 | // is added to the tasklist in front of MContinue.
|
|---|
| 96 | //
|
|---|
| 97 | MContinue::MContinue(MFilter *f, const char *name, const char *title)
|
|---|
| 98 | : fTaskList(0)
|
|---|
| 99 | {
|
|---|
| 100 | fName = name ? name : "MContinue";
|
|---|
| 101 | fTitle = title ? title : "Task returning kCONTINUE";
|
|---|
| 102 |
|
|---|
| 103 | SetFilter(f);
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | // --------------------------------------------------------------------------
|
|---|
| 107 | //
|
|---|
| 108 | // Delete the filter if it was created automatically
|
|---|
| 109 | //
|
|---|
| 110 | MContinue::~MContinue()
|
|---|
| 111 | {
|
|---|
| 112 | if (TestBit(kIsOwner))
|
|---|
| 113 | delete GetFilter();
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | // --------------------------------------------------------------------------
|
|---|
| 117 | //
|
|---|
| 118 | // PreProcess tries to find the tasklist MTaskList, adds the filter
|
|---|
| 119 | // before this instance to the tasklist and preprocesses the filter.
|
|---|
| 120 | //
|
|---|
| 121 | Int_t MContinue::PreProcess(MParList *list)
|
|---|
| 122 | {
|
|---|
| 123 | ResetBit(kFilterIsPrivate);
|
|---|
| 124 |
|
|---|
| 125 | if (!GetFilter())
|
|---|
| 126 | {
|
|---|
| 127 | if (IsAllowEmpty())
|
|---|
| 128 | {
|
|---|
| 129 | *fLog << warn << GetDescriptor() << " - WARNING: Filter empty... task removed." << endl;
|
|---|
| 130 | return kSKIP;
|
|---|
| 131 | }
|
|---|
| 132 |
|
|---|
| 133 | *fLog << err << dbginf << "Unknown fatal Error! (fFilter=NULL?!?)" << endl;
|
|---|
| 134 | return kFALSE;
|
|---|
| 135 | }
|
|---|
| 136 |
|
|---|
| 137 | fTaskList = (MTaskList*)list->FindTaskListWithTask(this);
|
|---|
| 138 | if (!fTaskList)
|
|---|
| 139 | {
|
|---|
| 140 | *fLog << err << dbginf << "ERROR - MTasklist not found... abort." << endl;
|
|---|
| 141 | return kFALSE;
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|
| 144 | if (fTaskList->FindObject(GetFilter()))
|
|---|
| 145 | {
|
|---|
| 146 | *fLog << inf << dbginf << "The filter is already in the tasklist..." << endl;
|
|---|
| 147 | return kTRUE;
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 | if ((TString)GetFilter()->GetName()==fName)
|
|---|
| 151 | GetFilter()->SetName(Form("MF:%s", fName.Data()));
|
|---|
| 152 |
|
|---|
| 153 | if (!fTaskList->AddToListBefore(GetFilter(), this))
|
|---|
| 154 | {
|
|---|
| 155 | *fLog << err << dbginf << "ERROR - Adding filter before MContinue... abort." << endl;
|
|---|
| 156 | return kFALSE;
|
|---|
| 157 | }
|
|---|
| 158 |
|
|---|
| 159 | // Make sure, that everything is correctly propageted to the childs
|
|---|
| 160 | GetFilter()->SetDisplay(fDisplay);
|
|---|
| 161 | GetFilter()->SetLogStream(fLog);
|
|---|
| 162 | GetFilter()->SetAccelerator(GetAccelerator());
|
|---|
| 163 |
|
|---|
| 164 | // Remeber that the filter is not already in tasklist
|
|---|
| 165 | SetBit(kFilterIsPrivate);
|
|---|
| 166 |
|
|---|
| 167 | return GetFilter()->CallPreProcess(list);
|
|---|
| 168 | }
|
|---|
| 169 |
|
|---|
| 170 | // --------------------------------------------------------------------------
|
|---|
| 171 | //
|
|---|
| 172 | // Propagate display to filter (if set)
|
|---|
| 173 | //
|
|---|
| 174 | void MContinue::SetDisplay(MStatusDisplay *d)
|
|---|
| 175 | {
|
|---|
| 176 | if (GetFilter())
|
|---|
| 177 | GetFilter()->SetDisplay(d);
|
|---|
| 178 |
|
|---|
| 179 | MTask::SetDisplay(d);
|
|---|
| 180 | }
|
|---|
| 181 |
|
|---|
| 182 | // --------------------------------------------------------------------------
|
|---|
| 183 | //
|
|---|
| 184 | // Propagate log stream to filter (if set)
|
|---|
| 185 | //
|
|---|
| 186 | void MContinue::SetLogStream(MLog *lg)
|
|---|
| 187 | {
|
|---|
| 188 | if (GetFilter())
|
|---|
| 189 | GetFilter()->SetLogStream(lg);
|
|---|
| 190 |
|
|---|
| 191 | MTask::SetLogStream(lg);
|
|---|
| 192 | }
|
|---|
| 193 |
|
|---|
| 194 | // --------------------------------------------------------------------------
|
|---|
| 195 | //
|
|---|
| 196 | // If the filter was added to the tasklist automatically it is removed
|
|---|
| 197 | // from the tasklist.
|
|---|
| 198 | //
|
|---|
| 199 | Int_t MContinue::PostProcess()
|
|---|
| 200 | {
|
|---|
| 201 | if (!TestBit(kFilterIsPrivate))
|
|---|
| 202 | return kTRUE;
|
|---|
| 203 |
|
|---|
| 204 | if (fTaskList->RemoveFromList(GetFilter()))
|
|---|
| 205 | return kTRUE;
|
|---|
| 206 |
|
|---|
| 207 | *fLog << err << "ERROR: MContinue::PostProcess - Cannot remove Filter from tasklist" << endl;
|
|---|
| 208 |
|
|---|
| 209 | return kFALSE;
|
|---|
| 210 | }
|
|---|
| 211 |
|
|---|
| 212 | // --------------------------------------------------------------------------
|
|---|
| 213 | //
|
|---|
| 214 | // If a filter is setup, call its 'IsInverted' to invert its meaning
|
|---|
| 215 | // (boolean "not")
|
|---|
| 216 | //
|
|---|
| 217 | void MContinue::SetInverted(Bool_t i)
|
|---|
| 218 | {
|
|---|
| 219 | if (GetFilter())
|
|---|
| 220 | GetFilter()->SetInverted(i);
|
|---|
| 221 | }
|
|---|
| 222 |
|
|---|
| 223 | // --------------------------------------------------------------------------
|
|---|
| 224 | //
|
|---|
| 225 | // If a filter is setup, its IsInverted status is returned. If now filter
|
|---|
| 226 | // has been setup yet, kFALSE is returned.
|
|---|
| 227 | //
|
|---|
| 228 | Bool_t MContinue::IsInverted() const
|
|---|
| 229 | {
|
|---|
| 230 | return GetFilter() ? GetFilter()->IsInverted() : kFALSE;
|
|---|
| 231 | }
|
|---|
| 232 |
|
|---|
| 233 | void MContinue::Print(Option_t *) const
|
|---|
| 234 | {
|
|---|
| 235 | *fLog << all << GetDescriptor() << ":";
|
|---|
| 236 | if (GetFilter())
|
|---|
| 237 | *fLog << " <" << GetFilter()->GetDescriptor() << ">";
|
|---|
| 238 | *fLog << endl;
|
|---|
| 239 | if (GetFilter())
|
|---|
| 240 | GetFilter()->Print();
|
|---|
| 241 | }
|
|---|
| 242 |
|
|---|
| 243 | // --------------------------------------------------------------------------
|
|---|
| 244 | //
|
|---|
| 245 | // Check for corresponding entries in resource file and setup filters.
|
|---|
| 246 | // Avoid trailing 0's!
|
|---|
| 247 | //
|
|---|
| 248 | // Example:
|
|---|
| 249 | // test.C:
|
|---|
| 250 | // MContinue cont("", "MyContinue");
|
|---|
| 251 | //
|
|---|
| 252 | // test.rc:
|
|---|
| 253 | // MyContinue.Condition: {0} && {1}
|
|---|
| 254 | // MyContinue.Inverted: yes
|
|---|
| 255 | // MyContinue.0: MHillas.fSize>1000
|
|---|
| 256 | // MyContinue.1: MHillas.fSize<10000
|
|---|
| 257 | // or (the syntax might change in the future!)
|
|---|
| 258 | // MyContinue.Condition: <MMyClass>
|
|---|
| 259 | // MMyClass.Variable1: ...
|
|---|
| 260 | // MMyClass.Variable2: ...
|
|---|
| 261 | //
|
|---|
| 262 | // For more details see MF::ReadEnv
|
|---|
| 263 | //
|
|---|
| 264 | Int_t MContinue::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
|
|---|
| 265 | {
|
|---|
| 266 | MFilter *f = MTask::GetFilter();
|
|---|
| 267 | if (IsEnvDefined(env, prefix, "Condition", print))
|
|---|
| 268 | {
|
|---|
| 269 | TString txt = GetEnvValue(env, prefix, "Condition", "");
|
|---|
| 270 | txt = txt.Strip(TString::kBoth);
|
|---|
| 271 | if (txt.BeginsWith("<") && txt.EndsWith(">"))
|
|---|
| 272 | {
|
|---|
| 273 | const TString name = txt(1, txt.Length()-2);
|
|---|
| 274 | f = (MFilter*)GetNewObject(name, MFilter::Class());
|
|---|
| 275 | if (!f)
|
|---|
| 276 | return kERROR;
|
|---|
| 277 | }
|
|---|
| 278 | }
|
|---|
| 279 |
|
|---|
| 280 | if (!f)
|
|---|
| 281 | f = new MF;
|
|---|
| 282 |
|
|---|
| 283 | f->SetName(fName);
|
|---|
| 284 |
|
|---|
| 285 | const Bool_t rc = f->ReadEnv(env, prefix, print);
|
|---|
| 286 | if (rc!=kTRUE)
|
|---|
| 287 | {
|
|---|
| 288 | if (f!=MTask::GetFilter())
|
|---|
| 289 | delete f;
|
|---|
| 290 | return rc;
|
|---|
| 291 | }
|
|---|
| 292 |
|
|---|
| 293 | if (f != MTask::GetFilter())
|
|---|
| 294 | {
|
|---|
| 295 | if (TestBit(kIsOwner))
|
|---|
| 296 | delete GetFilter();
|
|---|
| 297 | SetBit(kIsOwner);
|
|---|
| 298 | }
|
|---|
| 299 | MTask::SetFilter(f);
|
|---|
| 300 |
|
|---|
| 301 | return kTRUE;
|
|---|
| 302 | }
|
|---|