Changeset 14233 for trunk/FACT++/src
- Timestamp:
- 06/26/12 12:37:25 (12 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/Fits.cc
r13205 r14233 60 60 //! @param out Message object to use for propagating messages 61 61 // 62 void Fits::InitDataColumns(const vector<Description> &desc, const vector<string>& dataFormat, void* dataPointer, MessageImp* out)62 void Fits::InitDataColumns(const vector<Description> &desc, const vector<string>& dataFormat, const void* dataPointer, MessageImp* out) 63 63 { 64 64 fDataFormats = dataFormat; 65 fDataPointer = dataPointer; 65 //FIXME I removed the static assignment of the data pointer because it changes from event to event now. Remove the arg of this function 66 // fDataPointer = dataPointer; 66 67 67 68 if ((desc.size() == 0) && (dataFormat.size() == 0)) … … 314 315 //! @param conv the converter corresponding to the service being logged 315 316 // 316 bool Fits::Write(const Converter &conv )317 bool Fits::Write(const Converter &conv, const void* data) 317 318 { 318 319 //first copy the standard variables to the copy buffer … … 328 329 { 329 330 //now take care of the DIM data. The Converter is here for that purpose 330 conv.ToFits(fCopyBuffer.data()+shift, fDataPointer, fCopyBuffer.size()-shift);331 conv.ToFits(fCopyBuffer.data()+shift, data, fCopyBuffer.size()-shift); 331 332 } 332 333 catch (const runtime_error &e) -
trunk/FACT++/src/Fits.h
r12536 r14233 39 39 40 40 ///the pointer to the contiguous memory location where the data is stored (i.e. the dim data pointer) 41 void* fDataPointer;41 // void* fDataPointer; 42 42 ///the copy buffer. Required to put the standard and data variable in contguous memory 43 43 vector<char> fCopyBuffer; … … 61 61 62 62 Fits() : fFile(NULL), 63 fDataPointer(NULL),64 63 fEndMjD(0.0), 65 64 fNumOpenFitsFiles(NULL), … … 80 79 81 80 ///Adds columns specific to the service being logged. 82 void InitDataColumns(const vector<Description> &desc, const vector<string>& dataFormat, void* dataPointer, MessageImp* out);81 void InitDataColumns(const vector<Description> &desc, const vector<string>& dataFormat, const void* dataPointer, MessageImp* out); 83 82 84 83 ///Opens a FITS file … … 86 85 87 86 ///Write one line of data. Use the given converter. 88 bool Write(const Converter &conv );87 bool Write(const Converter &conv, const void* data); 89 88 90 89 ///Close the currently opened file. -
trunk/FACT++/src/datalogger.cc
r14217 r14233 84 84 #endif 85 85 86 #include "DimState.h" 86 87 87 88 //Dim structures … … 115 116 } 116 117 }; 118 119 EventImp nullEventImp; 117 120 ///Dim subscription type. Stores all the relevant info to handle a Dim subscription 118 121 struct SubscriptionType … … 137 140 /// that it is the first which is deleted -- and consequently none of 138 141 /// the other members can still be in use in an infoHandler) 139 shared_ptr<DimStampedInfo> dimInfo; 142 //DIM_REPLACE 143 //shared_ptr<DimStampedInfo> dimInfo; 144 unsigned int index; 145 140 146 ///Dim info constructor 141 SubscriptionType(DimStampedInfo* info=NULL) 147 //DIM_REPLACE 148 // SubscriptionType(DimStampedInfo* info=NULL) 149 SubscriptionType() 142 150 { 143 151 fConv = shared_ptr<Converter>(); … … 145 153 lastReceivedEvent = Time::None; 146 154 fitsBufferAllocated = false; 147 148 155 // Should be the last instantiated to make sure that all other 149 156 // variables which might be used are already initialized 150 dimInfo = shared_ptr<DimStampedInfo>(info); 157 //DIM_REPLACE 158 //dimInfo = shared_ptr<DimStampedInfo>(info); 159 index = 0; 151 160 } 152 161 ///default destructor … … 156 165 }; 157 166 158 class DataLogger : public StateMachineDim, DimServiceInfoListImp 167 class DataLogger : public StateMachineDim 168 //DIM_REPLACE 169 //, DimServiceInfoListImp 159 170 { 160 171 public: … … 216 227 ***************************************************/ 217 228 //overloading of DIM's infoHandler function 218 void infoHandler();229 int infoCallback(const EventImp& evt, unsigned int infoIndex); 219 230 220 231 /*************************************************** … … 222 233 ***************************************************/ 223 234 ///Reporting method for the services info received 224 void Report( DimInfo* I, SubscriptionType& sub);235 void Report(const EventImp& evt, SubscriptionType& sub); 225 236 226 237 ///Configuration of the nightly file path … … 229 240 int PrintState(const Event& evt); 230 241 ///checks whether or not the current info being treated is a run number 231 void CheckForRunNumber( DimInfo* I);242 void CheckForRunNumber(const EventImp& evt, unsigned int index); 232 243 /// start transition 233 244 int Start(); … … 244 255 #ifdef HAVE_FITS 245 256 ///Open fits files 246 void OpenFITSFiles(SubscriptionType& sub );257 void OpenFITSFiles(SubscriptionType& sub, const EventImp& evt); 247 258 ///Write data to FITS files 248 void WriteToFITS(SubscriptionType& sub );259 void WriteToFITS(SubscriptionType& sub, const void* data); 249 260 ///Allocate the buffers required for fits 250 void AllocateFITSBuffers(SubscriptionType& sub );261 void AllocateFITSBuffers(SubscriptionType& sub, const EventImp& evt); 251 262 #endif//has_fits 252 263 … … 314 325 bool ShouldSubscribe(const string& server, const string& service); 315 326 ///Subscribe to a given server and service 316 DimStampedInfo*SubscribeTo(const string& server, const string& service);327 // EventImp& SubscribeTo(const string& server, const string& service); 317 328 ///Open a text file and checks for ofstream status 318 329 bool OpenTextFile(ofstream& stream, const string& name); … … 331 342 * INHERITED FROM DimServiceInfoList 332 343 ***************************************************/ 344 ///Add a new server subscription 345 void AddServer(const string& server); 333 346 ///Add a new service subscription 334 void AddService(const string&, const string&, const string&, bool);347 void AddService(const Service& svc); 335 348 ///Remove a given service subscription 349 //FIXME unused 336 350 void RemoveService(const string, const string, bool); 337 351 ///Remove all the services associated with a given server 352 //FIXME unused 338 353 void RemoveAllServices(const string&); 339 354 ///pointer to the dim's subscription that should distribute the run numbers. 340 DimInfo* fRunNumberService; 355 //DIM_REPLACE 356 //DimInfo* fRunNumberService; 357 unsigned int fRunNumberService; 341 358 /*************************************************** 342 359 * Overwritten from MessageImp … … 350 367 int fCurrentDay; 351 368 Time lastFlush; 369 370 DimDnsServiceList fDimList; 371 vector<DimDescriptions*> fServerDescriptionsList; 372 373 //counter for keeping tracker of services 374 unsigned int servicesCounter; 352 375 public: 353 376 int Write(const Time &time, const std::string &txt, int qos=kMessage); … … 412 435 } 413 436 437 438 void DataLogger::AddServer(const string& server) 439 { 440 Info("Got request to add server " + server ); 441 if (server != "DIS_DNS") 442 { 443 DimDescriptions* d = new DimDescriptions(server); 444 d->Subscribe(*this); 445 fServerDescriptionsList.push_back(d); 446 } 447 448 } 449 414 450 // -------------------------------------------------------------------------- 415 451 // … … 419 455 //! @param isCmd whether this is a Dim Command or not. Commands are not logged 420 456 // 421 void DataLogger::AddService(const string& server, const string& service, const string&, bool isCmd) 422 { 423 //dataLogger does not subscribe to commands 457 void DataLogger::AddService(const Service& svc) 458 { 459 const string& server = svc.server; 460 const string& service = svc.service; 461 const bool isCmd = svc.iscmd; 462 463 Info("Got request to add service: "+server+"/"+service); 464 //dataLogger does not subscribe to commands 424 465 if (isCmd) 425 466 return; 426 467 427 Info("Got request to add service: "+server+"/"+service);428 468 429 469 //check the given subscription against black and white lists … … 438 478 return; 439 479 } 440 441 list[service].dimInfo.reset(SubscribeTo(server, service)); 480 //DIM_REPLACE 481 // list[service].dimInfo.reset(SubscribeTo(server, service)); 482 if (fDebugIsOn) 483 Debug("Subscribing to service "+server+"/"+service); 484 Subscribe(server + "/" + service) 485 (bind(&DataLogger::infoCallback, this, placeholders::_1, servicesCounter)); 442 486 list[service].server = server; 443 487 list[service].service = service; 488 list[service].index = servicesCounter; 444 489 fNumSubAndFitsData.numSubscriptions++; 445 490 //check if this is the run numbers service 446 491 if ((server == "FAD_CONTROL") && (service == "START_RUN")) 447 fRunNumberService = list[service].dimInfo.get(); 492 fRunNumberService = servicesCounter; 493 servicesCounter++; 448 494 Info("Added subscription to " + server + "/" + service); 449 495 } … … 457 503 void DataLogger::RemoveService(string server, string service, bool isCmd) 458 504 { 505 459 506 Info("Got request to remove service: "+server+"/"+service); 460 507 if (fDestructing)//this function is called by the super class, after the destructor has deleted its own subscriptions 461 508 return; 509 //FIXME unused 510 return; 462 511 463 512 if (isCmd) … … 482 531 483 532 if ((server == "FAD_CONTROL") && (service == "START_RUN")) 484 fRunNumberService = NULL;533 fRunNumberService = 0; 485 534 486 535 Info("Removed subscription to " + server + "/" + service); … … 499 548 return; 500 549 } 501 550 //FIXME unused 551 return; 502 552 fNumSubAndFitsData.numSubscriptions -= fServiceSubscriptions[server].size(); 503 553 … … 506 556 507 557 if (server == "FAD_CONTROL") 508 fRunNumberService = NULL;558 fRunNumberService = 0; 509 559 510 560 if (fDebugIsOn) … … 585 635 //! @param service the service name 586 636 // 587 DimStampedInfo* DataLogger::SubscribeTo(const string& server, const string& service) 588 { 589 if (fDebugIsOn) 590 Debug("Subscribing to service "+server+"/"+service); 591 592 return new DimStampedInfo((server + "/" + service).c_str(), (void*)NULL, 0, this); 593 } 637 /*EventImp& DataLogger::SubscribeTo(const string& server, const string& service) 638 { 639 640 //DIM_REPLACE 641 //return new DimStampedInfo((server + "/" + service).c_str(), (void*)NULL, 0, this); 642 EventImp& newSubscription = Subscribe(server + "/" + service); 643 newSubscription.bind(&infoHandler, this, placeholders::_1); 644 return newSubscription; 645 }*/ 594 646 // -------------------------------------------------------------------------- 595 647 // … … 703 755 { 704 756 shouldBackLog = true; 757 758 servicesCounter=1; 759 705 760 //initialize member data 706 761 fFilePath = "."; 762 763 fDimList.Subscribe(*this); 764 fDimList.SetCallbackServerAdd(bind(&DataLogger::AddServer, this, placeholders::_1)); 765 fDimList.SetCallbackServiceAdd(bind(&DataLogger::AddService, this, placeholders::_1)); 707 766 708 767 //calculate time "centered" around noon instead of midnight … … 809 868 NotifyOpenedFile("", 0, fOpenedRunFiles); 810 869 811 fRunNumberService = NULL; 870 fRunNumberService = 0; 871 812 872 fShouldAutoStart = false; 813 873 fAutoStarted = false; 874 875 814 876 if(fDebugIsOn) 815 877 { … … 855 917 } 856 918 919 for (auto it=fServerDescriptionsList.begin(); it!= fServerDescriptionsList.end(); it++) 920 delete *it; 921 857 922 if (fDebugIsOn) 858 923 Debug("DataLogger desctruction ends"); … … 880 945 //! Inherited from DimInfo. Handles all the Infos to which we subscribed, and log them 881 946 // 882 void DataLogger::infoHandler() 883 { 947 int DataLogger::infoCallback(const EventImp& evt, unsigned int subIndex) 948 { 949 // if (fDebugIsOn) 950 // { 951 // ostringstream str; 952 // str << "Got infoCallback called with service index= " << subIndex; 953 // Debug(str.str()); 954 // } 884 955 if ((GetCurrentState() == kSM_Ready) && (!fAutoStarted) && fShouldAutoStart) 885 956 { … … 892 963 fAutoStarted = true; 893 964 } 894 DimInfo* I = getInfo(); 895 896 if (I==NULL) 897 return; 965 898 966 899 967 //check if the service pointer corresponds to something that we subscribed to … … 904 972 for (x=fServiceSubscriptions.begin(); x != fServiceSubscriptions.end(); x++) 905 973 {//find current service is subscriptions 974 //Edit: this should be useless now... remove it sometimes ? 906 975 for (y=x->second.begin(); y!=x->second.end();y++) 907 if ( (y->second.dimInfo).get() == I)976 if (y->second.index == subIndex) 908 977 { 909 978 found = true; … … 914 983 } 915 984 if (!found) 916 return; 917 918 if (I->getSize() <= 0 || I->getData()==NULL) 919 { 920 return; 921 } 922 if (strlen(I->getFormat()) == 0) 923 { 924 ostringstream str; 925 str << "Format of " << I->getName() << " is empty (ptr=" << I->getData() << ", size=" << I->getSize() << ")... ignoring it."; 926 Warn(str); 927 return; 928 } 929 // Make sure that getTimestampMillisecs is NEVER called before 930 // getTimestamp is properly called 931 // check that the message has been updated by something, i.e. must be different from its initial value 932 if (I->getTimestamp() == 0) 933 { 934 return; 935 } 985 return GetCurrentState(); 986 987 if (evt.GetSize() == 0) 988 return GetCurrentState(); 989 if (evt.GetFormat() == "") 990 return GetCurrentState(); 991 936 992 // cout.precision(20); 937 993 // cout << "Orig timestamp: " << Time(I->getTimestamp(), I->getTimestampMillisecs()*1000).Mjd() << endl; … … 941 997 // subscribe to this service anyway and hence we have the pointer 942 998 // (no need to check for the name) 943 CheckForRunNumber( I);944 945 Report( I, y->second);999 CheckForRunNumber(evt, subIndex); 1000 1001 Report(evt, y->second); 946 1002 947 1003 //remove old run numbers 948 1004 TrimOldRunNumbers(); 1005 1006 return GetCurrentState(); 949 1007 } 950 1008 … … 1002 1060 //! the current DimInfo 1003 1061 // 1004 void DataLogger::CheckForRunNumber( DimInfo* I)1005 { 1006 if ( I!= fRunNumberService)1062 void DataLogger::CheckForRunNumber(const EventImp& evt, unsigned int index) 1063 { 1064 if (index != fRunNumberService) 1007 1065 return; 1008 1009 AddNewRunNumber( I->getLonglong(), Time(I->getTimestamp(), I->getTimestampMillisecs()*1000));1066 // int64_t newRun = reinterpret_cast<const uint64_t*>(evt.GetData())[0]; 1067 AddNewRunNumber(evt.GetXtra(), evt.GetTime()); 1010 1068 } 1011 1069 … … 1018 1076 //! The dataLogger's subscription corresponding to this DimInfo 1019 1077 // 1020 void DataLogger::Report( DimInfo* I, SubscriptionType& sub)1021 { 1022 const string fmt( I->getFormat());1078 void DataLogger::Report(const EventImp& evt, SubscriptionType& sub) 1079 { 1080 const string fmt(evt.GetFormat()); 1023 1081 1024 1082 const bool isItaReport = fmt!="C"; … … 1027 1085 return; 1028 1086 1029 if (fDebugIsOn && string( I->getName())!="DATA_LOGGER/MESSAGE")1087 if (fDebugIsOn && string(evt.GetName())!="DATA_LOGGER/MESSAGE") 1030 1088 { 1031 1089 ostringstream str; 1032 str << "Logging " << I->getName() << " [" << I->getFormat() << "] (" << I->getSize() << ")";1090 str << "Logging " << evt.GetName() << " [" << evt.GetFormat() << "] (" << evt.GetSize() << ")"; 1033 1091 Debug(str); 1034 1092 } … … 1105 1163 if (!sub.fConv) 1106 1164 { 1107 sub.fConv = shared_ptr<Converter>(new Converter(Out(), I->getFormat()));1165 sub.fConv = shared_ptr<Converter>(new Converter(Out(), evt.GetFormat())); 1108 1166 if (!sub.fConv->valid()) 1109 1167 { 1110 1168 ostringstream str; 1111 str << "Couldn't properly parse the format... service " << sub.dimInfo->getName() << " ignored.";1169 str << "Couldn't properly parse the format... service " << evt.GetName() << " ignored."; 1112 1170 Error(str); 1113 1171 return; … … 1116 1174 //construct the header 1117 1175 ostringstream header; 1118 const Time cTime( I->getTimestamp(), I->getTimestampMillisecs()*1000);1119 fQuality = I->getQuality();1176 const Time cTime(evt.GetTime()); 1177 fQuality = evt.GetQoS(); 1120 1178 //I had strange surprises with the quality from Dim before. Double check that the value is indeed valid. 1121 1179 if (fQuality != kMessage && … … 1132 1190 { 1133 1191 //write text header 1134 header << I->getName() << " " << fQuality << " ";1192 header << evt.GetName() << " " << fQuality << " "; 1135 1193 header << cTime.Y() << " " << cTime.M() << " " << cTime.D() << " "; 1136 1194 header << cTime.h() << " " << cTime.m() << " " << cTime.s() << " "; 1137 header << cTime.ms() << " " << I->getTimestamp() << " ";1195 header << cTime.ms() << " " << evt.GetTime() << " "; 1138 1196 1139 1197 string text; 1140 1198 try 1141 1199 { 1142 text = sub.fConv->GetString( I->getData(), I->getSize());1200 text = sub.fConv->GetString(evt.GetData(), evt.GetSize()); 1143 1201 } 1144 1202 catch (const runtime_error &e) 1145 1203 { 1146 1204 ostringstream str; 1147 str << "Parsing service " << sub.dimInfo->getName();1205 str << "Parsing service " << evt.GetName(); 1148 1206 str << " failed: " << e.what() << " removing the subscription for now."; 1149 1207 Error(str); … … 1157 1215 { 1158 1216 ostringstream str; 1159 str << "Service " << sub.dimInfo->getName() << " sent an empty string";1217 str << "Service " << evt.GetName() << " sent an empty string"; 1160 1218 Info(str); 1161 1219 return; … … 1178 1236 if (!sub.nightlyFile.IsOpen()) 1179 1237 if (GetCurrentState() != kSM_Ready) 1180 OpenFITSFiles(sub );1181 WriteToFITS(sub );1238 OpenFITSFiles(sub, evt); 1239 WriteToFITS(sub, evt.GetData()); 1182 1240 #endif 1183 1241 } … … 1187 1245 try 1188 1246 { 1189 strings = sub.fConv->ToStrings( I->getData());1247 strings = sub.fConv->ToStrings(evt.GetData()); 1190 1248 } 1191 1249 catch (const runtime_error &e) 1192 1250 { 1193 1251 ostringstream str; 1194 str << "Parsing service " << sub.dimInfo->getName();1252 str << "Parsing service " << evt.GetName(); 1195 1253 str << " failed: " << e.what() << " removing the subscription for now."; 1196 1254 Error(str); … … 1203 1261 { 1204 1262 ostringstream err; 1205 err << "There was more than one string message in service " << I->getName() << " going to fatal error state";1263 err << "There was more than one string message in service " << evt.GetName() << " going to fatal error state"; 1206 1264 Error(err.str()); 1207 1265 } 1208 1266 ostringstream msg; 1209 msg << I->getName() << ": " << strings[0];1267 msg << evt.GetName() << ": " << strings[0]; 1210 1268 1211 1269 if (fNightlyLogFile.is_open()) … … 1219 1277 if (!sub.nightlyFile.IsOpen()) 1220 1278 if (GetCurrentState() != kSM_Ready) 1221 OpenFITSFiles(sub );1222 WriteToFITS(sub );1279 OpenFITSFiles(sub, evt); 1280 WriteToFITS(sub, evt.GetData()); 1223 1281 } 1224 1282 … … 1525 1583 //! @param sub 1526 1584 //! the current DimInfo subscription being examined 1527 void DataLogger::OpenFITSFiles(SubscriptionType& sub )1528 { 1529 string serviceName(sub. dimInfo->getName());1585 void DataLogger::OpenFITSFiles(SubscriptionType& sub, const EventImp& evt) 1586 { 1587 string serviceName(sub.server + "_" + sub.service);//evt.GetName()); 1530 1588 1531 1589 for (unsigned int i=0;i<serviceName.size(); i++) … … 1544 1602 const string fileNameOnly = partialName.substr(partialName.find_last_of('/')+1, partialName.size()); 1545 1603 if (!sub.fitsBufferAllocated) 1546 AllocateFITSBuffers(sub );1604 AllocateFITSBuffers(sub, evt); 1547 1605 //get the size of the file we're about to open 1548 1606 if (fFilesStats.FileOpened(partialName)) … … 1572 1630 //! @param sub the subscription of interest. 1573 1631 // 1574 void DataLogger::AllocateFITSBuffers(SubscriptionType& sub )1632 void DataLogger::AllocateFITSBuffers(SubscriptionType& sub, const EventImp& evt) 1575 1633 { 1576 1634 //Init the time columns of the file … … 1595 1653 str << "Initializing data columns for service " << sub.server << "/" << sub.service; 1596 1654 Info(str); 1597 sub.nightlyFile.InitDataColumns( GetDescription(sub.server, sub.service), dataFormatsLocal, sub.dimInfo->getData(), this);1655 sub.nightlyFile.InitDataColumns(Description::SplitDescription(evt.GetDescription()), dataFormatsLocal, evt.GetData(), this); 1598 1656 1599 1657 sub.fitsBufferAllocated = true; … … 1603 1661 //! write a dimInfo data to its corresponding FITS files 1604 1662 // 1605 void DataLogger::WriteToFITS(SubscriptionType& sub) 1663 //FIXME: DO I REALLY NEED THE EVENT IMP HERE ??? 1664 void DataLogger::WriteToFITS(SubscriptionType& sub, const void* data) 1606 1665 { 1607 1666 //nightly File status (open or not) already checked 1608 1667 if (sub.nightlyFile.IsOpen()) 1609 1668 { 1610 if (!sub.nightlyFile.Write(*sub.fConv.get() ))1669 if (!sub.nightlyFile.Write(*sub.fConv.get(), data)) 1611 1670 { 1612 1671 RemoveService(sub.server, sub.service, false); … … 1976 2035 int RunShell(Configuration &conf) 1977 2036 { 1978 return Main::execute<T, DataLogger>(conf , true);2037 return Main::execute<T, DataLogger>(conf);//, true); 1979 2038 } 1980 2039
Note:
See TracChangeset
for help on using the changeset viewer.