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