//------------------------------------------------------------------------------ // Main geometry clas -- // (C) Piero Giubilato 2008-2010, Berkeley Lab -- //------------------------------------------------------------------------------ //______________________________________________________________________________ // {Trace} // [File name] "geom_Frame.cpp" // [Author] "Piero Giubilato" // [Version] "0.5" // [Modified by] "Piero Giubilato" // [Last revision] "31 Jan 2009" // [Language] "C++" // [Compiler] "Visual C++ 9.x" // [Member of] "Cool SEAL" // [Project] "SEAL" // [Description] "Main geometry class." // [Key documentation] // "Root user's guide" // "Visual C++ Reference Help" // {Trace} //______________________________________________________________________________ // Application components #include "geom_Frame.h" #include "global.h" // CINT Preprocessor class import definition //ClassImp(geom_Frame) //______________________________________________________________________________ geom_Frame::geom_Frame () { // Provides storage management for a detector geometry and hardware // implementation (layers + chips). // This constructor is the base one, with no parameters. By default, // one layer with one linked chipp will be addedd at instantiation, as // it is not possible having a frame without at least one layer and one // chip embedded inside. // Debug dbg_Print("geom_Frame::geom_Frame:()", DBG_LVL_ZERO); // Preset data_Preset(); } //______________________________________________________________________________ geom_Frame::~geom_Frame () { // Destructor: frees all allocated memory // Debug dbg_Print("geom_Frame::~geom_Frame:()", DBG_LVL_ZERO); // Delet all chips for (UInt_t i = 0; i < chip_Array.size(); i++) delete chip_Array[i]; // Delete all layers for (UInt_t i = 0; i < layer_Array.size(); i++) delete layer_Array[i]; // Delete all channels for (UInt_t i = 0; i < chn_Array.size(); i++) delete chn_Array[i]; } //______________________________________________________________________________ int geom_Frame::data_Preset() { // Preset all the geom of the object dbg_Print("geom_Frame::data_Preset:()", DBG_LVL_MAKE); // Clear the two main array, so setting no chips and layers chip_Array.clear(); layer_Array.clear(); chn_Array.clear(); // To be operative, a frame needs at least one chip, one layer defined and // one channel defined. // Create first a chip, then a layer which uses this chip chip_Add(); // Add a chip (hardware geometry description) layer_Add(); // Add a layer (in space hardware positioning) channel_Add(); // Hardware and layer connection // Update object status this->isOk(true); this->isModified(false); // All Ok return 0; } //______________________________________________________________________________ UInt_t geom_Frame::HrdID () const { // Retrieves the hardware id dbg_Print("geom_Frame::hard_Id:()", DBG_LVL_FLOW); return frame_HID; } //______________________________________________________________________________ void geom_Frame::HrdID (UInt_t val) { // Sets the hardware id dbg_Print("geom_Frame::hard_Id:(UInt)", DBG_LVL_FLOW); frame_HID = val; } //______________________________________________________________________________ UInt_t geom_Frame::chip_Add () { // Adds a chip to the frame. If everything ok, Returns the current number // of chips present into the frame. dbg_Print("geom_Frame::chip_Add:()", DBG_LVL_FLOW); // Adds the chip geom_Chip* new_Chip = new geom_Chip(); // Check for successfull instantiation if(!new_Chip) { dbg_Print("geom_Frame::chip_Add: failed instantiating the new chip", DBG_LVL_WARN); return 0; } // Increases the chip array chip_Array.push_back(new_Chip); // Updates object status this->isModified(true); // Returns current chip count return chip_Array.size(); } //______________________________________________________________________________ UInt_t geom_Frame::chip_Del (UInt_t chip_Idx) { // Removes the chip (chip_ID) from the frame. Note that it is not possible // to remove all the chips, at least one MUST be present. Returns the current // number of chips after the deletion. // Debug dbg_Print("geom_Frame::chip_Del:()", DBG_LVL_FLOW); // Exit if just one chip left if (chip_Array.size() == 1) return 1; // Check for the chip ID boundaries if (chip_Idx >= chip_Array.size()) return chip_Array.size(); // Delete the chip delete chip_Array[chip_Idx]; chip_Array.erase(chip_Array.begin() + chip_Idx); // Update object status this->isModified(true); // Return current chip count return chip_Array.size(); } //______________________________________________________________________________ UInt_t geom_Frame::layer_Add () { // Adds a layer to the frame. Return the current number of layers present // into the frame. // Debug dbg_Print("geom_Frame::layer_Add:()", DBG_LVL_FLOW); // Add the layer layer_Array.push_back(new geom_Layer()); // Update object status this->isModified(true); // Return current layer count return layer_Array.size(); } //______________________________________________________________________________ UInt_t geom_Frame::layer_Del (UInt_t layer_Idx) { // Removes the layer (layer_Idx) from the frame. Note that it is not possible // to remove all the layers, at least one MUST be present. Return the current // number of layer after the deletion. // Debug dbg_Print("geom_Frame::layer_Del:()", DBG_LVL_FLOW); // Exit if just one layer left if (layer_Array.size() == 1) return 1; // Check for the layer ID boundaries if (layer_Idx >= layer_Array.size()) return layer_Array.size(); // Delete the layer delete layer_Array[layer_Idx]; layer_Array.erase(layer_Array.begin() + layer_Idx); // Update object status this->isModified(true); // Return current layer count return layer_Array.size(); } //______________________________________________________________________________ UInt_t geom_Frame::channel_Add (UInt_t chip_Idx, UInt_t layer_Idx) { // Adds a channel to the frame. Returns the current number of channels // present into the frame. // Debug dbg_Print("geom_Frame::channel_Add:(UInt, UInt)", DBG_LVL_FLOW); // Link to the default chip and layer if not differently stated if (chip_Idx >= chip_Array.size()) chip_Idx = 0; if (layer_Idx >= layer_Array.size()) layer_Idx = 0; // Add the layer chn_Array.push_back(new geom_Channel(chip_Idx, layer_Idx)); // Update object status this->isModified(true); // Return current layer count return chn_Array.size(); } //______________________________________________________________________________ UInt_t geom_Frame::channel_Del (UInt_t channel_Idx) { // Removes the channel (channel_Idx) from the frame. It is not possible to // remove all the channels, at least one MUST be present. Returns the current // number of layer after the deletion. // Debug dbg_Print("geom_Frame::channel_Del: deleting a channel from the frame", DBG_LVL_MAKE); // Exit if just one layer left if (chn_Array.size() == 1) return 1; // Check for the layer ID boundaries if (channel_Idx >= chn_Array.size()) return chn_Array.size(); // Delete the layer delete chn_Array[channel_Idx]; chn_Array.erase(chn_Array.begin() + channel_Idx); // Update object status this->isModified(true); // Return current layer count return chn_Array.size(); } //______________________________________________________________________________ UInt_t geom_Frame::chip_Count () const { // Retrieves the number of chips present into the frame. // Numbers ranging from 0 to chip_Count - 1 represent // the valid chip Idxs. return chip_Array.size(); } //______________________________________________________________________________ UInt_t geom_Frame::layer_Count () const { // Retrieves the number of layers present into the frame. // Numbers ranging from 0 to layer_Count - 1 represent // the valid layers Idxs. return layer_Array.size(); } //______________________________________________________________________________ UInt_t geom_Frame::channel_Count () const { // Retrieves the number of channels present into the frame. // Numbers ranging from 0 to channel_Count - 1 represent // the valid channels Idxs. return chn_Array.size(); } //______________________________________________________________________________ UInt_t geom_Frame::dp_Count () const { // Retrieves the global number of data points generates by the frame. // It simply sums over all the defined chip. // Pivot sum UInt_t sum = 0; // Scans through the chip for (UInt_t i = 0; i < chip_Count(); i++) sum += chip(i)->dp_Count(); // Well done! return sum; } //______________________________________________________________________________ geom_Chip* geom_Frame::chip(UInt_t chip_Idx) const { // Retrieves the handle to the specified geom_Chip. // Returns NULL on error. // Check and returns if (chip_Idx >= chip_Array.size()) return NULL; else return chip_Array.at(chip_Idx); } //______________________________________________________________________________ geom_Layer* geom_Frame::layer(UInt_t layer_Idx) const { // Retrieves the handle to the specified geom_Layer. // Returns NULL on error. // Check and returns if (layer_Idx >= layer_Array.size()) return NULL; else return layer_Array.at(layer_Idx); } //______________________________________________________________________________ geom_Channel* geom_Frame::channel(UInt_t channel_Idx) const { // Retrieves the handle to the specified geom_Channel. // Returns NULL on error. // Check and returns if (channel_Idx >= chn_Array.size()) return NULL; else return chn_Array.at(channel_Idx); } //______________________________________________________________________________ void geom_Frame::Dump(UInt_t level) const { // Dumps all the object data into std::out // Shows the header and the data members TString space(' ', level); std::cout << space.Data() << "*geom_Layer: " << (int*)this << "\n"; std::cout << space.Data() << "class_Ver: " << class_Ver << "\n"; data_Object::Dump(level + 2); std::cout << space.Data() << "chip_Count: " << chip_Array.size() << "\n"; std::cout << space.Data() << "layer_Count: " << layer_Array.size() << "\n"; std::cout << space.Data() << "channel_Count: " << chn_Array.size() << "\n"; for (UInt_t i = 0; i < chip_Array.size(); i++) chip_Array[i]->Dump(level + 2); for (UInt_t i = 0; i < layer_Array.size(); i++) layer_Array[i]->Dump(level + 2); for (UInt_t i = 0; i < chn_Array.size(); i++) chn_Array[i]->Dump(level + 2); } //______________________________________________________________________________ void geom_Frame::Streamer(TBuffer &b) { // Read if (b.IsReading()) { // Debug dbg_Print ("geom_Frame::Streamer: read call", 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 ("geom_Frame::Streamer: read: version mismatch", DBG_LVL_WARN) dbg_Value(class_ver_Read, DBG_LVL_WARN); dbg_Value(class_Ver, DBG_LVL_WARN); } // Reads all the embedded chips UInt_t chip_Count = 0; b >> chip_Count; chip_Array.clear(); for (UInt_t i = 0; i < chip_Count; i++) { TString name("Chip%u", i); chip_Array.push_back(new geom_Chip()); chip_Array[i]->Read(name.Data()); } // Reads all the embedded layers UInt_t layer_Count = 0; b >> layer_Count; layer_Array.clear(); for (UInt_t i = 0; i < layer_Count; i++) { // Reads the layer and assign a default chip TString name("Layer%u", i); layer_Array.push_back(new geom_Layer()); layer_Array[i]->Read(name.Data()); } // Reads all the embedded channels UInt_t channel_Count = 0; b >> channel_Count; chn_Array.clear(); for (UInt_t i = 0; i < channel_Count; i++) { // Reads the channel TString name("Channel%u", i); chn_Array.push_back(new geom_Channel()); chn_Array[i]->Read(name.Data()); } // Write } else { // Debug dbg_Print ("geom_Frame::Streamer: write call", DBG_LVL_FLOW) // Writes class version b << class_Ver; // Writes all the embedded chips b << chip_Array.size(); for (UInt_t i = 0; i < chip_Array.size(); i++) { TString name("Chip%u", i); chip_Array[i]->Write(name.Data()); } // Writes all the embedded layers b << layer_Array.size(); for (UInt_t i = 0; i < layer_Array.size(); i++) { TString name("Layer%u", i); layer_Array[i]->Write(name.Data()); } // Writes all the embedded channels b << chn_Array.size(); for (UInt_t i = 0; i < chn_Array.size(); i++) { TString name("Channel%u", i); chn_Array[i]->Write(name.Data()); } } }