00001 #include "emcOMAsciiT.h"
00002 #include "emcPedestalFEM.h"
00003 #include <string>
00004 #include <vector>
00005 #include "emcDataManager.h"
00006 #include "EmcIndexer.h"
00007 #include <cassert>
00008 #include <cstdio>
00009 #include <fstream>
00010 #include "asciitimestamp.h"
00011
00012 namespace
00013 {
00014 bool reader(emcPedestalFEM& pedFEM, int code)
00015 {
00016 int femAbsPosition;
00017 int pinNumber;
00018 int idummy;
00019 if (code<0)
00020 {
00021 std::cerr << __FILE__ << ":" << __LINE__ << " Sorry, I need "
00022 << " a full code to be able to deduce the pinnumber"
00023 << std::endl;
00024 return false;
00025 }
00026 emcCalFEM::FEMDecode(code,femAbsPosition,pinNumber,idummy,idummy);
00027 assert(femAbsPosition==pedFEM.AbsolutePosition());
00028
00029
00030
00031
00032
00033 pedFEM.Reset();
00034 std::vector<std::string> valid_types;
00035
00036 pedFEM.GetListOfValidTypes(valid_types);
00037
00038 int SN, SM144N;
00039
00040 EmcIndexer::PXSM144_iSiSM144(femAbsPosition , SN, SM144N);
00041
00042 char filename[1024];
00043 const int nchannel_per_file = 144;
00044 const int namu_per_channel = 64;
00045 PHTimeStamp begin;
00046 PHTimeStamp insert;
00047
00048 emcDataManager* dm = emcDataManager::GetInstance();
00049
00050 for ( size_t ped_type = 0; ped_type < valid_types.size(); ped_type++)
00051 {
00052 if ( valid_types[ped_type] == "TACDEV" )
00053 {
00054
00055 continue;
00056 }
00057
00058
00059 sprintf(filename,
00060 "%s/PEDESTALS/%sSM%d.%s",
00061 dm->GetSourceDir(),
00062 EmcIndexer::EmcSectorId(SN),
00063 SM144N,
00064
00065 valid_types[ped_type].c_str());
00066
00067
00068 std::ifstream in(filename);
00069 if (!in)
00070 {
00071 std::cerr << __FILE__ << ":" << __LINE__
00072 << " Cannot open "
00073 << filename << std::endl;
00074 return false;
00075 }
00076
00077 begin = getTimeStamp(in);
00078 insert = getTimeStamp(in);
00079
00080 int amu;
00081
00082 emcPedestalFEM::AmuVector amuv(namu_per_channel);
00083
00084 for ( int i = 0; i < nchannel_per_file; i++ )
00085 {
00086
00087 for ( int AMU = 0; AMU < namu_per_channel; AMU++ )
00088 {
00089 in >> amu;
00090 amuv[AMU] = amu;
00091 }
00092 pedFEM.AppendOneChannel(valid_types[ped_type].c_str(),amuv);
00093 }
00094 in.close();
00095 }
00096
00097 PHTimeStamp end;
00098 end.setToFarFuture();
00099
00100 pedFEM.SetValidityPeriod(begin,end);
00101
00102 return true;
00103 }
00104
00105 emcOMAsciiT<emcPedestalFEM> gemcOMPedestalFEM("emcOMPedestal",
00106 "Read emcPedestalFEM objects",
00107 reader);
00108 }