static void notify_textchange(struct datawindow_priv *datawindow, int param1, int param2) { struct attr search_attr; struct search_list_result *res; char search_string[1024]; TCHAR converted_iso2[32]; int lineLength = Edit_LineLength(datawindow->hwndEdit, 0); TCHAR line[lineLength + 1]; (void)Edit_GetLine(datawindow->hwndEdit, 0, line, lineLength + 1); line[lineLength] = 0; (void)ListView_DeleteAllItems( datawindow->hwndList); TCHAR_TO_UTF8(line, search_string); search_attr.type = datawindow->currentSearchState; search_attr.u.str = search_string; if (lineLength<1) return; search_list_search(datawindow->sl, &search_attr, 1); TCHAR *tcharBuffer = NULL; int listIndex = 0; LVITEM lvI; lvI.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE; lvI.state = 0; lvI.stateMask = 0; while ((res=search_list_get_result(datawindow->sl)) && listIndex < 50) { switch (search_attr.type) { case attr_country_name: tcharBuffer = newSysString(res->country->name); break; case attr_town_name: tcharBuffer = newSysString(res->town->common.town_name); break; case attr_street_name: if (res->street->name) { tcharBuffer = newSysString(res->street->name); } else { continue; } break; default: dbg(0, "Unhandled search type"); } lvI.iItem = listIndex; lvI.iImage = listIndex; lvI.iSubItem = 0; lvI.lParam = (LPARAM) res->country->iso2; UTF8_TO_TCHAR(res->country->iso2, converted_iso2); lvI.pszText = converted_iso2;//LPSTR_TEXTCALLBACK; // sends an LVN_GETDISP message. (void)ListView_InsertItem(datawindow->hwndList, &lvI); ListView_SetItemText(datawindow->hwndList, listIndex, 1, tcharBuffer); g_free(tcharBuffer); dbg(0,"%s\n", res->country->name); listIndex++; } }
void drawLoop( TDirectory *target, TList *sourcelist, TCanvas *c1 ) { TString path( (char*)strstr( target->GetPath(), ":" ) ); path.Remove( 0, 2 ); TString sysString(path);sysString.Prepend(baseName->Data()); TFile *first_source = (TFile*)sourcelist->First(); first_source->cd( path ); TDirectory *current_sourcedir = gDirectory; //gain time, do not add the objects in the list in memory Bool_t status = TH1::AddDirectoryStatus(); TH1::AddDirectory(kFALSE); // loop over all keys in this directory TIter nextkey( current_sourcedir->GetListOfKeys() ); TKey *key, *oldkey=0; while ( (key = (TKey*)nextkey())) { //keep only the highest cycle number for each key if (oldkey && !strcmp(oldkey->GetName(),key->GetName())) continue; // read object from first source file first_source->cd( path ); TObject *obj = key->ReadObj(); if ( obj->IsA()->InheritsFrom( "TH1" ) && !obj->IsA()->InheritsFrom("TH2") ) { // descendant of TH1 -> merge it gLegend = new TLegend(.7,.15,.95,.4,""); gLegend->SetHeader(gDirectory->GetName()); Color_t color = 1; Style_t style = 22; TH1 *h1 = (TH1*)obj; h1->SetLineColor(color); h1->SetMarkerStyle(style); h1->SetMarkerColor(color); h1->Draw(); TString tmpName(first_source->GetName()); gLegend->AddEntry(h1,tmpName,"LP"); c1->Update(); // loop over all source files and add the content of the // correspondant histogram to the one pointed to by "h1" TFile *nextsource = (TFile*)sourcelist->After( first_source ); while ( nextsource ) { // make sure we are at the correct directory level by cd'ing to path nextsource->cd( path ); TKey *key2 = (TKey*)gDirectory->GetListOfKeys()->FindObject(h1->GetName()); if (key2) { TH1 *h2 = (TH1*)key2->ReadObj(); color++; style++; h2->SetLineColor(color); h2->SetMarkerStyle(style); h2->SetMarkerColor(color); h2->Draw("same"); TString tmpName(nextsource->GetName()); gLegend->AddEntry(h2,tmpName,"LP"); gLegend->Draw("same"); c1->Update(); //- delete h2; } nextsource = (TFile*)sourcelist->After( nextsource ); } } else if ( obj->IsA()->InheritsFrom( "TH2" ) ) { // descendant of TH2 -> merge it gLegend = new TLegend(.85,.15,1.0,.30,""); gLegend->SetHeader(gDirectory->GetName()); Color_t color = 1; Style_t style = 22; TH2 *h1 = (TH2*)obj; h1->SetLineColor(color); h1->SetMarkerStyle(style); h1->SetMarkerColor(color); h1->Draw(); TString tmpName(first_source->GetName()); gLegend->AddEntry(h1,tmpName,"LP"); c1->Update(); // loop over all source files and add the content of the // correspondant histogram to the one pointed to by "h1" TFile *nextsource = (TFile*)sourcelist->After( first_source ); while ( nextsource ) { // make sure we are at the correct directory level by cd'ing to path nextsource->cd( path ); TKey *key2 = (TKey*)gDirectory->GetListOfKeys()->FindObject(h1->GetName()); if (key2) { TH2 *h2 = (TH2*)key2->ReadObj(); color++; style++; h2->SetLineColor(color); h2->SetMarkerStyle(style); h2->SetMarkerColor(color); h2->Draw("same"); TString tmpName(nextsource->GetName()); gLegend->AddEntry(h2,tmpName,"LP"); gLegend->Draw("same"); c1->Update(); //- delete h2; } nextsource = (TFile*)sourcelist->After( nextsource ); } } else if ( obj->IsA()->InheritsFrom( "TGraph" ) ) { obj->IsA()->Print(); gLegend = new TLegend(.7,.15,.95,.4,""); gLegend->SetHeader(gDirectory->GetName()); Color_t color = 1; Style_t style = 22; TGraph *h1 =(TGraph*)obj; h1->SetLineColor(color); h1->SetMarkerStyle(style); h1->SetMarkerColor(color); h1->GetHistogram()->Draw(); h1->Draw(); TString tmpName(first_source->GetName()); gLegend->AddEntry(h1,tmpName,"LP"); c1->Update(); // loop over all source files and add the content of the // correspondant histogram to the one pointed to by "h1" TFile *nextsource = (TFile*)sourcelist->After( first_source ); while ( nextsource ) { // make sure we are at the correct directory level by cd'ing to path nextsource->cd( path ); TKey *key2 = (TKey*)gDirectory->GetListOfKeys()->FindObject(h1->GetName()); if (key2) { TGraph *h2 = (TGraph*)key2->ReadObj(); color++; style++; h2->SetLineColor(color); h2->SetMarkerStyle(style); h2->SetMarkerColor(color); h2->Draw("same"); TString tmpName(nextsource->GetName()); gLegend->AddEntry(h2,tmpName,"LP"); gLegend->Draw("same"); c1->Update(); //- delete h2; } nextsource = (TFile*)sourcelist->After( nextsource ); } } else if ( obj->IsA()->InheritsFrom( "TTree" ) ) { std::cout << "I don't draw trees" << std::endl; } else if ( obj->IsA()->InheritsFrom( "TDirectory" ) ) { // it's a subdirectory std::cout << "Found subdirectory " << obj->GetName() << std::endl; // create a new subdir of same name and title in the target file target->cd(); TDirectory *newdir = target->mkdir( obj->GetName(), obj->GetTitle() ); // create a new subdir of same name in the file system TString newSysString(sysString+"/"+obj->GetName()); if(makeGraphic) gSystem->mkdir(newSysString.Data(),kTRUE); // newdir is now the starting point of another round of merging // newdir still knows its depth within the target file via // GetPath(), so we can still figure out where we are in the recursion drawLoop( newdir, sourcelist, c1 ); } else { // object is of no type that we know or can handle std::cout << "Unknown object type, name: " << obj->GetName() << " title: " << obj->GetTitle() << std::endl; } // now write the merged TCanvas (which is "in" obj) to the target file // note that this will just store obj in the current directory level, // which is not persistent until the complete directory itself is stored // by "target->Write()" below if ( obj ) { target->cd(); if ( obj->IsA()->InheritsFrom( "TH1") || obj->IsA()->InheritsFrom("TGraph")) { // && !obj->IsA()->InheritsFrom("TH2") ) { TString newName(obj->GetName()); newName.ReplaceAll("(",1,"_",1); newName.ReplaceAll(")",1,"_",1); c1->SetName(newName); c1->Write( c1->GetName(),TObject::kOverwrite ); if(makeGraphic) { if (gROOT->IsBatch()) { c1->Print("temp.eps"); gSystem->Exec("pstopnm -ppm -xborder 0 -yborder 0 -portrait temp.eps"); char tempCommand[200]; sprintf(tempCommand,"ppmtogif temp.eps001.ppm > %s/%s.gif",sysString.Data(),c1->GetName()); gSystem->Exec(tempCommand); } else { c1->Print(sysString + "/" + TString(c1->GetName())+".gif"); } } } } //if(gLegend) delete gLegend; } // while ( ( TKey *key = (TKey*)nextkey() ) ) // save modifications to target file target->SaveSelf(kTRUE); TH1::AddDirectory(status); }