00001 #include "otsdaq-core/RootUtilities/DQMHistosOuterTracker.h"
00002 #include "otsdaq-core/DataDecoders/FSSRData.h"
00003 #include "otsdaq-core/DataDecoders/VIPICData.h"
00004 #include "otsdaq-core/NetworkUtilities/NetworkConverters.h"
00005 #include "otsdaq-core/ConfigurationInterface/ConfigurationManager.h"
00006
00007 #include "otsdaq-core/ConfigurationPluginDataFormats/DetectorConfiguration.h"
00008 #include "otsdaq-core/ConfigurationPluginDataFormats/FEConfiguration.h"
00009 #include "otsdaq-core/ConfigurationPluginDataFormats/DetectorToFEConfiguration.h"
00010 #include "otsdaq-core/ConfigurationPluginDataFormats/DataManagerConfiguration.h"
00011 #include "otsdaq-core/ConfigurationPluginDataFormats/DataBufferConfiguration.h"
00012 #include "otsdaq-core/ConfigurationPluginDataFormats/UDPDataStreamerConsumerConfiguration.h"
00013 #include "otsdaq-core/ConfigurationPluginDataFormats/UDPDataListenerProducerConfiguration.h"
00014 #include "otsdaq-core/ConfigurationDataFormats/FEInterfaceConfigurationBase.h"
00015
00016
00017
00018 #include <iostream>
00019 #include <string>
00020 #include <sstream>
00021
00022 #include <TH1.h>
00023 #include <TH2.h>
00024 #include <TH1F.h>
00025 #include <TH2F.h>
00026 #include <TProfile.h>
00027 #include <TCanvas.h>
00028 #include <TFrame.h>
00029 #include <TRandom.h>
00030 #include <TThread.h>
00031 #include <TROOT.h>
00032 #include <TDirectory.h>
00033 #include <TFile.h>
00034 #include <TStyle.h>
00035
00036 #include <stdint.h>
00037
00038
00039
00040
00041
00042 using namespace ots;
00043
00044
00045
00046 DQMHistosOuterTracker::DQMHistosOuterTracker(std::string supervisorApplicationUID, std::string bufferUID, std::string processorUID)
00047 : theFile_ (0)
00048 , theDataDecoder_ (supervisorApplicationUID, bufferUID, processorUID)
00049 , supervisorApplicationUID_(supervisorApplicationUID)
00050 , bufferUID_ (bufferUID)
00051 , processorUID_ (processorUID)
00052 {
00053 gStyle->SetPalette(1);
00054 }
00055
00056
00057 DQMHistosOuterTracker::~DQMHistosOuterTracker(void)
00058 {
00059 closeFile();
00060 }
00061
00062
00063 void DQMHistosOuterTracker::openFile (std::string fileName)
00064 {
00065 closeFile();
00066 currentDirectory_ = 0;
00067 theFile_ = TFile::Open(fileName.c_str(), "RECREATE");
00068 theFile_->cd();
00069
00070 }
00071
00072
00073 void DQMHistosOuterTracker::book()
00074 {
00075 std::cout << __COUT_HDR_FL__ << "Booking start!" << std::endl;
00076
00077 currentDirectory_ = theFile_->mkdir("General", "General");
00078 currentDirectory_->cd();
00079 numberOfTriggers_ = new TH1I("NumberOfTriggers", "Number of triggers", 1, -0.5, 0.5);
00080 currentDirectory_ = theFile_->mkdir("Planes", "Planes");
00081 currentDirectory_->cd();
00082 std::stringstream name;
00083 std::stringstream title;
00084
00085 const FEConfiguration* feConfiguration = theConfigurationManager_->__GET_CONFIG__(FEConfiguration);
00086 const DetectorToFEConfiguration* detectorToFEConfiguration = theConfigurationManager_->__GET_CONFIG__(DetectorToFEConfiguration);
00087 const DataManagerConfiguration* dataManagerConfiguration = theConfigurationManager_->__GET_CONFIG__(DataManagerConfiguration);
00088 const DataBufferConfiguration* dataBufferConfiguration = theConfigurationManager_->__GET_CONFIG__(DataBufferConfiguration);
00089 const UDPDataStreamerConsumerConfiguration* dataStreamerConsumerConfiguration = theConfigurationManager_->__GET_CONFIG__(UDPDataStreamerConsumerConfiguration);
00090 const DetectorConfiguration* detectorConfiguration = theConfigurationManager_->__GET_CONFIG__(DetectorConfiguration);
00091
00092
00093
00094
00095
00096
00097
00098 std::stringstream processName;
00099 std::vector<std::string> bufferList = dataManagerConfiguration->getListOfDataBuffers();
00100 std::vector<std::string> interfaceList = feConfiguration->getListOfFEIDs();
00101 for(const auto& itInterfaces: interfaceList)
00102 {
00103 std::string streamToIP;
00104 std::string streamToPort;
00105
00106
00107
00108
00109
00110
00111 if(feConfiguration->getFEInterfaceType(itInterfaces).find("FSSRInterface") != std::string::npos)
00112 {
00113 const ConfigurationBase* interfaceConfiguration = theConfigurationManager_->getConfigurationByName(feConfiguration->getFEInterfaceType(itInterfaces)+"Configuration");
00114 auto feinterfaceConfiguration = dynamic_cast<const FEInterfaceConfigurationBase*>(interfaceConfiguration);
00115 if(feinterfaceConfiguration) {
00116 streamToIP = feinterfaceConfiguration->getStreamingIPAddress(itInterfaces);
00117 streamToPort = feinterfaceConfiguration->getStreamingPort(itInterfaces);
00118 }
00119 }
00120
00121 for(const auto& itBuffers: bufferList)
00122 {
00123 std::vector<std::string> producerList = dataBufferConfiguration->getProducerIDList(itBuffers);
00124 std::vector<std::string> consumerList = dataBufferConfiguration->getConsumerIDList(itBuffers);
00125 for(const auto& itProducers: producerList)
00126 {
00127 if(dataBufferConfiguration->getProducerClass(itBuffers,itProducers) == "UDPDataListenerProducer")
00128 {
00129 const UDPDataListenerProducerConfiguration* listerConfiguration = static_cast<const UDPDataListenerProducerConfiguration*>(theConfigurationManager_->getConfigurationByName("UDPDataListenerProducerConfiguration"));
00130 if(listerConfiguration->getIPAddress(itProducers) == streamToIP && listerConfiguration->getPort(itProducers) == streamToPort)
00131 {
00132 for(const auto& itConsumers: consumerList)
00133 {
00134 std::cout << __COUT_HDR_FL__ << "CONSUMER LIST: " << itConsumers << std::endl;
00135 if(dataBufferConfiguration->getConsumerClass(itBuffers,itConsumers) == "UDPDataStreamerConsumer")
00136 {
00137
00138 std::string ipAddress = NetworkConverters::nameToStringIP(dataStreamerConsumerConfiguration->getIPAddress(itConsumers));
00139
00140 std::string port = NetworkConverters::unsignedToStringPort(dataStreamerConsumerConfiguration->getPort(itConsumers));
00141 planeOccupancies_[ipAddress][port] = std::map<unsigned int, TH1*>();
00142 std::cout << __COUT_HDR_FL__ << "IP: " << NetworkConverters::stringToNameIP(ipAddress) << " Port:----" << NetworkConverters::stringToUnsignedPort(port) << "----" << std::endl;
00143 const std::vector<std::string> rocList = detectorToFEConfiguration->getFEReaderDetectorList(itInterfaces);
00144 std::cout << __COUT_HDR_FL__ << "List of rocs for FER: " << itInterfaces << " has size: " << rocList.size() << std::endl;
00145 for(const auto& itROC: rocList)
00146 {
00147 std::string ROCType = detectorConfiguration->getDetectorType(itROC);
00148
00149 if(ROCType == "FSSR")
00150 {
00151 unsigned int fedChannel = detectorToFEConfiguration->getFEReaderChannel(itROC);
00152 if(planeOccupancies_[ipAddress][port].find(fedChannel) == planeOccupancies_[ipAddress][port].end())
00153 {
00154 name.str("");
00155 title.str("");
00156 name << "Plane_FE" << itInterfaces << "_Channel"<< fedChannel << "_Occupancy";
00157 title << "Plane FE" << itInterfaces << " Channel"<< fedChannel << " Occupancy";
00158 std::cout << __COUT_HDR_FL__ << "Adding:" << name.str() << std::endl;
00159 planeOccupancies_[ipAddress][port][fedChannel] = new TH1F(name.str().c_str(), title.str().c_str(), 640, -0.5, 639.5);
00160 }
00161 }
00162 }
00163 }
00164 }
00165 }
00166 }
00167 }
00168 }
00169 }
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229 std::cout << __COUT_HDR_FL__ << "Booking done!" << std::endl;
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259 }
00260
00261
00262 void DQMHistosOuterTracker::fill(std::string& buffer, std::map<std::string, std::string> header)
00263 {
00264
00265
00266
00267
00268
00269
00270 std::string ipAddress = header["IPAddress"];
00271 std::string port = header["Port"];
00272
00273
00274
00275 if (NetworkConverters::stringToUnsignedPort(port) == 48003)
00276 theDataDecoder_.convertBuffer(buffer, convertedBuffer_, false);
00277 else
00278 theDataDecoder_.convertBuffer(buffer, convertedBuffer_, true);
00279
00280 unsigned int bufferCounter = 0;
00281 uint32_t oldData = 0;
00282 while (!convertedBuffer_.empty())
00283 {
00284
00285
00286
00287
00288 if (NetworkConverters::stringToUnsignedPort(port) == 48003 && bufferCounter%2 == 1)
00289 {
00290 convertedBuffer_.pop();
00291 bufferCounter++;
00292 continue;
00293 }
00294
00295
00296 if (theDataDecoder_.isFSSRData(convertedBuffer_.front()))
00297 {
00298
00299
00300
00301 oldData = convertedBuffer_.front();
00302 FSSRData* detectorDataFSSR = 0;
00303 theDataDecoder_.decodeData(convertedBuffer_.front(), (DetectorDataBase**)&detectorDataFSSR);
00304
00305
00306
00307
00308
00309
00310 if( planeOccupancies_.find(ipAddress) != planeOccupancies_.end()
00311 && planeOccupancies_[ipAddress].find(port) != planeOccupancies_[ipAddress].end()
00312 && planeOccupancies_[ipAddress][port].find(detectorDataFSSR->getChannelNumber()) != planeOccupancies_[ipAddress][port].end())
00313 planeOccupancies_[ipAddress][port][detectorDataFSSR->getChannelNumber()]->Fill(detectorDataFSSR->getSensorStrip());
00314 else
00315 std::cout << __COUT_HDR_FL__
00316 << "ERROR: I haven't book histos for streamer " << NetworkConverters::stringToNameIP(ipAddress)
00317 << " port number: " << NetworkConverters::stringToUnsignedPort(port)
00318 << " channel: " << detectorDataFSSR->getChannelNumber()
00319 << " data: " << std::hex << convertedBuffer_.front() << std::dec
00320 << std::endl;
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336 }
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388 convertedBuffer_.pop();
00389 bufferCounter++;
00390 }
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404 }
00405
00406
00407 void DQMHistosOuterTracker::save(void)
00408 {
00409 std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << "Saving file!" << std::endl;
00410 if (theFile_ != 0)
00411 theFile_->Write();
00412 }
00413
00414
00415 void DQMHistosOuterTracker::load(std::string fileName)
00416 {
00417 closeFile();
00418 theFile_ = TFile::Open(fileName.c_str());
00419 if (!theFile_->IsOpen())
00420 return;
00421 theFile_->cd();
00422 numberOfTriggers_ = (TH1I*)theFile_->Get("General/NumberOfTriggers");
00423
00424 std::string directory = "Planes";
00425 std::stringstream name;
00426 for(unsigned int p=0; p<4; p++)
00427 {
00428 name.str("");
00429 name << directory << "/Plane_" << p << "_Occupancy";
00430
00431
00432 }
00433
00434
00435
00436
00437 closeFile();
00438 }
00439
00440
00441 void DQMHistosOuterTracker::closeFile(void)
00442 {
00443 if (theFile_ != 0)
00444 {
00445 theFile_->Close();
00446 theFile_ = 0;
00447 }
00448 }
00449
00450
00451 TObject* DQMHistosOuterTracker::get(std::string name)
00452 {
00453 if (theFile_ != 0)
00454 return theFile_->Get(name.c_str());
00455 return 0;
00456 }