Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

LogId.cxx

Go to the documentation of this file.
00001 
00002 //                                                                        
00003 // The LogId class contains a log ID number (encoding of detector
00004 // element position) as well as functions to obtain the location of
00005 // log in question. LogId is used in the CalDigi class.
00006 //                                                                        
00008 
00009 // access and set functions for binary calorimeter tags
00010 // Version 1.0 21 Oct 1998 Richard creation
00011 // Version 1.1 25 Oct 1999 R.Dubois Clone from LCD
00012 
00013 #include "digiRootData/LogId.h"
00014 
00015 ClassImp(LogId)
00016 
00017 LogId::LogId(){
00018     // Default constructor
00019     // All fields in tagword initialized to 0
00020     setTag(static_cast<UInt_t>(0));
00021 }
00022 
00023 LogId::LogId(UInt_t tag=0) {
00024     // Create a LogId object with number tag
00025     setTag(tag);
00026 }
00027 
00028 LogId::LogId(UShort_t tower, UShort_t layer, UShort_t column) {
00029     // Create a log id given the layer, column and tower
00030     setTag(static_cast<UInt_t>(0));
00031     setLayer(layer);
00032     setColumn(column);
00033     setTower(tower);
00034 }
00035 
00036 LogId::~LogId() {
00037     // Destructor
00038 }
00039 
00040 
00041 Bool_t LogId::isValidColumn(UInt_t columnVal) {
00042     // Check if given value is a valid Column number:
00043     return (
00044             ((columnVal <= BOUNDS_COLUMN) && !(columnVal & ~CAL_M_COLUMN)) ?
00045             kTRUE : kFALSE
00046            );
00047 }
00048 
00049 Bool_t LogId::isValidLayer(UInt_t layerVal) {
00050     // Check if given value is a valid Layer number:
00051     return (
00052             ((layerVal <= BOUNDS_LAYER) && !(layerVal & ~CAL_M_LAYER)) ?
00053             kTRUE : kFALSE
00054            );
00055 }
00056 
00057 
00058 Bool_t LogId::isValidTagStruct(TAG_STRUCT ts) {
00059     // Test the validity of a particular tag structure.
00060     // Ensures that fields which don't use all possible values are
00061     // within bounds. 
00062     if (!isValidColumn(ts.column)) return kFALSE;
00063     if (!isValidLayer(ts.layer)) return kFALSE;
00064     
00065     // If we got this far, everything must be ok...
00066     return kTRUE;
00067 }
00068 
00069 Bool_t LogId::isValidTagWord(UInt_t tagWord) {
00070     
00071     TAG_STRUCT ts;
00072     fillTagStruct(tagWord, &ts);
00073     
00074     return isValidTagStruct(ts);
00075 }
00076 
00077 // Fill a TAG_STRUCT with data from tagVal.
00078 // *** NOTE: There is no assertion that user supplied tagword contains
00079 // valid fields!
00080 void LogId::fillTagStruct(UInt_t tagVal, LogId::TAG_STRUCT *ts) {
00081     ts->column = getColumn(tagVal);
00082     ts->layer = getLayer(tagVal);
00083     ts->pipeline = 0;//getPipeline(tagVal);
00084     ts->sequence = 0;//getSequence(tagVal);
00085     ts->tower = getTower(tagVal);
00086     ts->xy = getXY(tagVal);
00087 }
00088 
00089 // Fill a tagword from a tag structure:
00090 // *** NOTE: There is no assertion that user supplied tag struct contains
00091 // valid fields!
00092 UInt_t LogId::fillTagWord(LogId::TAG_STRUCT *ts) {
00093     UInt_t tagWord = 0;
00094     tagWord += (ts->xy & CAL_M_XY) << CAL_V_XY;
00095     //tagWord += (ts->sequence & CAL_M_SEQ) << CAL_V_SEQ;
00096     //tagWord += (ts->pipeline & CAL_M_PIPE) << CAL_V_PIPE;
00097     // When setting layer bits, shed common XY bit from layer value...
00098     tagWord += ((ts->layer >> CAL_K_XY) & CAL_M_LAYER) << CAL_V_LAYER;
00099     tagWord += (ts->column & CAL_M_COLUMN) << CAL_V_COLUMN;
00100     tagWord += (ts->tower & CAL_M_TOWER) << CAL_V_TOWER;
00101 
00102     return tagWord;
00103 }
00104 
00105 Bool_t LogId::setTag(UInt_t tagVal) { 
00106     // Set value of tag word to tagVal if taVal is valid
00107 
00108     if (isValidTagWord(tagVal)) {
00109         m_tag = tagVal;
00110         return kTRUE;
00111     }
00112     else return kFALSE;
00113 }
00114 
00115 Bool_t LogId::setTag(TAG_STRUCT *ts) {
00116     // Fill tag word from values in a tag struct.
00117 
00118     if (isValidTagStruct(*ts)) {
00119         m_tag = fillTagWord(ts);
00120         return kTRUE;
00121     }
00122     else return kFALSE;
00123 }
00124 
00125 Bool_t LogId::setTower(UInt_t towerVal) {
00126     // clear the tower bits
00127     m_tag &= ~(CAL_M_TOWER << CAL_V_TOWER);
00128     // set the tower bits to the new value
00129     m_tag |= towerVal << CAL_V_TOWER;
00130     return kTRUE;
00131 }
00132 
00133 Bool_t LogId::setColumn(UInt_t columnVal) {
00134     // Sets the column field in the tag word
00135 
00136     if (!isValidColumn(columnVal)) 
00137         return kFALSE;
00138 
00139     // clear the column bits
00140     m_tag &= ~(CAL_M_COLUMN << CAL_V_COLUMN);
00141     // set the column bits to the new value
00142     m_tag |= columnVal << CAL_V_COLUMN;
00143 
00144     return kTRUE;
00145 }
00146 
00147 Bool_t LogId::setXY(CALAxes xyVal) {
00148     // Sets the XY field in the tag word
00149     // clear the XY bit
00150     m_tag &= ~(CAL_M_XY << CAL_V_XY);
00151     // set the XY bit to the new value
00152     m_tag |= xyVal << CAL_V_XY;
00153 
00154     return kTRUE;
00155 }
00156 
00157 Bool_t LogId::setLayer(UInt_t layerVal) {
00158     // Sets the layer field in the tag word
00159 
00160     // *** See note in header (in the private enum of tagword fields) 
00161     // *** as to why the following is done:
00162     // Strip off LSB, as it goes in the XY field...
00163     UInt_t xyVal = (layerVal & CAL_M_XY);
00164     // Now get the layer value minus the XY bit...
00165     UInt_t lVal = (layerVal >> CAL_K_XY);
00166 
00167     // Check if the remaining bits represent a valid layer value:
00168     if (lVal & ~CAL_M_LAYER)
00169         return kFALSE;
00170 
00171     // Set LAYER and XY fields...
00172     // Clear the layer bits
00173     m_tag &= ~(CAL_M_LAYER << CAL_V_LAYER);
00174     // set the layer bits to the new value
00175     m_tag |= lVal << CAL_V_LAYER;
00176     // clear the XY bit
00177     m_tag &= ~(CAL_M_XY << CAL_V_XY);
00178     // set the XY bit to the new value
00179     m_tag |= xyVal << CAL_V_XY;
00180 
00181     return kTRUE;
00182 }
00183 
00184 Bool_t LogId::setId(UShort_t tower, UShort_t layer, UShort_t column) {
00185     
00186     if (setLayer(layer) == kFALSE) return kFALSE;
00187     if (setColumn(column) == kFALSE) return kFALSE;
00188     if (setTower(tower) == kFALSE) return kFALSE;
00189 
00190     return kTRUE;
00191 }
00192 
00193 
00194 UInt_t LogId::getTag() const { 
00195     // Returns the log number - the whole tag word
00196     return m_tag;
00197 }
00198 
00199 UInt_t LogId::getId(UInt_t tagWord) {
00200     // Returns the id of this log.  Each log in the calorimeter has a unique
00201     // id value based upon it's position in the cal.
00202     // Now using Layer,Column,Tower to determine unique id
00203    // return static_cast<UInt_t>((tagWord >> CAL_V_ID) & CAL_M_ID);
00204     return static_cast<UInt_t>((tagWord >> CAL_V_NEWID) & CAL_M_NEWID);
00205 }
00206 
00207 UInt_t LogId::getId() const {
00208     // Returns the unique id of this log based on Tower, Layer, Column
00209     return getId(m_tag);
00210 }
00211 
00212 
00213 UShort_t LogId::getTower(UInt_t tagWord) {
00214     // Returns the GLAST tower this log belongs to.  In the '99/2000
00215     // beamtest, and for the 2001 Balloon flight this value is always 0.
00216     return static_cast<UShort_t>((tagWord >> CAL_V_TOWER) & CAL_M_TOWER);
00217 }
00218 
00219 UShort_t LogId::getTower() const {
00220     return getTower(m_tag);
00221 }
00222 
00223 UShort_t LogId::getColumn(UInt_t tagWord) {
00224     // Returns the column of the log in the calorimeter
00225     // Columns are numberd 0-9.  
00226     // Columns are numbers with increasing coordinate.
00227     // If this is an X log (oriented along the X axis), the columns are numbered with 
00228     // increasing Y coordinate.
00229     // Similarly for the Y logs (oriented along the Y axis), the columns are numbered with
00230     // increasing X coordinate.
00231     return static_cast<UShort_t>((tagWord >> CAL_V_COLUMN) & CAL_M_COLUMN);
00232 }
00233 
00234 UShort_t LogId::getColumn() const {
00235     // return column value from tag word:
00236     return getColumn(m_tag);
00237 }
00238 
00239 UShort_t LogId::getLayer(UInt_t tagWord) {
00240     // Returns the layer this log is in.  Layers are numbered from
00241     // 0: (closest to TKR) to 7: (furthest from TKR).
00242     UInt_t layerVal = (tagWord >> CAL_V_LAYER) & CAL_M_LAYER;
00243     layerVal <<= CAL_K_XY;
00244     layerVal |= getXY(tagWord);
00245 
00246     return UShort_t(layerVal);
00247 }
00248 
00249 UShort_t LogId::getLayer() const {
00250     // return layer value from tag word:
00251     return getLayer(m_tag);
00252 }
00253 
00254 
00255 UShort_t LogId::getXY(UInt_t tagWord) {
00256     // Returns the X / Y orientation of this log
00257     return static_cast<UShort_t>((tagWord >> CAL_V_XY) & CAL_M_XY);
00258 }
00259 
00260 LogId::CALAxes LogId::getXY() const {
00261     // Returns whether this log is in an X log or a Y log
00262     return (CALAxes)getXY(m_tag);
00263 }
00264 
00265 

Generated at Wed Nov 21 12:22:45 2001 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000