00001
00002
00003 #include <map>
00004
00005
00006
00007 #include "slowControl/SlowControlEntry.hh"
00008 #include "slowControl/DriftParams_t.hh"
00009 #include "slowControl/MeshParams_t.hh"
00010 #include "slowControl/PMParams_t.hh"
00011 #include "slowControl/SCSteerParams.hh"
00012 #include "slowControl/BoardSlowControl.hh"
00013 #include "slowControl/PMSlowControl.hh"
00014 #include "slowControl/SlowControlManager.hh"
00015
00016 #include "tools/MicroException.hh"
00017 #include "tools/SteerDesc.hh"
00018 #include "tools/Log.hh"
00019
00020 #include <iostream>
00021 #include <fstream>
00022 #include <iomanip>
00023
00024
00025
00026 using namespace std;
00027
00028
00029
00030
00031
00032 SlowControlManager::SlowControlManager()
00033 {
00034
00035
00036 }
00037
00038
00039 SlowControlManager::~SlowControlManager()
00040 {
00041 }
00042
00043
00044
00045 void SlowControlManager::build(const SteerDesc& sd) {
00046 for (int paramNum = 0 ; paramNum < sd.slowControls.size(); paramNum++) {
00047 const SlowControl_t& p = sd.slowControls[paramNum];
00048 addSteer(p.scId, p.type, p.chamberId,p.difId,p.boardId,p.pmId, p.name);
00049
00050 }
00051 }
00052
00053
00054 void SlowControlManager::addEntry(const SlowControlEntry& entry) {
00055
00056 genList.insert(entry);
00057 }
00058
00059
00060 const SlowControlEntry* SlowControlManager::getEntry(const double aTimeStamp)const {
00061
00062
00063
00064 std::set<SlowControlEntry>::const_iterator p = genList.begin();
00065 if ( aTimeStamp > p->getTimeStamp() + 20000 )
00066 {
00067 FILE_LOG(logWARNING) << " p->getTimeStamp() + 20000: " << fixed << p->getTimeStamp() + 20000 << endl;
00068 FILE_LOG(logWARNING) << " aTimeStamp: " << fixed << aTimeStamp << endl;
00069 throw MicroException("SlowControlManager : timestamp upper than max timestamp + 20000 ms:");
00070 }
00071
00072 int index = 0;
00073 for (p = genList.begin(); p != genList.end() ; p++)
00074 {
00075
00076 index++;
00077
00078
00079 if (aTimeStamp >= p->getTimeStamp() && p != genList.begin() )
00080 {
00081 return(&(*p));
00082 }
00083 }
00084
00085 throw MicroException("SlowControlManager : timestamp not found:");
00086 }
00087
00088
00089
00090 const BoardSlowControl& SlowControlManager::getBoard(const double timeStamp, const ui32 chamberId, const ui32 difId, const ui32 boardId)const {
00091 try
00092 {
00093 return this->getEntry(timeStamp)->getBoard(chamberId, difId, boardId);
00094 }
00095 catch (MicroException e)
00096 {
00097 throw MicroException("SlowControlManager : timestamp not found:");
00098 }
00099
00100 }
00101
00102
00103 i32 SlowControlManager::readDB(string path)
00104 {
00105 i32 nLines = 0;
00106
00107 ifstream inFile(path.c_str(), ifstream::in);
00108
00109 FILE_LOG(logDEBUG1) << "reading Slow Control data base" << endl;
00110 while (inFile.good()) {
00111 SlowControlEntry params;
00112 params.setTimeStamp(-1);
00113 for (std::list<SCSteerParams>::iterator sp = stList.begin(); sp != stList.end(); sp++) {
00114
00115 FILE_LOG(logDEBUG1) << " reading " << sp->type
00116 << " chamberId " << sp->chamberId
00117 << " difId " << sp->difId
00118 << " boardId " << sp->boardId
00119 << " pmId " << sp->pmId
00120 << " [" << sp->name << "]" << endl;
00121
00122 if (sp->type == TIMESTAMP) {
00123 double foo = 0;
00124 inFile >> foo;
00125 params.setTimeStamp(foo);
00126 FILE_LOG(logDEBUG1) << " timestamp " << fixed << params.getTimeStamp() << endl;
00127 }
00128 else if (sp->type == TEMPERATURE) {
00129 float foo = 0;
00130 inFile >> foo;
00131 params.setTemperature(foo);
00132 FILE_LOG(logDEBUG1) << " temperature " << fixed << params.getTemperature() << endl;
00133 }
00134 else if (sp->type == PRESSURE) {
00135 float foo = 0;
00136 inFile >> foo;
00137 params.setPressure(foo);
00138 FILE_LOG(logDEBUG1) << " pressure " << fixed << params.getPressure() << endl;
00139 }
00140 else if (sp->type == OVERPRESSURE) {
00141 float foo = 0;
00142 inFile >> foo;
00143 params.setOverPressure(foo);
00144 FILE_LOG(logDEBUG1) << " overPressure " << fixed << params.getOverPressure() << endl;
00145 }
00146 else if (sp->type == BOARD) {
00147 DriftParams_t drift(inFile);
00148 MeshParams_t mesh(inFile);
00149 try {
00150
00151 BoardSlowControl boardSC(sp->name,sp->chamberId, sp->difId, sp->boardId);
00152 boardSC.setParams(mesh,drift);
00153 params.setBoardParams(sp->chamberId, sp->difId, sp->boardId,boardSC);
00154
00155 FILE_LOG(logDEBUG1) << "chamberId " << sp->chamberId << " board " << sp->boardId << " : t=" << fixed << params.getTimeStamp() << ", drift " << drift << ", mesh " << mesh << endl;
00156 }
00157 catch (MicroException& e) {
00158 FILE_LOG(logERROR) << "board id " << sp->boardId << "difId " << sp->difId << "chamberId " << sp->chamberId << " and name[" << sp->name << "] not found " << endl;
00159 }
00160 }
00161 else if (sp->type == PM) {
00162 PMParams_t voltages(inFile);
00163 try {
00164
00165 PMSlowControl sc(sp->name , sp->pmId);
00166 sc.setParams(voltages);
00167 params.setPmParams(sp->pmId,sc);
00168 FILE_LOG(logDEBUG1) << " PM : t=" << fixed << params.getTimeStamp() << ", pm " << voltages << endl;
00169 }
00170 catch (MicroException& e) {
00171 FILE_LOG(logERROR) << "PM id " << sp->pmId << " [" << sp->name << "] not found " << endl;
00172 }
00173 }
00174
00175
00176 if (!inFile.good()) {
00177 break;
00178 }
00179 nLines++;
00180 }
00181
00182 if (params.getTimeStamp() > 0)
00183 addEntry(params);
00184 }
00185
00186 inFile.close();
00187 FILE_LOG(logINFO) << " found " << nLines << " slowcontrol inputs" << endl;
00188
00189
00190 FILE_LOG(logINFO) << "Slowcontrol data base read successfully" << endl;
00191 return 1;
00192 }
00193
00194
00195 void SlowControlManager::addSteer(const ui32 scId, const std::string type, const ui32 chamberId, const ui32 difId, const ui32 boardId, const ui32 pmId, const std::string name)
00196 { stList.push_back(SCSteerParams(scId, type, chamberId, difId, boardId, pmId, name)); };
00197
00198
00199