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