95 cout <<
"Merging to " <<
fileName << endl;
97 unsigned int size = 0;
100 int evtIndex = 0, runIndex = 0;
101 std::map<std::pair<int, int>,
int> evtMap;
102 std::map<int, int> runMap;
104 cout <<
"Merging runs" << endl;
105 for (
const Accessor* accessor : accessors) {
107 cout <<
"Cannot merge: one of the inputs is null!" << endl;
111 for (
unsigned int i = 0; i < accessor->nRuns(); i++) {
112 int run = accessor->runData(i)->run();
113 if (runMap.find(
run) != runMap.end())
continue;
114 runMap[
run] = runIndex;
122 cout <<
"Merging events" << endl;
123 unsigned int nEventsTotal = 0, iEvt = 0;
124 for (
const Accessor* accessor : accessors)
125 nEventsTotal += accessor->nEvents();
126 for (
const Accessor* accessor : accessors) {
127 for (
unsigned int i = 0; i < accessor->nEvents(); i++) {
129 if (iEvt % 100000 == 0) cout <<
"Merging event " << iEvt <<
"/" << nEventsTotal << endl;
130 std::pair<int, int> evtId(accessor->eventData(i)->run(), accessor->eventData(i)->event());
131 if (evtMap.find(evtId) != evtMap.end())
continue;
132 evtMap[evtId] = evtIndex;
133 std::map<int, int>::const_iterator idx = runMap.find(accessor->eventData(i)->run());
134 int newRunIndex = (idx == runMap.end() ? -999 : idx->second);
143 for (
unsigned int i = 0; i < newAcc->
nChannels(); i++) {
144 if (i % 10000 == 0) {
145 cout <<
"Merging channel " << i <<
"/" << newAcc->
nChannels() <<
" (current size = " << size <<
")" << endl;
149 for (
const Accessor* accessor : accessors) {
150 const History* history = accessor->cellHistory(i);
151 if (!history || !history->
isValid())
continue;
156 for (
unsigned int j = 0; j < history->
nData(); j++) {
159 = evtMap.find(std::make_pair(history->
data(j)->
run(), history->
data(j)->
event()));
160 if (newIndex == evtMap.end()) cout <<
"Event not found for cell " << i <<
", data " << j <<
"." << endl;
161 newDC->
setEventIndex(newIndex != evtMap.end() ? newIndex->second : -1);
163 if (!info->shape(history->
data(j)->
gain())) {
166 cout <<
"Shape not filled for hash = " << i <<
", index = " << j <<
", gain = " <<
Data::gainStr(history->
data(j)->
gain()) << endl;
167 info->setShape(history->
data(j)->
gain(), (shape ?
new ShapeInfo(*shape) :
nullptr));
176 cout <<
"Merging done, final size = " << size << endl;
188 std::vector<unsigned int> LBList;
189 std::ifstream infile(LBFile.Data());
192 std::getline(infile,line,
'\n');
193 TString
filter(line.c_str());
194 TObjArray* list =
filter.Tokenize(
", ");
195 if(list->GetEntries() == 0){
196 printf(
"No LB filtering specified, or bad format. Exiting.\n");
201 for(
int k = 0; k < list->GetEntries(); k++){
202 TObjString* tobs = (TObjString*)(list->At(k));
203 LBList.push_back((
unsigned int)(tobs->String()).Atoi());
206 printf(
"LB List: %d\n",(
int)LBList.size());
211 unsigned int size = 0;
214 int evtIndex = 0, runIndex = 0;
215 std::map<std::pair<int, int>,
int> evtMap;
216 std::map<int, int> runMap;
218 cout <<
"Merging runs" << endl;
219 for (
const Accessor* accessor : accessors) {
221 cout <<
"Cannot merge: one of the inputs is null!" << endl;
225 for (
unsigned int i = 0; i < accessor->nRuns(); i++) {
226 int run = accessor->runData(i)->run();
227 if (runMap.find(
run) != runMap.end())
continue;
228 runMap[
run] = runIndex;
236 cout <<
"Merging events" << endl;
237 unsigned int nEventsTotal = 0, iEvt = 0;
238 for (
const Accessor* accessor : accessors)
239 nEventsTotal += accessor->nEvents();
240 for (
const Accessor* accessor : accessors) {
241 for (
unsigned int i = 0; i < accessor->nEvents(); i++) {
243 if (iEvt % 100000 == 0) cout <<
"Merging event " << iEvt <<
"/" << nEventsTotal << endl;
248 for(
unsigned int ilb = 0 ; ilb < LBList.size() ; ilb++){
249 if(LBList.at(ilb)==accessor->eventData(i)->lumiBlock()){
258 std::pair<int, int> evtId(accessor->eventData(i)->run(), accessor->eventData(i)->event());
259 if (evtMap.find(evtId) != evtMap.end())
continue;
260 evtMap[evtId] = evtIndex;
261 std::map<int, int>::const_iterator idx = runMap.find(accessor->eventData(i)->run());
262 int newRunIndex = (idx == runMap.end() ? -999 : idx->second);
270 cout <<
"Merging cells" << endl;
271 for (
unsigned int i = 0; i < newAcc->
nChannels(); i++) {
272 if (i % 10000 == 0) {
273 cout <<
"Merging channel " << i <<
"/" << newAcc->
nChannels() <<
" (current size = " << size <<
")" << endl;
277 for (
const Accessor* accessor : accessors) {
278 const History* history = accessor->cellHistory(i);
279 if (!history || !history->
isValid())
continue;
284 for (
unsigned int j = 0; j < history->
nData(); j++) {
287 = evtMap.find(std::make_pair(history->
data(j)->
run(), history->
data(j)->
event()));
289 newDC->
setEventIndex(newIndex != evtMap.end() ? newIndex->second : -1);
291 if (!info->shape(history->
data(j)->
gain())) {
294 cout <<
"Shape not filled for hash = " << i <<
", index = " << j <<
", gain = " <<
Data::gainStr(history->
data(j)->
gain()) << endl;
295 info->setShape(history->
data(j)->
gain(), (shape ?
new ShapeInfo(*shape) :
nullptr));
308 cout <<
"Merging SC" << endl;
309 for (
unsigned int i = 0; i < newAcc->
nChannelsSC(); i++) {
310 if (i % 10000 == 0) {
311 cout <<
"Merging channel " << i <<
"/" << newAcc->
nChannelsSC() <<
" (current size = " << size <<
")" << endl;
314 for (
const Accessor* accessor : accessors) {
315 const History* history = accessor->getSCHistory(i);
316 if (!history || !history->
isValid())
continue;
321 for (
unsigned int j = 0; j < history->
nData(); j++) {
324 = evtMap.find(std::make_pair(history->
data(j)->
run(), history->
data(j)->
event()));
326 newDC->
setEventIndex(newIndex != evtMap.end() ? newIndex->second : -1);
328 if (!info->shape(history->
data(j)->
gain())) {
331 cout <<
"Shape not filled for hash = " << i <<
", index = " << j <<
", gain = " <<
Data::gainStr(history->
data(j)->
gain()) << endl;
332 info->setShape(history->
data(j)->
gain(), (shape ?
new ShapeInfo(*shape) :
nullptr));
345 cout <<
"Merging done, final size = " << size << endl;
366 if (filterList.
size() == 0) {
367 cout <<
"No filter categories specified, done! (?)" << endl;
368 return std::vector<TreeAccessor*>();
371 for (
unsigned int f = 0; f < filterList.
size(); f++) {
372 cout <<
"Skimming to " << filterList.
fileName(f) << endl;
373 if (!gSystem->AccessPathName(filterList.
fileName(f))) {
374 cout <<
"File already exists, exiting." << endl;
375 return std::vector<TreeAccessor*>();
379 std::vector<TreeAccessor*> newAccessors;
380 for (
unsigned int f = 0; f < filterList.
size(); f++)
382 std::map<std::pair<unsigned int, unsigned int>,
unsigned int> eventIndices;
383 std::vector< std::map<unsigned int, unsigned int> > eventsToKeep(filterList.
size());
384 std::vector< std::map<unsigned int, unsigned int> > runsToKeep(filterList.
size());
386 double nTot = 0, nPass = 0;
388 for (
unsigned int i = 0; i < accessor.nEvents(); i++) {
390 eventIndices[std::pair<unsigned int, unsigned int>(
eventData->run(),
eventData->event())] = i;
393 for (
unsigned int i = 0; i < accessor.nChannels(); i++) {
394 if (i % 25000 == 0) {
395 cout <<
"Filtering " << i <<
"/" << accessor.nChannels()
396 <<
" (passing so far = " << nPass <<
", total seen = " << nTot <<
")" << endl;
401 const History* history =
nullptr;
402 for (
unsigned int f = 0; f < filterList.
size(); f++) {
406 for (
unsigned int f = 0; f < filterList.
size(); f++) {
409 newAccessors[f]->add(newHist);
413 if (first) { nTot += history->
nData(); first =
false; }
415 for (
unsigned int k = 0; k < history->
nData(); k++) {
418 std::map<std::pair<unsigned int, unsigned int>,
unsigned int>
::const_iterator findIndex =
419 eventIndices.find(std::pair<unsigned int, unsigned int>(
eventData->run(),
eventData->event()));
420 if (findIndex == eventIndices.end()) {
421 cout <<
"Inconsistent event numbering!!!" << endl;
423 return std::vector<TreeAccessor*>();
425 int oldEvtIndex = findIndex->second;
426 bool isNewEvt = (eventsToKeep[f].find(oldEvtIndex) == eventsToKeep[f].end());
427 unsigned int newEvtIndex = (isNewEvt ? eventsToKeep[f].size() : eventsToKeep[f][oldEvtIndex]);
428 if (isNewEvt) eventsToKeep[f][oldEvtIndex] = newEvtIndex;
431 bool isNewRun = (runsToKeep[f].find(oldRunIndex) == runsToKeep[f].end());
432 unsigned int newRunIndex = (isNewRun ? runsToKeep[f].size() : runsToKeep[f][oldRunIndex]);
433 if (isNewRun) runsToKeep[f][oldRunIndex] = newRunIndex;
435 Data* newData = tweaker.
tweak(*history->
data(k), newEvtIndex);
437 cout <<
"Filtering failed on data " << k <<
" of cell " << i <<
", aborting" << endl;
439 for (
unsigned int f = 0; f < filterList.
size(); f++)
delete newAccessors[f];
440 return std::vector<TreeAccessor*>();
445 newAccessors[f]->add(newHist);
450 for (
unsigned int f = 0; f < filterList.
size(); f++) {
451 cout <<
"Adding runs..." << endl;
452 std::vector<unsigned int> runsToKeep_ordered(runsToKeep[f].size());
453 for (
const auto& runIndex : runsToKeep[f])
454 runsToKeep_ordered[runIndex.second] = runIndex.first;
456 for (
unsigned int runIndex : runsToKeep_ordered) {
458 newAccessors[f]->addRun(newRun);
461 cout <<
"Adding events..." << endl;
462 std::vector<unsigned int> eventsToKeep_ordered(eventsToKeep[f].size());
463 for (
const auto& eventIndex : eventsToKeep[f])
464 eventsToKeep_ordered[eventIndex.second] = eventIndex.first;
466 for (
unsigned int eventIndex : eventsToKeep_ordered) {
467 std::map<unsigned int, unsigned int>::const_iterator idx = runsToKeep[f].find(accessor.eventData(eventIndex)->runIndex());
468 int newRunIndex = (idx == runsToKeep[f].end() ? 0 : idx->second);
469 EventData* newEvent = tweaker.
tweak(*accessor.eventData(eventIndex), newRunIndex);
470 newAccessors[f]->addEvent(newEvent);
474 cout <<
"Filtering done! final size = " << nPass << endl;
476 for (
unsigned int f = 0; f < filterList.
size(); f++) {
477 cout <<
"Saving " << newAccessors[f]->fileName() << endl;
478 newAccessors[f]->save();
488 std::vector<short> samples(5, 0);
489 std::vector<float> autoCorrs(4, 0);
492 newAccessor->
addRun(dummyRun);
499 for (
unsigned int i = 0; i < accessor.nChannels(); i++) {
501 cout <<
"Templating " << i <<
"/" << accessor.nChannels() << endl;
502 const History* history = accessor.cellHistory(i);
503 if (!history || !history->
cellInfo()) {
505 newAccessor->
add(newHist);
511 newHist->add(dataContainer);
512 newAccessor->
add(newHist);
const CellInfo * cellInfo() const
unsigned int nDataContainers() const
const CellInfo * cellInfo() const
const Data * data(unsigned int i) const
unsigned int nData() const