//------------------------------------------------------------------------------ // Application default task -- // (C) Piero Giubilato 2008-2010, Berkeley Lab -- //------------------------------------------------------------------------------ //______________________________________________________________________________ // {Trace} // [File name] "task_Default.c" // [Author] "Piero Giubilato" // [Version] "1.0" // [Modified by] "Piero Giubilato" // [Last revision] "17 Feb 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 // 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); // 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 the working area cool::Gui->size_Set(480,640); cool::Gui->backColor(kc_Desk); // 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 latches btn_Test.push_back(new gui_CoolButton("Latch #1", 320, 240, 120, 36, kc_btn_Label, gui_CoolButton::kc_Green)); 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); // 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_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(); // Try to change color... static UInt_t color = 0; color +=255; std::cout << color << "\n"; } //______________________________________________________________________________ void task_Default::btn_test_Evn(const int arg) { // 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(); // Switch latch color demo if (arg == btn_Test[4]->obj_Id()) { if (btn_Test[4]->btn_Status()) { btn_Test[4]->Text("Pippo"); btn_Test[4]->backColor(cool::Gui->kc_Red); } else { btn_Test[4]->Text("Pluto"); btn_Test[4]->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); }