//------------------------------------------------------------------------------ // Application default task -- // (C) Piero Giubilato 2008-2010, Berkeley Lab -- //------------------------------------------------------------------------------ //______________________________________________________________________________ // {Trace} // [File name] "task_Default.c" // [Author] "Piero Giubilato" // [Version] "1.2" // [Modified by] "Piero Giubilato" // [Last revision] "28 May 2009" // [Language] "C++" // [Compiler] "Visual C++ 8.x 9.x" // [Member of] "Cool SEAL" // [Project] "SEAL" // [Description] "Application default (startup) task" // [Key documentation] // "Visual C++ Reference Help" // {Trace} //______________________________________________________________________________ // Standard components #include #include #include // Root components #include // Application components #include "global.h" #include "cool.h" #include "task_Default.h" #include "data_Burst.h" // Define some standard color #define kc_Desk cool::Gui->kc_blue_Dark #define kc_desk_Label cool::Gui->kc_White #define kc_Btn cool::Gui->kc_Blue #define kc_btn_Label cool::Gui->kc_White //______________________________________________________________________________ task_Default::task_Default() { // Standard constructor dbg_Print("task_Default::task_Default: constructor called", DBG_LVL_ZERO); // Switch off the auto update during GUI construnction //cool::Gui->update_Auto(false); // Set the working area cool::Gui->size_Set(480,640); cool::Gui->backColor(0x006628); // Show the title label /* lbl_Label.push_back(new gui_Label("Cool S.E.A.L.", 60, 40)); lbl_Label.back()->Transparent(true); lbl_Label.back()->fontSize(48); lbl_Label.back()->foreColor(kc_desk_Label); lbl_Label.back()->fontBold(true); // Show version lbl_Label.push_back(new gui_Label("Version 1.0.a beta", 60, 100)); lbl_Label.back()->foreColor(kc_desk_Label); lbl_Label.back()->Transparent(true); // Show the copyright lbl_Label.push_back(new gui_Label("(C) Berkeley Lab & INFN Padova 2008-2010", 60, 120)); lbl_Label.back()->fontBold(true); lbl_Label.back()->foreColor(kc_desk_Label); lbl_Label.back()->Transparent(true); // Show the author list lbl_Label.push_back(new gui_Label("Devis Contarato", 60, 150)); lbl_Label.back()->foreColor(kc_desk_Label); lbl_Label.back()->Transparent(true); lbl_Label.push_back(new gui_Label("Piero Giubilato", 160, 150)); lbl_Label.back()->foreColor(kc_desk_Label); lbl_Label.back()->Transparent(true); lbl_Label.push_back(new gui_Label("Nicola Pozzobon", 60, 170)); lbl_Label.back()->foreColor(kc_desk_Label); lbl_Label.back()->Transparent(true); lbl_Label.push_back(new gui_Label("Tomohiko Tanabe", 160, 170)); lbl_Label.back()->foreColor(kc_desk_Label); lbl_Label.back()->Transparent(true); */ // Set up the menu mnu_Main = new gui_Menu("Task"); mnu_Main->mnu_Entry("&Demo", 1); mnu_Main->mnu_Separator(); mnu_Main->mnu_Entry("About", 98); mnu_Main->mnu_Entry("Exit", 99); mnu_Main->task_Connect(this, &task_Default::mnu_main_Evn); // Test buttons /* btn_Test.push_back(new gui_CoolButton("Comparative speed", 60, 240, 160, 36, kc_btn_Label, kc_Btn)); btn_Test.push_back(new gui_CoolButton("Layers algebra", 60, 280, 160, 36, kc_btn_Label, kc_Btn)); btn_Test.push_back(new gui_CoolButton("Frames algebra", 60, 320, 160, 36, kc_btn_Label, kc_Btn)); btn_Test.push_back(new gui_CoolButton("Bursts algebra", 60, 360, 160, 36, kc_btn_Label, kc_Btn)); // Test LED strip for (UInt_t i = 0; i < btn_Test.size(); i++) led_Test.push_back(new gui_Led(226, 244 + i * 40)); */ // Test panels pnl_List.push_back(new gui_Panel(40, 480, 220, 120, cool::Gui->kc_Blue, false, 1)); // Test combos cmb_Test.push_back(new gui_Combo(pnl_List[0], 0, 20, 30, 64, 24)); cmb_Test.back()->label_Set("Pippo", 1); cmb_Test.push_back(new gui_Combo(pnl_List[0], 0, 20, 90, 64, 24)); cmb_Test.back()->label_Set("Pluto", 1); // Test latches btn_Test.push_back(new gui_CoolButton("Latch #1", 320, 440, 120, 36, kc_btn_Label, gui_CoolButton::kc_Green)); btn_Test.back()->btn_Mode(gui_CoolButton::km_Latch); //btn_Test.push_back(new gui_CoolButton("Latch #2", 320, 280, 120, 36, kc_btn_Label, kc_Btn)); //btn_Test.push_back(new gui_CoolButton("Latch #3", 320, 320, 120, 36, kc_btn_Label, kc_Btn)); //btn_Test.push_back(new gui_CoolButton("Latch #4", 320, 360, 120, 36, kc_btn_Label, kc_Btn)); //for (UInt_t i = 4; i < btn_Test.size(); i++) btn_Test[i]->btn_Mode(gui_CoolButton::km_Latch); // Connect test buttons for (UInt_t i = 0; i < btn_Test.size(); i++) btn_Test[i]->task_Connect(this, &task_Default::btn_test_Evn); // The color button /* btn_Color = new gui_CoolButton("Colors", 60, 440, 100, 36, gui_CoolButton::kc_White, gui_CoolButton::kc_Green); btn_Color->task_Connect(this, &task_Default::btn_color_Evn); */ // The map for (int i = 0; i < 8192; i++) map_Data[i] = (Int_t)floor(10 * sin((double)i/30)); /* map_Spectrum = new gui_Map(120, 60, 320, 320); //map_Spectrum->range_Auto(true); map_Spectrum->data_Set(map_Data, 32, 1); map_Spectrum->data_Style(gui_Map::ks_Plot); */ // 2D Test plot_Test = new gui_Plot(700, 60, 320, 320); plot_Test->data_Set(map_Data, 1024, 8); UInt_t color_List[8] = {0xFF0000, 0x00FF00, 0x0000FF, 0x880000, 0x008800, 0x000088, 0xFF8888, 0x88FF88}; plot_Test->plot_Color(color_List, 8); const char* label_List[8] = {"A","B","C","D","E","F","G","H"}; plot_Test->plot_Label(label_List, 8); // Exit button /* btn_Quit = new gui_CoolButton("Quit", 60, 480, 100, 36, gui_CoolButton::kc_White, gui_CoolButton::kc_Red); btn_Quit->task_Connect(this, &task_Default::btn_quit_Evn); */ // Updates the GUI //cool::Gui->Update(); } //______________________________________________________________________________ task_Default::~task_Default() { // Standard constructor dbg_Print("task_Default::~task_Default: destructor called", DBG_LVL_ZERO); // Destroy gui objects cool::Gui->delete_All(); } //______________________________________________________________________________ void task_Default::mnu_main_Evn(const int arg) { // The only menu of this task.... dbg_Print("task_Default::mnu_main_Evn: event!", DBG_LVL_MAKE); // Task launcher if (arg < 90) cool::Task->task_Run(arg); // About if (arg == 98) std::cout << "I know I'm really, really cool!\n"; // Quit if (arg == 99) cool::Gui->Quit(); } //______________________________________________________________________________ void task_Default::btn_color_Evn(const int arg) { // The button you just need dbg_Print("task_Default::btn_color_Evn:(Int)", DBG_LVL_FLOW); // Get a random color srand((unsigned)time(NULL)); UInt_t R = (rand() / 128); UInt_t G = (rand() / 128); UInt_t B = (rand() / 128); // Put the color as new background color cool::Gui->backColor((R << 16) + (G << 8) + B); //map_Spectrum->Resize(map_Spectrum->Width() + 1, map_Spectrum->Height()); } //______________________________________________________________________________ void task_Default::btn_quit_Evn(const int arg) { // The button you just need dbg_Print("task_Default::btn_quit_Evn: event!", DBG_LVL_FLOW); // Bye Bye cool::Gui->Quit(); } //______________________________________________________________________________ void task_Default::btn_test_Evn(const int arg) { // Info //std::cout << "btn_test_Evn\n"; // Chose //if (arg == btn_Test[0]->obj_Id()) test_Speed(); //if (arg == btn_Test[1]->obj_Id()) test_Layer(); //if (arg == btn_Test[2]->obj_Id()) test_Frame(); //if (arg == btn_Test[3]->obj_Id()) test_Burst(); // Kill if (pnl_List.size() >= 1) { delete pnl_List[0]; pnl_List.pop_back(); } // Switch latch color demo UInt_t idx = 0; if (arg == btn_Test[idx]->obj_Id()) { if (btn_Test[idx]->btn_Status()) { btn_Test[idx]->Text("Pippo"); btn_Test[idx]->backColor(cool::Gui->kc_Red); } else { btn_Test[idx]->Text("Pluto"); btn_Test[idx]->backColor(cool::Gui->kc_Green); } } } //______________________________________________________________________________ void task_Default::test_Speed() { // Info std::cout << LWHITE << "Speed test\n"; // Timing stuff UInt_t Repeat = 500; clock_t tStart, tStop; // Native type test, for comparison // -------------------------------- // Dummy Float_t* fArray = new Float_t[512*512]; Float_t* bArray = new Float_t[512*512]; Float_t fScalar = 1; std::cout << "Timing " << Repeat << " dummy +=... "; tStart = clock(); for (UInt_t i = 0; i < Repeat; i++) { for (UInt_t c = 0; c < 512*512; c++) fArray[c] += bArray[c]; } tStop = clock(); std::cout << "Sec: " << (Double_t)(tStop - tStart) / CLOCKS_PER_SEC << "\n"; std::cout << "Timing " << Repeat << " dummy *=... "; tStart = clock(); for (UInt_t i = 0; i < Repeat; i++) { for (UInt_t c = 0; c < 512*512; c++) fArray[c] *= fScalar; } tStop = clock(); std::cout << "Sec: " << (Double_t)(tStop - tStart) / CLOCKS_PER_SEC << "\n"; std::cout << "Timing " << Repeat << " dummy /=... "; tStart = clock(); for (UInt_t i = 0; i < Repeat; i++) { for (UInt_t c = 0; c < 512*512; c++) fArray[c] /= fScalar; } tStop = clock(); std::cout << "Sec: " << (Double_t)(tStop - tStart) / CLOCKS_PER_SEC << "\n"; delete []fArray; delete []bArray; // Data structures // --------------- // Set up data UInt_t size = 512; data_Layer* Pippo = new data_Layer(size, size); data_Layer* Pluto = new data_Layer(size, size); data_Layer* Result = new data_Layer(size, size); Pippo->dp_all_Range(100); *Pluto = 1; // Scalar = std::cout << "Timing " << Repeat << " scalar +=... "; tStart = clock(); for (UInt_t i = 0; i < Repeat; i++) *Result += 1; tStop = clock(); std::cout << "Sec: " << (Double_t)(tStop-tStart) / CLOCKS_PER_SEC << "\n"; std::cout << "Timing " << Repeat << " scalar -=... "; tStart = clock(); for (UInt_t i = 0; i < Repeat; i++) *Result -= 1; tStop = clock(); std::cout << "Sec: " << (Double_t)(tStop-tStart) / CLOCKS_PER_SEC << "\n"; std::cout << "Timing " << Repeat << " scalar *=... "; tStart = clock(); for (UInt_t i = 0; i < Repeat; i++) *Result *= 1; tStop = clock(); std::cout << "Sec: " << (Double_t)(tStop-tStart) / CLOCKS_PER_SEC << "\n"; std::cout << "Timing " << Repeat << " scalar /=... "; tStart = clock(); for (UInt_t i = 0; i < Repeat; i++) *Result /= 1; tStop = clock(); std::cout << "Sec: " << (Double_t)(tStop-tStart) / CLOCKS_PER_SEC << "\n"; // Array = std::cout << "Timing " << Repeat << " array +=... "; tStart = clock(); for (UInt_t i = 0; i < Repeat; i++) *Result += *Pluto; tStop = clock(); std::cout << "Sec: " << (Double_t)(tStop-tStart) / CLOCKS_PER_SEC << "\n"; std::cout << "Timing " << Repeat << " array -=... "; tStart = clock(); for (UInt_t i = 0; i < Repeat; i++) *Result -= *Pluto; tStop = clock(); std::cout << "Sec: " << (Double_t)(tStop-tStart) / CLOCKS_PER_SEC << "\n"; std::cout << "Timing " << Repeat << " array *=... "; tStart = clock(); for (UInt_t i = 0; i < Repeat; i++) *Result *= *Pluto; tStop = clock(); std::cout << "Sec: " << (Double_t)(tStop-tStart) / CLOCKS_PER_SEC << "\n"; std::cout << "Timing " << Repeat << " array /=... "; tStart = clock(); for (UInt_t i = 0; i < Repeat; i++) *Result /= *Pluto; tStop = clock(); std::cout << "Sec: " << (Double_t)(tStop-tStart) / CLOCKS_PER_SEC << "\n"; // Scalar binary std::cout << "Timing " << Repeat << " scalar +... "; tStart = clock(); for (UInt_t i = 0; i < Repeat; i++) *Result = *Pippo + 1; tStop = clock(); std::cout << "Sec: " << (Double_t)(tStop-tStart) / CLOCKS_PER_SEC << "\n"; std::cout << "Timing " << Repeat << " scalar -... "; tStart = clock(); for (UInt_t i = 0; i < Repeat; i++) *Result = *Pippo - 1; tStop = clock(); std::cout << "Sec: " << (Double_t)(tStop-tStart) / CLOCKS_PER_SEC << "\n"; std::cout << "Timing " << Repeat << " scalar *... "; tStart = clock(); for (UInt_t i = 0; i < Repeat; i++) *Result = *Pippo * 2; tStop = clock(); std::cout << "Sec: " << (Double_t)(tStop-tStart) / CLOCKS_PER_SEC << "\n"; std::cout << "Timing " << Repeat << " scalar /... "; tStart = clock(); for (UInt_t i = 0; i < Repeat; i++) *Result = *Pippo / 2; tStop = clock(); std::cout << "Sec: " << (Double_t)(tStop-tStart) / CLOCKS_PER_SEC << "\n"; // Array binary std::cout << "Timing " << Repeat << " array +... "; tStart = clock(); for (UInt_t i = 0; i < Repeat; i++) *Result = *Pippo + *Pluto; tStop = clock(); std::cout << "Sec: " << (Double_t)(tStop-tStart) / CLOCKS_PER_SEC << "\n"; std::cout << "Timing " << Repeat << " array -... "; tStart = clock(); for (UInt_t i = 0; i < Repeat; i++) *Result = *Pippo - *Pluto; tStop = clock(); std::cout << "Sec: " << (Double_t)(tStop-tStart) / CLOCKS_PER_SEC << "\n"; std::cout << "Timing " << Repeat << " array *... "; tStart = clock(); for (UInt_t i = 0; i < Repeat; i++) *Result = *Pippo * *Pluto; tStop = clock(); std::cout << "Sec: " << (Double_t)(tStop-tStart) / CLOCKS_PER_SEC << "\n"; std::cout << "Timing " << Repeat << " array /... "; tStart = clock(); for (UInt_t i = 0; i < Repeat; i++) *Result = *Pippo / *Pluto; tStop = clock(); std::cout << "Sec: " << (Double_t)(tStop-tStart) / CLOCKS_PER_SEC << "\n"; // Remove data delete Pippo; delete Pluto; delete Result; // Switch LED on led_Test[0]->Status(true); } //______________________________________________________________________________ void task_Default::test_Layer() { // Info cool::Out->Print("Layer test\n", LWHITE); // Dummy data data_Layer Layer1(4,4); Layer1 = 11; data_Layer Layer2(2,2); Layer2 = 22; data_Layer Layer3(5,5); Layer3 = 33; //cool::Out->Print("\nCopy starts here\n"); //Layer2 = (data_Layer)Layer1; Layer2 += Layer1; //cool::Out->Print("\nCopy ends here\n\n"); Layer2 += 33; Layer2 += 1.5; Layer2 -= 12; Layer2 /= 3; Layer2 *= 5; cool::Out->Print("\nTricks\n"); //Layer2 = Layer1 * 2; cool::Out->Print("\nTriks should end here\n"); Layer2 += Layer2; Layer1.dp_all_Pow(); Layer1.dp_all_Sqr(); Layer1 = 10; Layer2 = 100; Layer3 = 1000; data_Layer Layer4; Layer4 = Layer1 + Layer3 * Layer2 - Layer3; Double_t min, max; Layer4.dp_all_Limits(min, max); std::cout << "min: " << min << ", max: " << max << "\n"; Layer4.dp_Value(2)++; Layer4.Dump(); // Switch LED on led_Test[1]->Status(true); } //______________________________________________________________________________ void task_Default::test_Frame() { // Info cool::Out->Print("Frame test\n", LWHITE); // Set up some dummy detectors and a container geom_Frame* Det1 = new geom_Frame(); Det1->layer(0)->dp_Count(10, 5); Det1->layer_Add(); Det1->layer(1)->dp_Count(5, 10); geom_Frame* Det2 = new geom_Frame(); Det2->layer(0)->dp_Count(4, 8); Det2->layer_Add(); Det2->layer(1)->dp_Count(16, 2); std::vector fList; fList.push_back(Det1); fList.push_back(Det2); // Fit and unfit data_Frame* frame = new data_Frame(fList[0]); frame->Dump(); frame->frame_Fit(fList[1]); frame->Dump(); // Delete everything for (UInt_t i = 0; i < fList.size(); i++) delete fList[i]; delete frame; // Switch LED on led_Test[2]->Status(true); } //______________________________________________________________________________ void task_Default::test_Burst() { // Info cool::Out->Print("Burst test\n", LWHITE); // Set up some dummy detectors and a container std::vector fList; fList.push_back(new geom_Frame()); fList.push_back(new geom_Frame()); //geom_Frame* Det1 = new geom_Frame(); fList[0]->layer(0)->dp_Count(10, 2); fList[0]->layer_Add(); fList[0]->layer(1)->dp_Count(2, 10); //geom_Frame* Det2 = new geom_Frame(); fList[1]->layer(0)->dp_Count(4, 4); fList[1]->layer_Add(); fList[1]->layer(1)->dp_Count(6, 6); // Set a dummy layer data_Layer* LayerX = new data_Layer(5,6); // Set data frames cool::Out->Print("\nDATA FRAME\n"); UInt_t DetID = 0; data_Burst* bRaw = new data_Burst(fList[0], 1); bRaw->Name("bRaw"); data_Burst* bTop = new data_Burst(fList[0], 1); bRaw->Name("bTop"); data_Burst* bRes = new data_Burst(fList[0], 1); bRaw->Name("bRes"); data_Frame* fRaw = new data_Frame(fList[0]); fRaw->Name("raw data"); data_Frame* fSig = new data_Frame(fList[0]); fSig->Name("Signal"); data_Frame* fNoise = new data_Frame(fList[0]); fNoise->Name("Noise"); data_Frame* fPed = new data_Frame(fList[0]); fPed->Name("Pedestal"); data_Frame* fPed2 = new data_Frame(fList[0]); fPed2->Name("Pedestal^2"); // Play a bit... cool::Out->Print("\nPLAYING!\n"); fRaw->dp_all_Range(0, 1, 100); *fSig = *fList[0]; *fSig = *fRaw; *fSig += 2 - 6; *fSig += (*LayerX * 2); *fSig += *LayerX; fSig->dp_all_Set(1234); fSig->dp_all_Pow(2); // Reset the accumulators fPed->dp_all_Set(0); fPed2->dp_all_Set(0); UInt_t fCount = 100; // This is a dummy acq test for (UInt_t n = 0; n < fCount; n++) { // Simulate read //*fRaw = *LayerX; // Transfer the read frame into the main one *fSig = *fRaw; // Accumulates *fPed += *fSig; *fPed2 += fSig->dp_all_Pow(2); } // Calculates noise //data_Frame fA = fPed->dp_all_Div(fCount); //fB = fA.dp_all_Pow(2); *fNoise = (fPed->dp_all_Div(fCount)).dp_all_Pow(2); *fNoise += fPed2->dp_all_Div(fCount); // Write data bRaw->frame(0)->layer(1)->dp_Front()[5] = 33; bRaw->Dump(); //bRaw->frame_Fit(fList[1], 1); //bRaw->frame(0)->layer(0)->dp_Front()[5] = 33; //bRaw->Dump(); //bRaw->frame_Fit(fList[0], 1); //bRaw->Dump(); *fRaw = 10; fRaw->Dump(); // Simple operations *bRaw = 12; *bTop = 13; *bRes = *bRaw + *bTop; *bRes /= 2; bRes->Dump(); *bRes -= *fRaw; bRes->Dump(); bRes->dp_all_Pow(2); *bTop = *bRes; bTop->dp_all_Sqr(); bTop->Dump(); // Delete for (UInt_t i = 0; i < fList.size(); i++) delete fList[i]; delete bRaw; delete bRes; delete bTop; delete fRaw; delete fSig; delete fNoise; delete fPed; delete fPed2; delete LayerX; // Switch LED on led_Test[3]->Status(true); }