File indexing completed on 2025-12-17 09:24:06
0001 #include <QA.C>
0002
0003 #include <ffarawmodules/InttCheck.h>
0004 #include <ffarawmodules/StreamingCheck.h>
0005 #include <ffarawmodules/TpcCheck.h>
0006
0007 #include <ffamodules/FlagHandler.h>
0008 #include <ffamodules/HeadReco.h>
0009 #include <ffamodules/SyncReco.h>
0010
0011 #include <fun4all/Fun4AllDstOutputManager.h>
0012 #include <fun4all/Fun4AllInputManager.h>
0013 #include <fun4all/Fun4AllOutputManager.h>
0014 #include <fun4all/Fun4AllServer.h>
0015 #include <fun4all/Fun4AllUtils.h>
0016
0017 #include <fun4allraw/Fun4AllStreamingInputManager.h>
0018 #include <fun4allraw/InputManagerType.h>
0019 #include <fun4allraw/SingleGl1PoolInput.h>
0020 #include <fun4allraw/SingleInttPoolInput.h>
0021 #include <fun4allraw/SingleMicromegasPoolInput.h>
0022 #include <fun4allraw/SingleMvtxPoolInput.h>
0023 #include <fun4allraw/SingleTpcPoolInput.h>
0024
0025 #include <phool/recoConsts.h>
0026
0027 #include <TSystem.h>
0028
0029 #include <format>
0030 #include <fstream>
0031
0032 R__LOAD_LIBRARY(libfun4all.so)
0033 R__LOAD_LIBRARY(libffamodules.so)
0034 R__LOAD_LIBRARY(libfun4allraw.so)
0035 R__LOAD_LIBRARY(libffarawmodules.so)
0036 R__LOAD_LIBRARY(libintt.so)
0037
0038 bool isGood(const std::string &infile);
0039 int getrunnumber(const std::string &listfile);
0040
0041 void Fun4All_SingleStream_Combiner(int nEvents = 0,
0042 const int = 30117,
0043 const std::string & = "/sphenix/lustre01/sphnxpro/commissioning/slurp/tpccosmics/",
0044 const std::string &type = "streaming",
0045 const std::string &input_gl1file = "gl1daq.list",
0046 const std::string &input_tpcfile00 = "tpc00.list",
0047 const std::string &input_inttfile00 = "intt0.list",
0048 const std::string &input_mvtxfile00 = "mvtx0.list",
0049 const std::string &input_tpotfile = "tpot.list")
0050 {
0051
0052 std::vector<std::string> gl1_infile;
0053 gl1_infile.push_back(input_gl1file);
0054
0055
0056 std::vector<std::string> mvtx_infile;
0057 mvtx_infile.push_back(input_mvtxfile00);
0058
0059
0060 std::vector<std::string> intt_infile;
0061 intt_infile.push_back(input_inttfile00);
0062
0063 std::vector<std::string> tpc_infile;
0064 tpc_infile.push_back(input_tpcfile00);
0065
0066
0067 std::vector<std::string> tpot_infile;
0068 tpot_infile.push_back(input_tpotfile);
0069
0070 int runnumber = -99999;
0071 if (!gl1_infile.empty())
0072 {
0073 runnumber = getrunnumber(gl1_infile[0]);
0074 }
0075 else if (!mvtx_infile.empty())
0076 {
0077 runnumber = getrunnumber(mvtx_infile[0]);
0078 }
0079 else if (!intt_infile.empty())
0080 {
0081 runnumber = getrunnumber(intt_infile[0]);
0082 }
0083 else if (!tpc_infile.empty())
0084 {
0085 runnumber = getrunnumber(tpc_infile[0]);
0086 }
0087 else if (!tpot_infile.empty())
0088 {
0089 runnumber = getrunnumber(tpot_infile[0]);
0090 }
0091 if (runnumber == -99999)
0092 {
0093 std::cout << "could not extract run number from input files (all lists empty?)"
0094 << std::endl;
0095 gSystem->Exit(1);
0096 }
0097
0098 Fun4AllServer *se = Fun4AllServer::instance();
0099 se->Verbosity(1);
0100 recoConsts *rc = recoConsts::instance();
0101 rc->set_StringFlag("CDB_GLOBALTAG", "newcdbtag");
0102 Fun4AllStreamingInputManager *in = new Fun4AllStreamingInputManager("Comb");
0103
0104
0105
0106 int i = 0;
0107
0108 std::string readoutNumber;
0109
0110 for (const auto& iter : gl1_infile)
0111 {
0112 if (isGood(iter))
0113 {
0114 SingleGl1PoolInput *gl1_sngl = new SingleGl1PoolInput("GL1_" + std::to_string(i));
0115
0116 gl1_sngl->AddListFile(iter);
0117 in->registerStreamingInput(gl1_sngl, InputManagerType::GL1);
0118 i++;
0119 }
0120 }
0121 i = 0;
0122
0123 for (const auto& iter : intt_infile)
0124 {
0125 if (isGood(iter))
0126 {
0127 SingleInttPoolInput *intt_sngl = new SingleInttPoolInput("INTT_" + std::to_string(i));
0128
0129 auto pos = iter.find("intt");
0130 std::string num = iter.substr(pos + 4, 1);
0131 readoutNumber = "INTT" + num;
0132 intt_sngl->setHitContainerName("INTTRAWHIT_" + num);
0133
0134 intt_sngl->AddListFile(iter);
0135 in->registerStreamingInput(intt_sngl, InputManagerType::INTT);
0136 i++;
0137 }
0138 }
0139 i = 0;
0140 for (const auto& iter : mvtx_infile)
0141 {
0142 if (isGood(iter))
0143 {
0144
0145 std::string filepath;
0146 std::string felix;
0147 std::ifstream ifs(iter);
0148 while (std::getline(ifs, filepath))
0149 {
0150 auto pos = filepath.find("mvtx");
0151 felix = filepath.substr(pos + 4, 1);
0152 break;
0153 }
0154 readoutNumber = "MVTX" + felix;
0155 SingleMvtxPoolInput *mvtx_sngl = new SingleMvtxPoolInput("MVTX_" + std::to_string(i));
0156
0157
0158 mvtx_sngl->setHitContainerName("MVTXRAWHIT_" + felix);
0159 mvtx_sngl->setRawEventHeaderName("MVTXRAWEVTHEADER_" + felix);
0160 mvtx_sngl->AddListFile(iter);
0161 in->registerStreamingInput(mvtx_sngl, InputManagerType::MVTX);
0162 i++;
0163 }
0164 }
0165 i = 0;
0166 for (const auto& iter : tpc_infile)
0167 {
0168 if (isGood(iter))
0169 {
0170
0171 std::string filepath;
0172 std::string ebdc;
0173 std::ifstream ifs(iter);
0174 while (std::getline(ifs, filepath))
0175 {
0176 auto pos = filepath.find("ebdc");
0177 ebdc = filepath.substr(pos + 4, 2);
0178 break;
0179 }
0180
0181 SingleTpcPoolInput *tpc_sngl = new SingleTpcPoolInput("TPC_" + std::to_string(i));
0182
0183
0184 readoutNumber = "TPC" + ebdc;
0185 tpc_sngl->SetBcoRange(5);
0186 tpc_sngl->setHitContainerName("TPCRAWHIT_" + ebdc);
0187 tpc_sngl->AddListFile(iter);
0188 in->registerStreamingInput(tpc_sngl, InputManagerType::TPC);
0189 i++;
0190 }
0191 }
0192 i = 0;
0193
0194 for (const auto& iter : tpot_infile)
0195 {
0196 if (isGood(iter))
0197 {
0198 SingleMicromegasPoolInput *mm_sngl = new SingleMicromegasPoolInput("MICROMEGAS_" + std::to_string(i));
0199
0200 mm_sngl->SetBcoRange(10);
0201 mm_sngl->SetNegativeBco(2);
0202 mm_sngl->SetBcoRange(10);
0203 mm_sngl->SetBcoPoolSize(50);
0204 mm_sngl->AddListFile(iter);
0205 in->registerStreamingInput(mm_sngl, InputManagerType::MICROMEGAS);
0206 readoutNumber = "TPOT";
0207 i++;
0208 }
0209 }
0210
0211 se->registerInputManager(in);
0212
0213
0214
0215
0216
0217
0218
0219 SyncReco *sync = new SyncReco();
0220 se->registerSubsystem(sync);
0221
0222 HeadReco *head = new HeadReco();
0223 se->registerSubsystem(head);
0224
0225 FlagHandler *flag = new FlagHandler();
0226 se->registerSubsystem(flag);
0227
0228 std::string outfile = "./" + type + "-" + readoutNumber;
0229
0230 Fun4AllOutputManager *out = new Fun4AllDstOutputManager("out", outfile);
0231 se->registerOutputManager(out);
0232
0233 if (nEvents < 0)
0234 {
0235 return;
0236 }
0237 se->run(nEvents);
0238
0239 se->End();
0240
0241 std::string histoutfile = std::format("./HIST_{}-{}-{:08}-{:05}",type,readoutNumber, runnumber, 0) ;
0242 QAHistManagerDef::saveQARootFile(histoutfile);
0243
0244 delete se;
0245 std::cout << "all done" << std::endl;
0246 gSystem->Exit(0);
0247 }
0248
0249 bool isGood(const std::string &infile)
0250 {
0251 std::ifstream intest;
0252 intest.open(infile);
0253 bool goodfile = false;
0254 if (intest.is_open())
0255 {
0256 if (intest.peek() != std::ifstream::traits_type::eof())
0257 {
0258 goodfile = true;
0259 }
0260 intest.close();
0261 }
0262 return goodfile;
0263 }
0264
0265 int getrunnumber(const std::string &listfile)
0266 {
0267 if (!isGood(listfile))
0268 {
0269 std::cout << "listfile " << listfile << " is bad" << std::endl;
0270 gSystem->Exit(1);
0271 }
0272 std::ifstream ifs(listfile);
0273 std::string filepath;
0274 std::getline(ifs, filepath);
0275
0276 std::pair<int, int> runseg = Fun4AllUtils::GetRunSegment(filepath);
0277 int runnumber = runseg.first;
0278
0279 return runnumber;
0280 }