メインページ   モジュール   名前空間一覧   クラス階層   アルファベット順一覧   構成   ファイル一覧   構成メンバ   ファイルメンバ   関連ページ    

TExtractor.cc

解説を見る。
00001 // =====================================================================
00002 //  $Id: TExtractor.cc,v 1.4 2004/03/07 10:30:27 goiwai Exp $
00003 //  $Name: CLDAQ-1-14-03 $
00004 //  $Log: TExtractor.cc,v $
00005 //  Revision 1.4  2004/03/07 10:30:27  goiwai
00006 //  ROOTに組みこむためのおまじないマクロを埋めこみました。
00007 //  全てにおいて完全に動作するわけではありません。
00008 //
00009 //  Revision 1.3  2003/10/06 17:02:36  goiwai
00010 //  *** empty log message ***
00011 //
00012 //  Revision 1.2  2003/07/30 16:17:10  goiwai
00013 //  ファイルにコミットログをつけることにしました.
00014 //
00015 // =====================================================================
00016 #include "TExtractor.hh"
00017 #include "TDataRecord.hh"
00018 #include "TDataSection.hh"
00019 #include "TDataSegment.hh"
00020 #include "TDataElement.hh"
00021 
00022 TExtractor::TExtractor( const Tstring& id, Tobject_t objecttype, Tint nevents, Tint usec )
00023   : theExtractorID( id ), theMatrixElement(), theSamplingRate( usec ),
00024     theDataFoundStatus( Tfalse ), theFillMatrixStatus( Tfalse )
00025 {
00026   Tint ntuple;
00027   switch ( objecttype ) {
00028     case tObject1DHistogram:
00029       ntuple = 1;
00030       break;
00031     case tObject2DHistogram:
00032       ntuple = 2;
00033       break;
00034     case tObjectSubstituteGraph:
00035     case tObjectAppendGraph:
00036       ntuple = 2;
00037       break;
00038     case tObjectNtuple:
00039     default:
00040       ntuple = 0;
00041   }
00042   theMatrixElement = TMatrixElement( theExtractorID, objecttype, nevents, ntuple );
00043 }
00044 
00045 TExtractor::~TExtractor()
00046 {;}
00047 
00048 TDataSection TExtractor::FindDataSection( const TDataRecord& record, const Tstring& sectionid )
00049 {
00050   theDataFoundStatus = Tfalse;
00051   TDataSection section;
00052   for ( Tint i = 0; i < (Tint)record.size(); i ++ ) {
00053     if ( record[ i ].GetID() == sectionid &&
00054          record[ i ].GetObjectType() == tObjectDataSection &&
00055          record[ i ].size() != 0 ) {
00056     //if ( record[ i ].GetID() == sectionid && record[ i ].size() != 0 ) {
00057       section = record[ i ];
00058       theDataFoundStatus = Ttrue;
00059       break;
00060     }
00061   }
00062   return section;
00063 }
00064 
00065 TDataSegment TExtractor::FindDataSegment( const TDataSection& section, const Tstring& segmentid )
00066 {
00067   theDataFoundStatus = Tfalse;
00068   TDataSegment segment;
00069   for ( Tint i = 0; i < (Tint)section.size(); i ++ ) {
00070     if ( section[ i ].GetID() == segmentid &&
00071          section[ i ].GetObjectType() == tObjectDataSegment &&
00072          section[ i ].size() != 0 ) {
00073       //if ( section[ i ].GetID() == segmentid && section[ i ].size() != 0 ) {
00074       segment = section[ i ];
00075       theDataFoundStatus = Ttrue;
00076       break;
00077     }
00078   }
00079   return segment;
00080 }
00081 
00082 TDataElement TExtractor::FindDataElement( const TDataSegment& segment, const Tstring& elementid )
00083 {
00084   theDataFoundStatus = Tfalse;
00085   TDataElement element;
00086   for ( Tint i = 0; i < (Tint)segment.size(); i ++ ) {
00087     if ( segment[ i ].GetID() == elementid &&
00088          segment[ i ].GetElementType() != tTypeUnknown &&
00089          segment[ i ].GetNumberOfPrimitives() != 0 &&
00090          segment[ i ].GetObjectType() == tObjectDataElement ) {
00091       element = segment[ i ];
00092       theDataFoundStatus = Ttrue;
00093       break;
00094     }
00095   }
00096   return element;
00097 }
00098 
00099 TDataSegment TExtractor::FindDataSegment( const TDataRecord& record, const Tstring& sectionid, const Tstring& segmentid )
00100 {
00101   return FindDataSegment( FindDataSection( record, sectionid ), segmentid );
00102 }
00103 
00104 TDataSegment TExtractor::FindDataSegment( const TDataRecord& record, Tstring id[ 2 ] )
00105 {
00106   return FindDataSegment( FindDataSection( record, id[ 0 ] ), id[ 1 ] );
00107 }
00108 
00109 TDataElement TExtractor::FindDataElement( const TDataRecord& record, const Tstring& sectionid, const Tstring& segmentid, const Tstring& elementid )
00110 {
00111   // DoesDataFound() がうまくいかない
00112   return FindDataElement( FindDataSegment( FindDataSection( record, sectionid ), segmentid ), elementid );
00113 }
00114 
00115 TDataElement TExtractor::FindDataElement( const TDataRecord& record, Tstring id[ 3 ] )
00116 {
00117   return FindDataElement( FindDataSegment( FindDataSection( record, id[ 0 ] ), id[ 1 ] ), id[ 2 ] );
00118 }
00119 
00120 TDataElement TExtractor::FindDataElement( const TDataRecord& record, const TstringList& id )
00121 {
00122   return FindDataElement( FindDataSegment( FindDataSection( record, id[ 0 ] ), id[ 1 ] ), id[ 2 ] );
00123 }
00124 
00125 Tvoid TExtractor::FillMatrix( const TDataElementList& list )
00126 {
00127   switch ( theMatrixElement.GetObjectType() ) {
00128     case tObject1DHistogram:
00129       fillMatrixAs1DHistogram( list );
00130       break;
00131     case tObject2DHistogram:
00132       fillMatrixAs2DHistogram( list );
00133       break;
00134     case tObjectSubstituteGraph:
00135     case tObjectAppendGraph:
00136       fillMatrixAsGraph( list );
00137       break;
00138     case tObjectNtuple:
00139       fillMatrixAsNtuple( list );
00140       break;
00141     default:
00142       break;
00143   }
00144   return;
00145 }
00146 
00147 Tvoid TExtractor::fillMatrixAs1DHistogram( const TDataElementList& list )
00148 {
00149   theFillMatrixStatus = Tfalse;
00150 
00151   TDataElement element = list[ 0 ];
00152   Tvoid* data = element.GetData();
00153   Telement_t type = element.GetElementType();
00154   Tint nevents = theMatrixElement.GetNumberOfEvents();
00155   Tint nprimitives = element.GetNumberOfPrimitives();
00156 
00157   if ( nevents != nprimitives ) {
00158     Tstring head = "TExtractor::fillMatrixAs1DHistogram: ";
00159     Tcerr << head << "size of DataElement is incompatible with MatrixElement." << Tendl;
00160     Tcerr << head << "#events: " << nevents << " #primitives: " << nprimitives << Tendl;
00161     Tcerr << head << "resize a matrix element." << Tendl;
00162     theMatrixElement = TMatrixElement( theMatrixElement.GetMatrixID(), theMatrixElement.GetObjectType(), nprimitives, 1 );
00163   }
00164 
00165   switch ( type ) {
00166     case tTypeDouble:
00167       for ( Tint i = 0; i < nprimitives; i ++ )
00168         theMatrixElement[ i ][ 0 ] = ((Tdouble*)data)[ i ];
00169       theFillMatrixStatus = Ttrue;
00170       break;
00171     case tTypeInt:
00172     case tTypeLong:
00173       for ( Tint i = 0; i < nprimitives; i ++ )
00174         theMatrixElement[ i ][ 0 ] = ((Tint*)data)[ i ];
00175       theFillMatrixStatus = Ttrue;
00176       break;
00177     case tTypeUnsignedShort:
00178       for ( Tint i = 0; i < nprimitives; i ++ )
00179         theMatrixElement[ i ][ 0 ] = ((TUshort*)data)[ i ];
00180       theFillMatrixStatus = Ttrue;
00181       break;
00182     case tTypeShort:
00183     case tTypeWord:
00184       for ( Tint i = 0; i < nprimitives; i ++ )
00185         theMatrixElement[ i ][ 0 ] = ((Tshort*)data)[ i ];
00186       theFillMatrixStatus = Ttrue;
00187       break;
00188     case tTypeFloat:
00189       for ( Tint i = 0; i < nprimitives; i ++ )
00190         theMatrixElement[ i ][ 0 ] = ((Tfloat*)data)[ i ];
00191       theFillMatrixStatus = Ttrue;
00192       break;
00193     case tTypeUnsignedLong:
00194       for ( Tint i = 0; i < nprimitives; i ++ )
00195         theMatrixElement[ i ][ 0 ] = ((TUlong*)data)[ i ];
00196       theFillMatrixStatus = Ttrue;
00197       break;
00198     case tTypeUnknown:
00199     case tTypeObject:
00200     case tTypeString:
00201     default:
00202       break;
00203   }
00204 
00205   return;
00206 }
00207 
00208 Tvoid TExtractor::fillMatrixAsGraph( const TDataElementList& list )
00209 {
00210   theFillMatrixStatus = Tfalse;
00211 
00212   TDataElement xelement = list[ 0 ];
00213   TDataElement yelement = list[ 1 ];
00214 
00215   Tvoid* xdata = xelement.GetData();
00216   Tvoid* ydata = yelement.GetData();
00217 
00218   Telement_t xtype = xelement.GetElementType();
00219   Telement_t ytype = yelement.GetElementType();
00220   Tint nevents = theMatrixElement.GetNumberOfEvents();
00221 
00222   Tint xnprimitives = xelement.GetNumberOfPrimitives();
00223   Tint ynprimitives = yelement.GetNumberOfPrimitives();
00224 
00225   Tstring head = "TExtractor::fillMatrixAsGraph: ";
00226 
00227   if ( xnprimitives != ynprimitives ) {
00228     Tcerr << head << "number of horizontal elements is incompatible with vertical." << Tendl;
00229     Tcerr << head << "nothing to do, return." << Tendl;
00230     return;
00231   }
00232 
00233   if ( nevents != xnprimitives ) {
00234     Tcerr << head << "size of DataElement is incompatible with MatrixElement." << Tendl;
00235     Tcerr << head << "resize a matrix element." << Tendl;
00236     theMatrixElement = TMatrixElement( theMatrixElement.GetMatrixID(), theMatrixElement.GetObjectType(), xnprimitives, 2 );
00237   }
00238 
00239   switch ( xtype ) {
00240     case tTypeDouble:
00241       for ( Tint i = 0; i < xnprimitives; i ++ )
00242         theMatrixElement[ i ][ 0 ] = ((Tdouble*)xdata)[ i ];
00243       break;
00244     case tTypeInt:
00245     case tTypeLong:
00246       for ( Tint i = 0; i < xnprimitives; i ++ )
00247         theMatrixElement[ i ][ 0 ] = ((Tint*)xdata)[ i ];
00248       break;
00249     case tTypeUnsignedShort:
00250       for ( Tint i = 0; i < xnprimitives; i ++ )
00251         theMatrixElement[ i ][ 0 ] = ((TUshort*)xdata)[ i ];
00252       break;
00253     case tTypeShort:
00254     case tTypeWord:
00255       for ( Tint i = 0; i < xnprimitives; i ++ )
00256         theMatrixElement[ i ][ 0 ] = ((Tshort*)xdata)[ i ];
00257       break;
00258     case tTypeFloat:
00259       for ( Tint i = 0; i < xnprimitives; i ++ )
00260         theMatrixElement[ i ][ 0 ] = ((Tfloat*)xdata)[ i ];
00261       break;
00262     case tTypeUnsignedLong:
00263       for ( Tint i = 0; i < xnprimitives; i ++ )
00264         theMatrixElement[ i ][ 0 ] = ((TUlong*)xdata)[ i ];
00265       break;
00266     case tTypeUnknown:
00267     case tTypeObject:
00268     case tTypeString:
00269     default:
00270       break;
00271   }
00272 
00273   switch ( ytype ) {
00274     case tTypeDouble:
00275       for ( Tint i = 0; i < ynprimitives; i ++ )
00276         theMatrixElement[ i ][ 1 ] = ((Tdouble*)ydata)[ i ];
00277       theFillMatrixStatus = Ttrue;
00278       break;
00279     case tTypeInt:
00280     case tTypeLong:
00281       for ( Tint i = 0; i < ynprimitives; i ++ )
00282         theMatrixElement[ i ][ 1 ] = ((Tint*)ydata)[ i ];
00283       theFillMatrixStatus = Ttrue;
00284       break;
00285     case tTypeUnsignedShort:
00286       for ( Tint i = 0; i < ynprimitives; i ++ )
00287         theMatrixElement[ i ][ 1 ] = ((TUshort*)ydata)[ i ];
00288       theFillMatrixStatus = Ttrue;
00289       break;
00290     case tTypeShort:
00291     case tTypeWord:
00292       for ( Tint i = 0; i < ynprimitives; i ++ )
00293         theMatrixElement[ i ][ 1 ] = ((Tshort*)ydata)[ i ];
00294       theFillMatrixStatus = Ttrue;
00295       break;
00296     case tTypeFloat:
00297       for ( Tint i = 0; i < ynprimitives; i ++ )
00298         theMatrixElement[ i ][ 1 ] = ((Tfloat*)ydata)[ i ];
00299       theFillMatrixStatus = Ttrue;
00300       break;
00301     case tTypeUnsignedLong:
00302       for ( Tint i = 0; i < ynprimitives; i ++ )
00303         theMatrixElement[ i ][ 1 ] = ((TUlong*)ydata)[ i ];
00304       theFillMatrixStatus = Ttrue;
00305       break;
00306     case tTypeUnknown:
00307     case tTypeObject:
00308     case tTypeString:
00309     default:
00310       break;
00311   }
00312 
00313   return;
00314 }
00315 
00316 Tvoid TExtractor::fillMatrixAs2DHistogram( const TDataElementList& list )
00317 {
00318   theFillMatrixStatus = Tfalse;
00319 
00320   TDataElement xelement = list[ 0 ];
00321   TDataElement yelement = list[ 1 ];
00322 
00323   Tvoid* xdata = xelement.GetData();
00324   Tvoid* ydata = yelement.GetData();
00325 
00326   Telement_t xtype = xelement.GetElementType();
00327   Telement_t ytype = yelement.GetElementType();
00328   Tint nevents = theMatrixElement.GetNumberOfEvents();
00329 
00330   Tint xnprimitives = xelement.GetNumberOfPrimitives();
00331   Tint ynprimitives = yelement.GetNumberOfPrimitives();
00332 
00333   Tstring head = "TExtractor::fillMatrixAs2DHistogram: ";
00334 
00335   if ( xnprimitives != ynprimitives ) {
00336     Tcerr << head << "number of horizontal elements is incompatible with vertical." << Tendl;
00337     Tcerr << head << "nothing to do, return." << Tendl;
00338     return;
00339   }
00340 
00341   if ( nevents != xnprimitives ) {
00342     Tcerr << head << "size of DataElement is incompatible with MatrixElement." << Tendl;
00343     Tcerr << head << "resize a matrix element." << Tendl;
00344     theMatrixElement = TMatrixElement( theMatrixElement.GetMatrixID(), theMatrixElement.GetObjectType(), xnprimitives, 2 );
00345   }
00346 
00347   switch ( xtype ) {
00348     case tTypeDouble:
00349       for ( Tint i = 0; i < xnprimitives; i ++ )
00350         theMatrixElement[ i ][ 0 ] = ((Tdouble*)xdata)[ i ];
00351       break;
00352     case tTypeInt:
00353     case tTypeLong:
00354       for ( Tint i = 0; i < xnprimitives; i ++ )
00355         theMatrixElement[ i ][ 0 ] = ((Tint*)xdata)[ i ];
00356       break;
00357     case tTypeUnsignedShort:
00358       for ( Tint i = 0; i < xnprimitives; i ++ )
00359         theMatrixElement[ i ][ 0 ] = ((TUshort*)xdata)[ i ];
00360       break;
00361     case tTypeShort:
00362     case tTypeWord:
00363       for ( Tint i = 0; i < xnprimitives; i ++ )
00364         theMatrixElement[ i ][ 0 ] = ((Tshort*)xdata)[ i ];
00365       break;
00366     case tTypeFloat:
00367       for ( Tint i = 0; i < xnprimitives; i ++ )
00368         theMatrixElement[ i ][ 0 ] = ((Tfloat*)xdata)[ i ];
00369       break;
00370     case tTypeUnsignedLong:
00371       for ( Tint i = 0; i < xnprimitives; i ++ )
00372         theMatrixElement[ i ][ 0 ] = ((TUlong*)xdata)[ i ];
00373       break;
00374     case tTypeUnknown:
00375     case tTypeObject:
00376     case tTypeString:
00377     default:
00378       break;
00379   }
00380 
00381   switch ( ytype ) {
00382     case tTypeDouble:
00383       for ( Tint i = 0; i < ynprimitives; i ++ )
00384         theMatrixElement[ i ][ 1 ] = ((Tdouble*)ydata)[ i ];
00385       theFillMatrixStatus = Ttrue;
00386       break;
00387     case tTypeInt:
00388     case tTypeLong:
00389       for ( Tint i = 0; i < ynprimitives; i ++ )
00390         theMatrixElement[ i ][ 1 ] = ((Tint*)ydata)[ i ];
00391       theFillMatrixStatus = Ttrue;
00392       break;
00393     case tTypeUnsignedShort:
00394       for ( Tint i = 0; i < ynprimitives; i ++ )
00395         theMatrixElement[ i ][ 1 ] = ((TUshort*)ydata)[ i ];
00396       theFillMatrixStatus = Ttrue;
00397       break;
00398     case tTypeShort:
00399     case tTypeWord:
00400       for ( Tint i = 0; i < ynprimitives; i ++ )
00401         theMatrixElement[ i ][ 1 ] = ((Tshort*)ydata)[ i ];
00402       theFillMatrixStatus = Ttrue;
00403       break;
00404     case tTypeFloat:
00405       for ( Tint i = 0; i < ynprimitives; i ++ )
00406         theMatrixElement[ i ][ 1 ] = ((Tfloat*)ydata)[ i ];
00407       theFillMatrixStatus = Ttrue;
00408       break;
00409     case tTypeUnsignedLong:
00410       for ( Tint i = 0; i < ynprimitives; i ++ )
00411         theMatrixElement[ i ][ 1 ] = ((TUlong*)ydata)[ i ];
00412       theFillMatrixStatus = Ttrue;
00413       break;
00414     case tTypeUnknown:
00415     case tTypeObject:
00416     case tTypeString:
00417     default:
00418       break;
00419   }
00420 
00421   return;
00422 }
00423 
00424 Tvoid TExtractor::fillMatrixAsNtuple( const TDataElementList& list )
00425 {
00426   Tcout << "TExtractor::fillMatrixAsNtuple: under construction." << Tendl;
00427   return;
00428 }
00429 
00430 #ifdef __CLDAQ_ROOT_DLL
00431     ClassImp(TExtractor)
00432 #endif


CLDAQ - a Class Library for DataAcQuisition (Version 1.14.3)
Go IWAI -- goiwai at users.sourceforge.jp