void rewrite(const char *filename = "inherit.root") { TFile *file = TFile::Open(filename,"READ"); TFile *out = TFile::Open("inherit-2.root","RECREATE"); fprintf(stdout,"Testing Directory\n"); void *h = file->Get("holder"); // gDebug = 7; fprintf(stdout,"Testing Writing\n"); out->WriteObjectAny(h,"Holder","holdercopy"); fprintf(stdout,"Delete original\n"); TClass *cl = TClass::GetClass("Holder"); cl->Destructor(h); fprintf(stdout,"Testing the re-wrote object\n"); h = out->Get("holdercopy"); fprintf(stdout,"Delete copy\n"); cl->Destructor(h); // fprintf(stdout,"Testing TTree\n"); // TTree *tree; file->GetObject("tree",tree); // tree->GetEntry(0); // delete tree; }
TSClass* RegisterEnum(TClassRegistryParams& params, const char* source) { auto syntax = params.syntax; TClass* cl = new TClass(syntax->base_class.get()); syntax->base_class->AddNested(cl); syntax->lexer.ParseSource(source); cl->AnalyzeSyntax(syntax->lexer); syntax->lexer.GetToken(TTokenType::Done); TSClass* scl = new TSClass(syntax->sem_base_class.get(), cl); syntax->sem_base_class->AddClass(scl); scl->Build(); std::vector<TSClassField*> static_fields; std::vector<TSLocalVar*> static_variables; TGlobalBuildContext global_build_context(&static_fields, &static_variables); scl->LinkSignature(global_build_context); scl->InitAutoMethods(); scl->LinkBody(global_build_context); scl->CheckForErrors(); std::vector<TSClass*> owners; scl->CalculateSizes(owners); scl->CalculateMethodsSizes(); owners.clear(); syntax->sem_base_class->CalculateSizes(owners);//т.к. в этом классе могут использоваться другие шаблонные класса, реализацию которых нужно обновить InitializeStaticClassFields(static_fields, *params.static_objects); InitializeStaticVariables(static_variables, *params.static_objects); return scl; }
void CompDir(TDirectory *t1, TDirectory *tref, int run1, int runref) { t1->cd(); //loop on all entries of this directory TKey *key; TIter nextkey(t1->GetListOfKeys()); while ((key = (TKey*)nextkey())) { const char *classname = key->GetClassName(); TClass *cl = gROOT->GetClass(classname); if (!cl) continue; if (cl->InheritsFrom("TDirectory")) { t1->cd(key->GetName()); TDirectory *subdir = gDirectory; tref->cd(key->GetName()); TDirectory *subdirref = gDirectory; CompDir(subdir,subdirref,run1,runref); } else if (cl->InheritsFrom("TObjArray")) { TObjArray *subdir = (TObjArray*)t1->Get(key->GetName()); TObjArray *subdirref = (TObjArray*)tref->Get(key->GetName()); CompDir(subdir,subdirref,run1,runref); } else if (TString(classname) == "TH1F") { TH1 *h1 = (TH1*)t1->Get(key->GetName()); TH1 *href = (TH1*)tref->Get(key->GetName()); CompHist(h1,href,run1,runref); } else { // do nothing } } }
void KVIDentifier::CloneScaleStore(Int_t newzt, Int_t newar, Double_t dy, Double_t sx, Double_t sy) { // Create a new line from the selected one // with a new Z and A (optional) // this new line is scale from the selected one with a vertical sy // and horizontal sx (optional) factor // you need to undraw and draw the grid to see its implementation TClass* cl = new TClass(this->IsA()->GetName()); KVIDentifier* idbis = (KVIDentifier*)cl->New(); Double_t xx, yy; for (Int_t nn = 0; nn < this->GetN(); nn += 1) { this->GetPoint(nn, xx, yy); idbis->SetPoint(nn, xx, yy + dy); } idbis->SetOnlyZId(OnlyZId()); idbis->SetZ(newzt); idbis->SetMassFormula(GetMassFormula()); idbis->SetEditable(IsEditable()); if (newar != -1) { idbis->SetA(newar); } if ((sx > 0.) && (sy > 0.)) idbis->Scale(sx, sy); this->GetParent()->AddIdentifier(idbis); this->GetParent()->UnDraw(); this->GetParent()->Draw(); delete cl; }
TKey* FindMethod( TString name, TDirectory *dir=0 ) { // find the key for a method if (dir==0) dir = gDirectory; TIter mnext(dir->GetListOfKeys()); TKey *mkey; TKey *retkey=0; Bool_t loop=kTRUE; while (loop) { mkey = (TKey*)mnext(); if (mkey==0) { loop = kFALSE; } else { TString clname = mkey->GetClassName(); TClass *cl = gROOT->GetClass(clname); if (cl->InheritsFrom("TDirectory")) { TString mname = mkey->GetName(); // method name TString tname = "Method_"+name; // target name if (mname==tname) { // target found! loop = kFALSE; retkey = mkey; } } } } return retkey; }
void TestSchemaEvolution::gatherAllClasses() { static const char *classes[] = {"TH1F", "TH1S", "TH1D", "TH1I", "TH2F", "TH2S", "TH2D", "TH2I", "TH3F", "TH3S", "TH3D", "TH3I", "TProfile", "TProfile2D", "TF1", 0}; int i = 0; while (classes[i]) { TClass *tcl = TClass::GetClass(classes[i]); if (!tcl) continue; unique_classes_.insert(std::make_pair(classes[i], tcl->GetClassVersion())); analyseClass(tcl); ++i; } }
void CopyDir(TDirectory *source) { //copy all objects and subdirs of directory source as a subdir of the current directory source->ls(); TDirectory *savdir = gDirectory; TDirectory *adir = savdir->mkdir(source->GetName()); adir->cd(); //loop on all entries of this directory TKey *key; TIter nextkey(source->GetListOfKeys()); while ((key = (TKey*)nextkey())) { const char *classname = key->GetClassName(); TClass *cl = gROOT->GetClass(classname); if (!cl) continue; if (cl->InheritsFrom(TDirectory::Class())) { source->cd(key->GetName()); TDirectory *subdir = gDirectory; adir->cd(); CopyDir(subdir); adir->cd(); } else if (cl->InheritsFrom(TTree::Class())) { TTree *T = (TTree*)source->Get(key->GetName()); adir->cd(); TTree *newT = T->CloneTree(-1,"fast"); newT->Write(); } else { source->cd(); TObject *obj = key->ReadObj(); adir->cd(); obj->Write(); delete obj; } } adir->SaveSelf(kTRUE); savdir->cd(); }
std::vector<TString> GetInputVariableNames(TDirectory *dir ) { TIter next(dir->GetListOfKeys()); TKey* key = 0; //set<std::string> varnames; std::vector<TString> names; while ((key = (TKey*)next())) { if (key->GetCycle() != 1) continue; TClass *cl = gROOT->GetClass(key->GetClassName()); if (!cl->InheritsFrom("TH1")) continue; TString name(key->GetName()); Int_t pos = name.First("__"); name.Remove(pos); Bool_t hasname = false; std::vector<TString>::const_iterator iter = names.begin(); while(iter != names.end()){ if(name.CompareTo(*iter)==0) hasname=true; iter++; } if(!hasname) names.push_back(name); } return names; }
void efficiencies( TString fin = "TMVA.root", Int_t type = 2, Bool_t useTMVAStyle = kTRUE ) { // argument: type = 1 --> plot efficiency(B) versus eff(S) // type = 2 --> plot rejection (B) versus efficiency (S) // set style and remove existing canvas' TMVAGlob::Initialize( useTMVAStyle ); // checks if file with name "fin" is already open, and if not opens one TFile* file = TMVAGlob::OpenFile( fin ); // check if multi-cut MVA or only one set of MVAs Bool_t multiMVA=kFALSE; TIter nextDir(file->GetListOfKeys()); TKey *key; // loop over all directories and check if // one contains the key word 'multicutMVA' while ((key = (TKey*)nextDir())) { TClass *cl = gROOT->GetClass(key->GetClassName()); if (!cl->InheritsFrom("TDirectory")) continue; TDirectory *d = (TDirectory*)key->ReadObj(); TString path(d->GetPath()); if (path.Contains("multicutMVA")){ multiMVA=kTRUE; plot_efficiencies( file, type, d ); } } plot_efficiencies( file, type, gDirectory ); return; }
UInt_t GetListOfTitles( TDirectory *rfdir, TList & titles ) { // get a list of titles (i.e TDirectory) given a method dir UInt_t ni=0; if (rfdir==0) return 0; TList *keys = rfdir->GetListOfKeys(); if (keys==0) { cout << "+++ Directory '" << rfdir->GetName() << "' contains no keys" << endl; return 0; } // TIter rfnext(rfdir->GetListOfKeys()); TKey *rfkey; titles.Clear(); titles.SetOwner(kFALSE); while ((rfkey = (TKey*)rfnext())) { // make sure, that we only look at histograms TClass *cl = gROOT->GetClass(rfkey->GetClassName()); if (cl->InheritsFrom("TDirectory")) { titles.Add(rfkey); ni++; } } cout << "--- Found " << ni << " instance(s) of the method " << rfdir->GetName() << endl; return ni; }
KVVarGlob *KVEventSelector::AddGV(const Char_t * class_name, const Char_t * name) { //Add a global variable to the list of variables for the analysis. // //"class_name" must be the name of a valid class inheriting from KVVarGlob, e.g. any of the default global //variable classes defined as part of the standard KaliVeda package (in libKVvVarGlob.so). See //"Class Reference" page on website for the available classes (listed by category under "Global Variables: ..."). // //USER-DEFINED GLOBAL VARIABLES //The user may use her own global variables in an analysis class, without having to add them to the main libraries. //If the given class name is not known, it is assumed to be a user-defined class and we attempt to compile and load //the class from the user's source code. For this to work, the user must: // // (1) add to the ROOT macro path the directory where her class's source code is kept, e.g. in $HOME/.rootrc // add the following line: // // +Unix.*.Root.MacroPath: $(HOME)/myVarGlobs // // (2) for each user-defined class, add a line to $HOME/.kvrootrc to define a "plugin". E.g. for a class called MyNewVarGlob, // // +Plugin.KVVarGlob: MyNewVarGlob MyNewVarGlob MyNewVarGlob.cpp+ "MyNewVarGlob()" // // It is assumed that MyNewVarGlob.h and MyNewVarGlob.cpp will be found in $HOME/myVarGlobs (in this example). // //"name" is a unique name for the new global variable object which will be created and added to the internal //list of global variables. This name can be used to retrieve the object (see GetGV) in the user's analysis. // //Returns pointer to new global variable object in case more than the usual default initialisation is necessary. KVVarGlob *vg = 0; TClass *clas = gROOT->GetClass(class_name); if (!clas) { //class not in dictionary - user-defined class ? Look for plugin. TPluginHandler *ph = KVBase::LoadPlugin("KVVarGlob", class_name); if (!ph) { //not found Error("AddGV(const Char_t*,const Char_t*)", "Called with class_name=%s.\nClass is unknown: not in standard libraries, and plugin (user-defined class) not found", class_name); return 0; } else { vg = (KVVarGlob *) ph->ExecPlugin(0); } } else if (!clas->InheritsFrom("KVVarGlob")) { Error("AddGV(const Char_t*,const Char_t*)", "%s is not a valid class deriving from KVVarGlob.", class_name); return 0; } else { vg = (KVVarGlob *) clas->New(); } vg->SetName(name); AddGV(vg); return vg; }
void runCintexReflexOrder() { gSystem->Setenv("LINES","-1"); gSystem->Load("libCintex"); gSystem->Load("libReflexDict"); ROOT::Cintex::Cintex::Enable(); TClass* cl = TClass::GetClass("Reflex::Scope"); TMethod* m = (TMethod*) cl->GetListOfMethods()->FindObject("AddMemberTemplate"); TMethodArg* arg = (TMethodArg*) m->GetListOfMethodArgs()->First(); cout << "AddMemberTemplate() arg0: " << arg->GetFullTypeName() << endl; }
void counts(int run, int lumistart, int lumiend, string type, map<string,vector<tripletI> > &cnt, vector<tripletD> &cntref, string hlttype, bool docnt, bool doref) { TString filename = basedir + Form("/DQM_V0001_HLTpb_R000%i.root",run); TFile *f = new TFile(filename); if (!f->IsOpen()) { cout << "Error, could not open " << filename << endl; return; } TString tdirname = Form("DQMData/Run %i/HLT/Run summary/TriggerRates/",run) + TString(type); f->cd(tdirname); TProfile *hlumi = (TProfile*) f->Get(Form("DQMData/Run %i/HLT/Run summary/LumiMonitoring/lumiVsLS",run)); if (extrapol) extrapolate(hlumi); // if HLT: accept, error, pass L1 seed, pass prescaler, reject TIter next(gDirectory->GetListOfKeys()); TKey *key; while ((key = (TKey*)next())) { TClass *cl = gROOT->GetClass(key->GetClassName()); // it must be an histogram if (!cl->InheritsFrom("TH1")) continue; TH1 *h = (TH1*)key->ReadObj(); // the name must match one of the requested patterns bool match=false; TString hname(h->GetName()); for (vector<TRegexp>::const_iterator it=patterns.begin(); it!=patterns.end(); it++) { if (hname(*it).Length()!=0) { match=true; break; } } if (!match) continue; int nlumis = (lumiend+1-lumistart); if (extrapol) extrapolate(h); if (type != "HLT") fill(cnt[h->GetName()], h, run, lumistart, lumiend, docnt); else { string htitle(h->GetTitle()); if (htitle.find(hlttype) == string::npos) continue; else { TString thepath; Ssiz_t from=0; TString(htitle).Tokenize(thepath,from," "); fill(cnt[thepath.Data()], h, run, lumistart, lumiend, docnt); } } } if (doref) { fill(cntref, hlumi, run, lumistart, lumiend); } f->Close(); delete f; }
void TestSchemaEvolution::loopOnDataMembers(TClass *tcl) { TList *dms = tcl->GetListOfDataMembers(); TIter next(dms); while (TObject *obj = next()) { TClass *cl = TClass::GetClass(((TDataMember *)obj)->GetFullTypeName()); if (cl && cl->HasDictionary()) { unique_classes_.insert(std::make_pair(cl->GetName(), cl->GetClassVersion())); analyseClass(cl); } } }
template <class T> bool print_root_classname(const T *obj, const char* expect) { TClass *cl = testGetClass(typeid(*obj)); if (!cl || strcmp(cl->GetName(),expect)!=0 ) { cerr << "ERROR: in retrieving TClass"; if (cl) { cerr << " found " << cl->GetName() << endl; } else { cerr << " NOT found!" << endl; }; return 0; } cerr << cl->GetName() << endl; return 1; }
void TestSchemaEvolution::loopOnBases(TClass *tcl) { TList *bases = tcl->GetListOfBases(); TIter next(bases); while (TObject *obj = next()) { TClass *cl = TClass::GetClass(obj->GetName()); if (cl && cl->HasDictionary()) { unique_classes_.insert(std::make_pair(cl->GetName(), cl->GetClassVersion())); analyseClass(cl); } } }
// Generate dictionaries required to read `tree`. void ensure_dictionary(const char *class_name) { TClass* claim = TClass::GetClass(class_name); if (claim && claim->GetCollectionProxy() && dynamic_cast<TEmulatedCollectionProxy*>(claim->GetCollectionProxy())) { // Only executed if the dictionary isn't currently present init(); char *orig_dir = get_current_dir_name(); chdir(dictionary_tmpdir); std::cerr << "Generating dictionary for " << class_name << std::endl; gInterpreter->GenerateDictionary(class_name); chdir(orig_dir); free(static_cast<void*>(orig_dir)); } }
void loopdir() { TString tutdir = gROOT->GetTutorialsDir(); TFile *f1 = TFile::Open(tutdir+"/hsimple.root"); TIter next(f1->GetListOfKeys()); TKey *key; TCanvas c1; c1.Print("hsimple.ps["); while ((key = (TKey*)next())) { TClass *cl = gROOT->GetClass(key->GetClassName()); if (!cl->InheritsFrom("TH1")) continue; TH1 *h = (TH1*)key->ReadObj(); h->Draw(); c1.Print("hsimple.ps"); } c1.Print("hsimple.ps]"); }
std::vector<TString> GetClassNames(TDirectory *dir ) { TIter next(dir->GetListOfKeys()); TKey* key = 0; //set<std::string> varnames; std::vector<TString> names; while ((key = (TKey*)next())) { if (key->GetCycle() != 1) continue; TClass *cl = gROOT->GetClass(key->GetClassName()); if (!cl->InheritsFrom("TH1")) continue; TString name(key->GetName()); name.ReplaceAll("_Deco",""); name.ReplaceAll("_Gauss",""); name.ReplaceAll("_PCA",""); name.ReplaceAll("_Id",""); name.ReplaceAll("_vs_",""); char c = '_'; Int_t pos = name.Last(c); name.Remove(0,pos+1); /*Int_t pos = name.First("__"); name.Remove(0,pos+2); char c = '_'; pos = name.Last(c); name.Remove(pos); if(name.Contains("Gauss")){ pos = name.Last(c); name.Remove(pos); } pos = name.Last(c); if(pos!=-1) name.Remove(0,pos+1); */ Bool_t hasname = false; std::vector<TString>::const_iterator iter = names.begin(); while(iter != names.end()){ if(name.CompareTo(*iter)==0) hasname=true; iter++; } if(!hasname) names.push_back(name); } return names; }
TKey *NextKey( TIter & keyIter, TString className) { TKey *key=(TKey *)keyIter.Next(); TKey *rkey=0; Bool_t loop=(key!=0); // while (loop) { TClass *cl = gROOT->GetClass(key->GetClassName()); if (cl->InheritsFrom(className.Data())) { loop = kFALSE; rkey = key; } else { key = (TKey *)keyIter.Next(); if (key==0) loop = kFALSE; } } return rkey; }
Bool_t KVRTGIDManager::ReadAsciiFile(const Char_t *filename){ //Read file, create KVTGID fits corresponding to information in file. //Comment line beginning by '#' is skipped. ifstream fitfile ( filename ); if ( !fitfile.good() ) { Error ( "KVRTGIDManager::ReadAsciiFile", "File %s cannot be opened", filename ); return kFALSE; } KVString s, cname; while ( fitfile.good() ) { //read a line s.ReadLine ( fitfile ); if ( s.BeginsWith ( "#" ) ) continue; if ( s.BeginsWith ( "++" ) ) { //New fit //Get name of class by stripping off the '+' at the start of the line s.Remove ( 0, 2 ); cname = s; cname.Remove(s.Index("::") ); TClass *cl = TClass::GetClass(cname.Data()); if( cl && cl->InheritsFrom("KVTGID") ){ s.Remove ( 0, s.Index("::")+2 ); // Make new identification function KVTGID *fit = NULL; fit = KVTGID::ReadFromAsciiFile(s.Data(),fitfile); AddTGIDToGlobalList(fit); // when mass identification is possible, make a copy // for Z identification if(!fit->GetZorA()){ KVTGIDZ *fitz = new KVTGIDZ(*fit); fitz->SetTitle(Form("COPY from %p", fit)); AddTGIDToGlobalList(fitz); } } } } fitfile.close(); return kTRUE; }
void DeclareExternClass(TClassRegistryParams& params, TClassBinding* binding) { std::string source = BuildExternClassSource(binding->class_name, binding->methods); auto& syntax = params.syntax; TClass* cl = new TClass(syntax->base_class.get()); syntax->base_class->AddNested(cl); syntax->lexer.ParseSource(source.c_str()); cl->AnalyzeSyntax(syntax->lexer); syntax->lexer.GetToken(TTokenType::Done); binding->compiled = new TSClass(syntax->sem_base_class.get(), cl); syntax->sem_base_class->AddClass(binding->compiled); binding->compiled->Build(); binding->compiled->SetSize(LexerIntSizeOf(binding->size) / sizeof(int)); //binding->compiled->SetAutoMethodsInitialized(); }
int execInterpClassNew() { gROOT->ProcessLine(".L classlib.cxx+"); TClass * c = TClass::GetClass("class1"); if (!c) { fprintf(stderr,"Error: Could retrieve the TClass for class1\n"); return 0; } if (c->IsLoaded()) { fprintf(stderr,"Error: The TClass for class1 is marker as loaded.n"); return 0; } void *p = c->New(); if (!p) { fprintf(stderr,"Error: Could not create an object of type class1.\n"); return 1; } return 0; }
void customContextMenu() { TH1F *h; TH1F *h2; TClassMenuItem *n; TList *l; // Create test histograms h = new TH1F("h","Schtroumpf",100,-4,4); h->FillRandom("gaus"); h->Draw(); h2 = new TH1F("h2","h2",1000,-4,4); h2->FillRandom("gaus",30000); // Retrieve menu list from TClass TClass *cl = h->IsA(); l = cl->GetMenuList(); // Add some items to the popup menus n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "Test object, draw a second h","Draw",h2,"Option_t*"); l->AddFirst(n); n = new TClassMenuItem(TClassMenuItem::kPopupSeparator,cl); l->AddFirst(n); n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "test no 4","poptest4",0,"const char*"); l->AddFirst(n); n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "test no 3","poptest3",0,""); l->AddFirst(n); n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "test no 2 bis","poptest2bis",0,"TObject*",2); l->AddFirst(n); n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "test no 2","poptest2",0,"int,int,TObject*",2); l->AddFirst(n); n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "test no 1","poptest1",0,"int,int"); l->AddFirst(n); }
UInt_t GetListOfKeys( TList& keys, TString inherits, TDirectory *dir=0 ) { // get a list of keys with a given inheritance // the list contains TKey objects if (dir==0) dir = gDirectory; TIter mnext(dir->GetListOfKeys()); TKey *mkey; keys.Clear(); keys.SetOwner(kFALSE); UInt_t ni=0; while ((mkey = (TKey*)mnext())) { // make sure, that we only look at TDirectory with name Method_<xxx> TClass *cl = gROOT->GetClass(mkey->GetClassName()); if (cl->InheritsFrom(inherits)) { keys.Add(mkey); ni++; } } return ni; }
Bool_t ExistMethodName( TString name, TDirectory *dir=0 ) { // find the key for a method if (dir==0) dir = gDirectory; TIter mnext(dir->GetListOfKeys()); TKey *mkey; Bool_t loop=kTRUE; while (loop) { mkey = (TKey*)mnext(); if (mkey==0) { loop = kFALSE; } else { TString clname = mkey->GetClassName(); TString keyname = mkey->GetName(); TClass *cl = gROOT->GetClass(clname); if (keyname.Contains("Method") && cl->InheritsFrom("TDirectory")) { TDirectory* d_ = (TDirectory*)dir->Get( keyname ); if (!d_) { cout << "HUUUGE TROUBLES IN TMVAGlob::ExistMethodName() --> contact authors" << endl; return kFALSE; } TIter mnext_(d_->GetListOfKeys()); TKey *mkey_; while ((mkey_ = (TKey*)mnext_())) { TString clname_ = mkey_->GetClassName(); TClass *cl_ = gROOT->GetClass(clname_); if (cl_->InheritsFrom("TDirectory")) { TString mname = mkey_->GetName(); // method name if (mname==name) { // target found! return kTRUE; } } } } } } return kFALSE; }
void CompDir(TObjArray *t1, TObjArray *tref, int run1, int runref) { //loop on all entries of this directory if (t1->GetSize()==0) return; const char* classname = t1->Last()->ClassName(); TClass *cl = gROOT->GetClass(classname); TKey *key; TObjArrayIter nextkey(t1); while ((key = (TKey*)nextkey())) { if (!tref->FindObject(key->GetName())) continue; if (!cl) continue; if (cl->InheritsFrom("TDirectory")) { CompDir((TDirectory*) key, (TDirectory*) tref->FindObject(key->GetName()),run1,runref); } else if (cl->InheritsFrom("TObjArray")) { CompDir((TObjArray*) key, (TObjArray*) tref->FindObject(key->GetName()),run1,runref); } else if (TString(classname) == "TH1F") { CompHist((TH1F*) key, (TH1F*) tref->FindObject(key->GetName()),run1,runref); } else { // do nothing } } }
void vector_int_cint() { gROOT->ProcessLine(".autodict"); // disable auto building of dictionaries. const std::type_info& t = edm::Wrapper<vector<int> >::typeInfo(); TClass* tc = TClass::GetClass(t); std::cout << tc->GetName() << std::endl; TFile f1("vectorinttest.root"); fwlite::Event ev(&f1); fwlite::Handle<vector<int> > vip; for (ev.toBegin(); ! ev.atEnd(); ++ev) { edm::EventID id = ev.id(); cout << "Run " << id.run() << " event " << id.event() << endl; vip.getByLabel(ev,"VIP"); for (unsigned int i=0; i != vip.ref().size(); ++i) { cout <<vip.ref().at(i)<<" "; } cout << endl; } }
void loopdir(TFile* file, std::vector<TH1*>& histovec, std::vector<TGraph*>& graphvec, std::vector<TEfficiency*>& effvec) { TIter next(file->GetListOfKeys()); TKey *key; while ((key = (TKey*)next())) { TClass *cl = gROOT->GetClass(key->GetClassName()); if (cl->InheritsFrom("TH1")) { TH1 *h = (TH1*)key->ReadObj(); histovec.push_back(h); } else if (cl->InheritsFrom("TGraph")) { TGraph *g = (TGraph*)key->ReadObj(); graphvec.push_back(g); } else if (cl->InheritsFrom("TEfficiency")) { TEfficiency *e = (TEfficiency*)key->ReadObj(); effvec.push_back(e); } } }
//Clone the file excluding the histogram (code stolen from Rene Brun) void copyDir(TDirectory *source,std::string iSkipHist,bool iFirst=true) { //copy all objects and subdirs of directory source as a subdir of the current directory TDirectory *savdir = gDirectory; TDirectory *adir = savdir; if(!iFirst) adir = savdir->mkdir(source->GetName()); if(!iFirst) adir->cd(); //loop on all entries of this directory TKey *key; TIter nextkey(source->GetListOfKeys()); while ((key = (TKey*)nextkey())) { const char *classname = key->GetClassName(); TClass *cl = gROOT->GetClass(classname); if (!cl) continue; if (cl->InheritsFrom(TDirectory::Class())) { source->cd(key->GetName()); TDirectory *subdir = gDirectory; adir->cd(); copyDir(subdir,iSkipHist,false); adir->cd(); } else { source->cd(); TObject *obj = key->ReadObj(); std::string pFullName = std::string(adir->GetName())+"/"+std::string(obj->GetName()); std::string iSkipHist2 = iSkipHist; std::string fine_binning = "_fine_binning"; iSkipHist2.replace(iSkipHist2.find(fine_binning), fine_binning.length(),""); if(pFullName.find(iSkipHist) != std::string::npos || pFullName.find(iSkipHist2) != std::string::npos) { continue; } adir->cd(); obj->Write(); delete obj; } } adir->SaveSelf(kTRUE); savdir->cd(); }