31 if(fOutputFilename.empty()) {
32 fOutputFilename =
"temp.root";
43 if(fOutputFilename !=
"/dev/null") {
46 fOutputFile =
new TFile(fOutputFilename.c_str(),
"RECREATE");
48 throw std::runtime_error(Form(
"Failed to open \"%s\"\n", fOutputFilename.c_str()));
64 std::shared_ptr<const TFragment> event;
71 std::ostringstream str;
79 std::shared_ptr<const TFragment> event;
85 if(event !=
nullptr) {
94 std::this_thread::sleep_for(std::chrono::milliseconds(100));
110 std::cerr <<
Name() <<
": got a final run length of " <<
TRunInfo::RunLength() <<
" s, instead of the assumed run length of " <<
fRunLength <<
" s, some diagnostics information will be missing!" << std::endl;
125 gValues->Write(
"Values", TObject::kOverwrite);
137 parsingDiagnostics->
ReadPPG(ppg);
138 parsingDiagnostics->Write(
"ParsingDiagnostics", TObject::kOverwrite);
149 std::cout <<
Name() <<
": creating histograms using output file " <<
fOutputFile << std::endl;
161 if(nofTimeBins < 1000) {
164 }
else if(nofTimeBins > 10000) {
167 std::cout <<
"Warning, run is more than 10000 s long (run length " <<
TRunInfo::RunLength() <<
" s), reducing binning to 10 s (number of bins " << nofTimeBins <<
")!" << std::endl;
170 std::cout <<
Name() <<
": creating histograms with " << nofTimeBins <<
" time bins from 0 to " <<
fRunLength << std::endl;
172 fAccepted =
new TH2D(
"accepted",
"Accepted Channel ID vs. Channel Address;Channel Address;Accepted Channel ID",
174 fLostNetworkPackets =
new TH1D(
"lostNetworkPackets",
"lost network packets;time [s];lost network packets",
176 fLostChannelIds =
new TH2D(
"lostChannelIds",
"Lost Channel Id vs. Channel Number;Channel Number;Lost Channel Id",
178 fLostAcceptedIds =
new TH2D(
"lostAcceptedIds",
"Lost Accepted Channel Id vs. Channel Number;Channel Number;Lost Accepted Channel Id",
180 fLostChannelIdsTime =
new TH2D(
"lostChannelIdsTime",
"Lost Channel Id time vs. Channel Number;Channel Number;time [s]",
182 fLostAcceptedIdsTime =
new TH2D(
"lostAcceptedIdsTime",
"Lost Accepted Channel Id time vs. Channel Number;Channel Number;time [s]",
187 fAccepted->GetXaxis()->SetBinLabel(bin, Form(
"0x%04x", channel.first));
188 fLostChannelIds->GetXaxis()->SetBinLabel(bin, Form(
"0x%04x", channel.first));
189 fLostAcceptedIds->GetXaxis()->SetBinLabel(bin, Form(
"0x%04x", channel.first));
203 throw std::runtime_error(
Name() +
": trying to create histograms failed, can't produce diagnostics!");
206 auto timeStamp =
event->GetTimeStampNs();
207 auto address =
event->GetAddress();
208 auto acceptedId =
event->GetAcceptedChannelId();
209 auto channelId =
event->GetChannelId();
210 auto networkPacket =
event->GetNetworkPacketNumber();
268 }
else if(networkPacket != 0) {
298 fAccepted->Fill(Form(
"0x%04x", address),
static_cast<double>(acceptedId), 1.);
static GValue * Get(const std::string &name="")
std::atomic_size_t & ItemsPopped()
std::atomic_long & InputSize()
static StoppableThread * Get(const std::string &name)
void IncrementItemsPopped()
static int WriteToRoot(TFile *fileptr=nullptr)
static std::unordered_map< unsigned int, TChannel * > * GetChannelMap()
static size_t GetNumberOfChannels()
TH2D * fLostAcceptedIdsTime
void Process(const std::shared_ptr< const TFragment > &event)
TFragDiagnosticsLoop(const TFragDiagnosticsLoop &)=delete
std::map< unsigned int, std::array< int64_t, 2 > > fTimeStamps
bool Iteration() override
unsigned int fRollingThreshold
std::map< unsigned int, std::array< int64_t, 2 > > fChannelIds
std::array< int64_t, 2 > fNetworkPacketTimeStamp
void ClearQueue() override
static TFragDiagnosticsLoop * Get(std::string name="", std::string fOutputFilename="")
std::map< unsigned int, std::array< int64_t, 2 > > fAcceptedChannelIds
std::map< unsigned int, int > fNofRollovers
TH2D * fLostChannelIdsTime
std::map< unsigned int, bool > fRolling
std::array< int, 2 > fNetworkPacketNumber
std::string EndStatus() override
std::shared_ptr< ThreadsafeQueue< std::shared_ptr< const TFragment > > > fInputQueue
std::map< unsigned int, int > fRollnum
TH1D * fLostNetworkPackets
bool WriteDiagnostics() const
static TGRSIOptions * Get(int argc=0, char **argv=nullptr)
Do not use!
static bool WriteToFile(TFile *file=nullptr)
Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0) override
static bool WriteToRoot(TFile *fileptr=nullptr)
static double RunLength()
static TPPG * Get(bool verbose=false)