/* ======================================================================== *\ ! ! * ! * This file is part of MARS, the MAGIC Analysis and Reconstruction ! * Software. It is distributed to you in the hope that it can be a useful ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes. ! * It is distributed WITHOUT ANY WARRANTY. ! * ! * Permission to use, copy, modify and distribute this software and its ! * documentation for any purpose is hereby granted without fee, ! * provided that the above copyright notice appear in all copies and ! * that both that copyright notice and this permission notice appear ! * in supporting documentation. It is provided "as is" without express ! * or implied warranty. ! * ! ! ! Author(s): Thomas Bretz 04/2002 ! ! Copyright: MAGIC Software Development, 2000-2002 ! ! \* ======================================================================== */ ///////////////////////////////////////////////////////////////////////////// // // MDataChain // ///////////////////////////////////////////////////////////////////////////// #include "MDataChain.h" #include // isalnum, ... #include // strtod, ... #include "MLog.h" #include "MLogManip.h" #include "MDataList.h" #include "MDataValue.h" #include "MDataMember.h" # ClassImp(MDataChain); MDataChain::MDataChain(const char *rule, const char *name, const char *title) { fName = name ? name : "MDataChain"; fTitle = title ? title : "MDataChain"; *fLog << inf << "Trying to resolve rule..." << endl; if (!(fMember=ParseString(rule, 1))) { *fLog << err << dbginf << "Parsing '" << rule << "' failed." << endl; return; } *fLog << inf << endl; *fLog << "Using Filter rule " << fMember->GetName(); *fLog << " for " << fName << ":" << endl; fMember->Print(); *fLog << endl << endl; } // -------------------------------------------------------------------------- // // PreProcesses all members in the list // Bool_t MDataChain::PreProcess(const MParList *pList) { return fMember ? fMember->PreProcess(pList) : kFALSE; } // -------------------------------------------------------------------------- // // Destructor. Delete filters. // MDataChain::~MDataChain() { if (fMember) delete fMember; } // -------------------------------------------------------------------------- // // Returns the number of alphanumeric characters (including '.') // in the given string // Int_t MDataChain::IsAlNum(TString txt) { int l = txt.Length(); for (int i = 0; iInheritsFrom(MDataMember::Class()) || type!=is) { MDataList *list = new MDataList(is); list->SetName(Form("List_%c_%d", is, 10*level+nlist++)); list->SetOwner(); list->AddToList(member0); member0 = list; type = is; } continue; } *fLog << err << dbginf << "Syntax Error: First argument of condition missing." << endl; if (member0) delete member0; return NULL; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': { char *end; Double_t num = strtod(txt.Data(), &end); if (!end || txt.Data()==end) { *fLog << err << dbginf << "Error trying to convert '" << txt << "' to value." << endl; if (member0) delete member0; return NULL; } txt.Remove(0, end-txt.Data()); newmember = new MDataValue(num); } break; default: int i = IsAlNum(txt); if (i==0) { *fLog << err << dbginf << "Syntax Error: Name of data member missing in '" << txt << "'" << endl; if (member0) delete member0; return NULL; } TString text = txt(0, i); txt.Remove(0, i); // *fLog << all << "Creating: '" << text.Data() << "'" << endl; newmember = new MDataMember(text.Data()); } if (!member0) { member0 = newmember; continue; } if (!member0->InheritsFrom(MDataList::Class())) continue; ((MDataList*)member0)->AddToList(newmember); } return member0; } Double_t MDataChain::GetValue() const { return fMember ? fMember->GetValue() : 0; }