Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef __GO4MACRO__
00016 #ifndef __GO4ANAMACRO__
00017 #define __NOGO4MACRO__
00018 #endif
00019 #endif
00020
00021 #include <fstream.h>
00022 #include "Riostream.h"
00023 using namespace std;
00024
00025 #include "RVersion.h"
00026
00027
00028
00029
00030
00031
00032
00033 void paramiter(TDirectory *dir, const char* wildcard, TList* found)
00034 {
00035 #ifdef __GO4MACRO__
00036 TRegexp wild(wildcard, kTRUE);
00037 TGo4Iter iter(go4->Browser()->BrowserSlot("Analysis"), kFALSE);
00038 while(iter.next()) {
00039 if(!iter.isfolder() && (TString(iter.getname()).Index(wild) != kNPOS)) {
00040 TString itemname = Form("Analysis/%s", iter.getfullname());
00041 if (go4->Browser()->ItemKind(itemname.Data()) == TGo4Access::kndGo4Param) {
00042 go4->FetchItem(itemname.Data(), 1000);
00043 TObject* obj = go4->GetObject(itemname.Data());
00044 if (obj) found->Add(obj);
00045 }
00046 }
00047 }
00048 #endif
00049 #ifdef __GO4ANAMACRO__
00050 Bool_t reset = kTRUE;
00051 TObject* obj = 0;
00052 while((obj = go4->NextMatchingObject(wildcard,"Go4",reset))!=0) {
00053 reset = kFALSE;
00054 if (obj->InheritsFrom("TGo4Parameter")) found->Add(obj);
00055 }
00056 #endif
00057 #ifdef __NOGO4MACRO__
00058 if (dir==0) return;
00059
00060 TRegexp wild(wildcard, kTRUE);
00061 TIter next(dir->GetListOfKeys());
00062 TKey *key = 0;
00063 while((key=(TKey*)next())) {
00064 if(strcmp(key->GetClassName(),"TDirectoryFile")==0)
00065 paramiter(dir->GetDirectory(key->GetName()), wildcard, found);
00066 else
00067 if (TString(key->GetName()).Index(wild) != kNPOS) {
00068 TClass* cl = TClass::GetClass(key->GetClassName());
00069 if ((cl!=0) && cl->InheritsFrom("TGo4Parameter")) {
00070 TObject* obj = dir->Get(key->GetName());
00071 if (obj) found->Add(obj);
00072 }
00073 }
00074 }
00075 #endif
00076 }
00077
00078 TString MakeFuncName(const char* main, const char* objname)
00079 {
00080 TString subfunc = Form("%s_%s", main, objname);
00081 subfunc.ReplaceAll("#","_");
00082 subfunc.ReplaceAll("(","_");
00083 subfunc.ReplaceAll(")","_");
00084 subfunc.ReplaceAll("*","_");
00085 subfunc.ReplaceAll("@","_");
00086 subfunc.ReplaceAll("[","_");
00087 subfunc.ReplaceAll("]","_");
00088 return subfunc;
00089 }
00090
00091
00092
00093 Bool_t save1param(TObject* obj, const char* prefix)
00094 {
00095 if ((obj==0) || !obj->InheritsFrom("TGo4Parameter")) return kFALSE;
00096
00097 TGo4Parameter* param = (TGo4Parameter*) obj;
00098
00099 TString funcname = MakeFuncName(prefix, param->GetName());
00100
00101 std::cout << "Write macro " << funcname << std::endl;
00102 std::ofstream xout(funcname+".C");
00103
00104 xout << Form("// written by macro saveparam.C at %s",TDatime().AsString()) << std::endl;
00105 xout << Form("void %s()", funcname.Data()) << std::endl;
00106 xout << Form("{") << std::endl;
00107 xout << Form("#ifndef __GO4ANAMACRO__") << std::endl;
00108 xout << Form(" std::cout << \"Macro %s can execute only in analysis\" << std::endl;", funcname.Data()) << std::endl;
00109 xout << Form(" return;") << std::endl;
00110 xout << Form("#endif") << std::endl;
00111
00112 param->SavePrimitive(xout, "savemacro");
00113
00114 xout << std::endl;
00115 xout << "}" << std::endl;
00116 xout.close();
00117 return kTRUE;
00118 }
00119
00120 #ifdef __NOGO4MACRO__
00121
00122 void saveparam(const char* file, const char* wildcard = "*", const char* prefix = "set")
00123 {
00124 TFile *f = TFile::Open(file,"r");
00125 #else
00126 void saveparam(const char* wildcard = "*", const char* prefix = "set")
00127 {
00128 TFile *f = 0;
00129 const char* file = 0;
00130 #endif
00131
00132 TList lst;
00133 paramiter(f, wildcard, &lst);
00134 if (f!=0) { delete f; f = 0; }
00135
00136 TIter next(&lst);
00137
00138 TObject* obj = 0;
00139 while((obj = next()) != 0)
00140 save1param(obj, prefix);
00141
00142 lst.Clear();
00143 }
00144
00145