9 #include "art/Framework/Core/EDProducer.h"
10 #include "art/Framework/Services/Registry/ServiceHandle.h"
11 #include "art/Persistency/Common/PtrMaker.h"
12 #include "art/Utilities/ToolMacros.h"
13 #include "art/Utilities/make_tool.h"
14 #include "cetlib/cpu_timer.h"
15 #include "fhiclcpp/ParameterSet.h"
16 #include "messagefacility/MessageLogger/MessageLogger.h"
86 int GetDataset(
const std::string&,
int func(
void*,
int,
char**,
char**),
void*)
const;
98 fTag = pset.get<std::string>(
"Tag");
111 int callback(
void *data,
int argc,
char **argv,
char **azColName)
115 for(i = 0; i<argc; i++){
116 std::cout <<
"column: " << azColName[i] <<
"- value: " << (argv[i] ? argv[i] :
"NULL") <<
" ";
133 std::string fullFileName;
134 cet::search_path searchPath(
"FW_SEARCH_PATH");
136 if (!searchPath.find_file(
fDBFileName, fullFileName))
137 throw cet::exception(
"ChannelMapSQLite::GetDataset") <<
"Can't find input file: '" <<
fDBFileName <<
"'\n";
142 int rc = sqlite3_open(fullFileName.c_str(), &database);
145 throw cet::exception(
"ChannelMapSQLite::GetDataset") <<
"Can't open the database, return code:" << sqlite3_errmsg(database) <<
"'\n";
148 std::string select =
"SELECT * FROM " + table;
152 rc = sqlite3_exec(database, select.c_str(), func, data, &zErrMsg);
154 if( rc != SQLITE_OK )
156 std::cout <<
"ChannelMapSQLite::GetDataset: SQL error: " << zErrMsg << std::endl;
157 sqlite3_free(zErrMsg);
161 std::cout <<
"ChannelMapSQLite::GetDataset: Successfully read database" << std::endl;
164 sqlite3_close(database);
176 const unsigned int tpcIdentifier(0x00001000);
182 using FlangeIDToCrateMap = std::map<size_t,std::string>;
183 FlangeIDToCrateMap flangeIDToCrateMap;
184 flangeIDToCrateMap[19] =
"WW01T";
185 flangeIDToCrateMap[68] =
"WW01M";
186 flangeIDToCrateMap[41] =
"WW01B";
187 flangeIDToCrateMap[11] =
"WW02";
188 flangeIDToCrateMap[17] =
"WW03";
189 flangeIDToCrateMap[36] =
"WW04";
190 flangeIDToCrateMap[18] =
"WW05";
191 flangeIDToCrateMap[58] =
"WW06";
192 flangeIDToCrateMap[71] =
"WW07";
193 flangeIDToCrateMap[14] =
"WW08";
194 flangeIDToCrateMap[25] =
"WW09";
195 flangeIDToCrateMap[34] =
"WW10";
196 flangeIDToCrateMap[67] =
"WW11";
197 flangeIDToCrateMap[33] =
"WW12";
198 flangeIDToCrateMap[87] =
"WW13";
199 flangeIDToCrateMap[10] =
"WW14";
200 flangeIDToCrateMap[59] =
"WW15";
201 flangeIDToCrateMap[95] =
"WW16";
202 flangeIDToCrateMap[22] =
"WW17";
203 flangeIDToCrateMap[91] =
"WW18";
204 flangeIDToCrateMap[61] =
"WW19";
205 flangeIDToCrateMap[55] =
"WW20T";
206 flangeIDToCrateMap[97] =
"WW20M";
207 flangeIDToCrateMap[100] =
"WW20B";
208 flangeIDToCrateMap[83] =
"WE01T";
209 flangeIDToCrateMap[85] =
"WE01M";
210 flangeIDToCrateMap[7] =
"WE01B";
211 flangeIDToCrateMap[80] =
"WE02";
212 flangeIDToCrateMap[52] =
"WE03";
213 flangeIDToCrateMap[32] =
"WE04";
214 flangeIDToCrateMap[70] =
"WE05";
215 flangeIDToCrateMap[74] =
"WE06";
216 flangeIDToCrateMap[46] =
"WE07";
217 flangeIDToCrateMap[81] =
"WE08";
218 flangeIDToCrateMap[63] =
"WE09";
219 flangeIDToCrateMap[30] =
"WE10";
220 flangeIDToCrateMap[51] =
"WE11";
221 flangeIDToCrateMap[90] =
"WE12";
222 flangeIDToCrateMap[23] =
"WE13";
223 flangeIDToCrateMap[93] =
"WE14";
224 flangeIDToCrateMap[92] =
"WE15";
225 flangeIDToCrateMap[88] =
"WE16";
226 flangeIDToCrateMap[73] =
"WE17";
227 flangeIDToCrateMap[1] =
"WE18";
228 flangeIDToCrateMap[66] =
"WE19";
229 flangeIDToCrateMap[48] =
"WE20T";
230 flangeIDToCrateMap[13] =
"WE20M";
231 flangeIDToCrateMap[56] =
"WE20B";
232 flangeIDToCrateMap[94] =
"EW01T";
233 flangeIDToCrateMap[77] =
"EW01M";
234 flangeIDToCrateMap[72] =
"EW01B";
235 flangeIDToCrateMap[65] =
"EW02";
236 flangeIDToCrateMap[4] =
"EW03";
237 flangeIDToCrateMap[89] =
"EW04";
238 flangeIDToCrateMap[37] =
"EW05";
239 flangeIDToCrateMap[76] =
"EW06";
240 flangeIDToCrateMap[49] =
"EW07";
241 flangeIDToCrateMap[60] =
"EW08";
242 flangeIDToCrateMap[21] =
"EW09";
243 flangeIDToCrateMap[6] =
"EW10";
244 flangeIDToCrateMap[62] =
"EW11";
245 flangeIDToCrateMap[2] =
"EW12";
246 flangeIDToCrateMap[29] =
"EW13";
247 flangeIDToCrateMap[44] =
"EW14";
248 flangeIDToCrateMap[9] =
"EW15";
249 flangeIDToCrateMap[31] =
"EW16";
250 flangeIDToCrateMap[98] =
"EW17";
251 flangeIDToCrateMap[38] =
"EW18";
252 flangeIDToCrateMap[99] =
"EW19";
253 flangeIDToCrateMap[53] =
"EW20T";
254 flangeIDToCrateMap[82] =
"EW20M";
255 flangeIDToCrateMap[35] =
"EW20B";
256 flangeIDToCrateMap[96] =
"EE01T";
257 flangeIDToCrateMap[28] =
"EE01M";
258 flangeIDToCrateMap[16] =
"EE01T";
259 flangeIDToCrateMap[69] =
"EE02";
260 flangeIDToCrateMap[20] =
"EE02";
261 flangeIDToCrateMap[79] =
"EE02";
262 flangeIDToCrateMap[50] =
"EE02";
263 flangeIDToCrateMap[45] =
"EE02";
264 flangeIDToCrateMap[84] =
"EE02";
265 flangeIDToCrateMap[42] =
"EE02";
266 flangeIDToCrateMap[39] =
"EE02";
267 flangeIDToCrateMap[26] =
"EE02";
268 flangeIDToCrateMap[64] =
"EE02";
269 flangeIDToCrateMap[43] =
"EE02";
270 flangeIDToCrateMap[47] =
"EE02";
271 flangeIDToCrateMap[15] =
"EE02";
272 flangeIDToCrateMap[3] =
"EE02";
273 flangeIDToCrateMap[27] =
"EE02";
274 flangeIDToCrateMap[24] =
"EE02";
275 flangeIDToCrateMap[40] =
"EE02";
276 flangeIDToCrateMap[75] =
"EE02";
277 flangeIDToCrateMap[86] =
"EE20T";
278 flangeIDToCrateMap[54] =
"EE20M";
279 flangeIDToCrateMap[8] =
"EE20B";
281 unsigned int fragmentID = std::stol(argv[8],
nullptr,16);
283 if (fragmentID & tpcIdentifier)
285 if (fragmentBoardMap.find(fragmentID) == fragmentBoardMap.end())
287 unsigned int flangeID = std::stol(argv[1]);
288 fragmentBoardMap[fragmentID].first = flangeIDToCrateMap[flangeID];
291 unsigned int readoutID = std::stol(argv[0]);
292 fragmentBoardMap[fragmentID].second.emplace_back(readoutID);
306 const std::string dataType(
"readout_boards");
313 throw cet::exception(
"ChannelMapSQLite::BuildTPCFragmentIDToReadoutIDMap") <<
"Encountered error in reading the database: '" << error <<
"'\n";
330 unsigned int readoutBoardID = std::stol(argv[2]);
332 if (rbChanMap.find(readoutBoardID) == rbChanMap.end())
334 unsigned int readoutBoardSlot = std::stol(argv[4]);
336 rbChanMap[readoutBoardID].first = readoutBoardSlot;
340 unsigned int channelNum = std::stol(argv[5]);
341 unsigned int channelID = std::stol(argv[0]);
343 std::string fragmentBuffer = argv[10];
346 std::transform(fragmentBuffer.begin(),fragmentBuffer.end(),fragmentBuffer.begin(),[](
char c){
return std::tolower(c);});
348 unsigned int plane(3);
350 if (fragmentBuffer.find(
"collection") != std::string::npos) plane = 2;
351 else if (fragmentBuffer.find(
"induction 2") != std::string::npos) plane = 1;
352 else if (fragmentBuffer.find(
"induction 1") != std::string::npos) plane = 0;
354 if (plane > 2)
std::cout <<
"YIKES!!! Plane is " << plane <<
" for channel " << channelID <<
" with type " << std::string(fragmentBuffer) << std::endl;
363 const std::string dataType(
"daq_channels");
370 throw cet::exception(
"ChannelMapSQLite::BuildTPCReadoutBoardToChannelMap") <<
"Encountered error in reading the database: '" << error <<
"'\n";
382 unsigned int fragmentID = std::stol(argv[18]);
383 unsigned int digitizerChannelNo = std::stol(argv[9]);
384 unsigned int channelID = std::stol(argv[17]);
387 fragmentToDigitizerChannelMap[fragmentID].emplace_back(digitizerChannelNo,channelID);
395 fragmentToDigitizerChannelMap.clear();
397 const std::string dataType(
"pmt_placements");
404 throw cet::exception(
"ChannelMapSQLite::BuildFragmentToDigitizerChannelMap") <<
"Encountered error in reading the database: '" << error <<
"'\n";
423 unsigned int channelID = strcmp(argv[10],
"None")==0 ? 0 : std::stol(argv[10]);
424 unsigned int simmacaddress = strcmp(argv[11],
"None")==0 ? 0 : std::stol(argv[11]);
425 unsigned int hwmacaddress = strcmp(argv[12],
"None")==0 ? 0 : std::stol(argv[12]);
428 crtChannelIDToHWtoSimMacAddressPairMap[channelID]=std::make_pair(hwmacaddress, simmacaddress);
436 crtChannelIDToHWtoSimMacAddressPairMap.clear();
438 const std::string dataType(
"feb_channels");
445 throw cet::exception(
"ChannelMapSQLite::BuildCRTChannelIDToHWtoSimMacAddressPairMap") <<
"Encountered error in reading the database: '" << error <<
"'\n";
457 unsigned int simmacaddress = strcmp(argv[41],
"None")==0 ? 0 : std::stol(argv[41]);
458 unsigned int hwmacaddress = strcmp(argv[3],
"None")==0 ? 0 : std::stol(argv[3]);
461 topcrtHWtoSimMacAddressPairMap[hwmacaddress] = simmacaddress;
469 topcrtHWtoSimMacAddressPairMap.clear();
471 const std::string dataType(
"crtfeb");
478 throw cet::exception(
"ChannelMapSQLite::BuildTopCRTHWtoSimMacAddressPairMap") <<
"Encountered error in reading the database: '" << error <<
"'\n";
489 sideCRTChannelToCalibrationMap.clear();
491 std::string fullFileName;
492 cet::search_path searchPath(
"FW_SEARCH_PATH");
497 throw cet::exception(
"ChannelMapSQLite::GetDataset") <<
"Can't find calibration input file: '" <<
fCalibDBFileName <<
"'\n";
504 std::vector<unsigned int> channels;
507 for (
auto it = channels.begin(); it != channels.end(); ++it) {
519 sideCRTChannelToCalibrationMap.insert(std::make_pair(std::make_pair((
int)mac5,(
int)chan), std::make_pair(gain,ped)));
int GetNamedChannelData(DBChannelID_t channel, const std::string &name, bool &data)
int callback(void *data, int argc, char **argv, char **azColName)
int buildTPCReadoutBoardToChannelMap_callback(void *dataIn, int argc, char **argv, char **azColName)
int buildCRTChannelIDToHWtoSimMacAddressPairMap_callback(void *dataIn, int argc, char **argv, char **azColName)
bool UpdateData(DBTimeStamp_t raw_time)
This provides an art tool interface definition for tools handle the channel mapping The idea is to be...
std::pair< unsigned int, unsigned int > ChannelPlanePair
Define the returned data structures for a mapping between TPC readout boards and the channel informat...
virtual int BuildTopCRTHWtoSimMacAddressPairMap(TopCRTHWtoSimMacAddressPairMap &) const override
int GetChannelList(std::vector< DBChannelID_t > &channels) const
virtual int BuildCRTChannelIDToHWtoSimMacAddressPairMap(CRTChannelIDToHWtoSimMacAddressPairMap &) const override
Define the returned data structures for a mapping between CRT hardware mac_address to the simulated m...
int GetDataset(const std::string &, int func(void *, int, char **, char **), void *) const
std::map< unsigned int, CRTHWtoSimMacAddressPair > CRTChannelIDToHWtoSimMacAddressPairMap
int buildTopCRTHWtoSimMacAddressPairMap_callback(void *dataIn, int argc, char **argv, char **azColName)
virtual int BuildTPCFragmentIDToReadoutIDMap(TPCFragmentIDToReadoutIDMap &) const override
Define the returned data structures for a mapping between TPC Fragment IDs and the related crate and ...
std::map< unsigned int, SlotChannelVecPair > TPCReadoutBoardToChannelMap
std::string fCalibDBFileName
~ChannelMapSQLite()
Destructor.
virtual int BuildSideCRTCalibrationMap(SideCRTChannelToCalibrationMap &) const override
ChannelMapSQLite(fhicl::ParameterSet const &pset)
Constructor.
std::map< SideCRTMac5ToChannelPair, SideCRTGainToPedPair > SideCRTChannelToCalibrationMap
const unsigned int CHANNELSPERBOARD
virtual int BuildTPCReadoutBoardToChannelMap(TPCReadoutBoardToChannelMap &) const override
Define the returned data structures for a mapping between TPC readout boards and the channel informat...
std::map< unsigned int, CrateNameReadoutIDPair > TPCFragmentIDToReadoutIDMap
ChannelMapSQLite class definiton.
int buildFragmentToDigitizerChannelMap_callback(void *dataIn, int argc, char **argv, char **azColName)
std::map< size_t, DigitizerChannelChannelIDPairVec > FragmentToDigitizerChannelMap
virtual int BuildFragmentToDigitizerChannelMap(FragmentToDigitizerChannelMap &) const override
Define the returned data structures for a mapping between PMT Fragment IDs and the related crate and ...
IChannelMapping interface class definiton.
int buildTPCFragmentIDToReadoutIDMap_callback(void *dataIn, int argc, char **argv, char **azColName)
BEGIN_PROLOG could also be cout
std::map< unsigned int, unsigned int > TopCRTHWtoSimMacAddressPairMap