00001 #ifndef __EMCOMTOFT0FEMT_H__
00002 #define __EMCOMTOFT0FEMT_H__
00003
00004 #ifndef __EMCOMTRACEDFEMT_H__
00005 #include "emcOMTracedFEMT.h"
00006 #endif
00007 #ifndef __EMCTOFT0FEM_H__
00008 #include "emcTofT0FEM.h"
00009 #endif
00010
00011 class emcTracedFEM;
00012
00018 template <class T>
00019 class emcOMTracedFEMT<T,emcTofT0FEM> : public emcOMCalFEMT<T>
00020 {
00021
00022 public:
00023 emcOMTracedFEMT(const char* name, const char* title) :
00024 emcOMCalFEMT<T>(name, title)
00025 { }
00026
00028 virtual bool CanRead(const emcManageable& object) const;
00029
00031 virtual bool CanWrite(const emcManageable& object) const;
00032
00034 virtual void FromPdbCalBank(emcCalFEM& calfem, PdbCalBank& bank);
00035
00037 virtual std::string GetPersistentClassName(void) const
00038 {
00039 return "PdbEmcTracedValueBank";
00040 }
00041
00043 virtual void ToPdbCalBank(const emcCalFEM& calfem, PdbCalBank& bank);
00044
00045 };
00046
00047
00048
00049
00050
00051 #include "PdbCalBank.hh"
00052 #include "PdbEmcTracedValue.hh"
00053
00054 #ifndef __EMCINDEXER_H__
00055 #include "EmcIndexer.h"
00056 #endif
00057 #ifndef __EMCTRACEDVALUE_H__
00058 #include "emcTracedValue.h"
00059 #endif
00060
00061 #include <cassert>
00062 #include <ctime>
00063 #include <string>
00064 #include <fstream>
00065
00066
00067 template <class T>
00068 bool
00069 emcOMTracedFEMT<T, emcTofT0FEM>::CanRead(const emcManageable& object) const
00070 {
00071
00072
00073
00074 if ( object.GetSource() != storage() )
00075 {
00076 return false;
00077 }
00078
00079 const emcManageable* object_ptr = &object;
00080 const emcTofT0FEM* test = dynamic_cast<const emcTofT0FEM*>(object_ptr);
00081
00082 if (test)
00083 {
00084 std::string test_category = emcTofT0FEM(0,test->Version()).GetCategory();
00085 if ( test_category == object.GetCategory() )
00086 {
00087 return true;
00088 }
00089 else
00090 {
00091 return false;
00092 }
00093 }
00094
00095 return false;
00096 }
00097
00098
00099 template <class T>
00100 bool
00101 emcOMTracedFEMT<T, emcTofT0FEM>::CanWrite(const emcManageable& object) const
00102 {
00103
00104
00105
00106
00107 if ( object.GetDestination() != storage() )
00108 {
00109 return false;
00110 }
00111
00112 const emcManageable* object_ptr = &object;
00113 const emcTofT0FEM* test = dynamic_cast<const emcTofT0FEM*>(object_ptr);
00114
00115 if (test)
00116 {
00117 std::string test_category = emcTofT0FEM(0,test->Version()).GetCategory();
00118 if ( test_category == object.GetCategory() )
00119 {
00120 return true;
00121 }
00122 else
00123 {
00124 return false;
00125 }
00126 }
00127
00128 return false;
00129 }
00130
00131
00132 template <class T>
00133 void
00134 emcOMTracedFEMT<T, emcTofT0FEM>::FromPdbCalBank(emcCalFEM& calfem, PdbCalBank& bank)
00135 {
00136
00137
00138
00139
00140
00141
00142
00143
00144 emcTofT0FEM& tracedFEM = dynamic_cast<emcTofT0FEM&>(calfem);
00145
00146 int nitems = 0;
00147 size_t nchannels = 0;
00148 size_t thesize = bank.getLength();
00149 int j = 0, lastj = -1;
00150 int thex;
00151 float constant, slope;
00152 PdbEmcTracedValue* pdbtv;
00153
00154
00155 for ( size_t i = 0; i < thesize; i++ )
00156 {
00157 pdbtv = (PdbEmcTracedValue*) & (bank.getEntry(i));
00158 assert(pdbtv != 0);
00159 pdbtv->Get(j, thex, constant, slope);
00160 if (j < 144)
00161 {
00162 nitems++;
00163 if ( j > lastj )
00164 nchannels = j;
00165 }
00166 lastj = j;
00167 }
00168
00169 nchannels++;
00170
00171 int extra = thesize - nitems;
00172
00173 tracedFEM.SetNumberOfChannels(nchannels);
00174 int n = 0;
00175
00176
00177 for ( int i = 0; i < nitems; i++ )
00178 {
00179 pdbtv = (PdbEmcTracedValue*) & (bank.getEntry(i));
00180 pdbtv->Get(j, thex, constant, slope);
00181 tracedFEM.AddNewItem(j, new emcTracedValue(thex, constant, slope));
00182 n++;
00183 }
00184
00185
00186
00187 assert(extra == 1 || extra == 2 || extra==3);
00188
00189 pdbtv = (PdbEmcTracedValue*) & (bank.getEntry(n));
00190 assert(pdbtv != 0);
00191 pdbtv->Get(j, thex, constant, slope);
00192 assert(constant == 0);
00193 assert(slope == 0);
00194
00195 phtime_t xmax = thex;
00196
00197 if (extra == 3 )
00198 {
00199
00200 n++;
00201 pdbtv = (PdbEmcTracedValue*) & (bank.getEntry(n));
00202 assert(pdbtv != 0);
00203 pdbtv->Get(j, thex, constant, slope);
00204 assert(constant == 0);
00205 assert(slope == 0);
00206 calfem.SetXmin(thex);
00207 calfem.SetXmax(xmax);
00208 ++n;
00209 pdbtv = (PdbEmcTracedValue*) & (bank.getEntry(n));
00210 assert(pdbtv != 0);
00211 pdbtv->Get(j, thex, constant, slope);
00212 assert(thex==0);
00213 assert(slope==0);
00214 tracedFEM.setBBCT0(constant);
00215 }
00216 else if (extra == 2)
00217 {
00218
00219 n++;
00220 pdbtv = (PdbEmcTracedValue*) & (bank.getEntry(n));
00221 assert(pdbtv != 0);
00222 pdbtv->Get(j, thex, constant, slope);
00223 assert(constant == 0);
00224 assert(slope == 0);
00225 calfem.SetXmin(thex);
00226 calfem.SetXmax(xmax);
00227 }
00228 else
00229 {
00230
00231
00232 if ( EmcIndexer::isPbScFEM(calfem.AbsolutePosition()) )
00233 {
00234 phtime_t tics0 = calfem.GetStartValTime().getTics();
00235 calfem.SetXmin(tics0);
00236 calfem.SetXmax(xmax + tics0);
00237 }
00238 }
00239 }
00240
00241
00242 template <class T>
00243 void
00244 emcOMTracedFEMT<T,emcTofT0FEM>::ToPdbCalBank(const emcCalFEM& calfem, PdbCalBank& bank)
00245 {
00246 int nvalues = 0;
00247 const emcTofT0FEM& ctracedFEM = static_cast<const emcTofT0FEM&>(calfem);
00248 emcTofT0FEM& tracedFEM = const_cast<emcTofT0FEM&>(ctracedFEM);
00249
00250 nvalues += tracedFEM.GetNumberOfItems();
00251
00252
00253
00254
00255
00256 int theshift = 2;
00257 if ( tracedFEM.Version() > 0 )
00258 {
00259 theshift = 3;
00260 }
00261
00262 bank.setLength(nvalues + theshift);
00263
00264
00265
00266 PdbEmcTracedValue* pdbtv;
00267 emcTracedValue* val;
00268 int n = 0;
00269
00270 for ( size_t i = 0; i < tracedFEM.GetNumberOfChannels(); i++ )
00271 {
00272 tracedFEM.FirstItem(i);
00273 while ( (val = tracedFEM.NextItem()) != 0 )
00274 {
00275 pdbtv = (PdbEmcTracedValue*) & (bank.getEntry(n));
00276 assert(pdbtv != 0);
00277 pdbtv->Set(i, val->GetX(), val->GetConstant(), val->GetSlope());
00278 n++;
00279 }
00280 }
00281
00282 pdbtv = (PdbEmcTracedValue*) & (bank.getEntry(n));
00283 assert(pdbtv != 0);
00284 pdbtv->Set(tracedFEM.GetNumberOfChannels(), tracedFEM.GetXmax(), 0, 0);
00285 n++;
00286 pdbtv = (PdbEmcTracedValue*) & (bank.getEntry(n));
00287 assert(pdbtv != 0);
00288 pdbtv->Set(tracedFEM.GetNumberOfChannels() + 1, tracedFEM.GetXmin(), 0, 0);
00289 if ( theshift == 3 )
00290 {
00291 ++n;
00292 pdbtv = (PdbEmcTracedValue*) & (bank.getEntry(n));
00293 assert(pdbtv != 0);
00294 float bbct0 = tracedFEM.getValueFast(0);
00295 pdbtv->Set(tracedFEM.GetNumberOfChannels() + 2,
00296 0,
00297 bbct0,
00298 0);
00299 }
00300 }
00301 #endif