//------------------------------------------------------------------------------ // Main data classes -- // (C) Piero Giubilato 2007-2010, Berkeley Lab -- //------------------------------------------------------------------------------ //______________________________________________________________________________ // {Trace} // [File name] "data_Burst.cpp" // [Author] "Piero Giubilato" // [Version] "1.0" // [Modified by] "Piero Giubilato" // [Last revision] "16 Feb 2009" // [Language] "C++" // [Compiler] "Visual C++ 9.x" // [Member of] "Cool SEAL" // [Project] "SEAL" // [Description] "Main data classes." // [Key documentation] // "Root user's guide" // "Visual C++ Reference Help" // {Trace} //______________________________________________________________________________ // Overloading check #ifndef data_Burst_C #define data_Burst_C // Standard libs #include #include // Root components #include // Application components #include "data_Burst.h" // ***************************************************************************** // **** SPECIAL MEMBERS **** // ***************************************************************************** //______________________________________________________________________________ template data_Burst::data_Burst(): data_Object() { // Provides management for a data_Frame collection. This class is the main // data object used by all the other application functions. // Basic construnctor. dbg_Print("data_Burst::data_Burst:()", DBG_LVL_ZERO); // Preset data frame_Count(1); } //______________________________________________________________________________ template data_Burst::data_Burst(geom_Frame* frm_Ref, UInt_t frm_Count): data_Object() { // geom_Frame referred construnctor. dbg_Print("data_Burst::data_Burst:(geom_Frame*, frm_Count)", DBG_LVL_ZERO); // Preset data frame_Fit(frm_Ref, frm_Count); } //______________________________________________________________________________ template data_Burst::data_Burst(const data_Burst& Source): data_Object(Source) { // Default copy constructor dbg_Print("data_Burst::data_Burst:(data_Burst&)", DBG_LVL_ZERO); // Makes the copy data_Copy(Source); } //______________________________________________________________________________ template template data_Burst::data_Burst(const data_Burst& Source): data_object(Source) { // Casting copy constructor dbg_Print("data_Burst::data_Burst:(data_Burst&)", DBG_LVL_ZERO); // Makes the copy data_Copy(Source); } //______________________________________________________________________________ template data_Burst::~data_Burst() { // Destructor: frees all allocated memory (by deleting every // sub-object) // Debug dbg_Print("data_Burst::~data_Burst:()", DBG_LVL_ZERO); // Delete all cells for (UInt_t i = 0; i < fr_Array.size(); i++) delete fr_Array[i]; } // ***************************************************************************** // **** PRIVATE OBJECT ACCESS **** // ***************************************************************************** //______________________________________________________________________________ template template void data_Burst::data_Copy(const data_Burst& Source) { // Copies the data from another data_Burst, casting them dbg_Print("data_Burst::data_Copy:(data_Burst)", DBG_LVL_MAKE); // Self copy check if (this == (data_Burst*)&Source) return; // Parent copy data_Object::operator=(Source); // Shallow copy burst_frame_Ref = Source.frame_Fit(); // Deep copy frame_Count(Source.frame_Count()); for (UInt_t i = 0; i < frame_Count(); i++) *frame(i) = *(Source.frame(i)); } //______________________________________________________________________________ template template void data_Burst::data_Math(const U& Source, UInt_t Operation) { // Performs algebra with scalars dbg_Print("data_Burst::data_Math:(U&)", DBG_LVL_STEP); // Do it! for (UInt_t f = 0; f < fr_Array.size(); f++) { switch (Operation) { case km_Set: *fr_Array[f] = Source; break; case km_Add: *fr_Array[f] += Source; break; case km_Sub: *fr_Array[f] -= Source; break; case km_Mul: *fr_Array[f] *= Source; break; case km_Div: *fr_Array[f] /= Source; break; // Allowed for scalar only! case km_Sqr: fr_Array[f]->dp_all_Sqr(); break; case km_Pow: fr_Array[f]->dp_all_Pow((Int_t)Source); break; case km_Mir: fr_Array[f]->dp_all_Mir((T)Source); break; } } } //______________________________________________________________________________ template template void data_Burst::data_Math(const data_Layer& Source, UInt_t Operation) { // Performs algebra with data_Frames dbg_Print("data_Burst::data_Math:(data_Layer&)", DBG_LVL_STEP); // Do it! for (UInt_t f = 0; f < fr_Array.size(); f++) { switch (Operation) { case km_Set: *fr_Array[f] = Source; break; case km_Add: *fr_Array[f] += Source; break; case km_Sub: *fr_Array[f] -= Source; break; case km_Mul: *fr_Array[f] *= Source; break; case km_Div: *fr_Array[f] /= Source; break; } } } //______________________________________________________________________________ template template void data_Burst::data_Math(const data_Frame& Source, UInt_t Operation) { // Performs algebra with data_Frames dbg_Print("data_Burst::data_Math:(data_Frame&)", DBG_LVL_STEP); // Do it! for (UInt_t f = 0; f < fr_Array.size(); f++) { switch (Operation) { case km_Set: *fr_Array[f] = Source; break; case km_Add: *fr_Array[f] += Source; break; case km_Sub: *fr_Array[f] -= Source; break; case km_Mul: *fr_Array[f] *= Source; break; case km_Div: *fr_Array[f] /= Source; break; } } } //______________________________________________________________________________ template template void data_Burst::data_Math(const data_Burst& Source, UInt_t Operation) { // Performs algebra with data_Bursts dbg_Print("data_Burst::data_Math:(data_Burst&)", DBG_LVL_STEP); // Check for frame dimension UInt_t frCnt; (Source.frame_Count() < fr_Array.size()) ? frCnt = Source.frame_Count() : frCnt = fr_Array.size(); // Do it! for (UInt_t f = 0; f < frCnt; f++) { switch (Operation) { case km_Set: *fr_Array[f] = *(Source.frame(f)); break; case km_Add: *fr_Array[f] += *(Source.frame(f)); break; case km_Sub: *fr_Array[f] -= *(Source.frame(f)); break; case km_Mul: *fr_Array[f] *= *(Source.frame(f)); break; case km_Div: *fr_Array[f] /= *(Source.frame(f)); break; } } } //______________________________________________________________________________ template const geom_Frame* data_Burst::frame_Fit() const { // Returns a pointer to the last fitted frame. WARNING: a data_Burst does NOT // guarantees an associated geom_Frame, so this function can returns a NULL // pointer or even a wrong pointer. // All OK return burst_frame_Ref; } //______________________________________________________________________________ template const geom_Frame* data_Burst::frame_Fit(const geom_Frame* frm_Ref, UInt_t frm_Count) { // Derives the size of the data_Burst from the properties of an // existing geom_Frame object. Pay attention that this method is // provided to give a fast and accurate initialization of the data_Burst, // but it is not a link to the geom_Frame used nor it does check for // any change into the reference geom_Frame. // Returns the pointer to the frm_Ref on success, or NULL otherwise. // Note: this function call will erase any data presents into the // current data_Burst. // Debug dbg_Print("data_Burst::frame_Fit: fitting a geom_Frame", DBG_LVL_MAKE); // Checks if there is a valid frame to derive dimensions from. burst_frame_Ref = NULL; if (frm_Ref == NULL) return NULL; // Checks that there is no dummy frame count if (frm_Count == 0) frm_Count = 1; // Creates the necessary data frames frame_Count(frm_Count); // Sets each frame accordingly to the related geometry for (UInt_t i = 0; i < fr_Array.size(); i++) { fr_Array[i]->frame_Fit(frm_Ref); TString name("Frame %u", i); fr_Array[i]->Name(name.Data()); } // Updates the frame geometry reference burst_frame_Ref = frm_Ref; // All OK return burst_frame_Ref; } //______________________________________________________________________________ template UInt_t data_Burst::obj_Type() const { // Returns the object type (the class type itself) return data_Object::kot_Burst; } //______________________________________________________________________________ template UInt_t data_Burst::data_Type() const { // Returns the object data type (the class type itself) return frame(0)->data_Type(); } // ***************************************************************************** // **** FRAMES ACCESS **** // ***************************************************************************** //______________________________________________________________________________ template UInt_t data_Burst::frame_Count() const { // Gets the number of frames present into the set // Returns return fr_Array.size(); } //______________________________________________________________________________ template UInt_t data_Burst::frame_Count(UInt_t frm_Count) { // Sets the number of frames into the set. // Note: this call will erase any data into the set! // Returns the current number of frames, 0 on error. // Checks if (frm_Count == 0) frm_Count = 1; // Debug dbg_Print("data_Burst::frm_Count: resizing frames collection", DBG_LVL_MAKE); // Release all committed frames for (UInt_t i = 0; i < fr_Array.size(); i++) delete fr_Array[i]; // Preset the vector fr_Array.clear(); fr_Array.reserve(frm_Count); // Add all the cells needed for (UInt_t i = 0; i < frm_Count; i++) fr_Array.push_back(new data_Frame()); // All OK return fr_Array.size(); } //______________________________________________________________________________ template data_Frame* data_Burst::frame(UInt_t frm_Idx) const { // Returns the handle to a data frame. // Returns NULL if out of bounds. // Checks boundaries if (frm_Idx >= fr_Array.size()) return NULL; // Returns return fr_Array[frm_Idx]; } //______________________________________________________________________________ template UInt_t data_Burst::dp_Count() const { // Gets the total number of data points present into the data_Burst. // Count UInt_t dp_Count = 0; for (UInt_t i = 0; i < fr_Array.size(); i++) dp_Count += fr_Array[i]->dp_Count(); // Returns return dp_Count; } //______________________________________________________________________________ template UInt_t data_Burst::dp_Size() const { // Gets the total size (bytes) of data points present into the data_Burst. // Return return sizeof(dp_Size) * dp_Count(); } // ***************************************************************************** // **** DATA ACCESS **** // ***************************************************************************** //______________________________________________________________________________ template void data_Burst::dp_all_Limits(T& min, T& max) const { // Get the maximum value of the frame dbg_Print("data_Burst::dp_all_Limits:()", DBG_LVL_FLOW); // First frame T fr_Min, fr_Max; fr_Array[0]->dp_all_Limits(min, max); // All the others for (UInt_t f = 1; f < fr_Array.size(); f++) { fr_Array[l]->dp_all_Limits(fr_Min, fr_Max); if (fr_Min < min) min = fr_Min; if (fr_Max > max) max = fr_Max; } } //______________________________________________________________________________ template void data_Burst::dp_all_Stat(Double_t& avg, Double_t& sgm) const { // Get statistics about the frame layers dbg_Print("data_Burst::dp_all_Stat:(Double, Double)", DBG_LVL_FLOW); // Returns the minimum value present into the array Double_t frm_Avg, frm_Sgm; avg = 0; sgm = 0; // Through all layers for (UInt_t f = 0; f < fr_Array.size(); f++) { fr_Array[f]->dp_all_Stat(fr_Avg, fr_Sgm); avg += fr_Avg ; sgm += frm_Sgm; } // Calculates results avg /= fr_Array.size(); sgm /= pow((double)fr_Array.size(), 2); } //______________________________________________________________________________ template data_Frame& data_Burst::fr_all_Avg() const { // Generates a new frame that contains the "vertical" average, i.e. // each pixel own average value, of all the frames. dbg_Print("data_Burst::dp_Avg:()", DBG_LVL_FLOW); // Create the frame where tu store the results, and make it // equal to the first frame of the burst data_Frame* result = new data_Frame(fr_Array[0]); // Sum through all frames, layers, pixels for (UInt_t f = 1; f < fr_Array.size(); f++) *result += *fr_Array[f]; // Calculates results *result /= fr_Array.size(); // Done! return *result; } //______________________________________________________________________________ template data_Frame& data_Burst::fr_all_Sgm() const { // Generates a new frame that contains the "vertical" errors, i.e. // each pixel own sigma, of all the frames. dbg_Print("data_Burst::fr_all_Sgm:()", DBG_LVL_FLOW); // Create the frame where tu store the results, and make it // equal to the first frame of the burst data_Frame* result = new data_Frame(fr_Array[0]); data_Frame* sum = new data_Frame(fr_Array[0]); data_Frame* sum2 = new data_Frame(sum); sum2->dp_all_Pow(2); // Sum through all frames, layers, pixels for (UInt_t f = 1; f < fr_Array.size(); f++) { *sum += *fr_Array[f]; *sum2 += (fr_Array[f]->dp_all_Pow(2)); } // Calculates result *result = (sum2 /= fr_Array.size()) - sum->dp_all_Pow(2); result->dp_all_Sqr(); // Remove steps delete sum; delete sum2; // Done! return *result; } //______________________________________________________________________________ template data_Burst& data_Burst::dp_all_Range(T start, T dp_Step, T ly_Step) { // Build a step range; dp_Step is the step between subsequent layer dp, // while lp is the step between the start point of each layers couple . // (An internal copy would also work here) dbg_Print("data_Burst::dp_all_Range:(T, T, T)", DBG_LVL_FLOW); // Sets the value for (UInt_t f = 0; f < fr_Array.size(); f++) { fr_Array[f]->dp_all_Range(start, dp_Step, ly_Step); } // Return itself return *this; } // ***************************************************************************** // **** ROOT OVERLOADS **** // ***************************************************************************** //______________________________________________________________________________ template void data_Burst::Dump(UInt_t level) const { // Dumps all the object data into std::out // Shows the header TString space(' ', level); std::cout << space.Data() << "*data_Burst: " << (int*)this << "\n"; std::cout << space.Data() << "class_Ver: " << class_Ver << "\n"; // Shows the parent data_Object::Dump(level + 2); // shows the data members std::cout << space.Data() << "frame_Count: " << fr_Array.size() << "\n"; for (UInt_t i = 0; i < fr_Array.size(); i++) fr_Array[i]->Dump(level + 2); } //______________________________________________________________________________ template void data_Burst::Streamer(TBuffer &b) { // Fills the standar root streamer with the layers inside the frame // Read if (b.IsReading()) { // Debug dbg_Print ("data_Burst::Streamer: read", DBG_LVL_FLOW) // Reads class version UShort_t class_ver_Read = 0; b >> class_ver_Read; // Checks version if (class_ver_Read != class_Ver) { dbg_Print ("data_Frame::Streamer: read: version mismatch", DBG_LVL_WARN) dbg_Value(class_ver_Read, DBG_LVL_WARN); dbg_Value(class_Ver, DBG_LVL_WARN); } // Reads parent class data_Object::Streamer(b); // Reads all the embedded layers UInt_t fr_Count = 0; b >> fr_Count; fr_Array.clear(); for (UInt_t i = 0; i < fr_Count; i++) { TString name("Frame%u", i); fr_Array.push_back(new data_Frame()); fr_Array[i]->Read(name.Data()); } // Writes } else { // Debug dbg_Print ("data_Burst::Streamer: write",DBG_LVL_FLOW) // Writes class version b << class_Ver; // Writes parent class data_Object::Streamer(b); // Writes all the embedded layers b << fr_Array.size(); for (UInt_t i = 0; i < fr_Array.size(); i++) { TString name("Frame%u", i); fr_Array[i]->Write(name.Data()); } } } // Overloading check #endif