00001 #include "TEpicsEvent.h" 00002 00003 #include <sstream> 00004 #include <stdio.h> 00005 00006 #include "TGo4Log.h" 00007 00008 #include "typedefs.h" 00009 00010 00011 extern "C" 00012 { 00013 INTS4 f_ut_utime(INTS4 l_sec, INTS4 l_msec, CHARS *pc_time); 00014 } 00015 00016 #include "f_ut_utime.h" 00017 00018 00019 TEpicsEvent::TEpicsEvent() : 00020 TGo4EventElement() 00021 { 00022 } 00023 00024 TEpicsEvent::TEpicsEvent(const char* name, Short_t id) : 00025 TGo4EventElement(name,name,id) 00026 { 00027 TGo4Log::Info("TEpicsEvent: Create instance %s with composite id ", name, id); 00028 InitRecordNames(); 00029 } 00030 00031 00032 TEpicsEvent::~TEpicsEvent() 00033 { 00034 } 00035 00036 void TEpicsEvent::Clear(Option_t *t) 00037 { 00038 SetValid(kFALSE); // valid flag is used to mark newly updated event 00039 } 00040 00041 void TEpicsEvent::ResetData() 00042 { 00043 fEventId=0; 00044 fUTimeSeconds=0; 00045 fLongRecords.clear(); 00046 fDoubleRecords.clear(); 00047 } 00048 00049 void TEpicsEvent::PrintEvent() 00050 { 00051 TGo4EventElement::PrintEvent(); 00052 printf("\nEPICS event printout:\n Update Time:%s\n",GetUpdateTimeString()); 00053 for(unsigned i=0; i<GetNumLongs();++i) 00054 { 00055 std::string pv="Unknown record"; 00056 if(i<fEpicsLongIndices.size()) pv=fEpicsLongIndices[i]; 00057 printf("L[%d] - %s = %lld\t",i, pv.c_str(), GetLong(i)); 00058 if(((i+1)%4)==0) printf("\n"); 00059 } 00060 printf("\n"); 00061 for(unsigned i=0; i<GetNumDoubles();++i) 00062 { 00063 std::string pv="Unknown record"; 00064 if(i<fEpicsDoubleIndices.size()) pv=fEpicsDoubleIndices[i]; 00065 printf("D[%d] - %s = %e\t",i, pv.c_str(), GetDouble(i)); 00066 if(((i+1)%4)==0) printf("\n"); 00067 } 00068 printf("\n"); 00069 } 00070 00071 bool TEpicsEvent::IsLong(const std::string& pvname) const 00072 { 00073 std::vector<std::string>::const_iterator it = 00074 find(fEpicsLongIndices.begin(), fEpicsLongIndices.end(), pvname); 00075 return it!=fEpicsLongIndices.end(); 00076 } 00077 00078 bool TEpicsEvent::IsDouble(const std::string& pvname) const 00079 { 00080 std::vector<std::string>::const_iterator it = 00081 find(fEpicsDoubleIndices.begin(), fEpicsDoubleIndices.end(), pvname); 00082 return it!=fEpicsDoubleIndices.end(); 00083 } 00084 00085 00086 Long64_t TEpicsEvent::GetLong(const std::string& pvname) const 00087 { 00088 std::vector<std::string>::const_iterator it = 00089 find(fEpicsLongIndices.begin(), fEpicsLongIndices.end(), pvname); 00090 if(it==fEpicsLongIndices.end()){ 00091 // TGo4Log::Error("TEpicsEvent Error: no PV of key %s found in long array!", pvname.c_str()); 00092 return 0; 00093 } 00094 unsigned ix = it - fEpicsLongIndices.begin(); 00095 return GetLong(ix); 00096 } 00097 00098 Double_t TEpicsEvent::GetDouble(const std::string& pvname) const 00099 { 00100 std::vector<std::string>::const_iterator it = 00101 find(fEpicsDoubleIndices.begin(), fEpicsDoubleIndices.end(), pvname); 00102 if(it==fEpicsDoubleIndices.end()) { 00103 //TGo4Log::Error("TEpicsEvent Error: no PV of key %s found in double array!", pvname.c_str()); 00104 return 0; 00105 } 00106 unsigned ix = it - fEpicsDoubleIndices.begin(); 00107 return GetDouble(ix); 00108 } 00109 00110 const char* TEpicsEvent::GetUpdateTimeString() 00111 { 00112 if(fUTimeSeconds==0) 00113 { 00114 snprintf(fcTimeString,CBM_EPIX_STRLEN, "EPICS time not available"); 00115 } 00116 else 00117 { 00118 UInt_t timeseconds=fUTimeSeconds; 00119 UInt_t timemicros=0; 00120 f_ut_utime(timeseconds, timemicros, fcTimeString); 00121 } 00122 return fcTimeString; 00123 } 00124 00125 00126 void TEpicsEvent::UpdateRecordNames(const char* descriptor, size_t dlen) 00127 { 00128 std::istringstream input(std::string(descriptor, dlen), std::istringstream::in); 00129 char curbuf[256]; 00130 std::string curname; 00131 unsigned numlong(0), numdub(0); 00132 fEpicsLongIndices.clear(); 00133 fEpicsDoubleIndices.clear(); 00134 // first get number of long records: 00135 input.getline(curbuf,256,'\0'); // use string separators '\0' here 00136 sscanf(curbuf, "%u",&numlong); 00137 if (_VARPRINT_) 00138 TGo4Log::Info("Number of long descriptors: %u", numlong); 00139 for (unsigned i = 0; i < numlong; ++i) { 00140 input.getline(curbuf,256,'\0'); 00141 curname=curbuf; 00142 if (_VARPRINT_) 00143 TGo4Log::Info("Long descriptor %u curname %s", i, curname.c_str()); 00144 fEpicsLongIndices.push_back(curname); 00145 } 00146 // get number of double records: 00147 00148 input.getline(curbuf,256,'\0'); 00149 sscanf(curbuf,"%u",&numdub); 00150 if (_VARPRINT_) 00151 TGo4Log::Info("Number of double descriptors: %u", numdub); 00152 for (unsigned i = 0; i < numdub; ++i) { 00153 input.getline(curbuf,256,'\0'); 00154 curname=curbuf; 00155 if (_VARPRINT_) 00156 TGo4Log::Info("Double descriptor %u curname %s", i, curname.c_str()); 00157 fEpicsDoubleIndices.push_back(curname); 00158 } 00159 } 00160 00161 bool TEpicsEvent::CheckConsistent(bool printerr) 00162 { 00163 bool ok = true; 00164 00165 if ((fEpicsLongIndices.size() > 0) && (fEpicsLongIndices.size() != fLongRecords.size())) { 00166 ok = false; 00167 if (printerr) printf("Mismatch between number of long values %u and descr %u\n", 00168 (unsigned) fLongRecords.size(), (unsigned) fEpicsLongIndices.size()); 00169 } 00170 00171 00172 if ((fEpicsDoubleIndices.size() > 0) && (fEpicsDoubleIndices.size()!=fDoubleRecords.size())) { 00173 ok = false; 00174 if (printerr) printf("Mismatch between number of double values %u and descr %u\n", 00175 (unsigned) fDoubleRecords.size(), (unsigned) fEpicsDoubleIndices.size()); 00176 } 00177 00178 if (!ok) ResetData(); 00179 00180 return ok; 00181 } 00182 00183 00184 00185 void TEpicsEvent::InitRecordNames() 00186 { 00187 // here the map to assign indices to full process variable names 00188 // NOTE: this is the example setup from beamtime COSY December 2010 00189 // you may adjust this to your current beamtime setup! 00190 // NOTE 2: dabc will provide dynamically list of pv names 00191 // so adjustment to actual setup is not necessary here! 00192 00193 // may be loaded dynamically later 00194 fEpicsLongIndices.clear(); 00195 // put long indices here: 00196 00197 fEpicsDoubleIndices.clear(); 00198 // here double indices 00199 00200 /* fEpicsDoubleIndices.push_back("CBM:STSHV:0:CH0:imon"); 00201 fEpicsDoubleIndices.push_back("CBM:STSHV:0:CH0:vmon"); 00202 fEpicsDoubleIndices.push_back("CBM:STSHV:0:CH1:imon"); 00203 fEpicsDoubleIndices.push_back("CBM:STSHV:0:CH1:vmon"); 00204 fEpicsDoubleIndices.push_back("CBM:STSHV:0:CH2:imon"); 00205 fEpicsDoubleIndices.push_back("CBM:STSHV:0:CH2:vmon"); 00206 fEpicsDoubleIndices.push_back("CBM:STSHV:0:CH3:imon"); 00207 fEpicsDoubleIndices.push_back("CBM:STSHV:0:CH3:vmon"); 00208 fEpicsDoubleIndices.push_back("CBM:STSHV:0:CH4:imon"); 00209 fEpicsDoubleIndices.push_back("CBM:STSHV:0:CH4:vmon"); 00210 fEpicsDoubleIndices.push_back("CBM:STSHV:0:CH5:imon"); 00211 fEpicsDoubleIndices.push_back("CBM:STSHV:0:CH5:vmon"); 00212 fEpicsDoubleIndices.push_back("CBM:STSHV:1:CH0:imon"); 00213 fEpicsDoubleIndices.push_back("CBM:STSHV:1:CH0:vmon"); 00214 fEpicsDoubleIndices.push_back("CBM:STSHV:1:CH1:imon"); 00215 fEpicsDoubleIndices.push_back("CBM:STSHV:1:CH1:vmon"); 00216 fEpicsDoubleIndices.push_back("CBM:STSHV:1:CH2:imon"); 00217 fEpicsDoubleIndices.push_back("CBM:STSHV:1:CH2:vmon"); 00218 fEpicsDoubleIndices.push_back("CBM:STSHV:1:CH3:imon"); 00219 fEpicsDoubleIndices.push_back("CBM:STSHV:1:CH3:vmon"); 00220 fEpicsDoubleIndices.push_back("CBM:STSHV:1:CH4:imon"); 00221 fEpicsDoubleIndices.push_back("CBM:STSHV:1:CH4:vmon"); 00222 fEpicsDoubleIndices.push_back("CBM:STSHV:1:CH5:imon"); 00223 fEpicsDoubleIndices.push_back("CBM:STSHV:1:CH5:vmon"); 00224 fEpicsDoubleIndices.push_back("CBM:STSHV:2:CH0:imon"); 00225 fEpicsDoubleIndices.push_back("CBM:STSHV:2:CH0:vmon"); 00226 fEpicsDoubleIndices.push_back("CBM:STSHV:2:CH1:imon"); 00227 fEpicsDoubleIndices.push_back("CBM:STSHV:2:CH1:vmon"); 00228 fEpicsDoubleIndices.push_back("CBM:STSHV:2:CH2:imon"); 00229 fEpicsDoubleIndices.push_back("CBM:STSHV:2:CH2:vmon"); 00230 fEpicsDoubleIndices.push_back("CBM:STSHV:2:CH3:imon"); 00231 fEpicsDoubleIndices.push_back("CBM:STSHV:2:CH3:vmon"); 00232 fEpicsDoubleIndices.push_back("CBM:STSHV:2:CH4:imon"); 00233 fEpicsDoubleIndices.push_back("CBM:STSHV:2:CH4:vmon"); 00234 fEpicsDoubleIndices.push_back("CBM:STSHV:2:CH5:imon"); 00235 fEpicsDoubleIndices.push_back("CBM:STSHV:2:CH5:vmon"); 00236 fEpicsDoubleIndices.push_back("CBM:STSHV:3:CH0:imon"); 00237 fEpicsDoubleIndices.push_back("CBM:STSHV:3:CH0:vmon"); 00238 fEpicsDoubleIndices.push_back("CBM:STSHV:3:CH1:imon"); 00239 fEpicsDoubleIndices.push_back("CBM:STSHV:3:CH1:vmon"); 00240 fEpicsDoubleIndices.push_back("CBM:STSHV:3:CH2:imon"); 00241 fEpicsDoubleIndices.push_back("CBM:STSHV:3:CH2:vmon"); 00242 fEpicsDoubleIndices.push_back("CBM:STSHV:3:CH3:imon"); 00243 fEpicsDoubleIndices.push_back("CBM:STSHV:3:CH3:vmon"); 00244 fEpicsDoubleIndices.push_back("CBM:STSHV:3:CH4:imon"); 00245 fEpicsDoubleIndices.push_back("CBM:STSHV:3:CH4:vmon"); 00246 fEpicsDoubleIndices.push_back("CBM:STSHV:3:CH5:imon"); 00247 fEpicsDoubleIndices.push_back("CBM:STSHV:3:CH5:vmon"); 00248 fEpicsDoubleIndices.push_back("CBM:STSHV:4:CH0:imon"); 00249 fEpicsDoubleIndices.push_back("CBM:STSHV:4:CH0:vmon"); 00250 fEpicsDoubleIndices.push_back("CBM:STSHV:4:CH1:imon"); 00251 fEpicsDoubleIndices.push_back("CBM:STSHV:4:CH1:vmon"); 00252 fEpicsDoubleIndices.push_back("CBM:STSHV:4:CH2:imon"); 00253 fEpicsDoubleIndices.push_back("CBM:STSHV:4:CH2:vmon"); 00254 fEpicsDoubleIndices.push_back("CBM:STSHV:4:CH3:imon"); 00255 fEpicsDoubleIndices.push_back("CBM:STSHV:4:CH3:vmon"); 00256 fEpicsDoubleIndices.push_back("CBM:STSHV:4:CH4:imon"); 00257 fEpicsDoubleIndices.push_back("CBM:STSHV:4:CH4:vmon"); 00258 fEpicsDoubleIndices.push_back("CBM:STSHV:4:CH5:imon"); 00259 fEpicsDoubleIndices.push_back("CBM:STSHV:4:CH5:vmon"); 00260 fEpicsDoubleIndices.push_back("CBM:STSHV:5:CH0:imon"); 00261 fEpicsDoubleIndices.push_back("CBM:STSHV:5:CH0:vmon"); 00262 fEpicsDoubleIndices.push_back("CBM:STSHV:5:CH1:imon"); 00263 fEpicsDoubleIndices.push_back("CBM:STSHV:5:CH1:vmon"); 00264 fEpicsDoubleIndices.push_back("CBM:STSHV:5:CH2:imon"); 00265 fEpicsDoubleIndices.push_back("CBM:STSHV:5:CH2:vmon"); 00266 fEpicsDoubleIndices.push_back("CBM:STSHV:5:CH3:imon"); 00267 fEpicsDoubleIndices.push_back("CBM:STSHV:5:CH3:vmon"); 00268 fEpicsDoubleIndices.push_back("CBM:STSHV:5:CH4:imon"); 00269 fEpicsDoubleIndices.push_back("CBM:STSHV:5:CH4:vmon"); 00270 fEpicsDoubleIndices.push_back("CBM:STSHV:5:CH5:imon"); 00271 fEpicsDoubleIndices.push_back("CBM:STSHV:5:CH5:vmon"); 00272 fEpicsDoubleIndices.push_back("CBM:PS:01:GETVOLTS:1"); 00273 fEpicsDoubleIndices.push_back("CBM:PS:01:GETCUR:1"); 00274 fEpicsDoubleIndices.push_back("CBM:PS:01:GETVOLTS:2"); 00275 fEpicsDoubleIndices.push_back("CBM:PS:01:GETCUR:2"); 00276 fEpicsDoubleIndices.push_back("CBM:PS:01:GETVOLTS:3"); 00277 fEpicsDoubleIndices.push_back("CBM:PS:01:GETCUR:3"); 00278 fEpicsDoubleIndices.push_back("CBM:PS:01:GETVOLTS:4"); 00279 fEpicsDoubleIndices.push_back("CBM:PS:01:GETCUR:4"); 00280 fEpicsDoubleIndices.push_back("CBM:PS:02:GETVOLTS:1"); 00281 fEpicsDoubleIndices.push_back("CBM:PS:02:GETCUR:1"); 00282 fEpicsDoubleIndices.push_back("CBM:PS:02:GETVOLTS:2"); 00283 fEpicsDoubleIndices.push_back("CBM:PS:02:GETCUR:2"); 00284 fEpicsDoubleIndices.push_back("CBM:PS:02:GETVOLTS:3"); 00285 fEpicsDoubleIndices.push_back("CBM:PS:02:GETCUR:3"); 00286 fEpicsDoubleIndices.push_back("CBM:PS:02:GETVOLTS:4"); 00287 fEpicsDoubleIndices.push_back("CBM:PS:02:GETCUR:4"); 00288 fEpicsDoubleIndices.push_back("CBM:PS:03:GETVOLTS:1"); 00289 fEpicsDoubleIndices.push_back("CBM:PS:03:GETCUR:1"); 00290 fEpicsDoubleIndices.push_back("CBM:PS:03:GETVOLTS:2"); 00291 fEpicsDoubleIndices.push_back("CBM:PS:03:GETCUR:2"); 00292 fEpicsDoubleIndices.push_back("CBM:PS:03:GETVOLTS:3"); 00293 fEpicsDoubleIndices.push_back("CBM:PS:03:GETCUR:3"); 00294 fEpicsDoubleIndices.push_back("CBM:PS:03:GETVOLTS:4"); 00295 fEpicsDoubleIndices.push_back("CBM:PS:03:GETCUR:4"); 00296 fEpicsDoubleIndices.push_back("CBM:PS:04:GETVOLTS:1"); 00297 fEpicsDoubleIndices.push_back("CBM:PS:04:GETCUR:1"); 00298 fEpicsDoubleIndices.push_back("CBM:PS:04:GETVOLTS:2"); 00299 fEpicsDoubleIndices.push_back("CBM:PS:04:GETCUR:2"); 00300 fEpicsDoubleIndices.push_back("CBM:PS:04:GETVOLTS:3"); 00301 fEpicsDoubleIndices.push_back("CBM:PS:04:GETCUR:3"); 00302 fEpicsDoubleIndices.push_back("CBM:PS:04:GETVOLTS:4"); 00303 fEpicsDoubleIndices.push_back("CBM:PS:04:GETCUR:4"); 00304 fEpicsDoubleIndices.push_back("CBM:WAGO:CARD0:Temp1"); 00305 fEpicsDoubleIndices.push_back("CBM:WAGO:CARD0:Temp2"); 00306 fEpicsDoubleIndices.push_back("CBM:WAGO:CARD0:Temp3"); 00307 fEpicsDoubleIndices.push_back("CBM:WAGO:CARD0:Temp4"); 00308 fEpicsDoubleIndices.push_back("CBM:WAGO:CARD1:Temp1"); 00309 fEpicsDoubleIndices.push_back("CBM:WAGO:CARD1:Temp2"); 00310 fEpicsDoubleIndices.push_back("CBM:WAGO:CARD1:Temp3"); 00311 fEpicsDoubleIndices.push_back("CBM:WAGO:CARD1:Temp4"); 00312 fEpicsDoubleIndices.push_back("CBM:WAGO:CARD2:Temp1"); 00313 fEpicsDoubleIndices.push_back("CBM:WAGO:CARD2:Temp2"); 00314 fEpicsDoubleIndices.push_back("CBM:WAGO:CARD2:Temp3"); 00315 fEpicsDoubleIndices.push_back("CBM:WAGO:CARD2:Temp4"); 00316 fEpicsDoubleIndices.push_back("CBM:WAGO:CARD3:Temp1"); 00317 fEpicsDoubleIndices.push_back("CBM:WAGO:CARD3:Temp2"); 00318 fEpicsDoubleIndices.push_back("CBM:WAGO:CARD3:Temp3"); 00319 fEpicsDoubleIndices.push_back("CBM:WAGO:CARD3:Temp4"); 00320 fEpicsDoubleIndices.push_back("CBM:WAGO:CARD4:Temp1"); 00321 fEpicsDoubleIndices.push_back("CBM:WAGO:CARD4:Temp2"); 00322 fEpicsDoubleIndices.push_back("CBM:WAGO:CARD4:Temp3"); 00323 fEpicsDoubleIndices.push_back("CBM:WAGO:CARD4:Temp4"); 00324 fEpicsDoubleIndices.push_back("CBM:LAUDA0:Get00"); 00325 fEpicsDoubleIndices.push_back("CBM:LAUDA0:Read:Bath"); 00326 fEpicsDoubleIndices.push_back("CBM:MOTOR:GETPOSX"); 00327 fEpicsDoubleIndices.push_back("CBM:MOTOR:GETPOSY"); 00328 fEpicsDoubleIndices.push_back("CBM:rolu:step_to_mm_L"); 00329 fEpicsDoubleIndices.push_back("CBM:rolu:step_to_mm_O"); 00330 fEpicsDoubleIndices.push_back("CBM:rolu:step_to_mm_R"); 00331 fEpicsDoubleIndices.push_back("CBM:rolu:step_to_mm_U"); 00332 */ 00333 }